Last active
July 3, 2018 19:41
-
-
Save mws-rmain/4bf77f93968e2c62ca3078c76bb1e19d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QueueHandle_t gMsgGPS = NULL; | |
#define RX_DATA_SZ 63 | |
/* | |
---------------------------------------------------------------------------*/ | |
static void gps_rx_task(void *arg) | |
{ | |
struct ST_GPS_MSG msg; | |
static uint8_t data[RX_DATA_SZ+1]; | |
uint8_t *pCh; | |
uint8_t ch; | |
// const size_t xTriggerLevel = 1; | |
int i; | |
int rxBytes; | |
ESP_LOGI( TAG, "core:[%d] gps_rx_task()", xPortGetCoreID() ); | |
msgNdx = 0; | |
while (msgNdx < MSG_BUFFERS) | |
{ | |
msgBuff[msgNdx][0] = 0; | |
msgNdx++; | |
} | |
msgCounter = 0; | |
msgNdx = 0; | |
msgLen = 0; | |
pMsg = &msgBuff[msgNdx][0]; | |
static const char *RX_TASK_TAG = "GPS_RX"; | |
esp_log_level_set(RX_TASK_TAG, ESP_LOG_WARN); | |
while (1) { | |
rxBytes = uart_read_bytes(GPS_UART, data, RX_DATA_SZ, 1000 / portTICK_RATE_MS); | |
if (rxBytes > 0) { | |
if (dataDirectToGPS) | |
{ | |
// send received data directly out the diagnostic port | |
// uart_write_bytes(DIAG_UART, data, rxBytes ); | |
} else if (simulate) | |
{ | |
// Simulating - ignore anything coming in the serial port | |
msgNdx = 0; // Reset this, ready for next string | |
} else | |
{ | |
data[rxBytes] = 0; | |
// ESP_LOGI(RX_TASK_TAG, "Read %d bytes: '%s'", rxBytes, data); | |
// ESP_LOG_BUFFER_HEXDUMP(RX_TASK_TAG, data, rxBytes, ESP_LOG_INFO); | |
pCh = &data[0]; | |
for (i=0; (i<rxBytes); i++) { | |
ch = *pCh; | |
pCh++; | |
if (ch != '\n') { | |
if (ch == '$') { | |
// restart current message (no proper termination found?) | |
pMsg = &msgBuff[msgNdx][0]; | |
msgLen = 0; | |
} else if (ch != '\r') { | |
*pMsg = ch; | |
if (msgLen < (MSG_MAX_LENGTH-1)) { | |
msgLen++; | |
pMsg++; | |
} | |
} else | |
{ | |
*pMsg = 0; // terminate the string | |
if ((qMsgGPS != NULL) && (uxQueueSpacesAvailable( qMsgGPS ) >= 1)) { | |
msg.num = msgCounter++; | |
msg.ptr = &msgBuff[msgNdx][0]; | |
// ESP_LOGI(TAG, "msg.%d,len=%d[%s]", msg.num, msgLen, msg.ptr ); | |
xQueueSend(qMsgGPS, (void *)&msg, 0 ); | |
if ((++msgNdx) >= MSG_BUFFERS) | |
msgNdx = 0; | |
pMsg = &msgBuff[msgNdx][0]; | |
msgLen = 0; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
... | |
qMsgGPS = xQueueCreate(20, sizeof(struct ST_GPS_MSG)); | |
if (qMsgGPS == NULL) | |
ESP_LOGE( TAG, "!!! GPS Queue creation failed" ); | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment