📄 device.c
字号:
/*************************************************************************** device.c - question device version & supported protocols ------------------- begin : So M鋜 21 17:50:31 CET 2004 copyright : (C) 2004 by Dennis Real email : dev-null@users.sourceforge.net ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <stdio.h>#include <sys/ioctl.h>#include <string.h>#include <unistd.h>#include "def.h"#include "llayer.h"/* get supported protocols and protocol specific datatypes from gps (douglas adams says: don`t panic.) */DeviceInfo getVersion(int tty){ unsigned int s, t=0; char *gcommand; DeviceInfo back; int counted; int lastapp=-1; int lastdata=-1; back.product_ID=-1; back.software_version=-1; strncpy(back.product_description, "No garmin gps detected.", 255); back.player=-1; back.llayer=-1; back.appcommand=-1; back.appwaypoint=-1; back.datawaypoint=-1; back.approute=-1; back.datarouteheader=-1; back.dataroutewpt=-1; back.dataroutelink=-1; back.apptrack=-1; back.datatrackheader=-1; back.datatrackpoint=-1; back.appproxwpt=-1; back.dataproxwpt=-1; back.appalmanac=-1; back.dataalmanac=-1; back.appdatetimeinit=-1; back.datadatetimeinit=-1; back.apppositioninit=-1; back.datapositioninit=-1; back.apppvt=-1; back.datapvt=-1; /* get version and avilable protocols (A001) */ SendCommand(tty, "\xfe\x02\x00\x00", 4); gcommand=GetCommand(tty, &s); //ack if ( gcommand==NULL ) { fprintf(stderr, "Warning: GPS confused while detecting version...\n"); return back; } gcommand=GetCommand(tty, &s); // 255 pid product data ACKCommand(tty, gcommand, s); back.product_ID=(BYTE)gcommand[2]+(BYTE)gcommand[3]*256; back.software_version=(BYTE)gcommand[4]+(BYTE)gcommand[5]*256; for( t=0; t<s; t++ ) { back.product_description[t]=gcommand[t+6]; if ( gcommand[t+6]==0 ) continue; } usleep(500000); /* if A001 available */ ioctl(tty, FIONREAD, &counted); if ( counted!=0 ) { gcommand=GetCommand(tty, &s); //253 pid protocol array ACKCommand(tty, gcommand, s); for( t=2; t<s; t+=3 ) { /* A001: examine supported protocols and related datatypes */ #ifdef DEBUG fprintf(stderr, "%c%03d\n", gcommand[t], (BYTE)gcommand[t+1]+((BYTE)gcommand[t+2]*256));#endif if ( gcommand[t]=='P' ) { back.player=(BYTE)gcommand[t+1]+((BYTE)gcommand[t+2]*256); } else if ( gcommand[t]=='L' ) { back.llayer=(BYTE)gcommand[t+1]+((BYTE)gcommand[t+2]*256); } else if ( gcommand[t]=='A' ) { lastapp=(BYTE)gcommand[t+1]+((BYTE)gcommand[t+2]*256); switch(lastapp) { /* device command protocol */ case 10: case 11: back.appcommand=lastapp; break; /* waypoint transfer protocol */ case 100: back.appwaypoint=lastapp; break; /* route transfer protocol */ case 200: case 201: back.approute=lastapp; break; /* track log transfer protocol */ case 300: case 301: back.apptrack=lastapp; break; /* proximity waypoint protocol */ case 400: back.appproxwpt=lastapp; break; /* almanac transfer protocol */ case 500: back.appalmanac=lastapp; break; /* date & time initialization protocol */ case 600: back.appdatetimeinit=lastapp; break; /* position initialization protocol */ case 700: back.apppositioninit=lastapp; break; /* pvt data protocol */ case 800: back.apppvt=lastapp; break; } } else if ( gcommand[t]=='D' ) { /* protocol specific data types */ lastdata=(BYTE)gcommand[t+1]+((BYTE)gcommand[t+2]*256); switch(lastapp) { /* waypoint transfer protocol */ case 100: switch(lastdata) { case 100: case 101: case 102: case 103: case 104: case 105: case 106: case 107: case 108: case 109: case 150: case 151: case 152: case 154: case 155: back.datawaypoint=lastdata; break; } break; /* route transfer protocol */ case 200: case 201: switch (lastdata) { case 100: case 101: case 102: case 103: case 104: case 105: case 106: case 107: case 108: case 109: case 150: case 151: case 152: case 154: case 155: back.dataroutewpt=lastdata; break; case 200: case 201: case 202: back.datarouteheader=lastdata; break; case 210: back.dataroutelink=lastdata; break; } break; /* track log transfer protocol */ case 300: case 301: switch(lastdata) { case 300: case 301: back.datatrackpoint=lastdata; break; case 310: back.datatrackheader=lastdata; break; } break; /* proximity waypoint protocol */ case 400: switch(lastdata) { case 400: case 403: case 450: back.dataproxwpt=lastdata; break; } /* almanac transfer protocol */ case 500: switch(lastdata) { case 500: case 501: case 550: case 551: back.dataalmanac=lastdata; break; } break; /* date & time initialization protocol */ case 600: switch(lastdata) { case 600: back.datadatetimeinit=lastdata; break; } break; /* position initialization protocol */ case 700: switch(lastdata) { case 700: back.datapositioninit=lastdata; break; } break; /* pvt data protocol */ case 800: switch(lastdata) { case 800: back.datapvt=lastdata; break; } break; } // switch(lastapp) } // gcommand[ ]='D' } // for } // A001 else { /* old device, no A001 support. protocol support must set by a lookuptable. any volunteers? ;-) */ } return back;}void powerOff(int tty){ unsigned int s; char *gcommand; /* turn off power of gps */ SendCommand(tty, "\x0a\x02\x08\x00", 4); gcommand=GetCommand(tty, &s);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -