[Firebug-cvs] fireboard/fireboard/sensors/leadtek9546 UART1.nc,1.2,1.3 gps_driverM.nc,1.4,1.5 leadte
Brought to you by:
doolin
From: <do...@us...> - 2004-01-15 03:22:28
|
Update of /cvsroot/firebug/fireboard/fireboard/sensors/leadtek9546 In directory sc8-pr-cvs1:/tmp/cvs-serv13615 Modified Files: UART1.nc gps_driverM.nc leadtek_9546.h Removed Files: GpsC.nc HPLUARTC1.nc Log Message: Removed files containing code that was not used. Index: UART1.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/fireboard/sensors/leadtek9546/UART1.nc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** UART1.nc 14 Jan 2004 16:59:16 -0000 1.2 --- UART1.nc 15 Jan 2004 03:22:25 -0000 1.3 *************** *** 75,82 **** } implementation { ! components UARTM, HPLUARTC1; ByteComm = UARTM; Control = UARTM; ! UARTM.HPLUART -> HPLUARTC1; } --- 75,84 ---- } implementation { ! //components UARTM, HPLUARTC1; ! components UARTM, HPLUARTC; ByteComm = UARTM; Control = UARTM; ! //UARTM.HPLUART -> HPLUARTC1; ! UARTM.HPLUART -> HPLUARTC; } Index: gps_driverM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/fireboard/sensors/leadtek9546/gps_driverM.nc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** gps_driverM.nc 14 Jan 2004 14:54:39 -0000 1.4 --- gps_driverM.nc 15 Jan 2004 03:22:25 -0000 1.5 *************** *** 22,26 **** command void readGps(); ! command void stopGps(); command uint8_t extract_hours(char * data); --- 22,26 ---- command void readGps(); ! command uint8_t extract_hours(char * data); *************** *** 32,40 **** command uint16_t extract_Long_dec_min(char * data); command uint8_t extract_NSEWind(char * data); command result_t isGGA(uint8_t * data); - command result_t parseGGA(int8_t gga_string[GPS_MSG_LENGTH], uint8_t length); - command result_t logGPS(char gga_fields[GPS_FIELDS][GPS_CHAR_PER_FIELD]); command result_t log_gga_data_to_eeprom(GGA_Msg * pGGA); --- 32,45 ---- command uint16_t extract_Long_dec_min(char * data); command uint8_t extract_NSEWind(char * data); + command uint8_t extract_num_sats(char * data); command result_t isGGA(uint8_t * data); + command result_t parse_gga(GPS_Msg * gps_data); + command uint8_t get_gps_fix(char * data); + + command void spew_to_uart(GPS_Msg * gps_data); + + command result_t load_gga_struct(char gga_fields[GGA_FIELDS][GPS_CHAR_PER_FIELD]); command result_t log_gga_data_to_eeprom(GGA_Msg * pGGA); *************** *** 62,69 **** #define DBG_USR2 1 ! char state; ! char gps_state; ! GGA_Msg gga_msg; enum {IDLE, BUSY, BUSY_0, BUSY_1, GET_SAMPLE_0, GET_SAMPLE_1, --- 67,80 ---- #define DBG_USR2 1 ! uint8_t state; ! uint8_t gps_state; ! GGA_Msg gga_msg = {0}; ! ! /** This is essentially thread safe, because once it is ! * set, it will only reset to 0. Read the NMEA specs ! * to determine the values. ! */ ! norace uint8_t gps_fix = 0; enum {IDLE, BUSY, BUSY_0, BUSY_1, GET_SAMPLE_0, GET_SAMPLE_1, *************** *** 77,81 **** /** Control.init in GpsPacket.nc */ call GpsControl.init(); ! SODbg(DBG_USR2, "gps_driverM.StdControl.init()\n"); return SUCCESS; } --- 88,92 ---- /** Control.init in GpsPacket.nc */ call GpsControl.init(); ! SODbg(DBG_USR2, "gps_driverM.StdControl.init()\r\n"); return SUCCESS; } *************** *** 99,119 **** - command void stopGps() { - - if (call GpsCmd.PowerSwitch(GPS_POWER_OFF)) { - - SODbg(DBG_USR2,"gps_driverM.StdControl.stop(): GPS sensor powered off.\n"); - gps_state = GPS_FINISHED; - } - } - /** Ok, this function turns on the gps unit for reading, * which is turned of elsewhere when the read is finished. * If the read isn't finished, the function exits. */ command void readGps() { if (gps_state == GPS_WORKING) { ! SODbg(DBG_USR2, "gps_driverM.readGps(): GPS_WORKING\n"); return; } --- 110,124 ---- /** Ok, this function turns on the gps unit for reading, * which is turned of elsewhere when the read is finished. * If the read isn't finished, the function exits. + * + * FIXME: Get rid of this function, move the code into the + * appropriate Sensor interface function. */ command void readGps() { if (gps_state == GPS_WORKING) { ! SODbg(DBG_USR2, "gps_driverM.readGps(): GPS_WORKING\r\n"); return; } *************** *** 121,129 **** /* Implementation is in GpsPacket.nc */ if (call GpsCmd.PowerSwitch(GPS_POWER_ON)) { ! SODbg(DBG_USR2, "gps_driverM.readGps(): GPS powered on\n"); gps_state = GPS_WORKING; } } event result_t PowerSwitch.getDone(char value) { return SUCCESS; --- 126,135 ---- /* Implementation is in GpsPacket.nc */ if (call GpsCmd.PowerSwitch(GPS_POWER_ON)) { ! SODbg(DBG_USR2, "gps_driverM.readGps(): GPS powered on\r\n"); gps_state = GPS_WORKING; } } + event result_t PowerSwitch.getDone(char value) { return SUCCESS; *************** *** 131,134 **** --- 137,142 ---- event result_t PowerSwitch.setDone(bool local_result) { + SODbg(DBG_USR2,"gps_driverM.PowerSwitch.setDone()\r\n"); + //gps_state = GPS_FINISHED; return SUCCESS; } *************** *** 139,143 **** - event result_t IOSwitch.getDone(char value) { return SUCCESS; --- 147,150 ---- *************** *** 170,174 **** (data[4] == 'M') && (data[5] == 'C')) { ! return TRUE; } else { --- 177,181 ---- (data[4] == 'M') && (data[5] == 'C')) { ! return FALSE; } else { *************** *** 208,265 **** ! command result_t logGPS(char gga_fields[GPS_FIELDS][GPS_CHAR_PER_FIELD]) { ! ! ! char NS; ! char EW; ! //uint8_t j; ! uint8_t nos; // number of satellites ! ! //gga_msg.hours = 10*(gga_fields[1][0]-'0') + (gga_fields[1][1]-'0'); ! gga_msg.hours = call extract_hours(gga_fields[1]); ! ! //gga_msg.minutes = 10*(gga_fields[1][2]-'0') + (gga_fields[1][3]-'0'); ! gga_msg.minutes = call extract_minutes(gga_fields[1]); ! ! //gga_msg.dec_sec = 10000*(gga_fields[1][4]-'0') + 1000*(gga_fields[1][5]-'0') ! // + 100*(gga_fields[1][7]-'0') + 10*(gga_fields[1][8]-'0') ! // + (gga_fields[1][9]-'0'); ! gga_msg.dec_sec = call extract_dec_sec(gga_fields[1]); ! ! ! gga_msg.Lat_deg = 10*(gga_fields[2][0]-'0') + (gga_fields[2][1]-'0'); ! ! gga_msg.Lat_dec_min = 100000*(gga_fields[2][2]-'0') + 10000*(gga_fields[2][3]-'0') ! + 1000*(gga_fields[2][4]-'0') + 100*(gga_fields[2][5]-'0') ! + 10*(gga_fields[2][6]-'0') + (gga_fields[2][7]-'0'); ! ! ! gga_msg.Long_deg = 100*(gga_fields[4][0]-'0') + 10*(gga_fields[4][1]-'0') ! + (gga_fields[4][2]-'0'); ! ! gga_msg.Long_dec_min = 100000*(gga_fields[4][3]-'0') + 10000*(gga_fields[4][4]-'0') ! + 1000*(gga_fields[4][5]-'0') + 100*(gga_fields[4][6]-'0') ! + 10*(gga_fields[4][7]-'0') + (gga_fields[4][8]-'0'); ! ! NS = (gga_fields[3][0] == 'N') ? 1 : 0; ! EW = (gga_fields[5][0] == 'W') ? 1 : 0; ! gga_msg.NSEWind = EW | (NS<<4); // eg. Status = 000N000E = 00010000 ! ! ! nos = 10*(gga_fields[7][0]-'0') + (gga_fields[7][1]-'0'); ! ! ! return SUCCESS; ! } ! ! ! ! /////////// Make this into a function for spewing data ! ///// out of the UART. ! #if 0 ! command void spewUART(uint8_t data) { ! int i; ! for (i=0; i<=gps_data->data[0]; i++) { /** UARTPutChar is an SODebug function. * FIXME: Change this to use a char[]. --- 215,222 ---- ! command void spew_to_uart(GPS_Msg * gps_data) { ! int i; ! for (i=0; i<=gps_data->length; i++) { /** UARTPutChar is an SODebug function. * FIXME: Change this to use a char[]. *************** *** 267,273 **** UARTPutChar(gps_data->data[i]); } ! SODbg(DBG_USR2, "\n"); ! } ! #endif --- 224,230 ---- UARTPutChar(gps_data->data[i]); } ! SODbg(DBG_USR2, "\r\n"); ! } ! *************** *** 284,372 **** event TOS_MsgPtr GpsReceive.receive(TOS_MsgPtr data) { - //uint8_t i; GPS_MsgPtr gps_data = (GPS_MsgPtr)data; - /** Save these for now. */ - //int8_t gga_string[GPS_MSG_LENGTH]; - //bool gga_read = FALSE; - //bool gga_read_done = FALSE; - - call Leds.greenToggle(); - - signal Sensor.dataReady((void*)gps_data); - - return data; - - //Don't worry about this for now. if ((call isGGA(gps_data->data))) { ! SODbg(DBG_USR2, "gps_driverM.GpsReceive.receive() GGA Data\n"); ! signal Sensor.dataReady(gps_data); ! signal Sensor.dataReady((void*)gps_gga_mask); } - - #if 0 - uint8_t j = 0; - gga_read = TRUE; - gga_read_done = FALSE; ! while (!gga_read_done) { ! if(gps_data->data[i] == GPS_END_MSG) { ! if(gga_read) { - call stopGps(); - call parseGGA(gga_string, j); - gga_read = FALSE; - gga_read_done = TRUE; - } - } ! if(gga_read) { ! gga_string[j] = gps_data->data[i]; ! j++; ! } ! i++; ! } - } ! signal Sensor.dataReady(gps_data); ! #endif ! return data; } ! event result_t GpsSend.sendDone(TOS_MsgPtr msg, result_t success) { ! SODbg(DBG_USR2, "GpsSend.sendDone(): state: %i \n", state); ! return SUCCESS; ! } ! event result_t GpsCmd.SwitchesSet(uint8_t PowerState) { ! //SODbg(DBG_USR2, "gps_new.GpsCmd.SwitchesSet(): PowerState: %i \n\n", PowerState); ! call Leds.yellowOn(); ! call Leds.redOff(); return SUCCESS; } ! //**************** ! //*Parse GPS Data*http://www.ce.berkeley.edu/~mchen/ ! //**************** ! //* ! //* Fields are comma delimited ! //* NMEA string parsed by field and stored into ! //* gga_fields array ! ! ! command result_t parseGGA(int8_t gga_string[GPS_MSG_LENGTH], uint8_t length) { ! char gga_fields[GPS_FIELDS][GPS_CHAR_PER_FIELD]; // = {{0}}; bool end_of_field = FALSE; --- 241,318 ---- event TOS_MsgPtr GpsReceive.receive(TOS_MsgPtr data) { GPS_MsgPtr gps_data = (GPS_MsgPtr)data; if ((call isGGA(gps_data->data))) { ! //SODbg(DBG_USR2, "gps_driverM.GpsReceive.receive() GGA Data\r\n"); ! call parse_gga(gps_data); ! ! if (gps_fix) { ! signal Sensor.dataReady(gps_data); ! call Sensor.powerOff(); ! } } + return data; + } ! event result_t GpsSend.sendDone(TOS_MsgPtr msg, result_t success) { ! SODbg(DBG_USR2, "GpsSend.sendDone(): state: %i \r\n", state); ! return SUCCESS; ! } ! event result_t GpsCmd.SwitchesSet(uint8_t PowerState) { ! //SODbg(DBG_USR2, "gps_new.GpsCmd.SwitchesSet(): PowerState: %i \n\n", PowerState); ! call Leds.yellowOn(); ! call Leds.redOff(); ! return SUCCESS; ! } ! /** FIXME: Change this to count commas on the raw gga string. ! * Counting commas will save a lot of processing power otherwise ! * used for building char[][]s. ! */ ! command uint8_t get_gps_fix(char * data) { ! return (data[0] - '0'); } ! command result_t load_gga_struct(char gga_fields[GGA_FIELDS][GPS_CHAR_PER_FIELD]) { ! char NS; ! char EW; ! gga_msg.hours = call extract_hours(gga_fields[1]); ! gga_msg.minutes = call extract_minutes(gga_fields[1]); ! gga_msg.dec_sec = call extract_dec_sec(gga_fields[1]); ! gga_msg.Lat_deg = call extract_Lat_deg(gga_fields[2]); ! gga_msg.Lat_dec_min = call extract_Lat_dec_min(gga_fields[2]); ! gga_msg.Long_deg = call extract_Long_deg(gga_fields[4]); ! gga_msg.Long_dec_min = call extract_Long_dec_min(gga_fields[4]); ! NS = (gga_fields[3][0] == 'N') ? 1 : 0; ! EW = (gga_fields[5][0] == 'W') ? 1 : 0; ! gga_msg.NSEWind = EW | (NS<<4); // eg. Status = 000N000E = 00010000 ! gga_msg.num_sats = call extract_num_sats(gga_fields[7]); ! return SUCCESS; } ! /** The internal logic of this command is inherited from ! * whoknowswhere. It's too complicated for it's doing. ! * FIXME: Simplify the code in this command. ! */ ! command result_t parse_gga(GPS_Msg * gps_data) { ! //SODbg(DBG_USR2, "gps_new.GpsCmd.SwitchesSet(): PowerState: %i \n\n", PowerState); ! ! char gga_fields[GGA_FIELDS][GPS_CHAR_PER_FIELD]; // = {{0}}; bool end_of_field = FALSE; *************** *** 374,391 **** uint8_t j,m; uint16_t k=0; ! ! //***DEBUG: Output NMEA message*** ! uint16_t q; ! SODbg(DBG_USR2, "fireboardM.parseGGA(): \n"); ! for(q=0; q<length; q++) UARTPutChar(gga_string[q]); ! SODbg(DBG_USR2, "\n"); ! //******************************** ! ! ! // Just get out of this function for now. ! return SUCCESS; // Parse and store comma delimited fields into EEPROM ! while (i < GPS_FIELDS) { // assemble gga_fields array --- 320,327 ---- uint8_t j,m; uint16_t k=0; ! uint8_t length = gps_data->length; // Parse and store comma delimited fields into EEPROM ! while (i < GGA_FIELDS) { // assemble gga_fields array *************** *** 393,401 **** j = 0; while (!end_of_field & k < length) { ! if (gga_string[k] == GPS_DELIMITER) { end_of_field = TRUE; } else { ! gga_fields[i][j] = gga_string[k]; } j++; --- 329,337 ---- j = 0; while (!end_of_field & k < length) { ! if (gps_data->data[k] == GPS_DELIMITER) { end_of_field = TRUE; } else { ! gga_fields[i][j] = gps_data->data[k]; } j++; *************** *** 412,421 **** } ! call logGPS(gga_fields); ! return SUCCESS; } - command uint8_t extract_hours(char * data) { return (10*(data[0]-'0') + (data[1]-'0')); --- 348,361 ---- } ! // Finding the gps fix should probably done somewhere else. ! gps_fix = call get_gps_fix(gga_fields[6]); ! //SODbg(DBG_USR2, "gps_new.parse_gga(): gps_fix %i \r\n", gps_fix); ! ! //call load_gga_struct(gga_fields); ! ! return SUCCESS; } command uint8_t extract_hours(char * data) { return (10*(data[0]-'0') + (data[1]-'0')); *************** *** 439,455 **** command uint8_t extract_Lat_deg(char * data) { ! return 0; } command uint16_t extract_Lat_dec_min(char * data) { ! return 0; } command uint8_t extract_Long_deg(char * data) { ! return 0; } command uint16_t extract_Long_dec_min(char * data) { ! return 0; } --- 379,406 ---- command uint8_t extract_Lat_deg(char * data) { ! return 10*(data[0]-'0') + (data[1]-'0'); } command uint16_t extract_Lat_dec_min(char * data) { ! ! uint16_t dec_min; ! dec_min = 100000*(data[2]-'0') + 10000*(data[3]-'0') ! + 1000*(data[4]-'0') + 100*(data[5]-'0') ! + 10*(data[6]-'0') + (data[7]-'0'); ! return dec_min; } command uint8_t extract_Long_deg(char * data) { ! return (100*(data[0]-'0') + 10*(data[1]-'0') ! + (data[2]-'0')); } command uint16_t extract_Long_dec_min(char * data) { ! ! uint16_t dec_min; ! dec_min = 100000*(data[3]-'0') + 10000*(data[4]-'0') ! + 1000*(data[5]-'0') + 100*(data[6]-'0') ! + 10*(data[7]-'0') + (data[8]-'0'); ! return dec_min; } *************** *** 458,463 **** } ! ! --- 409,415 ---- } ! command uint8_t extract_num_sats(char * data) { ! return (10*(data[0]-'0') + (data[1]-'0')); ! } *************** *** 483,487 **** command result_t Sensor.powerOff() { ! call stopGps(); signal Sensor.powerOffDone(); return SUCCESS; --- 435,445 ---- command result_t Sensor.powerOff() { ! //call stopGps(); ! if (call GpsCmd.PowerSwitch(GPS_POWER_OFF)) { ! ! SODbg(DBG_USR2,"gps_driverM.StdControl.stop(): GPS sensor powered off.\n"); ! gps_state = GPS_FINISHED; ! } ! gps_fix = 0; signal Sensor.powerOffDone(); return SUCCESS; *************** *** 492,498 **** --- 450,463 ---- } + /** This will need to call Sensor.loadProgram with an appropriate + * NMEA string. + */ command result_t Sensor.setSamplingInterval(uint16_t sampling_rate) { return SUCCESS; } + + /** This will need to call Sensor.loadProgram with an appropriate + * NMEA string. + */ command result_t Sensor.getSamplingInterval(uint16_t sampling_rate) { return SUCCESS; *************** *** 515,522 **** --- 480,507 ---- } + + /** Not currently working for at least 2 reasons: + * 1. Not sure if the program string is correct for + * the LeadTek; + * 2. Not sure if any program string is correctly navigating + * the UART and loading into the LeadTek. + */ command result_t Sensor.loadProgram(uint8_t * program) { + + TOS_MsgPtr msg = {0}; + strcpy(msg->data,program); + signal Sensor.dataReady((void*)program); + + call GpsSend.send(msg); + return SUCCESS; } + /** In many cases we might want the GPS unit to be silent + * until a valid fix is obtained, report the fix, + * then shut up. Not being able to obtain a valid fix + * in some amount of time can be regarded as an error + * and signaled. + */ default event result_t Sensor.error(uint16_t error_code) { return SUCCESS; Index: leadtek_9546.h =================================================================== RCS file: /cvsroot/firebug/fireboard/fireboard/sensors/leadtek9546/leadtek_9546.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** leadtek_9546.h 14 Jan 2004 17:20:28 -0000 1.1 --- leadtek_9546.h 15 Jan 2004 03:22:25 -0000 1.2 *************** *** 86,90 **** #define GPS_MSG_LENGTH 100 #define GPS_CHAR 11 ! #define GPS_FIELDS 8 #define GPS_CHAR_PER_FIELD 10 #define GPS_DELIMITER ',' --- 86,90 ---- #define GPS_MSG_LENGTH 100 #define GPS_CHAR 11 ! #define GGA_FIELDS 8 #define GPS_CHAR_PER_FIELD 10 #define GPS_DELIMITER ',' *************** *** 123,130 **** * of the GPS unit. These are all in NMEA format. */ ! const uint8_t gps_gga_mask[] = {"$PFST,NMEA," NMEA_GGA_MASK NMEA_END1 NMEA_END2}; ! const uint8_t gps_rmc_mask[] = {"$PFST,NMEA," NMEA_RMC_MASK NMEA_END1 NMEA_END2}; ! const uint8_t gps_syncmode_on[] = {"$PFST,SYNCMODE,1" NMEA_END1 NMEA_END2}; ! const uint8_t gps_syncmode_off[] = {"$PFST,SYNCMODE,0" NMEA_END1 NMEA_END2}; --- 123,130 ---- * of the GPS unit. These are all in NMEA format. */ ! //const uint8_t gps_gga_mask[] = {"$PLTC,NMEA," NMEA_GGA_MASK NMEA_END1 NMEA_END2}; ! //const uint8_t gps_rmc_mask[] = {"$PLTC,NMEA," NMEA_RMC_MASK NMEA_END1 NMEA_END2}; ! //const uint8_t gps_syncmode_on[] = {"$PLTC,SYNCMODE,1" NMEA_END1 NMEA_END2}; ! const uint8_t gps_syncmode_off[] = {"$LTC,SYNCMODE,0" NMEA_END1 NMEA_END2}; *************** *** 153,157 **** uint8_t Long_deg; uint16_t Long_dec_min; ! uint8_t NSEWind; }; --- 153,158 ---- uint8_t Long_deg; uint16_t Long_dec_min; ! uint8_t NSEWind; ! uint8_t num_sats; }; --- GpsC.nc DELETED --- --- HPLUARTC1.nc DELETED --- |