| | |
| | | const static char SAVECONFIG[] = "saveconfig\r\n"; |
| | | const static char *PJKITEMS[] = {"gptra", "ptnlpjk"}; |
| | | const static char *GPSITEMS[] = {"gpgga", "gprmc", "gpvtg"}; |
| | | const char CMD_VERSION[] = "log version\r\n"; |
| | | |
| | | static gpsStatus_t gpsStatus; |
| | | static char rtkModel[32] = {0}; |
| | | |
| | | static int (*WriteRtk)(int id, const void *buf, int len); |
| | | |
| | | static rtk_info CurrRTKInfo; |
| | | static bool needSetPjk = false; |
| | | static int lostCnt; |
| | | |
| | | static void CheckPjkParam(void); |
| | | static void CheckPjkParamTimeout(union sigval sig); |
| | | static int WriteBluetooth(int id, const void *buf, int len); |
| | | static void GetModuleVersion(void); |
| | | |
| | | static void VersionTimeout(union sigval sig); |
| | | static void GpsDataTimeout(union sigval sig); |
| | | |
| | | static void *UartThread(void *p); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | void ConfigRTKModule(void) |
| | | void ConfigRTKModule(bool ayDevice) |
| | | { |
| | | // TODO |
| | | DEBUG("ConfigRTKModule"); |
| | |
| | | memset(&gpsStatus, 0, sizeof(gpsStatus)); |
| | | gpsStatus.hh = -1; |
| | | |
| | | RtkCommModeSel(1); |
| | | if (ayDevice) { |
| | | RtkCommModeSel(0); |
| | | |
| | | /*static struct serial_config serialConfig; |
| | | static struct serial_config serialConfig; |
| | | |
| | | strcpy(serialConfig.name, "/dev/ttyHSL0"); |
| | | serialConfig.baud = 115200; |
| | | serialConfig.data_bit = 8; |
| | | serialConfig.verify_bit = 'N'; |
| | | serialConfig.stop_bit = 1; |
| | | serialConfig.flow_ctrl = 0; |
| | | strcpy(serialConfig.name, "/dev/ttyHSL0"); |
| | | serialConfig.baud = 115200; |
| | | serialConfig.data_bit = 8; |
| | | serialConfig.verify_bit = 'N'; |
| | | serialConfig.stop_bit = 1; |
| | | serialConfig.flow_ctrl = 0; |
| | | |
| | | pthread_t pid; |
| | | pthread_attr_t attr; |
| | | pthread_attr_init(&attr); |
| | | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//detached |
| | | pthread_create(&pid, &attr, UartThread, &serialConfig);*/ |
| | | pthread_t pid; |
| | | pthread_attr_t attr; |
| | | pthread_attr_init(&attr); |
| | | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//detached |
| | | pthread_create(&pid, &attr, UartThread, &serialConfig); |
| | | } else { |
| | | RtkCommModeSel(1); |
| | | // 等待蓝牙连接 |
| | | } |
| | | } |
| | | |
| | | // 蓝牙连接后 |
| | | void ConfigRTKModuleLater(void) |
| | | { |
| | | AppTimer_delete(GpsDataTimeout); |
| | | AppTimer_delete(VersionTimeout); |
| | | AppTimer_delete(CheckPjkParamTimeout); |
| | | AppTimer_add(CheckPjkParamTimeout, D_SEC(1)); |
| | | } |
| | |
| | | void handleRTKRebootComp(const struct nmea *s) |
| | | { |
| | | DEBUG("RTK Reboot complete!!"); |
| | | CheckPjkParam(); |
| | | // CheckPjkParam(); |
| | | GetModuleVersion(); |
| | | } |
| | | |
| | | void handlePJKParam(const struct nmea *s) { |
| | | DEBUG("handlePJKParam"); |
| | | //PJK Parameter: A:6378137.000, 1/F:298.257223563, B0:0.000000deg, L0:120.000000, N0:0.000, E0:500000.000. |
| | | //PJK Parameter: A:6378137.000, 1/F:298.257223563, B0:29.512453deg, L0:106.455336, N0:0.000, E0:0.000. |
| | | // bool setparam = true; |
| | | // |
| | | // const char DP1[] = "A:6378137.000"; |
| | | // const char DP2[] = "1/F:298.257223563"; |
| | | // const char DP3[] = "B0:29.512453deg"; |
| | | // const char DP4[] = "L0:106.455336"; |
| | | // const char DP5[] = "N0:0.000"; |
| | | // const char DP6[] = "E0:0.000"; |
| | | |
| | | AppTimer_delete(CheckPjkParamTimeout); |
| | | |
| | | // for (int i = 0; i < s->nmea_num; ++i) { |
| | | // char out[64] = {0}; |
| | | // |
| | | // memcpy(out, s->nmea_value[i].data, s->nmea_value[i].length); |
| | | // |
| | | // DEBUG("handlePJKParam = %s", out); |
| | | // } |
| | | // |
| | | // if (s->nmea_num != 6) return; |
| | | // |
| | | // if (memcmp(s->nmea_value[0].data, DP1, strlen(DP1))) { |
| | | // setparam = true; |
| | | // } |
| | | // if (memcmp(s->nmea_value[1].data, DP2, strlen(DP2))) { |
| | | // setparam = true; |
| | | // } |
| | | // if (memcmp(s->nmea_value[2].data, DP3, strlen(DP3))) { |
| | | // setparam = true; |
| | | // } |
| | | // if (memcmp(s->nmea_value[3].data, DP4, strlen(DP4))) { |
| | | // setparam = true; |
| | | // } |
| | | // if (memcmp(s->nmea_value[4].data, DP5, strlen(DP5))) { |
| | | // setparam = true; |
| | | // } |
| | | // if (memcmp(s->nmea_value[5].data, DP6, strlen(DP6))) { |
| | | // setparam = true; |
| | | // } |
| | | // |
| | | // if (setparam) { |
| | | // SetAYFactoryParam(5); |
| | | // } |
| | | |
| | | SetAYFactoryParam(5); |
| | | needSetPjk = true; |
| | | |
| | | lostCnt = 0; |
| | | AppTimer_delete(GpsDataTimeout); |
| | | AppTimer_add(GpsDataTimeout, D_SEC(5)); |
| | | |
| | | uint8_t buff[33]; |
| | | |
| | | memcpy(buff, rtkModel, 32); |
| | | buff[32] = 1; |
| | | PlatformStatusChanged(RTK_STATUS_EVT, buff, 33); |
| | | } |
| | | |
| | | void SetAYFactoryParam(int freq) |
| | |
| | | int RxBufLen = 0; |
| | | |
| | | if (res == 0) { |
| | | CheckPjkParam(); |
| | | // CheckPjkParam(); |
| | | GetModuleVersion(); |
| | | } |
| | | |
| | | while (res == 0) { |
| | |
| | | if (RxBufLen > 0) { |
| | | #if 1 |
| | | if (VirtualIsConnected()) { //PC模拟用时 |
| | | static bool first = false; |
| | | |
| | | if (!first) { |
| | | first = true; |
| | | |
| | | uint8_t buff[33] = "emulator"; |
| | | buff[32] = 1; |
| | | PlatformStatusChanged(RTK_STATUS_EVT, buff, 33); |
| | | } |
| | | RxBufLen = 0; |
| | | } else { |
| | | const uint8_t *ptr = parseGPS(RxBuf, RxBuf + RxBufLen); |
| | |
| | | } |
| | | |
| | | void handleUnrecognisedNMEA(const uint8_t *data, uint16_t length) { |
| | | // char buff[4096] = {0}; |
| | | // memcpy(buff, data, MIN(length, 3000)); |
| | | char buff[4096] = {0}; |
| | | memcpy(buff, data, MIN(length, 4000)); |
| | | // DEBUG("handleUnrecognisedNMEA: %s", buff); |
| | | |
| | | if (length >= 100) { |
| | | string cs(buff); |
| | | |
| | | if (cs.find("K708") != string::npos) { |
| | | // 最初的标准基站模块 |
| | | DEBUG("K708 模块"); |
| | | strcpy(rtkModel, "K708"); |
| | | |
| | | AppTimer_delete(VersionTimeout); |
| | | CheckPjkParam(); |
| | | } else if (cs.find("K726") != string::npos) { |
| | | // 移动站模块,也可以用做基站功能 |
| | | DEBUG("K726 模块"); |
| | | strcpy(rtkModel, "K726"); |
| | | |
| | | AppTimer_delete(VersionTimeout); |
| | | CheckPjkParam(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void handleGPGGA(const struct nmea *s) |
| | | { |
| | | static uint32_t qfCnt = 0; |
| | | |
| | | DEBUG("handleGPGGA num = %d", s->nmea_num); |
| | | // DEBUG("handleGPGGA num = %d", s->nmea_num); |
| | | if (s->nmea_num >= 10) { |
| | | lostCnt = 0; |
| | | AppTimer_delete(GpsDataTimeout); |
| | | AppTimer_add(GpsDataTimeout, D_SEC(5)); |
| | | |
| | | gpsStatus.gps_status = str2int(s->nmea_value[5].data, s->nmea_value[5].length); |
| | | |
| | | int hh = str2int(s->nmea_value[0].data, 2); |
| | |
| | | |
| | | void handleGPRMC(const struct nmea *s) |
| | | { |
| | | DEBUG("handleGPRMC num = %d", s->nmea_num); |
| | | // DEBUG("handleGPRMC num = %d", s->nmea_num); |
| | | |
| | | if (s->nmea_num >= 9) { |
| | | int hh = str2int(s->nmea_value[0].data, 2); |
| | |
| | | } |
| | | |
| | | void handlePJK(const struct nmea *s) { |
| | | DEBUG("handlePJK num = %d", s->nmea_num); |
| | | // DEBUG("handlePJK num = %d", s->nmea_num); |
| | | |
| | | int hh = str2int(s->nmea_value[0].data, 2); |
| | | int mm = str2int(s->nmea_value[0].data + 2, 2); |
| | |
| | | } |
| | | |
| | | void handleGPTRA(const struct nmea *s) { |
| | | DEBUG("handleGPTRA num = %d", s->nmea_num); |
| | | // DEBUG("handleGPTRA num = %d", s->nmea_num); |
| | | |
| | | int hh = str2int(s->nmea_value[0].data, 2); |
| | | int mm = str2int(s->nmea_value[0].data + 2, 2); |
| | |
| | | |
| | | static void CheckPjkParam(void) |
| | | { |
| | | int n = WriteRtk(RTK_MODULE_UART, INQ_PJK_PARAM, strlen(INQ_PJK_PARAM)); |
| | | DEBUG("CN = %d", n); |
| | | WriteRtk(RTK_MODULE_UART, INQ_PJK_PARAM, strlen(INQ_PJK_PARAM)); |
| | | DEBUG("获取PJK参数..."); |
| | | AppTimer_delete(CheckPjkParamTimeout); |
| | | AppTimer_add(CheckPjkParamTimeout, D_SEC(3)); |
| | | } |
| | |
| | | static void CheckPjkParamTimeout(union sigval sig) { |
| | | AppTimer_delete(CheckPjkParamTimeout); |
| | | |
| | | DEBUG("RTK Module failure!!"); |
| | | DEBUG("获取PJK参数超时"); |
| | | |
| | | // PlayTTS("RTK模块无法通讯", NULL); |
| | | uint8_t buff[33]; |
| | | memcpy(buff, rtkModel, 32); |
| | | buff[32] = 0; |
| | | PlatformStatusChanged(RTK_STATUS_EVT, buff, 33); |
| | | |
| | | CheckPjkParam(); |
| | | GetModuleVersion(); |
| | | } |
| | | |
| | | static int WriteBluetooth(int id, const void *buf, int len) |
| | |
| | | SendMcuCommand(0x000B, (uint8_t *)buf, len); |
| | | return len; |
| | | } |
| | | |
| | | static void GetModuleVersion(void) |
| | | { |
| | | AppTimer_delete(VersionTimeout); |
| | | AppTimer_add(VersionTimeout, D_SEC(3)); |
| | | WriteRtk(RTK_MODULE_UART, CMD_VERSION, strlen(CMD_VERSION)); |
| | | |
| | | DEBUG("获取版本..."); |
| | | } |
| | | |
| | | static void VersionTimeout(union sigval sig) |
| | | { |
| | | AppTimer_delete(VersionTimeout); |
| | | DEBUG("版本获取超时"); |
| | | GetModuleVersion(); |
| | | |
| | | uint8_t buff[33]; |
| | | memcpy(buff, rtkModel, 32); |
| | | buff[32] = 0; |
| | | PlatformStatusChanged(RTK_STATUS_EVT, buff, 33); |
| | | } |
| | | |
| | | static void GpsDataTimeout(union sigval sig) |
| | | { |
| | | AppTimer_delete(GpsDataTimeout); |
| | | |
| | | if (++lostCnt >= 3) { |
| | | DEBUG("RTK模块收不到GPS数据"); |
| | | GetModuleVersion(); |
| | | } else { |
| | | AppTimer_add(GpsDataTimeout, D_SEC(5)); |
| | | } |
| | | } |