📄 refclock_ripencc.c
字号:
lon_deg = (short)lon; lon_min = (lon - lon_deg) * 60.0; for (i=0; i<8; i++) { sv[i] = buf[i + 66]; if (sv[i]) { TSIPPKT spt; /* local structure for sendpacket */ b = (unsigned char) (sv[i]<0 ? -sv[i] : sv[i]); /* request tracking status */ cmd_0x3C (&spt, b); ripencc_send(peer,spt); } } sprintf(logbuf, "C1 %02d%02d%04d %02d%02d%02d %d %7.0f %.1f %.0f %.1f %d %02d%09.6f %c %02d%09.6f %c %.0f %d %d %d %d %d %d %d %d", day, month, year, hour, minute, second, mode, bias, biasunc, rate, rateunc, utcoff, lat_deg, lat_min, north_south, lon_deg, lon_min, east_west, alt, sv[0], sv[1], sv[2], sv[3], sv[4], sv[5], sv[6], sv[7]);#ifdef DEBUG_NCC if (debug) puts(logbuf);#endif /* DEBUG_NCC */ record_clock_stats(&peer->srcadr, logbuf); return (0);}#ifdef TRIMBLE_OUTPUT_FUNC/* * Parse any packet using Trimble machinery */int parseany(rpt, peer) TSIPPKT *rpt; struct peer *peer; { static char logbuf[1024]; /* logging string buffer */ TranslateTSIPReportToText (rpt, logbuf); /* anything else */#ifdef DEBUG_NCC if (debug) puts(&logbuf[1]);#endif /* DEBUG_NCC */ record_clock_stats(&peer->srcadr, &logbuf[1]); return(0);}#endif /* TRIMBLE_OUTPUT_FUNC *//* * Parse UTC Parameter Packet * * See the IDE for documentation! * * 0 = success * -1 = errors */int parse0x4F(rpt, peer) TSIPPKT *rpt; struct peer *peer; { register struct ripencc_unit *up; double a0; float a1, tot; int dt_ls, wn_t, wn_lsf, dn, dt_lsf; static char logbuf[1024]; /* logging string buffer */ unsigned char *buf; buf = rpt->buf; if (rpt->len != 26) return (-1); a0 = bGetDouble (buf); a1 = bGetSingle (&buf[8]); dt_ls = bGetShort (&buf[12]); tot = bGetSingle (&buf[14]); wn_t = bGetShort (&buf[18]); wn_lsf = bGetShort (&buf[20]); dn = bGetShort (&buf[22]); dt_lsf = bGetShort (&buf[24]); sprintf(logbuf, "L1 %d %d %d %g %g %g %d %d %d", dt_lsf - dt_ls, dt_ls, dt_lsf, a0, a1, tot, wn_t, wn_lsf, dn); #ifdef DEBUG_NCC if (debug) puts(logbuf);#endif /* DEBUG_NCC */ record_clock_stats(&peer->srcadr, logbuf); up = (struct ripencc_unit *) peer->procptr->unitptr; up->leapdelta = dt_lsf - dt_ls; return (0);}/* * Parse Tracking Status packet * * 0 = success * -1 = errors */int parse0x5C(rpt, peer) TSIPPKT *rpt; struct peer *peer; { unsigned char prn, channel, aqflag, ephstat; float snr, azinuth, elevation; static char logbuf[1024]; /* logging string buffer */ unsigned char *buf; buf = rpt->buf; if (rpt->len != 24) return(-1); prn = buf[0]; channel = (unsigned char)(buf[1] >> 3); if (channel == 0x10) channel = 2; else channel++; aqflag = buf[2]; ephstat = buf[3]; snr = bGetSingle(&buf[4]); elevation = bGetSingle(&buf[12]) * R2D; azinuth = bGetSingle(&buf[16]) * R2D; sprintf(logbuf, "S1 %02d %d %d %02x %4.1f %5.1f %4.1f", prn, channel, aqflag, ephstat, snr, azinuth, elevation);#ifdef DEBUG_NCC if (debug) puts(logbuf);#endif /* DEBUG_NCC */ record_clock_stats(&peer->srcadr, logbuf); return (0);}/******* Code below is from Trimble Tsipchat *************//* * ************************************************************************* * * Trimble Navigation, Ltd. * OEM Products Development Group * P.O. Box 3642 * 645 North Mary Avenue * Sunnyvale, California 94088-3642 * * Corporate Headquarter: * Telephone: (408) 481-8000 * Fax: (408) 481-6005 * * Technical Support Center: * Telephone: (800) 767-4822 (U.S. and Canada) * (408) 481-6940 (outside U.S. and Canada) * Fax: (408) 481-6020 * BBS: (408) 481-7800 * e-mail: trimble_support@trimble.com * ftp://ftp.trimble.com/pub/sct/embedded/bin * * ************************************************************************* * * ------- BYTE-SWAPPING ------- * TSIP is big-endian (Motorola) protocol. To use on little-endian (Intel) * systems, the bytes of all multi-byte types (shorts, floats, doubles, etc.) * must be reversed. This is controlled by the MACRO BYTESWAP; if defined, it * assumes little-endian protocol. * -------------------------------- * * T_PARSER.C and T_PARSER.H contains primitive functions that interpret * reports received from the receiver. A second source file pair, * T_FORMAT.C and T_FORMAT.H, contin the matching TSIP command formatters. * * The module is in very portable, basic C language. It can be used as is, or * with minimal changes if a TSIP communications application is needed separate * from TSIPCHAT. The construction of most argument lists avoid the use of * structures, but the developer is encouraged to reconstruct them using such * definitions to meet project requirements. Declarations of T_PARSER.C * functions are included in T_PARSER.H to provide prototyping definitions. * * There are two types of functions: a serial input processing routine, * tsip_input_proc() * which assembles incoming bytes into a TSIPPKT structure, and the * report parsers, rpt_0x??(). * * 1) The function tsip_input_proc() accumulates bytes from the receiver, * strips control bytes (DLE), and checks if the report end sequence (DLE ETX) * has been received. rpt.status is defined as TSIP_PARSED_FULL (== 1) * if a complete packet is available. * * 2) The functions rpt_0x??() are report string interpreters patterned after * the document called "Trimble Standard Interface Protocol". It should be * noted that if the report buffer is sent into the receiver with the wrong * length (byte count), the rpt_0x??() returns the Boolean equivalence for * TRUE. * * ************************************************************************* * *//**/static void tsip_input_proc ( TSIPPKT *rpt, int inbyte)/* reads bytes until serial buffer is empty or a complete report * has been received; end of report is signified by DLE ETX. */{ unsigned char newbyte; if (inbyte < 0 || inbyte > 0xFF) return; newbyte = (unsigned char)(inbyte); switch (rpt->status) { case TSIP_PARSED_DLE_1: switch (newbyte) { case 0: case ETX: /* illegal TSIP IDs */ rpt->len = 0; rpt->status = TSIP_PARSED_EMPTY; break; case DLE: /* try normal message start again */ rpt->len = 0; rpt->status = TSIP_PARSED_DLE_1; break; default: /* legal TSIP ID; start message */ rpt->code = newbyte; rpt->len = 0; rpt->status = TSIP_PARSED_DATA; break; } break; case TSIP_PARSED_DATA: switch (newbyte) { case DLE: /* expect DLE or ETX next */ rpt->status = TSIP_PARSED_DLE_2; break; default: /* normal data byte */ rpt->buf[rpt->len] = newbyte; rpt->len++; /* no change in rpt->status */ break; } break; case TSIP_PARSED_DLE_2: switch (newbyte) { case DLE: /* normal data byte */ rpt->buf[rpt->len] = newbyte; rpt->len++; rpt->status = TSIP_PARSED_DATA; break; case ETX: /* end of message; return TRUE here. */ rpt->status = TSIP_PARSED_FULL; break; default: /* error: treat as TSIP_PARSED_DLE_1; start new report packet */ rpt->code = newbyte; rpt->len = 0; rpt->status = TSIP_PARSED_DATA; } break; case TSIP_PARSED_FULL: case TSIP_PARSED_EMPTY: default: switch (newbyte) { case DLE: /* normal message start */ rpt->len = 0; rpt->status = TSIP_PARSED_DLE_1; break; default: /* error: ignore newbyte */ rpt->len = 0; rpt->status = TSIP_PARSED_EMPTY; } break; } if (rpt->len > MAX_RPTBUF) { /* error: start new report packet */ rpt->status = TSIP_PARSED_EMPTY; rpt->len = 0; }}#ifdef TRIMBLE_OUTPUT_FUNC/**/short rpt_0x3D (TSIPPKT *rpt, unsigned char *tx_baud_index, unsigned char *rx_baud_index, unsigned char *char_format_index, unsigned char *stop_bits, unsigned char *tx_mode_index, unsigned char *rx_mode_index)/* Channel A configuration for dual port operation */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 6) return TRUE; *tx_baud_index = buf[0]; *rx_baud_index = buf[1]; *char_format_index = buf[2]; *stop_bits = (unsigned char)((buf[3] == 0x07) ? 1 : 2); *tx_mode_index = buf[4]; *rx_mode_index = buf[5]; return FALSE;}/**/short rpt_0x40 (TSIPPKT *rpt, unsigned char *sv_prn, short *week_num, float *t_zc, float *eccentricity, float *t_oa, float *i_0, float *OMEGA_dot, float *sqrt_A, float *OMEGA_0, float *omega, float *M_0)/* almanac data for specified satellite */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 39) return TRUE; *sv_prn = buf[0]; *t_zc = bGetSingle (&buf[1]); *week_num = bGetShort (&buf[5]); *eccentricity = bGetSingle (&buf[7]); *t_oa = bGetSingle (&buf[11]); *i_0 = bGetSingle (&buf[15]); *OMEGA_dot = bGetSingle (&buf[19]); *sqrt_A = bGetSingle (&buf[23]); *OMEGA_0 = bGetSingle (&buf[27]); *omega = bGetSingle (&buf[31]); *M_0 = bGetSingle (&buf[35]); return FALSE;}short rpt_0x41 (TSIPPKT *rpt, float *time_of_week, float *UTC_offset, short *week_num)/* GPS time */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 10) return TRUE; *time_of_week = bGetSingle (buf); *week_num = bGetShort (&buf[4]); *UTC_offset = bGetSingle (&buf[6]); return FALSE;}short rpt_0x42 (TSIPPKT *rpt, float pos_ECEF[3], float *time_of_fix)/* position in ECEF, single precision */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 16) return TRUE; pos_ECEF[0] = bGetSingle (buf); pos_ECEF[1]= bGetSingle (&buf[4]); pos_ECEF[2]= bGetSingle (&buf[8]); *time_of_fix = bGetSingle (&buf[12]); return FALSE;}short rpt_0x43 (TSIPPKT *rpt, float ECEF_vel[3], float *freq_offset, float *time_of_fix)/* velocity in ECEF, single precision */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 20) return TRUE; ECEF_vel[0] = bGetSingle (buf); ECEF_vel[1] = bGetSingle (&buf[4]); ECEF_vel[2] = bGetSingle (&buf[8]); *freq_offset = bGetSingle (&buf[12]); *time_of_fix = bGetSingle (&buf[16]); return FALSE;}short rpt_0x45 (TSIPPKT *rpt, unsigned char *major_nav_version, unsigned char *minor_nav_version, unsigned char *nav_day, unsigned char *nav_month, unsigned char *nav_year, unsigned char *major_dsp_version, unsigned char *minor_dsp_version, unsigned char *dsp_day, unsigned char *dsp_month, unsigned char *dsp_year)/* software versions */ { unsigned char *buf; buf = rpt->buf; if (rpt->len != 10) return TRUE; *major_nav_version = buf[0]; *minor_nav_version = buf[1]; *nav_day = buf[2]; *nav_month = buf[3]; *nav_year = buf[4]; *major_dsp_version = buf[5]; *minor_dsp_version = buf[6]; *dsp_day = buf[7]; *dsp_month = buf[8]; *dsp_year = buf[9]; return FALSE;}short rpt_0x46 (TSIPPKT *rpt, unsigned char *status1, unsigned char *status2)/* receiver health and status */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 2) return TRUE; *status1 = buf[0]; *status2 = buf[1]; return FALSE;}short rpt_0x47 (TSIPPKT *rpt, unsigned char *nsvs, unsigned char *sv_prn, float *snr)/* signal levels for all satellites tracked */{ short isv; unsigned char *buf; buf = rpt->buf; if (rpt->len != 1 + 5*buf[0]) return TRUE; *nsvs = buf[0]; for (isv = 0; isv < (*nsvs); isv++) { sv_prn[isv] = buf[5*isv + 1]; snr[isv] = bGetSingle (&buf[5*isv + 2]); } return FALSE;}short rpt_0x48 (TSIPPKT *rpt, unsigned char *message)/* GPS system message */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 22) return TRUE; memcpy (message, buf, 22); message[22] = 0; return FALSE;}short rpt_0x49 (TSIPPKT *rpt, unsigned char *sv_health)/* health for all satellites from almanac health page */{ short i; unsigned char *buf; buf = rpt->buf; if (rpt->len != 32) return TRUE; for (i = 0; i < 32; i++) sv_health [i]= buf[i]; return FALSE;}short rpt_0x4A (TSIPPKT *rpt, float *lat, float *lon, float *alt, float *clock_bias, float *time_of_fix)/* position in lat-lon-alt, single precision */{ unsigned char *buf; buf = rpt->buf; if (rpt->len != 20) return TRUE; *lat = bGetSingle (buf); *lon = bGetSingle (&buf[4]); *alt = bGetSingle (&buf[8]); *clock_bias = bGetSingle (&buf[12]); *time_of_fix = bGetSingle (&buf[16]); return FALSE;}short rpt_0x4A_2 (TSIPPKT *rpt,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -