However, I am thinking that I am going to have to add the other code like printing on the LCD to the machine. And I think that it is logical since I am going to have to wait for the data before printing them to the LCD. I started writing some code and please have a look. Or I just want to know if this is possible on a microcontroller.
Some of the function implementations are not included in the code. Just a skelton code.
Code: Select all
typedef enum state{
Idle,
RetrieveMsgID,
RetrieveSentenceData,
RetrieveChecksum,
RetrieveEndOfSentence,
WaitForNextMessage, //Multipart messages, ex: GPGSV
DisplayData,
Timeout
} State;
State _state;
void init_NMEA_FSM(){
_state=Idle;
makeNullTerminating(msgID,6);
while(1){
switch(_state){
case Idle:
idle();
break;
case RetrieveMsgID:
retrieveMsgId();
break;
case RetrieveSentenceData:
retrieveSentenceData();
break;
case RetrieveChecksum:
break;
case RetrieveEndOfSentence:
break;
case WaitForNextMessage:
break;
case DisplayData:
break;
case Timeout:
handleTimeOut();
break;
}
}
}
void idle(){
while(readFromBuffer()!='$'); //Wait for the $ to come along
_state=RetrieveMsgID;//Change the machine state
}
void retrieveMsgId(){
readNextParameter(msgID);
_state=RetrieveSentenceData;
}
void retrieveSentenceData(){
if(strcmp(msgID,"GPGLL")==0){//processGLL
}
}
void handleTimeOut(){
_state=Idle;
}
}