| | |
| | | struct event_queue_t *next; |
| | | } *eventQueue; |
| | | |
| | | static bool mAyDevice = false; |
| | | |
| | | struct platformSocket exceptSocket, currSocket; |
| | | static sem_t sem_status_changed; |
| | | |
| | |
| | | static void LoginPlatformTimeout(union sigval sig); |
| | | static void TriggerHeartbeat(union sigval sig); |
| | | static void RequestRtkNoResp(union sigval sig); |
| | | |
| | | |
| | | static void AddEvnet(uint32_t event, const uint8_t *data, int length) |
| | | { |
| | |
| | | free(p1); |
| | | } |
| | | |
| | | void InitPlatform(const uint8_t *phone, const char *domain_name, int port) |
| | | void InitPlatform(bool ayDevice, const uint8_t *phone, const char *domain_name, int port) |
| | | { |
| | | DEBUG("InitPlatform"); |
| | | |
| | | mAyDevice = ayDevice; |
| | | |
| | | memset(&gbf, 0, sizeof(gbf)); |
| | | memset(&rbf, 0, sizeof(rbf)); |
| | |
| | | if (domain_name == NULL || strlen(domain_name) == 0 || port == 0) |
| | | return; |
| | | |
| | | DEBUG("ConnectPlatform %s: %d", domain_name, port); |
| | | DEBUG("连接RTK平台 %s: %d", domain_name, port); |
| | | // TODO |
| | | struct platformSocketInfo *ptr = (struct platformSocketInfo *)malloc(sizeof(struct platformSocketInfo)); |
| | | |
| | |
| | | |
| | | static void PlatformChangeEntry(uint32_t events, const uint8_t *data, int length) |
| | | { |
| | | if (events & PLATFORM_CONNECT_EVT) { |
| | | DEBUG("平台连接成功 %s:%d", currSocket.domain_name, currSocket.port); |
| | | MA_RtkPlatformConnect(1, currSocket.domain_name, currSocket.port); |
| | | switch (events) { |
| | | case PLATFORM_CONNECT_EVT: { |
| | | DEBUG("平台连接成功 %s:%d", currSocket.domain_name, currSocket.port); |
| | | MA_RtkPlatformConnect(1, currSocket.domain_name, currSocket.port); |
| | | |
| | | platformStatus.connected = 1; |
| | | if (!platformStatus.registed || platformStatus.platformKeyLength == 0) { |
| | | RegisterPlatform(); |
| | | } else if (!platformStatus.login) { |
| | | LoginPlatform(); |
| | | platformStatus.connected = 1; |
| | | if (!platformStatus.registed || platformStatus.platformKeyLength == 0) { |
| | | RegisterPlatform(); |
| | | } else if (!platformStatus.login) { |
| | | LoginPlatform(); |
| | | } |
| | | |
| | | MA_SendBlueStatus("name", "00:1B:35:16:20:4A", 3); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (events & PLATFORM_DISCONNECT_EVT) { |
| | | DEBUG("平台断开 %s:%d", currSocket.domain_name, currSocket.port); |
| | | MA_RtkPlatformConnect(0, currSocket.domain_name, currSocket.port); |
| | | case PLATFORM_DISCONNECT_EVT: { |
| | | DEBUG("平台断开 %s:%d", currSocket.domain_name, currSocket.port); |
| | | MA_RtkPlatformConnect(0, currSocket.domain_name, currSocket.port); |
| | | |
| | | AppTimer_delete(ConnectPlatformLater); |
| | | AppTimer_add(ConnectPlatformLater, D_SEC(2)); |
| | | AppTimer_delete(ConnectPlatformLater); |
| | | AppTimer_add(ConnectPlatformLater, D_SEC(2)); |
| | | |
| | | platformStatus.login = 0; |
| | | platformStatus.connected = 0; |
| | | platformStatus.login = 0; |
| | | platformStatus.connected = 0; |
| | | |
| | | AppTimer_delete(TriggerHeartbeat); |
| | | AppTimer_delete(RegisterPlatformTimeout); |
| | | AppTimer_delete(LoginPlatformTimeout); |
| | | AppTimer_delete(TriggerHeartbeat); |
| | | AppTimer_delete(RegisterPlatformTimeout); |
| | | AppTimer_delete(LoginPlatformTimeout); |
| | | |
| | | // PlayTTS("基准源断开", NULL); |
| | | } |
| | | if (events & PLATFORM_REGISTER_EVT) { |
| | | DEBUG("PLATFORM_REGISTER_EVT"); |
| | | |
| | | platformStatus.login = 0; |
| | | if (data[0] == 0) { |
| | | platformStatus.registed = 1; |
| | | platformStatus.platformKeyLength = length - 1; |
| | | memcpy(platformStatus.platformKey, data+1, length-1); |
| | | LoginPlatform(); |
| | | } else { |
| | | platformStatus.registed = 0; |
| | | break; |
| | | } |
| | | MA_RtkPlatformRegister(data[0], data + 1, length - 1); |
| | | } |
| | | if (events & PLATFORM_LOGIN_EVT) { |
| | | DEBUG("PLATFORM_LOGIN_EVT"); |
| | | case PLATFORM_REGISTER_EVT: { |
| | | DEBUG("平台注册结果:%d", data[0]); |
| | | |
| | | if (data[0] == 0) { |
| | | platformStatus.login = 1; |
| | | requestPlatformSendRtk = true; |
| | | AppTimer_delete(TriggerHeartbeat); |
| | | AppTimer_add(TriggerHeartbeat, D_SEC(30)); |
| | | platformStatus.login = 0; |
| | | if (data[0] == 0) { |
| | | platformStatus.registed = 1; |
| | | platformStatus.platformKeyLength = length - 1; |
| | | memcpy(platformStatus.platformKey, data + 1, length - 1); |
| | | LoginPlatform(); |
| | | } else { |
| | | platformStatus.registed = 0; |
| | | } |
| | | MA_RtkPlatformRegister(data[0], data + 1, length - 1); |
| | | break; |
| | | } |
| | | case PLATFORM_LOGIN_EVT: { |
| | | DEBUG("平台登录结果:%d", data[0]); |
| | | |
| | | if (data[0] == 0) { |
| | | platformStatus.login = 1; |
| | | requestPlatformSendRtk = true; |
| | | AppTimer_delete(TriggerHeartbeat); |
| | | AppTimer_add(TriggerHeartbeat, D_SEC(30)); |
| | | |
| | | // PlayTTS("基准源建立", NULL); |
| | | } else { |
| | | platformStatus.login = 0; |
| | | } else { |
| | | platformStatus.login = 0; |
| | | } |
| | | MA_RtkPlatformLogin(data[0]); |
| | | break; |
| | | } |
| | | MA_RtkPlatformLogin(data[0]); |
| | | } |
| | | if (events & GPS_UPDATE_EVT) { |
| | | DEBUG("GPS_UPDATE_EVT length %d", length); |
| | | const gpsStatus_t *gps = (gpsStatus_t *)data; |
| | | case GPS_UPDATE_EVT: { |
| | | const gpsStatus_t *gps = (gpsStatus_t *) data; |
| | | |
| | | gbf.qf = gps->gps_status; |
| | | gbf.latitude = gps->latitude; |
| | | gbf.longitude = gps->longitude; |
| | | gbf.altitude = gps->altitude; |
| | | gbf.speed = gps->speed; |
| | | gbf.sat_num = gps->satNum; |
| | | gbf.trackTure = gps->trackTure; |
| | | sprintf(gbf.utc, "%04d%02d%02d%02d%02d%02d.%02d", 2000 + gps->YY, gps->MM, gps->DD, gps->hh, gps->mm, gps->ss, gps->mss); |
| | | if (!strcmp(rbf.utc, gbf.utc)) { |
| | | rbf.sat_num = gbf.sat_num; |
| | | rbf.latitude = gbf.latitude; |
| | | rbf.longitude = gbf.longitude; |
| | | rbf.altitude = gbf.altitude; |
| | | rbf.speed = gbf.speed; |
| | | rbf.trackTure = gbf.trackTure; |
| | | MA_SendRtkBrief(&rbf); |
| | | } |
| | | gbf.qf = gps->gps_status; |
| | | gbf.latitude = gps->latitude; |
| | | gbf.longitude = gps->longitude; |
| | | gbf.altitude = gps->altitude; |
| | | gbf.speed = gps->speed; |
| | | gbf.sat_num = gps->satNum; |
| | | gbf.trackTure = gps->trackTure; |
| | | sprintf(gbf.utc, "%04d%02d%02d%02d%02d%02d.%02d", 2000 + gps->YY, gps->MM, gps->DD, |
| | | gps->hh, gps->mm, gps->ss, gps->mss); |
| | | if (!strcmp(rbf.utc, gbf.utc)) { |
| | | rbf.sat_num = gbf.sat_num; |
| | | rbf.latitude = gbf.latitude; |
| | | rbf.longitude = gbf.longitude; |
| | | rbf.altitude = gbf.altitude; |
| | | rbf.speed = gbf.speed; |
| | | rbf.trackTure = gbf.trackTure; |
| | | MA_SendRtkBrief(&rbf); |
| | | } |
| | | // MA_SendGpsBrief(&brief); |
| | | RequestRtkDownload(gps, 1); |
| | | |
| | | DEBUG("GPS_UPDATE_EVT ================"); |
| | | } |
| | | if (events & RTK_UPDATE_EVT) { |
| | | DEBUG("RTK_UPDATE_EVT length %d", length); |
| | | |
| | | // uint32_t ost = AppTimer_GetTickCount(); |
| | | |
| | | const rtk_info *rtk = (rtk_info *)data; |
| | | |
| | | rbf.qf = rtk->qf; |
| | | rbf.coord_x = rtk->y; |
| | | rbf.coord_y = rtk->x; |
| | | rbf.heading = rtk->heading; |
| | | rbf.pitch = rtk->pitch; |
| | | rbf.roll = rtk->roll; |
| | | rbf.coord_x_dir = 'N'; |
| | | rbf.coord_y_dir = 'E'; |
| | | sprintf(rbf.utc, "%04d%02d%02d%02d%02d%02d.%02d", 2000 + rtk->YY, rtk->MM, rtk->DD, rtk->hh, rtk->mm, rtk->ss, rtk->dss); |
| | | if (!strcmp(rbf.utc, gbf.utc)) { |
| | | rbf.sat_num = gbf.sat_num; |
| | | rbf.latitude = gbf.latitude; |
| | | rbf.longitude = gbf.longitude; |
| | | rbf.altitude = gbf.altitude; |
| | | rbf.speed = gbf.speed; |
| | | rbf.trackTure = gbf.trackTure; |
| | | MA_SendRtkBrief(&rbf); |
| | | RequestRtkDownload(gps, 1); |
| | | break; |
| | | } |
| | | case RTK_UPDATE_EVT: { |
| | | uint32_t ost = AppTimer_GetTickCount(); |
| | | uint32_t ost1 = ost; |
| | | |
| | | UpdateRTKInfo(rtk); |
| | | const rtk_info *rtk = (rtk_info *) data; |
| | | |
| | | // DEBUG("driver_test 评判耗时 %ld", AppTimer_GetTickCount() - ost); |
| | | rbf.qf = rtk->qf; |
| | | rbf.coord_x = rtk->y; |
| | | rbf.coord_y = rtk->x; |
| | | rbf.heading = rtk->heading; |
| | | rbf.pitch = rtk->pitch; |
| | | rbf.roll = rtk->roll; |
| | | rbf.coord_x_dir = 'N'; |
| | | rbf.coord_y_dir = 'E'; |
| | | sprintf(rbf.utc, "%04d%02d%02d%02d%02d%02d.%02d", 2000 + rtk->YY, rtk->MM, rtk->DD, |
| | | rtk->hh, rtk->mm, rtk->ss, rtk->dss); |
| | | if (!strcmp(rbf.utc, gbf.utc)) { |
| | | rbf.sat_num = gbf.sat_num; |
| | | rbf.latitude = gbf.latitude; |
| | | rbf.longitude = gbf.longitude; |
| | | rbf.altitude = gbf.altitude; |
| | | rbf.speed = gbf.speed; |
| | | rbf.trackTure = gbf.trackTure; |
| | | MA_SendRtkBrief(&rbf); |
| | | } |
| | | |
| | | DEBUG("RTK_UPDATE_EVT ================="); |
| | | } |
| | | if (events & MCU_UPDATE_EVT) { |
| | | DEBUG("MCU_UPDATE_EVT length %d", length); |
| | | // 0-31 version |
| | | // 32-33 selftest |
| | | // 34-35 gpio |
| | | // 36-37 speed |
| | | // 38-39 engine |
| | | // 40-55 sn |
| | | struct mcuBrief brief; |
| | | ost1 = AppTimer_GetTickCount() - ost1; |
| | | |
| | | memset(&brief, 0, sizeof(brief)); |
| | | UpdateRTKInfo(rtk); |
| | | |
| | | int x = 0; |
| | | while(data[x] != 0 && x < 32) x++; |
| | | ost = AppTimer_GetTickCount() - ost; |
| | | |
| | | ConvertHex2String(brief.version, data, x); |
| | | brief.selftest = BUILD_UINT16(data[33], data[32]); |
| | | if (ost > 100) |
| | | DEBUG("driver_test 评判耗时 %ld %ld", ost1, ost); |
| | | break; |
| | | } |
| | | case RTK_STATUS_EVT: { |
| | | DEBUG("模块信息 %02X %02X %02X %02X %02X %02X", data[0], data[1], data[2], data[3], data[4], data[5]); |
| | | if (length == 33) |
| | | MA_SendRtkStatus((char *)data, data[32]); |
| | | break; |
| | | } |
| | | case MCU_UPDATE_EVT: { |
| | | // 0-31 version |
| | | // 32-33 selftest |
| | | // 34-35 gpio |
| | | // 36-37 speed |
| | | // 38-39 engine |
| | | // 40-55 sn |
| | | struct mcuBrief brief; |
| | | |
| | | memset(&brief, 0, sizeof(brief)); |
| | | |
| | | int x = 0; |
| | | while (data[x] != 0 && x < 32) x++; |
| | | |
| | | ConvertHex2String(brief.version, data, x); |
| | | brief.selftest = BUILD_UINT16(data[33], data[32]); |
| | | // brief.gpio = BUILD_UINT16(data[35], data[34]); |
| | | // brief.speed = BUILD_UINT16(data[37], data[36]); |
| | | // brief.engine = BUILD_UINT16(data[39], data[38]); |
| | | // memcpy(brief.sn, data+40, 16); |
| | | memcpy(brief.sn, data+34, 16); |
| | | memcpy(brief.sn, data + 34, 16); |
| | | |
| | | MA_SendMcuBrief(&brief); |
| | | MA_SendMcuBrief(&brief); |
| | | |
| | | if (defaultMcuRom.more > 0) { |
| | | char str[64] = {0}; |
| | | if (defaultMcuRom.more > 0) { |
| | | char str[64] = {0}; |
| | | |
| | | memcpy(str, data, 32); |
| | | memcpy(str, data, 32); |
| | | |
| | | vector<string> ver = split(str, "_"); |
| | | vector<string> ver = split(str, "_"); |
| | | |
| | | if (strlen(defaultMcuRom.verCode) > 0 && ver.size() >= 4 && strcmp(defaultMcuRom.verCode, ver[3].c_str()) != 0 && defaultMcuRom.rom != NULL) { |
| | | UploadDfuFile(defaultMcuRom.rom, defaultMcuRom.length); |
| | | delete []defaultMcuRom.rom; |
| | | defaultMcuRom.rom = NULL; |
| | | if (strlen(defaultMcuRom.verCode) > 0 && ver.size() >= 4 && |
| | | strcmp(defaultMcuRom.verCode, ver[3].c_str()) != 0 && |
| | | defaultMcuRom.rom != NULL) { |
| | | UploadDfuFile(defaultMcuRom.rom, defaultMcuRom.length); |
| | | delete[]defaultMcuRom.rom; |
| | | defaultMcuRom.rom = NULL; |
| | | } |
| | | defaultMcuRom.more = 0; |
| | | } |
| | | defaultMcuRom.more = 0; |
| | | } |
| | | // UpdateSensor(brief.gpio, brief.speed, brief.engine); |
| | | } |
| | | if (events & CAN_UPDATE_EVT) { |
| | | struct canBrief brief; |
| | | break; |
| | | } |
| | | case CAN_UPDATE_EVT: { |
| | | struct canBrief brief; |
| | | |
| | | brief.gpio = BUILD_UINT16(data[1], data[0]); |
| | | brief.rpm = BUILD_UINT16(data[3], data[2]); |
| | | brief.speed = (double) BUILD_UINT16(data[5], data[4]) / 10.0; |
| | | brief.voltage = (double) BUILD_UINT16(data[7], data[6]) / 10.0; |
| | | brief.gpio = BUILD_UINT16(data[1], data[0]); |
| | | brief.rpm = BUILD_UINT16(data[3], data[2]); |
| | | brief.speed = (double) BUILD_UINT16(data[5], data[4]) / 10.0; |
| | | brief.voltage = (double) BUILD_UINT16(data[7], data[6]) / 10.0; |
| | | |
| | | MA_SendCanStatus(&brief); |
| | | } |
| | | if (events & CAR_SENSOR_UPDATE_EVT) { |
| | | struct carSensorBrief brief; |
| | | int x = 20; |
| | | MA_SendCanStatus(&brief); |
| | | break; |
| | | } |
| | | case CAR_SENSOR_UPDATE_EVT: { |
| | | struct carSensorBrief brief; |
| | | int x = 20; |
| | | |
| | | brief.odo = BUILD_UINT32(data[3], data[2], data[1], data[0]); |
| | | brief.trip = BUILD_UINT32(data[7], data[6], data[5], data[4]); |
| | | brief.tripTime = BUILD_UINT32(data[11], data[10], data[9], data[8]); |
| | | brief.cellVolt = ((double) BUILD_UINT16(data[13], data[12])) / 10.0; |
| | | brief.speed = ((double) BUILD_UINT16(data[15], data[14])) / 10.0; |
| | | brief.engine = BUILD_UINT16(data[17], data[16]); |
| | | brief.sas = (short)BUILD_UINT16(data[19], data[18]); |
| | | brief.key = data[x++]; |
| | | brief.gear = data[x++]; |
| | | brief.aps = data[x++]; |
| | | brief.door = data[x++]; |
| | | brief.seatBelt = data[x++]; |
| | | brief.clutch = data[x++]; |
| | | brief.horn = data[x++]; |
| | | brief.wiper = data[x++]; |
| | | brief.handBreak = data[x++]; |
| | | brief.mainBreak = data[x++]; |
| | | brief.leftTurnLamp = data[x++]; |
| | | brief.rightTurnLamp = data[x++]; |
| | | brief.clearanceLamp = data[x++]; |
| | | brief.dippedBeamLamp = data[x++]; |
| | | brief.mainBeamLamp = data[x++]; |
| | | brief.fogLamp = data[x++]; |
| | | brief.assBreak = data[x++]; |
| | | brief.surround1 = data[x++]; |
| | | brief.surround2 = data[x++]; |
| | | brief.surround3 = data[x++]; |
| | | brief.surround4 = data[x++]; |
| | | brief.odo = BUILD_UINT32(data[3], data[2], data[1], data[0]); |
| | | brief.trip = BUILD_UINT32(data[7], data[6], data[5], data[4]); |
| | | brief.tripTime = BUILD_UINT32(data[11], data[10], data[9], data[8]); |
| | | brief.cellVolt = ((double) BUILD_UINT16(data[13], data[12])) / 10.0; |
| | | brief.speed = ((double) BUILD_UINT16(data[15], data[14])) / 10.0; |
| | | brief.engine = BUILD_UINT16(data[17], data[16]); |
| | | brief.sas = (short) BUILD_UINT16(data[19], data[18]); |
| | | brief.key = data[x++]; |
| | | brief.gear = data[x++]; |
| | | brief.aps = data[x++]; |
| | | brief.door = data[x++]; |
| | | brief.seatBelt = data[x++]; |
| | | brief.clutch = data[x++]; |
| | | brief.horn = data[x++]; |
| | | brief.wiper = data[x++]; |
| | | brief.handBreak = data[x++]; |
| | | brief.mainBreak = data[x++]; |
| | | brief.leftTurnLamp = data[x++]; |
| | | brief.rightTurnLamp = data[x++]; |
| | | brief.clearanceLamp = data[x++]; |
| | | brief.dippedBeamLamp = data[x++]; |
| | | brief.mainBeamLamp = data[x++]; |
| | | brief.fogLamp = data[x++]; |
| | | brief.assBreak = data[x++]; |
| | | brief.surround1 = data[x++]; |
| | | brief.surround2 = data[x++]; |
| | | brief.surround3 = data[x++]; |
| | | brief.surround4 = data[x++]; |
| | | |
| | | MA_SendCarSensorBrief(&brief); |
| | | MA_SendCarSensorBrief(&brief); |
| | | |
| | | car_sensor_t sensor; |
| | | x = 20; |
| | | car_sensor_t sensor; |
| | | x = 20; |
| | | |
| | | sensor.odo = BUILD_UINT32(data[3], data[2], data[1], data[0]); |
| | | sensor.trip = BUILD_UINT32(data[7], data[6], data[5], data[4]); |
| | | sensor.tripTime = BUILD_UINT32(data[11], data[10], data[9], data[8]); |
| | | sensor.cellVolt = (double)(BUILD_UINT16(data[13], data[12])) / 10.0; |
| | | sensor.speed = BUILD_UINT16(data[15], data[14]); |
| | | sensor.engine = BUILD_UINT16(data[17], data[16]); |
| | | sensor.sas = (short)BUILD_UINT16(data[19], data[18]); |
| | | sensor.key = data[x++]; |
| | | sensor.gear = data[x++]; |
| | | sensor.aps = data[x++]; |
| | | sensor.door = data[x++]; |
| | | sensor.seatBelt = data[x++]; |
| | | sensor.clutch = data[x++]; |
| | | sensor.horn = data[x++]; |
| | | sensor.wiper = data[x++]; |
| | | sensor.handBreak = data[x++]; |
| | | sensor.mainBreak = data[x++]; |
| | | sensor.leftTurnLamp = data[x++]; |
| | | sensor.rightTurnLamp = data[x++]; |
| | | sensor.clearanceLamp = data[x++]; |
| | | sensor.dippedBeamLamp = data[x++]; |
| | | sensor.mainBeamLamp = data[x++]; |
| | | sensor.fogLamp = data[x++]; |
| | | sensor.assBreak = data[x++]; |
| | | sensor.surround1 = data[x++]; |
| | | sensor.surround2 = data[x++]; |
| | | sensor.surround3 = data[x++]; |
| | | sensor.surround4 = data[x++]; |
| | | sensor.odo = BUILD_UINT32(data[3], data[2], data[1], data[0]); |
| | | sensor.trip = BUILD_UINT32(data[7], data[6], data[5], data[4]); |
| | | sensor.tripTime = BUILD_UINT32(data[11], data[10], data[9], data[8]); |
| | | sensor.cellVolt = (double) (BUILD_UINT16(data[13], data[12])) / 10.0; |
| | | sensor.speed = BUILD_UINT16(data[15], data[14]); |
| | | sensor.engine = BUILD_UINT16(data[17], data[16]); |
| | | sensor.sas = (short) BUILD_UINT16(data[19], data[18]); |
| | | sensor.key = data[x++]; |
| | | sensor.gear = data[x++]; |
| | | sensor.aps = data[x++]; |
| | | sensor.door = data[x++]; |
| | | sensor.seatBelt = data[x++]; |
| | | sensor.clutch = data[x++]; |
| | | sensor.horn = data[x++]; |
| | | sensor.wiper = data[x++]; |
| | | sensor.handBreak = data[x++]; |
| | | sensor.mainBreak = data[x++]; |
| | | sensor.leftTurnLamp = data[x++]; |
| | | sensor.rightTurnLamp = data[x++]; |
| | | sensor.clearanceLamp = data[x++]; |
| | | sensor.dippedBeamLamp = data[x++]; |
| | | sensor.mainBeamLamp = data[x++]; |
| | | sensor.fogLamp = data[x++]; |
| | | sensor.assBreak = data[x++]; |
| | | sensor.surround1 = data[x++]; |
| | | sensor.surround2 = data[x++]; |
| | | sensor.surround3 = data[x++]; |
| | | sensor.surround4 = data[x++]; |
| | | |
| | | if (sensor.clutch == 1) |
| | | sensor.gear = 0; |
| | | if (sensor.clutch == 1) |
| | | sensor.gear = 0; |
| | | |
| | | UpdateSensor(&sensor); |
| | | } |
| | | if (events & CARD_UPDATE_EVT) { |
| | | DEBUG("CARD_UPDATE_EVT length %d", length); |
| | | UpdateSensor(&sensor); |
| | | break; |
| | | } |
| | | case CARD_UPDATE_EVT: { |
| | | DEBUG("CARD_UPDATE_EVT length %d", length); |
| | | |
| | | int ret = -1; |
| | | int ret = -1; |
| | | |
| | | for (int i = 0; i < length; ++i) { |
| | | if (data[i] != 0) { |
| | | ret = 0; |
| | | break; |
| | | for (int i = 0; i < length; ++i) { |
| | | if (data[i] != 0) { |
| | | ret = 0; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | struct cardBrief brief; |
| | | |
| | | brief.result = ret; |
| | | |
| | | ConvertHex2String(brief.card, data, length); |
| | | |
| | | MA_SendCardBrief(&brief); |
| | | break; |
| | | } |
| | | |
| | | struct cardBrief brief; |
| | | |
| | | brief.result = ret; |
| | | |
| | | ConvertHex2String(brief.card, data, length); |
| | | |
| | | MA_SendCardBrief(&brief); |
| | | } |
| | | if (events & PLAY_TTS_DONE_EVT) { |
| | | tts_back_t *cb = (tts_back_t *) data; |
| | | if (cb->callback != NULL) { |
| | | cb->callback(cb->seq); |
| | | } |
| | | } |
| | | if (events & MASTER_COMM_EVT) { |
| | | union { |
| | | int a; |
| | | uint8_t b[sizeof(int)]; |
| | | } c; |
| | | |
| | | c.b[0] = data[0]; |
| | | c.b[1] = data[1]; |
| | | c.b[2] = data[2]; |
| | | c.b[3] = data[3]; |
| | | |
| | | if (length == 4) |
| | | MA_MainProcMsgEntry(c.a, NULL); |
| | | else { |
| | | MA_MainProcMsgEntry(c.a, (char *) data + 4); |
| | | } |
| | | } |
| | | if (events & BLUETOOTH_STATUS_EVT) { |
| | | DEBUG("BLUETOOTH_STATUS_EVT"); |
| | | uint8_t sta; |
| | | |
| | | if (length == 128) { |
| | | MA_SendBlueStatus((char *)data, (char *)data+64, 3); |
| | | sta = 3; |
| | | } else if (length == 64) { |
| | | MA_SendBlueStatus(NULL, (char *)data, 3); |
| | | sta = 3; |
| | | } else { |
| | | MA_SendBlueStatus(NULL, NULL, data[0]); |
| | | sta = data[0]; |
| | | } |
| | | |
| | | if (sta == 3) { |
| | | // Connected |
| | | btConnected = true; |
| | | ParseMcuInit(); |
| | | ConfigRTKModuleLater(); |
| | | |
| | | PlayTTS("蓝牙连接", NULL); |
| | | } else if (sta == 2) { |
| | | // Disconnect |
| | | btConnected = false; |
| | | PlayTTS("蓝牙断开", NULL); |
| | | } else if (sta == 1) { |
| | | // Open |
| | | btEnable = true; |
| | | |
| | | if (strlen(btAddr) > 0) { |
| | | ConnectToBluetooth(btAddr, NULL); |
| | | case PLAY_TTS_DONE_EVT: { |
| | | tts_back_t *cb = (tts_back_t *) data; |
| | | if (cb->callback != NULL) { |
| | | cb->callback(cb->seq); |
| | | } |
| | | break; |
| | | } |
| | | case MASTER_COMM_EVT: { |
| | | union { |
| | | int a; |
| | | uint8_t b[sizeof(int)]; |
| | | } c; |
| | | |
| | | c.b[0] = data[0]; |
| | | c.b[1] = data[1]; |
| | | c.b[2] = data[2]; |
| | | c.b[3] = data[3]; |
| | | |
| | | if (length == 4) |
| | | MA_MainProcMsgEntry(c.a, NULL); |
| | | else { |
| | | MA_MainProcMsgEntry(c.a, (char *) data + 4); |
| | | } |
| | | break; |
| | | } |
| | | case BLUETOOTH_STATUS_EVT: { |
| | | DEBUG("BLUETOOTH_STATUS_EVT"); |
| | | |
| | | if (!mAyDevice) { |
| | | uint8_t sta; |
| | | |
| | | if (length == 128) { |
| | | MA_SendBlueStatus((char *) data, (char *) data + 64, 3); |
| | | sta = 3; |
| | | } else if (length == 64) { |
| | | MA_SendBlueStatus(NULL, (char *) data, 3); |
| | | sta = 3; |
| | | } else { |
| | | MA_SendBlueStatus(NULL, NULL, data[0]); |
| | | sta = data[0]; |
| | | } |
| | | |
| | | if (sta == 3) { |
| | | // Connected |
| | | btConnected = true; |
| | | ParseMcuInit(); |
| | | ConfigRTKModuleLater(); |
| | | |
| | | PlayTTS("蓝牙连接", NULL); |
| | | } else if (sta == 2) { |
| | | // Disconnect |
| | | if (btConnected) { |
| | | btConnected = false; |
| | | PlayTTS("蓝牙断开", NULL); |
| | | } |
| | | } else if (sta == 1) { |
| | | // Open |
| | | btEnable = true; |
| | | |
| | | if (strlen(btAddr) > 0) { |
| | | ConnectToBluetooth(btAddr, NULL); |
| | | } |
| | | // ConnectToBluetooth("00:1B:35:16:20:4A", NULL); |
| | | // ConnectToBluetooth("00:1B:35:16:20:4A", "3800");`` |
| | | // ConnectToBluetooth("00:1D:43:9A:E0:79", "1900"); |
| | | // ConnectToBluetooth("DESKTOP-IE9V7U8", "0000"); |
| | | PlayTTS("蓝牙启动", NULL); |
| | | } else { |
| | | // Close |
| | | btEnable = false; |
| | | btConnected = false; |
| | | PlayTTS("蓝牙关闭", NULL); |
| | | PlayTTS("蓝牙启动", NULL); |
| | | } else { |
| | | // Close |
| | | btEnable = false; |
| | | btConnected = false; |
| | | PlayTTS("蓝牙关闭", NULL); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | if (events & BLUETOOTH_DATA_EVT) { |
| | | ParseMcu(data, length); |
| | | case BLUETOOTH_DATA_EVT: { |
| | | ParseMcu(data, length); |
| | | break; |
| | | } |
| | | case SENSOR_CHANGE_EVT: { |
| | | SensorXChanged(BUILD_UINT16(data[1], data[0]), BUILD_UINT32(data[5], data[4], data[3], data[2])); |
| | | break; |
| | | } |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | static void RegisterPlatformTimeout(union sigval sig) |
| | | { |
| | | DEBUG("RegisterPlatformTimeout"); |
| | | DEBUG("RTK平台注册超时"); |
| | | AppTimer_delete(RegisterPlatformTimeout); |
| | | RegisterPlatform(); |
| | | } |
| | | |
| | | static void RegisterPlatform(void) |
| | | { |
| | | DEBUG("RTK平台注册..."); |
| | | AppTimer_delete(RegisterPlatformTimeout); |
| | | AppTimer_add(RegisterPlatformTimeout, D_SEC(15)); |
| | | SendDeviceRegister(deviceInfo.province, deviceInfo.city, deviceInfo.device_model, |
| | |
| | | |
| | | static void LoginPlatformTimeout(union sigval sig) |
| | | { |
| | | DEBUG("RTK平台登录超时"); |
| | | AppTimer_delete(LoginPlatformTimeout); |
| | | LoginPlatform(); |
| | | } |
| | | |
| | | static void LoginPlatform(void) |
| | | { |
| | | DEBUG("RTK平台登录..."); |
| | | uint32_t tim = time(NULL); |
| | | uint8_t data[12]; |
| | | uint8_t *ciphertext; |
| | |
| | | AppTimer_delete(LoginPlatformTimeout); |
| | | AppTimer_add(LoginPlatformTimeout, D_SEC(15)); |
| | | |
| | | |
| | | DESEncrypt(platformStatus.platformKey, platformStatus.platformKeyLength, data, 4, &ciphertext); |
| | | |
| | | if (ciphertext != NULL) { |