From 3b7d1e5993cb40704a7ed752a2955803ffc0a6d4 Mon Sep 17 00:00:00 2001 From: adrcs Date: Mon, 10 Feb 2025 13:03:31 -0700 Subject: [PATCH] Updated to Rev 04b --- code/IP400/Src/beacon.c | 68 +++++++++++++++++++++++++++++++++++++++++ code/IP400/Src/chat.c | 6 ++++ code/IP400/Src/usart.c | 14 ++++++++- code/IP400/Src/utils.c | 19 ++++++++++-- 4 files changed, 104 insertions(+), 3 deletions(-) diff --git a/code/IP400/Src/beacon.c b/code/IP400/Src/beacon.c index 00efa55..a802db5 100644 --- a/code/IP400/Src/beacon.c +++ b/code/IP400/Src/beacon.c @@ -49,6 +49,7 @@ #define GPS_FIX_LEN 20 // gps fix length #define GPS_BFR_SIZE 140 // GPS buffer size +#if __ENABLE_GPS // NMEA GGA Sentence fields char *nmeaMsgTag = "RMC"; // sentence we are processing enum { @@ -68,6 +69,35 @@ enum { NMEA_STATE_MSG, // in the message }; +#define N_NMEA_SEN 14 // number of NMEA sentences +enum { + NMEA_CMD_DISABLED=0, // disabled + NMEA_CMD_ONCE, // once per fix + NMEA_CMD_2FIX, // once every 2 fixes + NMEA_CMD_3FIX, // once every 3 fixes + NMEA_CMD_4FIX, // once every 4 fixes + NMEA_CMD_5FIX, // once every 5 fixes +}; + +char *nmeaCmd = "$PMTK314"; // command +uint8_t senCmds[N_NMEA_SEN] = { + NMEA_CMD_DISABLED, // 0:GLL disabled + NMEA_CMD_ONCE, // 1: RMC once + NMEA_CMD_DISABLED, // 2: VTG disabled + NMEA_CMD_DISABLED, // 3: GGA disabled + NMEA_CMD_DISABLED, // 4: GSA disabled + NMEA_CMD_DISABLED, // 5: GSV disabled + NMEA_CMD_DISABLED, // 6 not used + NMEA_CMD_DISABLED, // 7 + NMEA_CMD_DISABLED, // 13 + NMEA_CMD_DISABLED, // 14 + NMEA_CMD_DISABLED, // 15 + NMEA_CMD_DISABLED, // 16 + NMEA_CMD_DISABLED, // 17 + NMEA_CMD_DISABLED // 18 +}; +#endif + // hemispheres enum { N_HEMI=0, // North @@ -97,6 +127,7 @@ uint8_t GPSProcBuf[GPS_BFR_SIZE]; uint8_t *GPSBufPtr; uint8_t GPSMsgSize; uint8_t NMEAState; +char cmdBuf[MAX_BEACON]; // BOOL haveGPSFix = FALSE; BOOL gpsEchoReady=FALSE; @@ -108,6 +139,7 @@ char *gpsFlds[GPS_BFR_SIZE]; // fwd Refs in this module in GPS mode BOOL processGPSMessage(uint8_t *GPSMsgBuf, uint8_t bufferSize); +void sendGPSCmd(void); #endif //fwd refs w/o GPS @@ -158,6 +190,11 @@ void Beacon_Task_exec(void) } timerCtrValue = timerInitValue; +#if __ENABLE_GPS + // send a command to the GPS every beacon interval + sendGPSCmd(); +#endif + // start with the header beacon_hdr.setup.flags = setup_memory.params.setup_data.flags; beacon_hdr.setup.txPower = setup_memory.params.radio_setup.outputPower; @@ -288,6 +325,37 @@ void GPS_Task_exec(void) } #if __ENABLE_GPS +/* + * Send a command to the GPS device to limit traffic + */ +void sendGPSCmd(void) +{ + uint8_t cksum = 0; + char *buf = cmdBuf; + strcpy(buf, nmeaCmd); + buf += strlen(nmeaCmd); + + for(int j=1;j", entCall); dp = dest_call; diff --git a/code/IP400/Src/usart.c b/code/IP400/Src/usart.c index 150a6f5..b4f0d73 100644 --- a/code/IP400/Src/usart.c +++ b/code/IP400/Src/usart.c @@ -237,8 +237,12 @@ void USART_Print_string(char *format, ...) // Transmit completed: trigger semaphore void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { +#if __ENABLE_GPS + // Not interested in LPUART + if(huart->Instance == LPUART1) + return; +#endif BaseType_t xHigherPriorityTaskWoken = pdFALSE; - xSemaphoreGiveFromISR(txCompleted, &xHigherPriorityTaskWoken); } @@ -269,6 +273,14 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) } #if __ENABLE_GPS +// send a string to the LPUART +void LPUART_Send_String(char *str, uint16_t len) +{ + // send using interrupt + HAL_UART_Transmit_IT(&hlpuart1, (const uint8_t *)str, len); +} + + // receive a byte with DMA, wait for DMA completed interrupt void LPUART_Receive_char(void) { diff --git a/code/IP400/Src/utils.c b/code/IP400/Src/utils.c index 47f4281..6d5e370 100644 --- a/code/IP400/Src/utils.c +++ b/code/IP400/Src/utils.c @@ -39,13 +39,28 @@ int ascii2Dec(char *dec) return retval*sgn; } +// nibble to ascii +char nib2ascii(uint8_t nib) +{ + char anib = (char)(nib + '0'); + anib = (anib > '9') ? anib+('A'-'9') : anib; + return anib; +} + +// hex to ascii +void hex2ascii(uint8_t hex, char *buf) +{ + *buf++= nib2ascii(hex>>4); + *buf = nib2ascii(hex & 0xf); +} + // see if an entry is floating point BOOL isfloat(char *val) { while(*val) if(*val++ == '.') - return TRUE; - return FALSE; + return 1U; + return 0U; } // convert an ascii string to a double