📄 garmin.c
字号:
{ 74, 0, 1, 10, 100, 201, 100, 300, 300, -1, -1, 500},
{ 76, 0, 1, 10, 102, 201, 102, 300, 300, 400, 102, 501},
{ 77,-301, 1, 10, 100, 201, 100, 300, 300, 400, 400, 501},
{ 77,-350, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{ 77,-361, 1, 10, 103, 201, 103, 300, 300, -1, -1, 501},
{ 77, 361, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{ 87, 0, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{ 95, 0, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{ 96, 0, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{ 97, 0, 1, 10, 103, 201, 103, 300, 300, -1, -1, 501},
{ 98, 0, 2, 11, 150, 201, 150, -1, -1, 400, 450, 551},
{100, 0, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{105, 0, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{106, 0, 1, 10, 103, 201, 103, 300, 300, 400, 403, 501},
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
};
INT ProtocolIndex=-1; // index into above table which holds the valid
// protocols for this connected device
/* -------------------------------------------------------------------------- */
D100_Wpt_Type *D100_Wpt;
D101_Wpt_Type *D101_Wpt;
D102_Wpt_Type *D102_Wpt;
D103_Wpt_Type *D103_Wpt;
D104_Wpt_Type *D104_Wpt;
D105_Wpt_Type *D105_Wpt; // StreetPilot Waypoint
D106_Wpt_Type *D106_Wpt; // StreetPilot Route Waypoint
D107_Wpt_Type *D107_Wpt; // 12CX
D108_Wpt_Type *D108_Wpt; // eMap
D150_Wpt_Type *D150_Wpt;
D151_Wpt_Type *D151_Wpt;
D152_Wpt_Type *D152_Wpt;
D154_Wpt_Type *D154_Wpt;
D155_Wpt_Type *D155_Wpt;
D200_Rte_Hdr_Type D200;
D201_Rte_Hdr_Type *D201;
D202_Rte_Hdr_Type *D202;
D300_Trk_Point_Type *D300_Trk_Point;
D400_Prx_Wpt_Type *D400_Prx_Wpt;
D403_Prx_Wpt_Type *D403_Prx_Wpt;
D450_Prx_Wpt_Type *D450_Prx_Wpt;
D600_Date_Time_Type *dtime;
short SerialMsgLen;
FILE *disout;
INT gLine=0; // GPS III Scan line (0-99) being read
unsigned char bmh[118] = {
66, 77, 182, 31, 0, 0, 0, 0, 0, 0, 118, 0, 0,
0, 40, 0, 0, 0, 160, 0, 0, 0, 100, 0, 0, 0,
1, 0, 4, 0, 0, 0, 0, 0, 64, 31, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 16, 0,
0, 0, 0, 0, 0, 0, 99, 99, 99, 0, 181, 181, 181,
0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0,
255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255,
255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255,
255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0
}; // bmh[118]
unsigned char (*bmdata)[80]; // GPS III
/* -------------------------------------------------------------------------- */
PROCX void settime_record(time_t dot)
{
if(dot==0) dot = time(NULL) - 631065600L;
strcpy(record.datetime,secs2dt(dot, (short)gPrefs.offset));
} // settime_record()
/* -------------------------------------------------------------------------- */
PROCX long toSemiCircles(double b)
{
return((long)(b*CONVERT));
} // toSemiCircles(double b)
/* -------------------------------------------------------------------------- */
PROCX double toDegrees(long a)
{
LONGdouble t;
t=(LONGdouble)(a);
return ((double)(t/CONVERT));
} // toDegrees(long a)
//
// Performs a strncpy and then converts all but first 0 to a ' ' in dest string
//
PROCX void strncpad(char *d, char *s, INT count)
{
INT i;
strncpy(d,s,count);
for(i=0;i<count;i++) {
if(d[i]==0) break;
}
i++;
for(i=i;i<count;i++) d[i]=' ';
} // strncpad
/* -------------------------------------------------------------------------- */
/*
* Send a waypoint to the GPS
* Returns a result code--zero if GPS receiver did not respond
*/
PROCX void doSWaypoint(INT prox)
{
short ret;
byte mlen=0;
long laa,loo;
char msgtype[50];
INT wpt_type;
//
// first waypoint? Then send number to send if known
//
if(prox==0) {
strcpy(msgtype,"Waypoint Data");
if(firstwaypoint&&!in_route)
send_num_points(waypoints,"Waypoints");
firstwaypoint=0;
}
if(prox==1) {
if(ProxDataRecord==0) {
fprintf(stderr,"Proximity waypoints are not supported in this GPS unit.\n");
return;
}
strcpy(msgtype,"Proximity Waypoint Data");
if(firstPwaypoint&&!in_route)
send_num_points(proximityp,"Proximity");
firstPwaypoint=0;
}
//
// convert symbols if Product_ID is that of a 12/II+ gps
//
if(Ggps == G12XL) {
ret = record.icon_smbl = convert_to_12xl(record.icon_smbl);
if(ret < 0)
record.icon_smbl=convert_to_12xl(default_G12_icon);
}
memset(message,' ',MAX_LENGTH); // set space
laa = toSemiCircles(record.la);
loo = toSemiCircles(record.lo);
// blank fill name
for(ret=0;ret<6;ret++) {
if(record.ident[ret]==0) break;
}
for(ret=ret;ret<6;ret++) record.ident[ret]=0x20;
//
// setup common parts, i.e. the first part of the format is the same for
// the following Data transfer protocols
//
if(in_route) wpt_type=RouteDataRecord;
else wpt_type=WaypDataRecord;
switch(wpt_type) {
case 100:
mlen=sizeof(D100_Wpt_Type);
case 101:
case 102:
case 103:
case 104:
case 107:
case 151:
case 152:
case 154:
case 155:
D100_Wpt = (D100_Wpt_Type *)&message[2];
D100_Wpt->posn.lat = laa;
D100_Wpt->posn.lon = loo;
// clear out ident
memset(D100_Wpt->ident,' ',6);
if(datatype==105 || datatype==106) {
strncpy(D100_Wpt->ident,(char*) StreetPilotWptName,6);
}
else {
strncpy(D100_Wpt->ident, record.ident,6);
}
// stick in the date just for fun
D100_Wpt->unused= 0L; // dt2secs((short)gPrefs.offset);
// clear out comment
memset(D100_Wpt->cmnt,' ',40);
if(strlen(record.comment)) {
strncpad(D100_Wpt->cmnt, record.comment, 40);
}
} // switch(wpt_type)
switch(wpt_type) {
case 101: {
D101_Wpt = (D101_Wpt_Type *)&message[2];
D101_Wpt->smbl= record.icon_smbl|(record.icon_dspl<<8);
if(prox==1) D101_Wpt->dst = record.ProxDist; else D101_Wpt->dst=0.0;
mlen=sizeof(D101_Wpt_Type);
break;
}
case 102: {
D102_Wpt = (D102_Wpt_Type *)&message[2];
D102_Wpt->smbl= record.icon_smbl|(record.icon_dspl<<8);
if(prox==1) D102_Wpt->dst = record.ProxDist; else D102_Wpt->dst=0.0;
mlen=sizeof(D102_Wpt_Type);
break;
}
case 103: {
D103_Wpt = (D103_Wpt_Type *)&message[2];
//
// Translate to 12/II+ icon display type
//
// Program 12/II+ Display mode
// 3 0 Symbol with Waypoint Name
// 1 1 Symbol
// 5 2 Symbol with Waypoint Comment
//
switch(record.icon_dspl) {
case 3: record.icon_dspl = 0; break;
case 5: record.icon_dspl = 2; break;
}
D103_Wpt->dspl = record.icon_dspl;
D103_Wpt->smbl = record.icon_smbl;
mlen=sizeof(D103_Wpt_Type);
break;
}
case 104: {
D104_Wpt = (D104_Wpt_Type *)&message[2];
D104_Wpt->smbl = record.icon_smbl;
D104_Wpt->dspl = record.icon_dspl;
if(prox==1) D104_Wpt->dst = record.ProxDist; else D104_Wpt->dst=0.0;
mlen=sizeof(D104_Wpt_Type);
break;
}
case 105: {
D105_Wpt = (D105_Wpt_Type *)&message[2];
D105_Wpt->posn.lat = laa;
D105_Wpt->posn.lon = loo;
D105_Wpt->smbl = record.icon_smbl;
if(D105orD106 == 0) strcpy((char*)StreetPilotWptName,record.ident);
strcpy((char*)D105_Wpt->wpt_ident, (char*)StreetPilotWptName);
mlen=sizeof(D105_Wpt_Type)+strlen((char*)D105_Wpt->wpt_ident);
break;
}
// 7.5.7. D106_Wpt_Type
// Example products: StreetPilot (route waypoints).
//typedef struct
//{
// byte class; // class
// byte subclass[13]; // subclass
// Semicircle_Type posn; // position
// Symbol_Type smbl; // symbol id
// char wpt_ident[1]; // null-terminated string -- length isn't
// // really specified, I added 10 for a place
// // holder for the decode of D106 waypoints
///* char lnk_ident[]; null-terminated string */
//} D106_Wpt_Type;
case 106: {
if(record.class == 255) record.class = 0; // 'user'
//d106:;
D106_Wpt = (D106_Wpt_Type *)&message[2];
D106_Wpt->class = record.class;
for(ret=0;ret<13;ret++) D106_Wpt->subclass[ret] = record.subclass[ret];
D106_Wpt->posn.lat = laa;
D106_Wpt->posn.lon = loo;
D106_Wpt->smbl = record.icon_smbl;
//
// This code segment concatonates the name and link ident into two null
// terminated strings.
//
if(D105orD106 == 0) strcpy((char*)StreetPilotWptName,record.ident);
for(ret=0;ret<strlen((char*)StreetPilotWptName);ret++)
if(StreetPilotWptName[ret]=='|') StreetPilotWptName[ret]=' ';
trim((char*)StreetPilotWptName);
for(ret=0;ret<strlen((char*)StreetPilotLnk_ident);ret++)
if(StreetPilotLnk_ident[ret]=='|') StreetPilotLnk_ident[ret]=' ';
trim((char *)StreetPilotLnk_ident);
strcpy((char*)D106_Wpt->wpt_ident, (char*)StreetPilotWptName);
D106_Wpt->wpt_ident[ret=strlen((char*)StreetPilotWptName)]=' ';
D106_Wpt->wpt_ident[ret+1]=0;
strcat((char*)D106_Wpt->wpt_ident, (char*)StreetPilotLnk_ident);
D106_Wpt->wpt_ident[ret]=0;
mlen=sizeof(D106_Wpt_Type) +
strlen((char*)StreetPilotWptName) +
strlen((char*)StreetPilotLnk_ident)+1;
break;
}
case 107: {
D107_Wpt = (D107_Wpt_Type *)&message[2];
//
// Translate to 12/II+ icon display type
//
// Program 12/II+ Display mode
// 3 0 Symbol with Waypoint Name
// 1 1 Symbol
// 5 2 Symbol with Waypoint Comment
//
switch(record.icon_dspl) {
case 3: record.icon_dspl = 0; break;
case 5: record.icon_dspl = 2; break;
}
D107_Wpt->dspl = record.icon_dspl;
D107_Wpt->smbl = record.icon_smbl;
if(prox==1) D107_Wpt->dst = record.ProxDist; else D107_Wpt->dst=0.0;
switch(record.color) {
case 0: // SA Black
case 4: // SA Yellow
D107_Wpt->color=0;
break;
case 1: // SA Red = 12CX Red
D107_Wpt->color=1;
break;
case 2: // SA Blue
D107_Wpt->color=3;
break;
case 3: // SA Green
D107_Wpt->color=2;
break;
}
mlen=sizeof(D107_Wpt_Type);
break;
} // case 107
case 150: {
if(record.class == 255) record.class = 4; // 'user'
D150_Wpt = (D150_Wpt_Type *)&message[2];
D150_Wpt->posn.lat = laa;
D150_Wpt->posn.lon = loo;
D150_Wpt->class = record.class;
D150_Wpt->alt = record.alt;
strncpad(D150_Wpt->ident,record.ident, 6);
strncpad(D150_Wpt->cc,record.cc, 2);
strncpad(D150_Wpt->city,record.city, 24);
strncpad(D150_Wpt->state,record.state, 2);
strncpad(D150_Wpt->name,record.name, 30);
strncpad(D150_Wpt->cmnt,record.comment, 40);
mlen=sizeof(D150_Wpt_Type);
break;
}
case 151: {
if(record.class == 255) record.class = 2; // 'user'
D151_Wpt = (D151_Wpt_Type *)&message[2];
if(prox==1) D151_Wpt->dst = record.ProxDist; else D151_Wpt->dst=0.0;
strncpad(D151_Wpt->ident,record.ident, 6);
strncpad(D151_Wpt->name, record.name, 30);
strncpad(D151_Wpt->city, record.city, 24);
strncpad(D151_Wpt->state, record.state, 2);
D151_Wpt->alt = record.alt;
strncpad(D151_Wpt->cc, record.cc, 2);
D151_Wpt->class = record.class;
mlen=sizeof(D151_Wpt_Type);
break;
}
case 152: {
if(record.class == 255) record.class = 4; // 'user'
D152_Wpt = (D152_Wpt_Type *)&message[2];
D152_Wpt->unused2=0;
if(prox==1) D152_Wpt->dst = record.ProxDist; else D152_Wpt->dst=0.0;
strncpad(D152_Wpt->ident,record.ident, 6);
strncpad(D152_Wpt->name, record.name, 30);
strncpad(D152_Wpt->city, record.city, 24);
strncpad(D152_Wpt->state, record.state, 2);
D152_Wpt->alt = record.alt;
strncpad(D152_Wpt->cc, record.cc, 2);
D152_Wpt->class = record.class;
mlen=sizeof(D152_Wpt_Type);
break;
}
case 154: {
if(record.class == 255) record.class = 4; // 'user'
D154_Wpt = (D154_Wpt_Type *)&message[2];
D154_Wpt->unused2=0;
if(prox==1) D154_Wpt->dst = record.ProxDist; else D154_Wpt->dst=0.0;
if(strlen(D154_Wpt->ident)) {
strncpad(D154_Wpt->ident,record.ident, 6);
}
if(strlen(D154_Wpt->name)) {
strncpad(D154_Wpt->name, record.name, 30);
}
if(strlen(D154_Wpt->city)) {
strncpad(D154_Wpt->city, record.city, 24);
}
strncpad(D154_Wpt->state, record.state, 2);
D154_Wpt->alt = record.alt;
strncpad(D154_Wpt->cc, record.cc, 2);
D154_Wpt->class = record.class;
D154_Wpt->smbl = record.icon_smbl;
mlen=sizeof(D154_Wpt_Type);
break;
}
case 155: {
if(record.class == 255) record.class = 4;
D155_Wpt = (D155_Wpt_Type *)&message[2];
D155_Wpt->unused2=0;
if(prox==1) D155_Wpt->dst = record.ProxDist; else D155_Wpt->dst=0.0;
if(strlen(record.ident)) {
strncpad(D155_Wpt->ident,record.ident, 6);
}
if(strlen(record.name)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -