| | |
| | | #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 |
| | | |
| | |
| | | uint32_t downloadRtk : 1; |
| | | } platformStatus; |
| | | |
| | | |
| | | |
| | | struct platformSocket exceptSocket, currSocket; |
| | | static uint32_t eventMask; |
| | | static sem_t sem_status_changed; |
| | |
| | | |
| | | 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; |
| | |
| | | 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) |
| | |
| | | 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) { |
| | |
| | | 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)); |
| | |
| | | } |
| | | 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); |
| | | |
| | |
| | | TextSpeak("终端注册成功"); |
| | | DisplayText("终端注册成功"); |
| | | SetPlatformKey(data, length); |
| | | SetSharedValue(VK_REG, 1); |
| | | PlatformStatusChanged(PLATFORM_REGISTER_EVT); |
| | | } |
| | | } |