feat():modify spi

This commit is contained in:
2026-06-24 21:58:02 +08:00
parent f006c77b37
commit c3fb70558d
6 changed files with 12 additions and 13 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -277,6 +277,8 @@ public:
{ {
someip_log_i("Start event [0x%04x] notify thread.",_event); someip_log_i("Start event [0x%04x] notify thread.",_event);
std::vector<byte_t> lastData; // 用于 on-change 模式去重
while (running_) while (running_)
{ {
@@ -289,23 +291,16 @@ public:
if (_update_on_change || (0U == _cycle)) if (_update_on_change || (0U == _cycle))
{ {
// for update on change // for update on change: only notify when data changes
/* If data is not empty and changed, to notify */ std::vector<byte_t> notify_data = _notify_data_func();
static std::vector<byte_t> lastData;
std::vector<byte_t> notify_data;
notify_data.clear();
notify_data = _notify_data_func();
if ((nullptr != _notify_data_func) && (lastData != notify_data)) if (lastData != notify_data)
{ {
lastData = notify_data; lastData = notify_data;
std::shared_ptr<payload> _payload = runtime::get()->create_payload(); std::shared_ptr<payload> _payload = runtime::get()->create_payload();
_payload->set_data(notify_data); _payload->set_data(notify_data);
someip_log_d("Notify event[0x%04x] with data size[%d] payload length[%d].", _event, notify_data.size(), _payload->get_length());
someip_log_d("Notify event[0x%04x] with data size[%d] payload length[%d].", _event,notify_data.size(), _payload->get_length());
app_->notify(_service, _instance, _event, _payload); app_->notify(_service, _instance, _event, _payload);
} }
} }

View File

@@ -168,12 +168,12 @@ void my_spi_server_thread_func(void* arg) {
// 调用SpiProtocol_Unpack解析SPI数据 // 调用SpiProtocol_Unpack解析SPI数据
SpiProtocol_RxResultType result; SpiProtocol_RxResultType result;
int32_t unpack_ret = SpiProtocol_Unpack(buf, sizeof(buf), SPI_PROTO_FRAME_SIZE, &result); int32_t unpack_ret = SpiProtocol_Unpack(buf, sizeof(buf), SPI_PROTO_FRAME_SIZE, &result);
if (unpack_ret != SPI_PROTO_ERR_NONE) if (unpack_ret < 0)
{ {
printf("SpiProtocol_Unpack error: %d\n", unpack_ret); printf("SpiProtocol_Unpack error: %d\n", unpack_ret);
continue; continue;
} }
printf("SpiProtocol_Unpack success\n"); printf("SpiProtocol_Unpack success, tlv_count=%d\n", unpack_ret);
// 处理解包后的数据:提取 CAN0~CAN5 数据分发到对应缓冲区 // 处理解包后的数据:提取 CAN0~CAN5 数据分发到对应缓冲区
for (uint8_t i = 0; i < result.tlv_count; i++) for (uint8_t i = 0; i < result.tlv_count; i++)
@@ -187,6 +187,10 @@ void my_spi_server_thread_func(void* arg) {
g_can_data[can_ch].assign(result.tlvs[i].value, g_can_data[can_ch].assign(result.tlvs[i].value,
result.tlvs[i].value + result.tlvs[i].length); result.tlvs[i].value + result.tlvs[i].length);
printf("CAN%d data updated, length=%u\n", can_ch, result.tlvs[i].length); printf("CAN%d data updated, length=%u\n", can_ch, result.tlvs[i].length);
printf(" HEX: ");
for (size_t j = 0; j < g_can_data[can_ch].size(); j++)
printf("%02X ", g_can_data[can_ch][j]);
printf("\n");
} }
else else
{ {