📄 taip.c
字号:
/* Search message list for 2 character TAIP id */
for (mid = 0; mid < NMSGS; mid++) {
if (strnicmp (&buf [2], msgs [mid].id, 2) == 0) {
break;
}
}
if (mid != NMSGS) { /* If message id was found in list... */
/* Erase data storage area */
memset ((char *)&taip_data, 0, sizeof (taip_data));
/* call the message parser */
(*msgs [mid].parse_f)(&taip_data, &buf [4]);
/* call the message displayer with the parsed data */
(*msgs [mid].disp_f)(&taip_data);
}
else { /* message was not found in list */
char msg [3];
strncpy (msg, &buf [2], 2);
msg [2] = 0;
printf ("Message type \"%s\" not found in message list", msg);
}
}
/*
* unsigned int checksum (char *text)
*
* Calculate a checksum for a string that ends with a '*'
*
* Given
* text - a TAIP formatted packet ending with a '*'
* the '*' is the character preceding the checksum in a TAIP
* packet.
* Returns (as the value of the function)
* an integer checksum of "text"
*/
static unsigned int checksum (text)
unsigned char *text;
{
int
i,
len; /* length of passed string */
unsigned int
cs; /* checksum */
len = strlen (text); /* length of passed string */
cs = 0; /* clear checksum */
/*
* Until we pass a '*' or the string ends (reach a 0 character),
* calculate the checksum as the exclusive OR'ing of all characters
* in the string
*/
for (i = 0; i < len && (i == 0 || text [i - 1] != '*'); i++) {
cs ^= (unsigned int)text [i];
}
return cs; /* return the checksum */
}
/****************************************************************************/
/*
* Display a PV solution
*/
static void disp_pv (pos)
TAIP_POS *pos;
{
char
str [132];
str_hms (str, pos->time);
printf ("PV %s ", str);
str_lat (str, pos->lat);
printf ("%s ", str);
str_lon (str, pos->lon);
printf ("%s ", str);
printf ("%.2f\xf8 ", R2D * pos->cog);
printf ("%.2fmph ", MPS2MPH * pos->sog);
printf ("%s ", fix_type_str [pos->fix_type]);
printf ("%s\n", fix_age_str [pos->fix_age]);
}
/*
* Display routines for all other messages besides PV
*/
static void disp_al (al)
TAIP_AL *al;
{}
static void disp_am (pos)
TAIP_POS *pos;
{}
static void disp_ap (port)
TAIP_PORT *port;
{}
static void disp_cp (pos)
TAIP_POS *pos;
{}
static void disp_id (id)
TAIP_ID *id;
{}
static void disp_ip (ip)
TAIP_IP *ip;
{}
static void disp_ln (pos)
TAIP_POS *pos;
{}
static void disp_pt (port)
TAIP_PORT *port;
{}
static void disp_rm (rm)
TAIP_RM *rm;
{}
static void disp_st (st)
TAIP_ST *st;
{}
static void disp_tm (tm)
TAIP_TM *tm;
{}
static void disp_vr (vr)
TAIP_VR *vr;
{}
static void disp_x1 (x1)
TAIP_X1 *x1;
{}
/*
* parse_fix_type (int chr);
*
* Parse the "fix type" character from a TAIP message.
*
* Given
* chr - fix type character from TAIP message
* Return (as the value of the function)
* an integer value corresponding to the #define POS_FIX_XXX's above
*/
static int parse_fix_type (chr)
int chr; /* fix type character from TAIP message */
{
int
fix_type; /* fix type value */
fix_type = chr - '0'; /* convert from ASCII to integer */
if (fix_type < 0 || fix_type > 9) { /* make sure it is valid */
fix_type = POS_FIX_UNK;
}
return fix_type; /* return fix type value */
}
/*
* parse_fix_age (int chr);
*
* Parse the "fix age" character from a TAIP message.
*
* Given
* chr - fix age character from TAIP message
* Return (as the value of the function)
* an integer value corresponding to the #define POS_AGE_XXX's above
*/
static int parse_fix_age (chr)
int chr;
{
int
fix_age; /* fix age value */
fix_age = chr - '0'; /* convert from ASCII to integer */
if (fix_age < 0 || fix_age > 9) { /* make sure it is valid */
fix_age = POS_AGE_UNK;
}
return fix_age; /* return fix age value */
}
/*
* parse_al (TAIP_AL *al, char *buf)
*
* Parse a TAIP "AL" message to a TAIP_AL structure
*
* Sample AL Message: >RAL68069+00030-00212<
*
* Given
* al - a pointer to a TAIP_AL structure to be filled
* buf - a pointer to an AL message without the leading ">RAL"
* Return (in al)
* parsed AL message
*/
static void parse_al (al, buf)
TAIP_AL *al; /* pointer to a TAIP_AL structure to be filled */
char *buf; /* pointer to an AL message without the leading ">RAL" */
{
al->time = antof (&buf [0], 5); /* Time */
al->alt = antof (&buf [5], 6); /* Altitude */
al->vspd = MPH2MPS * antof (&buf [11], 4); /* Vertical speed */
al->fix_type = parse_fix_type (buf [15]); /* Fix type */
al->fix_age = parse_fix_age (buf [16]); /* Fix age */
}
/*
* parse_ap (TAIP_PORT *port, char *buf)
*
* Parse a TAIP "AP" message to a TAIP_PORT structure
*
* Sample AP Message: >RAP1200,8,1,N,1,0<
*
* Given
* port - a pointer to a TAIP_PORT structure to be filled
* buf - a pointer to an AP message without the leading ">RAP"
* Return (in port)
* parsed PORT message
*/
static void parse_ap (port, buf)
TAIP_PORT *port; /* pointer to a TAIP_PORT structure to be filled */
char *buf; /* pointer to an AP message without the leading ">RAP" */
{
port->baud = atoi (&buf [0]); /* Baud rate */
port->data_bits = atoi (&buf [5]); /* Data bits */
port->stop_bits = atoi (&buf [7]); /* Stop Bits */
port->parity = buf [9] == 'E' ? 2 : (buf [9] == 'O' ? 1 : 0); /* Parity */
port->port = atoi (&buf [11]); /* Port */
}
/*
* parse_cp (TAIP_CP *cp, char *buf)
*
* Parse a TAIP "CP" message to a TAIP_CP structure
*
* Sample CP Message: >RCP68069+373943-122038412<
*
* Given
* pos - a pointer to a TAIP_POS structure to be filled
* buf - a pointer to an CP message without the leading ">RCP"
* Return (in cp)
* parsed CP message
*/
static void parse_cp (pos, buf)
TAIP_POS *pos; /* pointer to a TAIP_POS structure to be filled */
char *buf; /* pointer to a CP message without the leading ">RCP" */
{
/* id of TAIP message providing position */
strcpy (pos->id, "CP");
/* Time */
pos->time = antof (&buf [0], 5);
/* Latitude converted to radians */
pos->lat = D2R * antof (&buf [5], 7) * 1.0e-4;
/* Longitude converted to radians */
pos->lon = D2R * antof (&buf [12], 8) * 1.0e-4;
/* Fix Type */
pos->fix_type = parse_fix_type (buf [20]);
/* Fix Age */
pos->fix_age = parse_fix_age (buf [21]);
}
/*
* parse_id (TAIP_ID *id, char *buf)
*
* Parse a TAIP "ID" message to a TAIP_ID structure
*
* Sample ID Message: >RID1000<
*
* Given
* id - a pointer to a TAIP_ID structure to be filled
* buf - a pointer to an ID message without the leading ">RID"
* Return (in id)
* parsed ID message
*/
static void parse_id (id, buf)
TAIP_ID *id; /* pointer to a TAIP_ID structure to be filled */
char *buf; /* pointer to an ID message without the leading ">RID" */
{
strncpy (id->id, buf, 4); /* copy up to 4 characters of id */
id->id [4] = 0; /* make sure it's truncated at 4 characters */
}
/*
* parse_ip (TAIP_IP *ip, char *buf)
*
* Parse a TAIP "IP" message to a TAIP_IP structure
*
* Sample IP Message: >RIP+37-122+0003<
*
* Given
* ip - a pointer to a TAIP_IP structure to be filled
* buf - a pointer to an IP message without the leading ">RIP"
* Return (in ip)
* parsed IP message
*/
static void parse_ip (ip, buf)
TAIP_IP *ip; /* pointer to a TAIP_IP structure to be filled */
char *buf; /* pointer to an IP message without the leading ">RIP" */
{
ip->lat_deg = antoi (&buf [0], 3); /* Degrees of latitude */
ip->lon_deg = antoi (&buf [3], 4); /* Degrees of longitude */
ip->alt = antol (&buf [7], 5) * 10; /* Altitude in meters */
}
/*
* parse_pt (TAIP_PT *pt, char *buf)
*
* Parse a TAIP "PT" message to a TAIP_PT structure
*
* Sample PT Message: >RPT4800,8,1,N<
*
* Given
* port - a pointer to a TAIP_PORT structure to be filled
* buf - a pointer to an PT message without the leading ">RPT"
* Return (in pt)
* parsed PT message
*/
static void parse_pt (port, buf)
TAIP_PORT *port; /* pointer to a TAIP_PORT structure to be filled */
char *buf; /* pointer to a PT message without the leading ">RPT" */
{
port->baud = atoi (&buf [0]); /* Baud rate */
port->data_bits = atoi (&buf [5]); /* Data bits */
port->stop_bits = atoi (&buf [7]); /* Stop bits */
port->parity = buf [9] == 'E' ? 2 : (buf [9] == 'O' ? 1 : 0); /* Parity */
}
/*
* parse_rm (TAIP_RM *rm, char *buf)
*
* Parse a TAIP "RM" message to a TAIP_RM structure
*
* Sample RM Message: >RRM;ID_FLAG=F;CS_FLAG=F;EC_FLAG=F;FR_FLAG=T<
*
* Given
* rm - a pointer to a TAIP_RM structure to be filled
* buf - a pointer to an RM message without the leading ">RRM"
* Return (in rm)
* parsed RM message
*/
static void parse_rm (rm, buf)
TAIP_RM *rm; /* pointer to a TAIP_RM structure to be filled */
char *buf; /* pointer to a RM message without the leading ">RRM" */
{
/* Set all flags FALSE */
rm->id_flag = rm->cs_flag = rm->fr_flag = rm->ec_flag = FALSE;
/*
* Scan through the TAIP message for semicolons,
* advancing the "buf" pointer each time.
*/
while ((buf = strchr (buf, ';')) != NULL) {
/* if scan finds ";ID_FLAG=" ... */
if (strncmp (buf, ";ID_FLAG=", 9) == 0) {
rm->id_flag = buf [9] == 'T'; /* set TRUE if ID_FLAG=T */
}
/* if scan finds ";CS_FLAG=" ... */
else if (strncmp (buf, ";CS_FLAG=", 9) == 0) {
rm->cs_flag = buf [9] == 'T'; /* set TRUE if CS_FLAG=T */
}
/* if scan finds ";EC_FLAG=" ... */
else if (strncmp (buf, ";EC_FLAG=", 9) == 0) {
rm->ec_flag = buf [9] == 'T'; /* set TRUE if EC_FLAG=T */
}
/* if scan finds ";FR_FLAG=" ... */
else if (strncmp (buf, ";FR_FLAG=", 9) == 0) {
rm->fr_flag = buf [9] == 'T'; /* set TRUE if FR_FLAG=T */
}
/* Advance the buf pointer past the semicolon for the next search */
++buf;
}
}
/*
* parse_st (TAIP_ST *st, char *buf)
*
* Parse a TAIP "ST" message to a TAIP_ST structure
*
* Sample ST Message: >RST0000240000<
*
* Given
* st - a pointer to a TAIP_ST structure to be filled
* buf - a pointer to an ST message without the leading ">RST"
* Return (in st)
* parsed ST message
*/
static void parse_st (st, buf)
TAIP_ST *st; /* pointer to a TAIP_ST structure to be filled */
char *buf; /* pointer to a ST message without the leading ">RST" */
{
int
i;
/* Copy the 5 status codes from the TAIP message to the ST structure */
for (i = 0; i < 5; i++) {
st->codes [i] = hatoi2 (&buf[i*2]);
}
}
/*
* parse_vr (TAIP_VR *vr, char *buf)
*
* Parse a TAIP "VR" message to a TAIP_VR structure
*
* Sample VR Message: >RVR PLACER 300D; VERSION 1.94 (08/05/92); COPYRIGHT (C) 1991, 1992 TRIMBLE NAVIGATION<
*
* Given
* vr - a pointer to a TAIP_VR structure to be filled
* buf - a pointer to an VR message without the leading ">RVR"
* Return (in vr)
* parsed VR message
*/
static void parse_vr (vr, buf)
TAIP_VR *vr; /* pointer to a TAIP_VR structure to be filled */
char *buf; /* pointer to a VR message without the leading ">RVR" */
{
char
*ptr;
/* Fill structure with unknowns in case some info is missing in VR */
strcpy (vr->name, "????????");
strcpy (vr->vers, "?.??");
strcpy (vr->rel_date, "??/??/??");
/* Copy the product name */
strncpy (vr->name, buf+1, VR_NAME_LEN);
vr->name [VR_NAME_LEN] = 0; /* truncate product name to maximum size */
/* if name contains a ';', stop the string there */
if ((ptr = strchr (vr->name, ';')) != NULL) {
*ptr = 0;
}
/* Scan for a ';' */
if ((buf = strchr (buf, ';')) != NULL) {
/* if Version follows... */
if (strncmp (buf, "; VERSION ", 10) == 0) {
/* copy into structure */
strncpy (vr->vers, buf + 10, VR_VERS_LEN);
vr->vers [VR_VERS_LEN] = 0; /* length limited */
buf += 15; /* skip over version info */
if (*buf == '(') { /* if date is here */
strncpy (vr->rel_date, buf + 1, VR_REL_LEN); /* copy date */
vr->rel_date [VR_REL_LEN] = 0; /* length limited */
}
}
}
}
/*
* parse_tm (TAIP_TM *tm, char *buf)
*
* Parse a TAIP "TM" message to a TAIP_TM structure
*
* Sample TM Message: >RTM1854223750511199208104100000<
*
* Given
* tm - a pointer to a TAIP_TM structure to be filled
* buf - a pointer to an TM message without the leading ">RTM"
* Return (in tm)
* parsed TM message
*/
static void parse_tm (tm, buf)
TAIP_TM *tm; /* pointer to a TAIP_TM structure to be filled */
char *buf; /* pointer to a TM message without the leading ">RTM" */
{
/*
0123456789012345678901234567
hhmmsssssDDMMYYYYoofuuvrrrrr 28 characters long
*/
tm->hr = antoi (&buf [ 0], 2); /* hour */
tm->mn = antoi (&buf [ 2], 2); /* minute */
tm->sc = antoi (&buf [ 4], 2); /* second */
tm->ms = antoi (&buf [ 6], 3); /* milliseconds */
tm->dy = antoi (&buf [ 9], 2); /* day */
tm->mo = antoi (&buf [11], 2); /* month */
tm->yr = antoi (&buf [13], 4); /* year */
tm->gpsutc = antoi (&buf [17], 2); /* GPS to UTC time offset */
tm->fix_type = parse_fix_type (buf [19]); /* Fix Type */
tm->n_sv = antoi (&buf [20], 2); /* Quantity of satellites */
tm->gpsutc_valid = buf[22] == '1'; /* Is GPS to UTC offset valid? */
}
/*
* parse_pv (TAIP_PV *pv, char *buf)
*
* Parse a TAIP "PV" message to a TAIP_PV structure
*
* Sample PV Message: >RPV68069+3739434-1220383600100012<
*
* Given
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -