I am writting a driver for a GPS unit in linux. I can set on the GPS unit what data it should send out it's ethernet port. The data is arranged in structs of different sizes depending on what it is. For example one packet could be for the GPS solution (containing position, velocity, and orientation data). Another packet could be error information. Regardless, each packet starts with a unique ID. So what I want to do is abitrarily read in all packets from the unit and parse them as they come in depending on the packets unique ID. I am not sure how to do this elegantly though. I don't want to do a switch or else if sequence. So:
if(packet_id == 1) parse_gps_solution(packet_data); //function call that parses the data into the correct struct else if(packet_id == 2) parse_gps_error(packet_data); else if(packet_id == 3) parse_raw_gps(packet_data); etc...
This is not what I want. I am trying to see if there is a way I can elegantly parse using the packet ID itself, I am just not sure how I could do this. I would appreciate any and all brain storming suggestions. Any questions, please ask. Thank you.
Edited by spetro3387