From 6f2dc73bb6bd5ff48cb4a2e77e9e7b6a93828902 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期二, 07 一月 2020 19:21:39 +0800 Subject: [PATCH] 修改进程间接口,统一为foo(int, string) --- lib/src/main/cpp/rtk_platform/platform.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 43 insertions(+), 13 deletions(-) diff --git a/lib/src/main/cpp/rtk_platform/platform.cpp b/lib/src/main/cpp/rtk_platform/platform.cpp index f1f0358..30dec58 100644 --- a/lib/src/main/cpp/rtk_platform/platform.cpp +++ b/lib/src/main/cpp/rtk_platform/platform.cpp @@ -16,6 +16,8 @@ #include "../defs.h" #include "../rtk_module/rtk.h" #include "../mcu/mcu_if.h" +#include "../master/comm_if.h" +#include "../utils/xconvert.h" #define PARSE_BUFF_SIZE 4096 @@ -48,6 +50,8 @@ uint32_t downloadRtk : 1; } platformStatus; + + struct platformSocket exceptSocket, currSocket; static uint32_t eventMask; static sem_t sem_status_changed; @@ -79,19 +83,13 @@ eventMask = 0; platform_tcp_fd = -1; + memset(&currSocket, 0, sizeof(currSocket)); - strcpy(exceptSocket.domain_name, domain_name); - exceptSocket.port = port; + memset(&platformStatus, 0, sizeof(platformStatus)); sem_init(&sem_status_changed, 0, 0); - strcpy(deviceInfo.imei, GetImei()); - deviceInfo.province = 53; - deviceInfo.city = 100; - strcpy((char *)deviceInfo.device_model, "RTKBaseStation"); - strcpy((char *)deviceInfo.device_sn, "2019101500000001"); - - PlatformTxInit(phone); + PlatformTxInit(); pthread_t pid; pthread_attr_t attr; @@ -99,7 +97,39 @@ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//detached pthread_create(&pid, &attr, StatusListenThread, NULL); - ConnectPlatform(domain_name, port); + MA_ReqRtkPlatformConfig(); +} + +void ConfigPlatform(const rtk_platform_cfg_t *p) +{ + DEBUG("ConfigPlatform"); + + strcpy(exceptSocket.domain_name, p->domain_name); + exceptSocket.port = p->port; + deviceInfo.province = p->province; + deviceInfo.city = p->city; + strcpy((char *)deviceInfo.device_model, p->device_model); + strcpy((char *)deviceInfo.device_sn, p->device_sn); + strcpy(deviceInfo.imei, p->imei); + SetPlatformTxPhoneNum(p->phone); + + platformStatus.registed = p->registered; + platformStatus.platformKeyLength = strlen(p->password) / 2; + + if (platformStatus.platformKeyLength > 0) { + ConvertString2Hex(platformStatus.platformKey, sizeof(platformStatus.platformKey), p->password); + } else { + platformStatus.registed = 0; + } + + pthread_mutex_lock(&platform_tx_mutex); + if (platform_tcp_fd > 0 && (exceptSocket.port != currSocket.port || strcmp(currSocket.domain_name, exceptSocket.domain_name))) { + DisconnectTCP(platform_tcp_fd); + platform_tcp_fd = -1; + } else if (platform_tcp_fd <= 0) { + ConnectPlatform(exceptSocket.domain_name, exceptSocket.port); + } + pthread_mutex_unlock(&platform_tx_mutex); } void PlatformStatusChanged(uint32_t event) @@ -149,6 +179,7 @@ char out[64]; sprintf(out, "骞冲彴杩炴帴鎴愬姛 %s:%d", currSocket.domain_name, currSocket.port); DisplayText(out); + MA_RtkPlatformConnect(1, currSocket.domain_name, currSocket.port); platformStatus.connected = 1; if (!platformStatus.registed || platformStatus.platformKeyLength == 0) { @@ -162,6 +193,7 @@ char out[64]; sprintf(out, "骞冲彴鏂紑 %s:%d", currSocket.domain_name, currSocket.port); DisplayText(out); + MA_RtkPlatformConnect(0, currSocket.domain_name, currSocket.port); AppTimer_delete(ConnectPlatformLater); AppTimer_add(ConnectPlatformLater, D_SEC(2)); @@ -175,8 +207,7 @@ } if (events & PLATFORM_REGISTER_EVT) { DEBUG("PLATFORM_REGISTER_EVT"); - platformStatus.platformKeyLength = GetPlatformKey(platformStatus.platformKey); - platformStatus.registed = GetSharedValue(VK_REG); + platformStatus.login = 0; DEBUG("platformStatus.platformKeyLength = %d", platformStatus.platformKeyLength); @@ -329,7 +360,6 @@ TextSpeak("缁堢娉ㄥ唽鎴愬姛"); DisplayText("缁堢娉ㄥ唽鎴愬姛"); SetPlatformKey(data, length); - SetSharedValue(VK_REG, 1); PlatformStatusChanged(PLATFORM_REGISTER_EVT); } } -- Gitblit v1.8.0