| | |
| | | #include "../common/apptimer.h" |
| | | #include "../rtk_platform/platform.h" |
| | | #include "../native-lib.h" |
| | | #include "virtual_rtk.h" |
| | | #include "../mcu/mcu_if.h" |
| | | |
| | | #define DEBUG(fmt, args...) LOGD("<rtk> <%s>: " fmt, __func__, ##args) |
| | | |
| | |
| | | |
| | | static gpsStatus_t gpsStatus; |
| | | |
| | | static int (*WriteRtk)(int id, const void *buf, int len); |
| | | |
| | | static rtk_info CurrRTKInfo; |
| | | static bool needSetPjk = false; |
| | | |
| | | static void CheckPjkParam(void); |
| | | static void CheckPjkParamTimeout(union sigval sig); |
| | | static int WriteBluetooth(int id, const void *buf, int len); |
| | | |
| | | static void *UartThread(void *p); |
| | | |
| | | void RtkCommModeSel(int mode) |
| | | { |
| | | if (mode == 0) { |
| | | WriteRtk = WriteSerialPort; |
| | | } else { |
| | | WriteRtk = WriteBluetooth; |
| | | } |
| | | } |
| | | |
| | | void ConfigRTKModule(void) |
| | | { |
| | |
| | | memset(&gpsStatus, 0, sizeof(gpsStatus)); |
| | | gpsStatus.hh = -1; |
| | | |
| | | static struct serial_config serialConfig; |
| | | RtkCommModeSel(1); |
| | | |
| | | /*static struct serial_config serialConfig; |
| | | |
| | | strcpy(serialConfig.name, "/dev/ttyHSL0"); |
| | | serialConfig.baud = 115200; |
| | |
| | | pthread_attr_t attr; |
| | | pthread_attr_init(&attr); |
| | | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//detached |
| | | pthread_create(&pid, &attr, UartThread, &serialConfig); |
| | | pthread_create(&pid, &attr, UartThread, &serialConfig);*/ |
| | | } |
| | | |
| | | void ConfigRTKModuleLater(void) |
| | | { |
| | | AppTimer_delete(CheckPjkParamTimeout); |
| | | AppTimer_add(CheckPjkParamTimeout, D_SEC(1)); |
| | | } |
| | | |
| | | void FactorySettings(void) |
| | | { |
| | | WriteSerialPort(RTK_MODULE_UART, FACTORY, strlen(FACTORY)); |
| | | WriteRtk(RTK_MODULE_UART, FACTORY, strlen(FACTORY)); |
| | | } |
| | | |
| | | void RebootModule(void) |
| | | { |
| | | WriteSerialPort(RTK_MODULE_UART, REBOOT, strlen(REBOOT)); |
| | | WriteRtk(RTK_MODULE_UART, REBOOT, strlen(REBOOT)); |
| | | } |
| | | |
| | | void handleRTKRebootComp(const struct nmea *s) |
| | |
| | | } |
| | | |
| | | 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; |
| | |
| | | |
| | | void SetAYFactoryParam(int freq) |
| | | { |
| | | WriteSerialPort(RTK_MODULE_UART, UNLOGALL, strlen(UNLOGALL)); |
| | | WriteSerialPort(RTK_MODULE_UART, IFCOM2, strlen(IFCOM2)); |
| | | WriteRtk(RTK_MODULE_UART, UNLOGALL, strlen(UNLOGALL)); |
| | | WriteRtk(RTK_MODULE_UART, IFCOM2, strlen(IFCOM2)); |
| | | |
| | | if (freq == 0) |
| | | freq = 5; |
| | |
| | | for (int i = 0; i < sizeof(PJKITEMS)/ sizeof(PJKITEMS[0]); ++i) { |
| | | char cmd[64]; |
| | | sprintf(cmd, "log com1 %s ontime %0.1f\r\n", PJKITEMS[i], 1.0/(double)freq); |
| | | WriteSerialPort(RTK_MODULE_UART, cmd, strlen(cmd)); |
| | | WriteRtk(RTK_MODULE_UART, cmd, strlen(cmd)); |
| | | } |
| | | |
| | | for (int i = 0; i < sizeof(GPSITEMS)/ sizeof(GPSITEMS[0]); ++i) { |
| | | char cmd[64]; |
| | | sprintf(cmd, "log com1 %s ontime %0.1f\r\n", GPSITEMS[i], 1.0/(double)freq); |
| | | WriteSerialPort(RTK_MODULE_UART, cmd, strlen(cmd)); |
| | | WriteRtk(RTK_MODULE_UART, cmd, strlen(cmd)); |
| | | } |
| | | |
| | | // WriteSerialPort(RTK_MODULE_UART, AY_PJKPARAM, strlen(AY_PJKPARAM)); |
| | |
| | | |
| | | sprintf(buff, "set pjkpara 6378137 298.257223563 0 %d 0 500000\r\n", centLon); |
| | | |
| | | WriteSerialPort(RTK_MODULE_UART, buff, strlen(buff)); |
| | | WriteRtk(RTK_MODULE_UART, buff, strlen(buff)); |
| | | |
| | | DEBUG("%s", buff); |
| | | } |
| | |
| | | |
| | | if (RxBufLen > 0) { |
| | | #if 1 |
| | | const uint8_t *ptr = parseGPS(RxBuf, RxBuf + RxBufLen); |
| | | if(ptr != RxBuf) { |
| | | memcpy(RxBuf, ptr, RxBufLen - (ptr - RxBuf)); |
| | | RxBufLen -= ptr - RxBuf; |
| | | } else if(RxBufLen == PARSE_BUFF_SIZE) { //填满了,且没有一个\r,都抛弃 |
| | | DEBUG("Parse GPS error"); |
| | | if (VirtualIsConnected()) { //PC模拟用时 |
| | | RxBufLen = 0; |
| | | } else { |
| | | const uint8_t *ptr = parseGPS(RxBuf, RxBuf + RxBufLen); |
| | | if (ptr != RxBuf) { |
| | | memcpy(RxBuf, ptr, RxBufLen - (ptr - RxBuf)); |
| | | RxBufLen -= ptr - RxBuf; |
| | | } else if (RxBufLen == PARSE_BUFF_SIZE) { //填满了,且没有一个\r,都抛弃 |
| | | DEBUG("Parse GPS error"); |
| | | RxBufLen = 0; |
| | | } |
| | | } |
| | | #else |
| | | RxBufLen = 0; //PC模拟用时 |
| | |
| | | } |
| | | pthread_exit(NULL); |
| | | } |
| | | |
| | | |
| | | void handleUnrecognisedNMEA(const uint8_t *data, uint16_t length) { |
| | | // char buff[4096] = {0}; |
| | |
| | | |
| | | static void CheckPjkParam(void) |
| | | { |
| | | int n = WriteSerialPort(RTK_MODULE_UART, INQ_PJK_PARAM, strlen(INQ_PJK_PARAM)); |
| | | int n = WriteRtk(RTK_MODULE_UART, INQ_PJK_PARAM, strlen(INQ_PJK_PARAM)); |
| | | DEBUG("CN = %d", n); |
| | | AppTimer_delete(CheckPjkParamTimeout); |
| | | AppTimer_add(CheckPjkParamTimeout, D_SEC(3)); |
| | |
| | | |
| | | CheckPjkParam(); |
| | | } |
| | | |
| | | static int WriteBluetooth(int id, const void *buf, int len) |
| | | { |
| | | // SendToBluetooth((uint8_t *)buf, len); |
| | | SendMcuCommand(0x000B, (uint8_t *)buf, len); |
| | | return len; |
| | | } |