sync
This commit is contained in:
@@ -36,6 +36,7 @@ enum buzz_data_type
|
||||
BUZZ_DATA_DEVICE_INFO = 0x02,
|
||||
BUZZ_DATA_FS_INFO = 0x03,
|
||||
BUZZ_DATA_FW_INFO = 0x04,
|
||||
BUZZ_DATA_BATT_INFO = 0x05,
|
||||
|
||||
BUZZ_DATA_FILE_GET = 0x20,
|
||||
BUZZ_DATA_FILE_PUT = 0x21,
|
||||
@@ -122,6 +123,17 @@ struct __attribute__((packed)) buzz_resp_fw_info
|
||||
uint8_t kernel_version_length; /* Länge der Kernel-Versionszeichenkette */
|
||||
char data[]; /* Variabler String ohne Null-Terminierung: [fw_version][kernel_version] */
|
||||
};
|
||||
|
||||
/* Payload für die Batterie-Infos */
|
||||
struct __attribute__((packed)) buzz_resp_batt_info
|
||||
{
|
||||
uint8_t data_type; /* BUZZ_DATA_BATT_INFO */
|
||||
uint8_t batt_status; /* batt_mgmt_state_t */
|
||||
uint8_t batt_level; /* 0..4 */
|
||||
uint8_t batt_percent; /* 0..100 */
|
||||
uint16_t batt_voltage_mv; /* Little Endian */
|
||||
};
|
||||
|
||||
/* Payload für das Entfernen einer Datei */
|
||||
struct __attribute__((packed)) buzz_rm_file_payload
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "buzz_proto.h"
|
||||
#include "batt_mgmt.h"
|
||||
#include "fs_mgmt.h"
|
||||
#include "fw_mgmt.h"
|
||||
|
||||
@@ -293,6 +294,41 @@ static void handle_fw_info_request(struct buzz_frame_msg *msg)
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_batt_info_request(struct buzz_frame_msg *msg)
|
||||
{
|
||||
struct buzz_proto_header *hdr = (struct buzz_proto_header *)msg->data_ptr;
|
||||
struct buzz_resp_batt_info *resp_data = (struct buzz_resp_batt_info *)(msg->data_ptr + sizeof(*hdr));
|
||||
batt_mgmt_info_t batt_info;
|
||||
uint16_t voltage_mv = 0;
|
||||
int rc = batt_mgmt_get_info(&batt_info);
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG_WRN("Failed to get battery info: %d", rc);
|
||||
send_error_frame(msg, abs(rc));
|
||||
return;
|
||||
}
|
||||
|
||||
if (batt_info.voltage_mv > 0)
|
||||
{
|
||||
voltage_mv = (batt_info.voltage_mv > UINT16_MAX) ? UINT16_MAX : (uint16_t)batt_info.voltage_mv;
|
||||
}
|
||||
|
||||
hdr->frame_type = BUZZ_FRAME_RESPONSE;
|
||||
hdr->payload_length = sys_cpu_to_le16(sizeof(struct buzz_resp_batt_info));
|
||||
|
||||
resp_data->data_type = BUZZ_DATA_BATT_INFO;
|
||||
resp_data->batt_status = (uint8_t)batt_info.state;
|
||||
resp_data->batt_level = batt_info.level;
|
||||
resp_data->batt_percent = batt_info.percent;
|
||||
resp_data->batt_voltage_mv = sys_cpu_to_le16(voltage_mv);
|
||||
|
||||
if (msg->reply_cb)
|
||||
{
|
||||
msg->reply_cb(msg->data_ptr, sizeof(struct buzz_proto_header) + sizeof(struct buzz_resp_batt_info));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_ls_request(struct buzz_frame_msg *msg)
|
||||
{
|
||||
struct buzz_proto_header *hdr = (struct buzz_proto_header *)msg->data_ptr;
|
||||
@@ -698,6 +734,11 @@ static void handle_request(struct buzz_frame_msg *msg)
|
||||
handle_fw_info_request(msg);
|
||||
break;
|
||||
|
||||
case BUZZ_DATA_BATT_INFO:
|
||||
LOG_DBG("Received BATT Info Request");
|
||||
handle_batt_info_request(msg);
|
||||
break;
|
||||
|
||||
case BUZZ_DATA_FILE_GET:
|
||||
LOG_DBG("Received FILE_GET Request");
|
||||
handle_file_get_request(msg, false);
|
||||
|
||||
Reference in New Issue
Block a user