some work done..
This commit is contained in:
@@ -6,20 +6,46 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cm_nmea_decoder.h"
|
#include "cm_nmea_decoder.h"
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#define MAX_NMEA_MSG_TYPES 2
|
#define MAX_NMEA_MSG_TYPES 2
|
||||||
const char *nmea_msg_types[MAX_NMEA_MSG_TYPES] = {"$GPGLL", "$GPGFF"};
|
const char *nmea_msg_types[MAX_NMEA_MSG_TYPES] = {"$GPGLL", "$GPGFF"};
|
||||||
typedef int (*nmeaDecoder_Evt_fpt)(cm_nmea_msg_t *inst, char *str);
|
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!
|
//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] = {
|
nmeaDecoder_Evt_fpt nmea_decodeFuncs[1] = {
|
||||||
|
(void *)&sGPGLL_decode,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sNMEA_getMsgType(char *str){
|
static int sNMEA_getMsgType(char *str){
|
||||||
@@ -34,12 +60,12 @@ static int sNMEA_getMsgType(char *str){
|
|||||||
|
|
||||||
int cm_nmea_characterDecode(char in){
|
int cm_nmea_characterDecode(char in){
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function returns the message type, so the user knows which message has been decoded!
|
// 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.
|
// Find which type of message we need to decode.
|
||||||
int nmea_msg_idx = sNMEA_getMsgType(str);
|
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;
|
if(nmea_msg_idx == -1) return nmea_msg_idx;
|
||||||
|
|
||||||
// Use the correct function to decode!
|
// 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,6 @@ typedef struct {
|
|||||||
|
|
||||||
}cm_nmea_msg_t;
|
}cm_nmea_msg_t;
|
||||||
|
|
||||||
|
int cm_nmea_stringDecode(cm_nmea_msg_t *inst, char *str);
|
||||||
|
|
||||||
#endif /* MAIN_CM_NMEA_DECODER_CM_NMEA_DECODER_H_ */
|
#endif /* MAIN_CM_NMEA_DECODER_CM_NMEA_DECODER_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user