some work done..

This commit is contained in:
Christian Lind Vie Madsen
2025-06-26 16:11:40 +02:00
parent e1d6b6d52b
commit 59c08f05f8
2 changed files with 35 additions and 7 deletions

View File

@@ -6,20 +6,46 @@
*/
#include "cm_nmea_decoder.h"
#include <stdlib.h>
#include <string.h>
#define MAX_NMEA_MSG_TYPES 2
const char *nmea_msg_types[MAX_NMEA_MSG_TYPES] = {"$GPGLL", "$GPGFF"};
typedef int (*nmeaDecoder_Evt_fpt)(cm_nmea_msg_t *inst, char *str);
static int sGPGLL_decode(char *str){
static int findLenToChar(const char *str, const char character){
int i = 0;
while((str[i] != character) && (str[i] != '\0')) i++;
return i;
}
static int sGPGLL_decode(cm_nmea_msg_t *inst, char *str){
//Move pointer until we meet a "," or NULL!
while((*str != ",") && (*str != NULL)) str++;
while((str != NULL) && (*str != ',')) str++;
// Move past ','
if (*str == ',') str++;
// Find comma
int comma_idx = findLenToChar(str, '.');
// Replace with '\0'
str[comma_idx] = '\0';
// Decode first part of latitude
inst->gpgll_msg.coordinates.deg = atoi(str);
printf("deg: %d, str: %s \r\n ",comma_idx,str);
return 0;
}
nmeaDecoder_Evt_fpt nmea_decodeFuncs[1] = {
(void *)&sGPGLL_decode,
};
static int sNMEA_getMsgType(char *str){
@@ -34,12 +60,12 @@ static int sNMEA_getMsgType(char *str){
int cm_nmea_characterDecode(char in){
return 0;
}
// This function returns the message type, so the user knows which message has been decoded!
int cm_nmea_stringDecode(char *str){
int cm_nmea_stringDecode(cm_nmea_msg_t *inst, char *str){
// Find which type of message we need to decode.
int nmea_msg_idx = sNMEA_getMsgType(str);
@@ -48,6 +74,8 @@ int cm_nmea_stringDecode(char *str){
if(nmea_msg_idx == -1) return nmea_msg_idx;
// Use the correct function to decode!
if(nmea_msg_idx >= 0) nmea_msg_types[nmea_msg](str);
if(nmea_msg_idx >= 0) nmea_decodeFuncs[nmea_msg_idx](inst,str);
return nmea_msg_idx;
}