int32 GPS_Serial_Send_Ack(gpsdevh *fd, GPS_PPacket *tra, GPS_PPacket *rec) { UC data[2]; GPS_Util_Put_Short(data,(US)(*rec)->type); GPS_Make_Packet(tra,LINK_ID[0].Pid_Ack_Byte,data,2); if(!GPS_Write_Packet(fd,*tra)) { GPS_Error("Error acknowledging packet"); gps_errno = SERIAL_ERROR; return 0; } return 1; }
int32 GPS_Command_Off(const char *port) { static UC data[2]; gpsdevh *fd; GPS_PPacket tra; GPS_PPacket rec; GPS_Util_Little(); if(!GPS_Device_On(port, &fd)) return gps_errno; if(!(tra = GPS_Packet_New()) || !(rec = GPS_Packet_New())) return MEMORY_ERROR; GPS_Util_Put_Short(data,COMMAND_ID[gps_device_command].Cmnd_Turn_Off_Pwr); /* robertl - LINK_ID isn't set yet. Hardcode it to Garmin spec value */ GPS_Make_Packet(&tra, 10, /* LINK_ID[gps_link_type].Pid_Command_Data, */ data,2); if(!GPS_Write_Packet(fd,tra)) return gps_errno; if(!GPS_Device_Chars_Ready(fd)) { if(!GPS_Get_Ack(fd, &tra, &rec)) return gps_errno; GPS_User("Power off command acknowledged"); } GPS_Packet_Del(&tra); GPS_Packet_Del(&rec); if(!GPS_Device_Off(fd)) return gps_errno; return 1; }
/* @funcstatic GPS_Input_Get_D108 ************************************ ** ** Get a D108 Entry ** ** @param [w] way [GPS_PWay *] pointer to waypoint entry ** @param [r] inf [FILE *] stream ** ** @return [int32] number of entries ************************************************************************/ static int32 GPS_Input_Get_D108(GPS_PWay *way, FILE *inf) { char s[GPS_ARB_LEN]; char *p; double f; int32 d; int32 xc; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_Strnull((*way)->ident,s); if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%lf",&f)!=1) return gps_errno; (*way)->lat = f; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%lf",&f)!=1) return gps_errno; (*way)->lon = f; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_errno; (*way)->colour = d; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_errno; (*way)->dspl = d; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_errno; (*way)->smbl = d; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_errno; (*way)->alt = d; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%lf",&f)!=1) return gps_errno; (*way)->dpth = f; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_String((*way)->state,2,s); if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_String((*way)->cc,2,s); if(!GPS_Input_Read_Line(s,inf)) return gps_errno; p=strchr(s,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_errno; (*way)->wpt_class = d; xc = d; if(xc>=0x80 && xc<=0x85) { if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_String((char *)(*way)->subclass,18,s); } else { GPS_Util_Put_Short((*way)->subclass,0); GPS_Util_Put_Int((*way)->subclass+2,0); GPS_Util_Put_Uint((*way)->subclass+6,0xffffffff); GPS_Util_Put_Uint((*way)->subclass+10,0xffffffff); GPS_Util_Put_Uint((*way)->subclass+14,0xffffffff); } if(!xc) { if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_Strnull((*way)->cmnt,s); } if(xc>=0x40 && xc<=0x46) { if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_Strnull((*way)->facility,s); if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_Strnull((*way)->city,s); } if(xc==0x83) { if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_Strnull((*way)->addr,s); } if(xc==0x82) { if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_Strnull((*way)->cross_road,s); } return 1; }
static int32 GPS_Input_Get_Route201(GPS_PWay **way, FILE *inf) { char s[GPS_ARB_LEN]; int32 n; int32 type; int32 rtype; int32 i; long pos; int32 ret; char *p; int32 d; gps_errno = INPUT_ERROR; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; if(sscanf(s,"Route Type: %d",(int *)&rtype)!=1) return gps_errno; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; if(sscanf(s,"Waypoints Type: %d",(int *)&type)!=1) return gps_errno; pos = ftell(inf); n = 1; while(strncmp(s,"End",3)) { if(!GPS_Input_Read_Line(s,inf)) return gps_errno; if(strstr(s,"Latitude") || strstr(s,"Route") || strstr(s,"Link Class")) ++n; } fseek(inf,0L,0); if(!(*way=(GPS_PWay *)malloc(n*sizeof(GPS_PWay *)))) return MEMORY_ERROR; for(i=0;i<n;++i) { if(!((*way)[i]=GPS_Way_New())) return MEMORY_ERROR; (*way)[i]->prot = type; } if(!GPS_Input_Read_Line(s,inf)) return gps_errno; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; if(!GPS_Input_Read_Line(s,inf)) return gps_errno; for(i=0;i<n;++i) { (*way)[i]->rte_prot = rtype; (*way)[i]->islink = 0; if(strstr(s,"Route")) { (*way)[i]->isrte = 1; switch(rtype) { case 200: p = strchr(s,':'); p = strchr(p+1,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_error; (*way)[i]->rte_num=d; break; case 201: p = strchr(s,':'); p = strchr(p+1,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_error; (*way)[i]->rte_num=d; p = strchr(p+1,':'); GPS_Input_Load_String((*way)[i]->rte_cmnt,20,p+1); break; case 202: p = strchr(s,':'); p = strchr(p+1,':'); GPS_Input_Load_Strnull((*way)[i]->rte_ident,p+1); break; } if(!GPS_Input_Read_Line(s,inf)) return gps_errno; continue; } else (*way)[i]->isrte=0; if(strstr(s,"Link Class")) { (*way)[i]->islink = 1; p = strchr(s,':'); if(sscanf(p+1,"%d",(int *)&d)!=1) return gps_error; (*way)[i]->rte_link_class=d; if(!((*way)[i]->rte_link_class==3 || (*way)[i]->rte_link_class ==0xff)) { if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_String((*way)[i]->rte_link_subclass,18,s); } else { GPS_Util_Put_Short((UC *)(*way)[i]->rte_link_subclass,0); GPS_Util_Put_Int((UC *)(*way)[i]->rte_link_subclass+2,0); GPS_Util_Put_Uint((UC *)(*way)[i]->rte_link_subclass+6, 0xffffffff); GPS_Util_Put_Uint((UC *)(*way)[i]->rte_link_subclass+10, 0xffffffff); GPS_Util_Put_Uint((UC *)(*way)[i]->rte_link_subclass+14, 0xffffffff); } if(!GPS_Input_Read_Line(s,inf)) return gps_errno; GPS_Input_Load_Strnull((*way)[i]->rte_link_ident,s); continue; } else (*way)[i]->islink=0; if(strstr(s,"End")) { GPS_Error("Get_Route201: Unexpected End"); return INPUT_ERROR; } switch(type) { case 100: ret = GPS_Input_Get_D100(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 101: ret = GPS_Input_Get_D101(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 102: ret = GPS_Input_Get_D102(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 103: ret = GPS_Input_Get_D103(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 104: ret = GPS_Input_Get_D104(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 105: ret = GPS_Input_Get_D105(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 106: ret = GPS_Input_Get_D106(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 107: ret = GPS_Input_Get_D107(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 108: ret = GPS_Input_Get_D108(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 150: ret = GPS_Input_Get_D150(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 151: ret = GPS_Input_Get_D151(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 152: ret = GPS_Input_Get_D152(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 154: ret = GPS_Input_Get_D154(&((*way)[i]),inf); if(ret<0) return gps_errno; break; case 155: ret = GPS_Input_Get_D155(&((*way)[i]),inf); if(ret<0) return gps_errno; break; default: GPS_Error("Input_Get_Waypoints: Unknown protocol"); return PROTOCOL_ERROR; } if(!GPS_Input_Read_Line(s,inf)) return gps_errno; } return n; }