Use TX=GPIO3 and RX=GPIO2 at 921600 to match the terminal adapter wiring; log received message id and which handler command is triggered. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.4 KiB
C
52 lines
1.4 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;
|
|
|
|
if (uart_send_uart_message(&response) != ESP_OK) {
|
|
ESP_LOGE(TAG, "failed to send response");
|
|
}
|
|
}
|
|
|
|
void cmd_version_register(void) {
|
|
if (msg_register_handler(alox_MessageType_VERSION, handle_version) != ESP_OK) {
|
|
ESP_LOGE(TAG, "register failed");
|
|
}
|
|
}
|