Centralize command dispatch over a FreeRTOS queue so UART and future ESP-NOW transports can register handlers; implement the protobuf VERSION command with framed nanopb responses including build git hash. Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
#include "cmd_handler.h"
|
|
#include "cmd_version.h"
|
|
#include "esp_log.h"
|
|
#include "pb_encode.h"
|
|
#include "uart_messages.pb.h"
|
|
#include "uart_proto.h"
|
|
#include <string.h>
|
|
|
|
#ifndef POWERPOD_FW_VERSION
|
|
#define POWERPOD_FW_VERSION 1u
|
|
#endif
|
|
|
|
#ifndef POWERPOD_GIT_HASH
|
|
#define POWERPOD_GIT_HASH "unknown"
|
|
#endif
|
|
|
|
static const char *TAG = "[VERSION]";
|
|
|
|
static bool encode_git_hash(pb_ostream_t *stream, const pb_field_t *field,
|
|
void *const *arg) {
|
|
const char *str = (const char *)*arg;
|
|
if (str == NULL) {
|
|
str = "";
|
|
}
|
|
if (!pb_encode_tag_for_field(stream, field)) {
|
|
return false;
|
|
}
|
|
return pb_encode_string(stream, (const pb_byte_t *)str, strlen(str));
|
|
}
|
|
|
|
static void handle_version(const uint8_t *data, size_t len) {
|
|
(void)data;
|
|
(void)len;
|
|
|
|
alox_UartMessage response = alox_UartMessage_init_zero;
|
|
response.type = alox_MessageType_VERSION;
|
|
response.which_payload = alox_UartMessage_version_response_tag;
|
|
response.payload.version_response.version = POWERPOD_FW_VERSION;
|
|
response.payload.version_response.git_hash.funcs.encode = encode_git_hash;
|
|
response.payload.version_response.git_hash.arg = (void *)POWERPOD_GIT_HASH;
|
|
|
|
esp_err_t err = uart_send_uart_message(&response);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "failed to send version response: %s", esp_err_to_name(err));
|
|
return;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "version=%u git=%s", (unsigned)POWERPOD_FW_VERSION,
|
|
POWERPOD_GIT_HASH);
|
|
}
|
|
|
|
void cmd_version_register(void) {
|
|
esp_err_t err =
|
|
msg_register_handler(alox_MessageType_VERSION, handle_version);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "register failed: %s", esp_err_to_name(err));
|
|
}
|
|
}
|