diff --git a/include/etif_detail.h b/include/etif_detail.h new file mode 100644 index 0000000..c188b10 --- /dev/null +++ b/include/etif_detail.h @@ -0,0 +1,27 @@ +#ifndef _INCLUDE_EXTERN_INTERFACE_DETAIL_H_ +#define _INCLUDE_EXTERN_INTERFACE_DETAIL_H_ + +#include +#include "extern_interface.h" + +#define PrintFilePos() + +#ifdef __cplusplus +extern "C" { +#endif + +void handle_pack(uint32_t type, size_t len, union PacketData data); +void get_telemetry_data(struct TelemetryRequestData* data); + +void* telemetry_host_com_thread(void* args); +void* upper_host_com_thread(void* arg); + +extern int g_iHostCom_tty_id; +extern int g_iEnableAlarmCode; +extern uint8_t g_iAlarmCode[4]; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/extern_interface.h b/include/extern_interface.h index 3ecfc25..f0d63fc 100644 --- a/include/extern_interface.h +++ b/include/extern_interface.h @@ -12,6 +12,8 @@ #define ET_TYPE_ALARM 4 #define ET_TYPE_TELEMETRY_REQUEST 5 +#define ET_SYS_STATUS_WAKE 1 + #if defined(_MSC_VER) #define EXTERN_INTERFACE_PUBLIC __declspec(dllexport) #elif defined(__GNUC__) @@ -28,7 +30,7 @@ struct TelemetryRequestData { int sys_state; bool volume_key_pressed; bool wakeup_key_pressed; - int volume_grade; + int volume_grade; // 0, 1, 2 int sys_ver_high; int sys_ver_low; int app_ver_high; diff --git a/src/extern_interface.cpp b/src/extern_interface.cpp index 0f9b38f..c3e6bdf 100644 --- a/src/extern_interface.cpp +++ b/src/extern_interface.cpp @@ -1,5 +1,5 @@ #include -#include "extern_interface.h" +#include "etif_detail.h" #include "event.h" #include "inicpp.hpp" @@ -13,6 +13,8 @@ int extern_interface_init(const char* config_path, et_callback_t cb) { et_callback = cb; pthread_create(&event_thread, NULL, sys_event_thread, NULL); + pthread_create(&upperhost_thread, NULL, upper_host_com_thread, NULL); + pthread_create(&telemetry_thread, NULL, telemetry_host_com_thread, NULL); } void extern_interface_send(uint32_t type, size_t len, union PacketData data) { @@ -28,10 +30,10 @@ void extern_interface_send(uint32_t type, size_t len, union PacketData data) { } } -void extern_interface_handle(uint32_t type, size_t len, union PacketData data) { +void handle_pack(uint32_t type, size_t len, union PacketData data) { et_callback(type, len, data); } -void get_telemetry_request_data(TelemetryRequestData* data) { - extern_interface_handle(ET_TYPE_TELEMETRY_REQUEST, sizeof(TelemetryRequestData), { .pd_pointer = data }); +void get_telemetry_data(TelemetryRequestData* data) { + handle_pack(ET_TYPE_TELEMETRY_REQUEST, sizeof(TelemetryRequestData), { .pd_pointer = data }); } diff --git a/src/host_com.cpp b/src/host_com.cpp index da1b663..913fceb 100644 --- a/src/host_com.cpp +++ b/src/host_com.cpp @@ -5,6 +5,7 @@ #include "telemetry.h" #include "dataqueue.hpp" #include "command.h" +#include "etif_detail.h" #define PrintFilePos() @@ -25,22 +26,24 @@ volatile int32_t g_iMS2Reboot = 1000; /* create a msg data for upper host telemetry*/ void set_telemetry_host_data(TelemetryData4UpperHost* pTelemetryData) { + TelemetryRequestData data; + get_telemetry_data(&data); pTelemetryData->work_status = 0xAA; pTelemetryData->com_status = 0xAA; pTelemetryData->coprocessor1_status = 0xAA; pTelemetryData->coprocessor2_status = 0xAA; pTelemetryData->voice_circuit_status = 0xAA; pTelemetryData->telemetry_count = g_iUpperHostTelemetryCount++; - if (g_bCloseASR) { + if (data.close_asr) { pTelemetryData->voice_mode = 0xAA; } - else if (g_iSysState == SYS_STATUS_WAKE) { + else if (data.sys_state == ET_SYS_STATUS_WAKE) { pTelemetryData->voice_mode = 0x55; } else { pTelemetryData->voice_mode = 0xA5; } - if (g_iSysState == SYS_STATUS_WAKE) { + if (data.sys_state == ET_SYS_STATUS_WAKE) { pTelemetryData->recognition_status = 0x55; } else { @@ -75,25 +78,15 @@ void set_telemetry_host_data(TelemetryData4UpperHost* pTelemetryData) { //} //pTelemetryData->volume_key_status = g_bVolumeKeyState ? 0xAA : 0x55; //pTelemetryData->wake_key_status = g_bWakeupKeyState ? 0xAA : 0x55; - pTelemetryData->volume_key_status = g_bVolumeKeyPressed ? 0xAA : 0x55; - pTelemetryData->wake_key_status = g_bWakeupKeyPressed ? 0xAA : 0x55; - g_bVolumeKeyPressed = false; - g_bWakeupKeyPressed = false; + pTelemetryData->volume_key_status = data.volume_key_pressed ? 0xAA : 0x55; + pTelemetryData->wake_key_status = data.wakeup_key_pressed ? 0xAA : 0x55; pTelemetryData->key_status_backup = 0x55; - if ( g_iCurVolumeGrade == g_iVolumeGradeCnt-1 ) {//large - pTelemetryData->current_volume = 0x3; - } - else if ( g_iCurVolumeGrade == 0 ) {//small - pTelemetryData->current_volume = 0x1; - } - else {//midium - pTelemetryData->current_volume = 0x2; - } - pTelemetryData->system_version_high = g_iSysVerHigh; - pTelemetryData->system_version_low = g_iSysVerLow; - pTelemetryData->application_version_high = g_iAppVerHigh; - pTelemetryData->application_version_low = g_iAppVerLow; + pTelemetryData->current_volume = data.volume_grade; + pTelemetryData->system_version_high = data.sys_ver_high; + pTelemetryData->system_version_low = data.sys_ver_low; + pTelemetryData->application_version_high = data.app_ver_high; + pTelemetryData->application_version_low = data.app_ver_low; // 2024.10.10 if (g_iEnableAlarmCode == 0) { pTelemetryData->alarm_code[0] = 0xAA;