kopia lustrzana https://github.com/rs1729/RS
json update, m10 utc offset
rodzic
3969a12aa3
commit
da27d32a67
|
@ -34,18 +34,9 @@ typedef struct {
|
|||
i8_t inv;
|
||||
i8_t aut;
|
||||
i8_t col; // colors
|
||||
i8_t jsn; // JSON output (auto_rx)
|
||||
} option_t;
|
||||
|
||||
/*
|
||||
int option_verbose = 0, // ausfuehrliche Anzeige
|
||||
option_raw = 0, // rohe Frames
|
||||
option_inv = 0, // invertiert Signal
|
||||
option_res = 0, // genauere Bitmessung
|
||||
option_color = 0,
|
||||
option_ptu = 0,
|
||||
option_dc = 0,
|
||||
wavloaded = 0;
|
||||
*/
|
||||
|
||||
/*
|
||||
9600 baud -> 9616 baud ?
|
||||
|
@ -80,13 +71,15 @@ static char rawheader[] = "10011001100110010100110010011001";
|
|||
|
||||
|
||||
typedef struct {
|
||||
int week; int gpssec;
|
||||
int week; int tow_ms; int gpssec;
|
||||
int jahr; int monat; int tag;
|
||||
int wday;
|
||||
int std; int min; int sek;
|
||||
int std; int min; float sek;
|
||||
double lat; double lon; double alt;
|
||||
double vH; double vD; double vV;
|
||||
double vx; double vy; double vD2;
|
||||
ui8_t numSV;
|
||||
ui8_t utc_ofs;
|
||||
char SN[12];
|
||||
ui8_t frame_bytes[FRAME_LEN+AUX_LEN+4];
|
||||
char frame_bits[BITFRAME_LEN+BITAUX_LEN+8];
|
||||
|
@ -153,11 +146,61 @@ static int bits2bytes(char *bitstr, ui8_t *bytes) {
|
|||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
M10 w/ trimble GPS
|
||||
|
||||
frame[0x0] = framelen
|
||||
frame[0x1] = 0x9F (type M10)
|
||||
|
||||
init/noGPS: frame[0x2]=0x23
|
||||
GPS: frame[0x2]=0x20 (GPS trimble pck 0x8F-20 sub-id)
|
||||
|
||||
frame[0x02..0x21] = GPS trimble pck 0x8F-20 byte 0..31 (sub-id, vel, tow, lat, lon, alt, fix, NumSV, UTC-ofs, week)
|
||||
frame[0x22..0x2D] = GPS trimble pck 0x8F-20 byte 32..55:2 (PRN 1..12 only)
|
||||
|
||||
Trimble Copernicus II
|
||||
GPS packet 0x8F-20 (p.138)
|
||||
byte
|
||||
0 sub-pck id (always 0x20)
|
||||
2-3 velE (i16) 0.005m/s
|
||||
4-5 velN (i16) 0.005m/s
|
||||
6-7 velU (i16) 0.005m/s
|
||||
8-11 TOW (ms)
|
||||
12-15 lat (scale 2^32/360) (i32) -90..90
|
||||
16-19 lon (scale 2^32/360) (ui32) 0..360 <-> (i32) -180..180
|
||||
20-23 alt (i32) mm above ellipsoid)
|
||||
24 bit0: vel-scale (0: 0.005m/s)
|
||||
26 datum (1: WGS-84)
|
||||
27 fix: bit0(0:valid fix, 1:invalid fix), bit2(0:3D, 1:2D)
|
||||
28 numSVs
|
||||
29 UTC offset = (GPS - UTC) sec
|
||||
30-31 GPS week
|
||||
32+2*n PRN_(n+1), bit0-5
|
||||
|
||||
frame[0x32..0x5C] sensors (rel.hum., temp.)
|
||||
frame[0x5D..0x61] SN
|
||||
frame[0x62] counter
|
||||
frame[0x63..0x64] check (AUX len=0x76: frame[0x63..0x74], frame[0x75..0x76])
|
||||
|
||||
|
||||
6449/10sec-frame:
|
||||
GPS trimble pck 0x47 (signal levels): numSats sat1 lev1 sat2 lev2 ..
|
||||
frame[0x0] = framelen
|
||||
frame[0x1] = 0x49
|
||||
frame[0x2] = numSats (max 12)
|
||||
frame[0x3+2*n] = PRN_(n+1)
|
||||
frame[0x4+2*n] = signal level (float32 -> i8-byte level)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define stdFLEN 0x64 // pos[0]=0x64
|
||||
#define pos_GPSTOW 0x0A // 4 byte
|
||||
#define pos_GPSlat 0x0E // 4 byte
|
||||
#define pos_GPSlon 0x12 // 4 byte
|
||||
#define pos_GPSalt 0x16 // 4 byte
|
||||
#define pos_GPSsats 0x1E // 1 byte
|
||||
#define pos_GPSutc 0x1F // 1 byte
|
||||
#define pos_GPSweek 0x20 // 2 byte
|
||||
//Velocity East-North-Up (ENU)
|
||||
#define pos_GPSvE 0x04 // 2 byte
|
||||
|
@ -203,6 +246,9 @@ static int get_GPSweek(gpx_t *gpx) {
|
|||
ui8_t gpsweek_bytes[2];
|
||||
int gpsweek;
|
||||
|
||||
gpx->numSV = gpx->frame_bytes[pos_GPSsats];
|
||||
gpx->utc_ofs = gpx->frame_bytes[pos_GPSutc];
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
byte = gpx->frame_bytes[pos_GPSweek + i];
|
||||
gpsweek_bytes[i] = byte;
|
||||
|
@ -223,7 +269,8 @@ static int get_GPStime(gpx_t *gpx) {
|
|||
int i;
|
||||
unsigned byte;
|
||||
ui8_t gpstime_bytes[4];
|
||||
int gpstime, day; // int ms;
|
||||
int gpstime, day;
|
||||
int ms;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = gpx->frame_bytes[pos_GPSTOW + i];
|
||||
|
@ -235,18 +282,20 @@ static int get_GPStime(gpx_t *gpx) {
|
|||
gpstime |= gpstime_bytes[i] << (8*(3-i));
|
||||
}
|
||||
|
||||
//ms = gpstime % 1000;
|
||||
gpx->tow_ms = gpstime;
|
||||
ms = gpstime % 1000;
|
||||
gpstime /= 1000;
|
||||
gpx->gpssec = gpstime;
|
||||
|
||||
day = gpstime / (24 * 3600);
|
||||
if ((day < 0) || (day > 6)) return -1;
|
||||
|
||||
gpstime %= (24*3600);
|
||||
|
||||
if ((day < 0) || (day > 6)) return -1;
|
||||
gpx->wday = day;
|
||||
gpx->std = gpstime/3600;
|
||||
gpx->std = gpstime/3600;
|
||||
gpx->min = (gpstime%3600)/60;
|
||||
gpx->sek = gpstime%60;
|
||||
gpx->sek = gpstime%60 + ms/1000.0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -626,7 +675,7 @@ double get_RH(int csOK) {
|
|||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static int print_pos(gpx_t *gpx, int csOK) {
|
||||
int err;
|
||||
int err, err2;
|
||||
|
||||
err = 0;
|
||||
err |= get_GPSweek(gpx);
|
||||
|
@ -634,6 +683,7 @@ static int print_pos(gpx_t *gpx, int csOK) {
|
|||
err |= get_GPSlat(gpx);
|
||||
err |= get_GPSlon(gpx);
|
||||
err |= get_GPSalt(gpx);
|
||||
err2 = get_GPSvel(gpx);
|
||||
|
||||
if (!err) {
|
||||
|
||||
|
@ -641,28 +691,25 @@ static int print_pos(gpx_t *gpx, int csOK) {
|
|||
|
||||
if (gpx->option.col) {
|
||||
fprintf(stdout, col_TXT);
|
||||
fprintf(stdout, " (W "col_GPSweek"%d"col_TXT") ", gpx->week);
|
||||
if (gpx->option.vbs >= 3) fprintf(stdout, " (W "col_GPSweek"%d"col_TXT") ", gpx->week);
|
||||
fprintf(stdout, col_GPSTOW"%s"col_TXT" ", weekday[gpx->wday]);
|
||||
fprintf(stdout, col_GPSdate"%04d-%02d-%02d"col_TXT" ("col_GPSTOW"%02d:%02d:%02d"col_TXT") ",
|
||||
fprintf(stdout, col_GPSdate"%04d-%02d-%02d"col_TXT" "col_GPSTOW"%02d:%02d:%06.3f"col_TXT" ",
|
||||
gpx->jahr, gpx->monat, gpx->tag, gpx->std, gpx->min, gpx->sek);
|
||||
fprintf(stdout, " lat: "col_GPSlat"%.5f"col_TXT" ", gpx->lat);
|
||||
fprintf(stdout, " lon: "col_GPSlon"%.5f"col_TXT" ", gpx->lon);
|
||||
fprintf(stdout, " alt: "col_GPSalt"%.2f"col_TXT" ", gpx->alt);
|
||||
if (gpx->option.vbs) {
|
||||
err |= get_GPSvel(gpx);
|
||||
if (!err) {
|
||||
//if (gpx->option.vbs == 2) fprintf(stdout, " "col_GPSvel"(%.1f , %.1f : %.1f)"col_TXT" ", gpx->vx, gpx->vy, gpx->vD2);
|
||||
fprintf(stdout, " vH: "col_GPSvel"%.1f"col_TXT" D: "col_GPSvel"%.1f"col_TXT"° vV: "col_GPSvel"%.1f"col_TXT" ", gpx->vH, gpx->vD, gpx->vV);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
get_SN(gpx);
|
||||
fprintf(stdout, " SN: "col_SN"%s"col_TXT, gpx->SN);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
fprintf(stdout, " # ");
|
||||
if (csOK) fprintf(stdout, " "col_CSok"[OK]"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"[NO]"col_TXT);
|
||||
}
|
||||
if (!err2) {
|
||||
//if (gpx->option.vbs == 2) fprintf(stdout, " "col_GPSvel"(%.1f , %.1f : %.1f)"col_TXT" ", gpx->vx, gpx->vy, gpx->vD2);
|
||||
fprintf(stdout, " vH: "col_GPSvel"%.1f"col_TXT" D: "col_GPSvel"%.1f"col_TXT"° vV: "col_GPSvel"%.1f"col_TXT" ", gpx->vH, gpx->vD, gpx->vV);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
get_SN(gpx);
|
||||
fprintf(stdout, " SN: "col_SN"%s"col_TXT, gpx->SN);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
fprintf(stdout, " # ");
|
||||
if (csOK) fprintf(stdout, " "col_CSok"[OK]"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"[NO]"col_TXT);
|
||||
}
|
||||
if (gpx->option.ptu) {
|
||||
float t = get_Temp(gpx, csOK);
|
||||
|
@ -676,27 +723,24 @@ static int print_pos(gpx_t *gpx, int csOK) {
|
|||
fprintf(stdout, ANSI_COLOR_RESET"");
|
||||
}
|
||||
else {
|
||||
fprintf(stdout, " (W %d) ", gpx->week);
|
||||
if (gpx->option.vbs >= 3) fprintf(stdout, " (W %d) ", gpx->week);
|
||||
fprintf(stdout, "%s ", weekday[gpx->wday]);
|
||||
fprintf(stdout, "%04d-%02d-%02d (%02d:%02d:%02d) ",
|
||||
fprintf(stdout, "%04d-%02d-%02d %02d:%02d:%06.3f ",
|
||||
gpx->jahr, gpx->monat, gpx->tag, gpx->std, gpx->min, gpx->sek);
|
||||
fprintf(stdout, " lat: %.5f ", gpx->lat);
|
||||
fprintf(stdout, " lon: %.5f ", gpx->lon);
|
||||
fprintf(stdout, " alt: %.2f ", gpx->alt);
|
||||
if (gpx->option.vbs) {
|
||||
err |= get_GPSvel(gpx);
|
||||
if (!err) {
|
||||
//if (gpx->option.vbs == 2) fprintf(stdout, " (%.1f , %.1f : %.1f°) ", gpx->vx, gpx->vy, gpx->vD2);
|
||||
fprintf(stdout, " vH: %.1f D: %.1f° vV: %.1f ", gpx->vH, gpx->vD, gpx->vV);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
get_SN(gpx);
|
||||
fprintf(stdout, " SN: %s", gpx->SN);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
fprintf(stdout, " # ");
|
||||
if (csOK) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
|
||||
}
|
||||
if (!err2) {
|
||||
//if (gpx->option.vbs == 2) fprintf(stdout, " (%.1f , %.1f : %.1f°) ", gpx->vx, gpx->vy, gpx->vD2);
|
||||
fprintf(stdout, " vH: %.1f D: %.1f° vV: %.1f ", gpx->vH, gpx->vD, gpx->vV);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
get_SN(gpx);
|
||||
fprintf(stdout, " SN: %s", gpx->SN);
|
||||
}
|
||||
if (gpx->option.vbs >= 2) {
|
||||
fprintf(stdout, " # ");
|
||||
if (csOK) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
|
||||
}
|
||||
if (gpx->option.ptu) {
|
||||
float t = get_Temp(gpx, csOK);
|
||||
|
@ -710,6 +754,42 @@ static int print_pos(gpx_t *gpx, int csOK) {
|
|||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
|
||||
if (gpx->option.jsn) {
|
||||
// Print out telemetry data as JSON
|
||||
if (csOK) {
|
||||
int j;
|
||||
char sn_id[4+12] = "M10-";
|
||||
// UTC = GPS - UTC_OFS (ab 1.1.2017: UTC_OFS=18sec)
|
||||
int utc_s = gpx->gpssec - gpx->utc_ofs;
|
||||
int utc_week = gpx->week;
|
||||
int utc_jahr; int utc_monat; int utc_tag;
|
||||
int utc_std; int utc_min; float utc_sek;
|
||||
if (utc_s < 0) {
|
||||
utc_week -= 1;
|
||||
utc_s += 604800; // 604800sec = 1week
|
||||
}
|
||||
Gps2Date(utc_week, utc_s, &utc_jahr, &utc_monat, &utc_tag);
|
||||
utc_s %= (24*3600); // 86400sec = 1day
|
||||
utc_std = utc_s/3600;
|
||||
utc_min = (utc_s%3600)/60;
|
||||
utc_sek = utc_s%60 + (gpx->tow_ms % 1000)/1000.0;
|
||||
|
||||
strncpy(sn_id+4, gpx->SN, 12);
|
||||
sn_id[15] = '\0';
|
||||
for (j = 0; sn_id[j]; j++) { if (sn_id[j] == ' ') sn_id[j] = '-'; }
|
||||
|
||||
fprintf(stdout, "{ \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f, \"sats\": %d",
|
||||
sn_id, utc_jahr, utc_monat, utc_tag, utc_std, utc_min, utc_sek, gpx->lat, gpx->lon, gpx->alt, gpx->vH, gpx->vD, gpx->vV, gpx->numSV);
|
||||
if (gpx->option.ptu) {
|
||||
float t = get_Temp(gpx, 0);
|
||||
if (t > -273.0) fprintf(stdout, ", \"temp\": %.1f", t);
|
||||
}
|
||||
fprintf(stdout, " }\n");
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -886,6 +966,7 @@ int main(int argc, char **argv) {
|
|||
else if (strcmp(*argv, "--iq0") == 0) { option_iq = 1; } // differential/FM-demod
|
||||
else if (strcmp(*argv, "--iq2") == 0) { option_iq = 2; }
|
||||
else if (strcmp(*argv, "--iq3") == 0) { option_iq = 3; } // iq2==iq3
|
||||
else if (strcmp(*argv, "--json") == 0) { gpx.option.jsn = 1; }
|
||||
else {
|
||||
fp = fopen(*argv, "rb");
|
||||
if (fp == NULL) {
|
||||
|
|
|
@ -62,7 +62,7 @@ typedef struct {
|
|||
int frmlen;
|
||||
} rscfg_t;
|
||||
|
||||
rscfg_t cfg_rs41 = { 41, (320-56)/2, 56, 8, 8, 320}; // const: msgpos, parpos
|
||||
static rscfg_t cfg_rs41 = { 41, (320-56)/2, 56, 8, 8, 320}; // const: msgpos, parpos
|
||||
|
||||
|
||||
#define NDATA_LEN 320 // std framelen 320
|
||||
|
@ -77,7 +77,7 @@ typedef struct {
|
|||
int frnr;
|
||||
char id[9];
|
||||
ui8_t numSV;
|
||||
int week; int gpssec;
|
||||
int week; int tow_ms; int gpssec;
|
||||
int jahr; int monat; int tag;
|
||||
int wday;
|
||||
int std; int min; float sek;
|
||||
|
@ -633,9 +633,10 @@ static int get_GPStime(gpx_t *gpx) {
|
|||
}
|
||||
|
||||
memcpy(&gpstime, gpstime_bytes, 4);
|
||||
|
||||
gpx->tow_ms = gpstime;
|
||||
ms = gpstime % 1000;
|
||||
gpstime /= 1000;
|
||||
|
||||
gpx->gpssec = gpstime;
|
||||
|
||||
day = (gpstime / (24 * 3600)) % 7;
|
||||
|
@ -644,9 +645,9 @@ static int get_GPStime(gpx_t *gpx) {
|
|||
gpstime %= (24*3600);
|
||||
|
||||
gpx->wday = day;
|
||||
gpx->std = gpstime / 3600;
|
||||
gpx->std = gpstime / 3600;
|
||||
gpx->min = (gpstime % 3600) / 60;
|
||||
gpx->sek = gpstime % 60 + ms/1000.0;
|
||||
gpx->sek = gpstime % 60 + ms/1000.0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1111,18 +1112,19 @@ static int print_position(gpx_t *gpx, int ec) {
|
|||
|
||||
|
||||
if (gpx->option.jsn) {
|
||||
// Print JSON output required by auto_rx.
|
||||
// Print out telemetry data as JSON
|
||||
if (!err && !err1 && !err3) { // frame-nb/id && gps-time && gps-position (crc-)ok; 3 CRCs, RS not needed
|
||||
// eigentlich GPS, d.h. UTC = GPS - 18sec (ab 1.1.2017)
|
||||
printf("{ \"frame\": %d, \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f, \"sats\": %d", gpx->frnr, gpx->id, gpx->jahr, gpx->monat, gpx->tag, gpx->std, gpx->min, gpx->sek, gpx->lat, gpx->lon, gpx->alt, gpx->vH, gpx->vD, gpx->vU, gpx->numSV );
|
||||
fprintf(stdout, "{ \"frame\": %d, \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f, \"sats\": %d",
|
||||
gpx->frnr, gpx->id, gpx->jahr, gpx->monat, gpx->tag, gpx->std, gpx->min, gpx->sek, gpx->lat, gpx->lon, gpx->alt, gpx->vH, gpx->vD, gpx->vU, gpx->numSV);
|
||||
if (gpx->option.ptu && !err0 && gpx->T > -273.0) {
|
||||
printf(", \"temp\":%.1f", gpx->T );
|
||||
fprintf(stdout, ", \"temp\": %.1f", gpx->T );
|
||||
}
|
||||
if (gpx->aux) { // <=> gpx->xdata[0]!='\0'
|
||||
printf(", \"aux\":\"%s\"", gpx->xdata );
|
||||
fprintf(stdout, ", \"aux\": \"%s\"", gpx->xdata );
|
||||
}
|
||||
printf(" }\n");
|
||||
printf("\n");
|
||||
fprintf(stdout, " }\n");
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ typedef struct {
|
|||
int sats[4];
|
||||
double dop;
|
||||
int freq;
|
||||
ui32_t crc;
|
||||
unsigned short aux[4];
|
||||
double diter;
|
||||
} gpx_t;
|
||||
|
@ -78,7 +79,6 @@ int option_verbose = 0, // ausfuehrliche Anzeige
|
|||
option_vel = 0, // velocity
|
||||
option_aux = 0, // Aux/Ozon
|
||||
option_der = 0, // linErr
|
||||
option_ths = 0,
|
||||
option_json = 0, // JSON output (auto_rx)
|
||||
rawin = 0;
|
||||
int wav_channel = 0; // audio channel: left
|
||||
|
@ -193,17 +193,23 @@ void Gps2Date(long GpsWeek, long GpsSeconds, int *Year, int *Month, int *Day) {
|
|||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
|
||||
#define crc_FRAME (1<<0)
|
||||
#define pos_FrameNb 0x08 // 2 byte
|
||||
#define pos_SondeID 0x0C // 8 byte // oder: 0x0A, 10 byte?
|
||||
#define pos_CalData 0x17 // 1 byte, counter 0x00..0x1f
|
||||
#define pos_Calfreq 0x1A // 2 byte, calfr 0x00
|
||||
|
||||
#define crc_GPS (1<<2)
|
||||
#define posGPS_TOW 0x48 // 4 byte
|
||||
#define posGPS_PRN 0x4E // 12*5 bit in 8 byte
|
||||
#define posGPS_STATUS 0x56 // 12 byte
|
||||
#define posGPS_DATA 0x62 // 12*8 byte
|
||||
|
||||
#define crc_PTU (1<<1)
|
||||
#define pos_PTU 0x2C // 24 byte
|
||||
|
||||
#define crc_AUX (1<<3)
|
||||
#define pos_AUX 0xC6 // 10 byte
|
||||
#define pos_AuxData 0xC8 // 8 byte
|
||||
|
||||
|
||||
|
@ -215,6 +221,7 @@ void Gps2Date(long GpsWeek, long GpsSeconds, int *Year, int *Month, int *Day) {
|
|||
#define LEN_CFG (2*(BLOCK_CFG & 0xFF))
|
||||
#define LEN_GPS (2*(BLOCK_GPS & 0xFF))
|
||||
#define LEN_PTU (2*(BLOCK_PTU & 0xFF))
|
||||
#define LEN_AUX (2*(BLOCK_AUX & 0xFF))
|
||||
|
||||
|
||||
int crc16(int start, int len) {
|
||||
|
@ -266,6 +273,7 @@ int get_SondeID() {
|
|||
// BLOCK_CFG == frame[pos_FrameNb-2 .. pos_FrameNb-1] ?
|
||||
crc_frame = framebyte(pos_FrameNb+LEN_CFG) | (framebyte(pos_FrameNb+LEN_CFG+1) << 8);
|
||||
crc = crc16(pos_FrameNb, LEN_CFG);
|
||||
if (crc_frame != crc) gpx.crc |= crc_FRAME;
|
||||
/*
|
||||
if (option_crc) {
|
||||
//fprintf(stdout, " (%04X:%02X%02X) ", BLOCK_CFG, frame[pos_FrameNb-2], frame[pos_FrameNb-1]);
|
||||
|
@ -291,20 +299,37 @@ int get_SondeID() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int get_PTU() {
|
||||
int ret=0;
|
||||
int crc_frame, crc;
|
||||
|
||||
crc_frame = frame[pos_PTU+LEN_PTU] | (frame[pos_PTU+LEN_PTU+1] << 8);
|
||||
crc = crc16(pos_PTU, LEN_PTU);
|
||||
if (crc_frame != crc) gpx.crc |= crc_PTU;
|
||||
|
||||
ret = 0;
|
||||
if (option_crc && crc != crc_frame) {
|
||||
ret = -2;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char weekday[7][3] = { "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"};
|
||||
|
||||
int get_GPStime() {
|
||||
int i, ret=0;
|
||||
unsigned byte;
|
||||
ui8_t gpstime_bytes[4];
|
||||
int gpstime = 0, // 32bit
|
||||
day;
|
||||
ui32_t gpstime = 0; // 32bit
|
||||
int day;
|
||||
int ms;
|
||||
int crc_frame, crc;
|
||||
|
||||
// BLOCK_GPS == frame[posGPS_TOW-2 .. posGPS_TOW-1] ?
|
||||
crc_frame = framebyte(posGPS_TOW+LEN_GPS) | (framebyte(posGPS_TOW+LEN_GPS+1) << 8);
|
||||
crc = crc16(posGPS_TOW, LEN_GPS);
|
||||
if (crc_frame != crc) gpx.crc |= crc_GPS;
|
||||
/*
|
||||
if (option_crc) {
|
||||
//fprintf(stdout, " (%04X:%02X%02X) ", BLOCK_GPS, frame[posGPS_TOW-2], frame[posGPS_TOW-1]);
|
||||
|
@ -333,23 +358,33 @@ int get_GPStime() {
|
|||
gpstime %= (24*3600);
|
||||
|
||||
gpx.wday = day;
|
||||
gpx.std = gpstime / 3600;
|
||||
gpx.std = gpstime / 3600;
|
||||
gpx.min = (gpstime % 3600) / 60;
|
||||
gpx.sek = gpstime % 60 + ms/1000.0;
|
||||
gpx.sek = gpstime % 60 + ms/1000.0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_Aux() {
|
||||
int i;
|
||||
int i, ret=0;
|
||||
unsigned short byte;
|
||||
int crc_frame, crc;
|
||||
|
||||
crc_frame = frame[pos_AUX+LEN_AUX] | (frame[pos_AUX+LEN_AUX+1] << 8);
|
||||
crc = crc16(pos_AUX, LEN_AUX);
|
||||
if (crc_frame != crc) gpx.crc |= crc_AUX;
|
||||
|
||||
ret = 0;
|
||||
if (option_crc && crc != crc_frame) {
|
||||
ret = -2;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = framebyte(pos_AuxData+2*i)+(framebyte(pos_AuxData+2*i+1)<<8);
|
||||
gpx.aux[i] = byte;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_Cal() {
|
||||
|
@ -368,15 +403,14 @@ int get_Cal() {
|
|||
fprintf(stdout, "\n");
|
||||
fprintf(stdout, "[%5d] ", gpx.frnr);
|
||||
fprintf(stdout, " 0x%02x:", calfr);
|
||||
}
|
||||
for (i = 0; i < 16; i++) {
|
||||
byte = framebyte(pos_CalData+1+i);
|
||||
if (option_verbose == 4) {
|
||||
for (i = 0; i < 16; i++) {
|
||||
byte = framebyte(pos_CalData+1+i);
|
||||
fprintf(stdout, " %02x", byte);
|
||||
}
|
||||
if ((gpx.crc & crc_FRAME)==0) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
|
||||
}
|
||||
|
||||
if (option_aux) {
|
||||
get_Aux();
|
||||
if (option_verbose == 4) {
|
||||
fprintf(stdout, " # ");
|
||||
for (i = 0; i < 8; i++) {
|
||||
|
@ -384,11 +418,6 @@ int get_Cal() {
|
|||
fprintf(stdout, "%02x ", byte);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (gpx.aux[0] != 0 || gpx.aux[1] != 0 || gpx.aux[2] != 0 || gpx.aux[3] != 0) {
|
||||
fprintf(stdout, " # %04x %04x %04x %04x", gpx.aux[0], gpx.aux[1], gpx.aux[2], gpx.aux[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (calfr == 0x00) {
|
||||
|
@ -399,13 +428,13 @@ int get_Cal() {
|
|||
//fprintf(stdout, ":%04x ", byte);
|
||||
freq = 400000 + 10*byte; // kHz;
|
||||
gpx.freq = freq;
|
||||
fprintf(stdout, " : fq %d kHz", freq);
|
||||
fprintf(stdout, ": fq %d", freq);
|
||||
for (i = 0; i < 2; i++) {
|
||||
bytes[i] = framebyte(pos_Calfreq + 2 + i);
|
||||
}
|
||||
killtime = bytes[0] + (bytes[1] << 8);
|
||||
if (killtime < 0xFFFF && option_verbose == 4) {
|
||||
fprintf(stdout, " ; KT:%ds", killtime);
|
||||
fprintf(stdout, "; KT:%ds", killtime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1083,20 +1112,20 @@ int rs92_ecc(int msglen) {
|
|||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
|
||||
int print_position() { // GPS-Hoehe ueber Ellipsoid
|
||||
int print_position(int ec) { // GPS-Hoehe ueber Ellipsoid
|
||||
int j, k, n = 0;
|
||||
int err1, err2;
|
||||
int err1, err2, err3, err4;
|
||||
|
||||
err1 = 0;
|
||||
if (!option_verbose) err1 = err_gps;
|
||||
err1 |= get_FrameNb();
|
||||
err1 |= get_SondeID();
|
||||
err2 = get_PTU();
|
||||
err3 = 0;
|
||||
//err3 |= get_GPSweek();
|
||||
err3 |= get_GPStime();
|
||||
err4 = get_Aux();
|
||||
|
||||
err2 = err1 | err_gps;
|
||||
//err2 |= get_GPSweek();
|
||||
err2 |= get_GPStime();
|
||||
|
||||
if (!err2 && (almanac || ephem)) {
|
||||
if (!err3 && (almanac || ephem)) {
|
||||
k = get_pseudorange();
|
||||
if (k >= 4) {
|
||||
n = get_GPSkoord(k);
|
||||
|
@ -1106,87 +1135,107 @@ int print_position() { // GPS-Hoehe ueber Ellipsoid
|
|||
if (!err1) {
|
||||
fprintf(stdout, "[%5d] ", gpx.frnr);
|
||||
fprintf(stdout, "(%s) ", gpx.id);
|
||||
}
|
||||
|
||||
if (!err2) {
|
||||
//if (option_verbose)
|
||||
{
|
||||
Gps2Date(gpx.week, gpx.gpssec, &gpx.jahr, &gpx.monat, &gpx.tag);
|
||||
//fprintf(stdout, "(W %d) ", gpx.week);
|
||||
fprintf(stdout, "(%04d-%02d-%02d) ", gpx.jahr, gpx.monat, gpx.tag);
|
||||
}
|
||||
fprintf(stdout, "%s ", weekday[gpx.wday]); // %04.1f: wenn sek >= 59.950, wird auf 60.0 gerundet
|
||||
fprintf(stdout, "%02d:%02d:%06.3f", gpx.std, gpx.min, gpx.sek);
|
||||
|
||||
if (n > 0) {
|
||||
fprintf(stdout, " ");
|
||||
|
||||
if (almanac) fprintf(stdout, " lat: %.4f lon: %.4f alt: %.1f ", gpx.lat, gpx.lon, gpx.alt);
|
||||
else fprintf(stdout, " lat: %.5f lon: %.5f alt: %.1f ", gpx.lat, gpx.lon, gpx.alt);
|
||||
|
||||
if (option_verbose && option_vergps != 8) {
|
||||
fprintf(stdout, " (d:%.1f)", gpx.diter);
|
||||
if (!err3) {
|
||||
if (almanac || ephem)
|
||||
{
|
||||
Gps2Date(gpx.week, gpx.gpssec, &gpx.jahr, &gpx.monat, &gpx.tag);
|
||||
//fprintf(stdout, "(W %d) ", gpx.week);
|
||||
fprintf(stdout, "(%04d-%02d-%02d) ", gpx.jahr, gpx.monat, gpx.tag);
|
||||
}
|
||||
if (option_vel /*&& option_vergps >= 2*/) {
|
||||
fprintf(stdout," vH: %4.1f D: %5.1f° vV: %3.1f ", gpx.vH, gpx.vD, gpx.vU);
|
||||
}
|
||||
if (option_verbose) {
|
||||
if (option_vergps != 2) {
|
||||
fprintf(stdout, " DOP[%02d,%02d,%02d,%02d] %.1f",
|
||||
gpx.sats[0], gpx.sats[1], gpx.sats[2], gpx.sats[3], gpx.dop);
|
||||
fprintf(stdout, "%s ", weekday[gpx.wday]); // %04.1f: wenn sek >= 59.950, wird auf 60.0 gerundet
|
||||
fprintf(stdout, "%02d:%02d:%06.3f", gpx.std, gpx.min, gpx.sek);
|
||||
|
||||
if (n > 0) {
|
||||
fprintf(stdout, " ");
|
||||
|
||||
if (almanac) fprintf(stdout, " lat: %.4f lon: %.4f alt: %.1f ", gpx.lat, gpx.lon, gpx.alt);
|
||||
else fprintf(stdout, " lat: %.5f lon: %.5f alt: %.1f ", gpx.lat, gpx.lon, gpx.alt);
|
||||
|
||||
if (option_verbose && option_vergps != 8) {
|
||||
fprintf(stdout, " (d:%.1f)", gpx.diter);
|
||||
}
|
||||
else { // wenn option_vergps=2, dann n=N=k(-1)
|
||||
fprintf(stdout, " DOP[");
|
||||
for (j = 0; j < n; j++) {
|
||||
fprintf(stdout, "%d", prn[j]);
|
||||
if (j < n-1) fprintf(stdout, ","); else fprintf(stdout, "] %.1f ", gpx.dop);
|
||||
if (option_vel /*&& option_vergps >= 2*/) {
|
||||
fprintf(stdout," vH: %4.1f D: %5.1f° vV: %3.1f ", gpx.vH, gpx.vD, gpx.vU);
|
||||
}
|
||||
if (option_verbose) {
|
||||
if (option_vergps != 2) {
|
||||
fprintf(stdout, " DOP[%02d,%02d,%02d,%02d] %.1f",
|
||||
gpx.sats[0], gpx.sats[1], gpx.sats[2], gpx.sats[3], gpx.dop);
|
||||
}
|
||||
else { // wenn option_vergps=2, dann n=N=k(-1)
|
||||
fprintf(stdout, " DOP[");
|
||||
for (j = 0; j < n; j++) {
|
||||
fprintf(stdout, "%d", prn[j]);
|
||||
if (j < n-1) fprintf(stdout, ","); else fprintf(stdout, "] %.1f ", gpx.dop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (option_json)
|
||||
{
|
||||
// Print out telemetry data as JSON, even if we don't have a valid GPS lock.
|
||||
if (!err1 && !err2){
|
||||
if (option_aux) {
|
||||
if (option_verbose != 4 && (gpx.crc & crc_AUX)==0 || !option_crc) {
|
||||
if (gpx.aux[0] != 0 || gpx.aux[1] != 0 || gpx.aux[2] != 0 || gpx.aux[3] != 0) {
|
||||
printf("\n{ \"frame\": %d, \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f, \"aux\": \"%04x%04x%04x%04x\"}\n", gpx.frnr, gpx.id, gpx.jahr, gpx.monat, gpx.tag, gpx.std, gpx.min, gpx.sek, gpx.lat, gpx.lon, gpx.alt, gpx.vH, gpx.vD, gpx.vU , gpx.aux[0], gpx.aux[1], gpx.aux[2], gpx.aux[3]);
|
||||
} else {
|
||||
printf("\n{ \"frame\": %d, \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f }\n", gpx.frnr, gpx.id, gpx.jahr, gpx.monat, gpx.tag, gpx.std, gpx.min, gpx.sek, gpx.lat, gpx.lon, gpx.alt, gpx.vH, gpx.vD, gpx.vU );
|
||||
fprintf(stdout, " # %04x %04x %04x %04x", gpx.aux[0], gpx.aux[1], gpx.aux[2], gpx.aux[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get_Cal();
|
||||
|
||||
if (option_vergps == 8 /*|| option_vergps == 2*/)
|
||||
{
|
||||
fprintf(stdout, "\n");
|
||||
for (j = 0; j < 60; j++) { fprintf(stdout, "%d", prn_le[j]); if (j % 5 == 4) fprintf(stdout, " "); }
|
||||
fprintf(stdout, ": ");
|
||||
for (j = 0; j < 12; j++) fprintf(stdout, "%2d ", prns[j]);
|
||||
fprintf(stdout, "\n");
|
||||
fprintf(stdout, " status: ");
|
||||
for (j = 0; j < 12; j++) fprintf(stdout, "%02X ", sat_status[j]); //range[prns[j]].status
|
||||
fprintf(stdout, "\n");
|
||||
fprintf(stdout, " # ");
|
||||
fprintf(stdout, "[");
|
||||
for (j=0; j<4; j++) fprintf(stdout, "%d", (gpx.crc>>j)&1);
|
||||
fprintf(stdout, "]");
|
||||
if (option_ecc == 2) {
|
||||
if (ec > 0) fprintf(stdout, " (%d)", ec);
|
||||
if (ec < 0) fprintf(stdout, " (-)");
|
||||
}
|
||||
|
||||
}
|
||||
get_Cal();
|
||||
|
||||
if (!err3) {
|
||||
if (option_vergps == 8 /*|| option_vergps == 2*/)
|
||||
{
|
||||
fprintf(stdout, "\n");
|
||||
for (j = 0; j < 60; j++) { fprintf(stdout, "%d", prn_le[j]); if (j % 5 == 4) fprintf(stdout, " "); }
|
||||
fprintf(stdout, ": ");
|
||||
for (j = 0; j < 12; j++) fprintf(stdout, "%2d ", prns[j]);
|
||||
fprintf(stdout, "\n");
|
||||
fprintf(stdout, " status: ");
|
||||
for (j = 0; j < 12; j++) fprintf(stdout, "%02X ", sat_status[j]); //range[prns[j]].status
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (option_json) {
|
||||
// Print out telemetry data as JSON //even if we don't have a valid GPS lock
|
||||
if ((gpx.crc & (crc_FRAME | crc_GPS))==0 && (almanac || ephem)) //(!err1 && !err3)
|
||||
{ // eigentlich GPS, d.h. UTC = GPS - 18sec (ab 1.1.2017)
|
||||
fprintf(stdout, "\n{ \"frame\": %d, \"id\": \"%s\", \"datetime\": \"%04d-%02d-%02dT%02d:%02d:%06.3fZ\", \"lat\": %.5f, \"lon\": %.5f, \"alt\": %.5f, \"vel_h\": %.5f, \"heading\": %.5f, \"vel_v\": %.5f",
|
||||
gpx.frnr, gpx.id, gpx.jahr, gpx.monat, gpx.tag, gpx.std, gpx.min, gpx.sek, gpx.lat, gpx.lon, gpx.alt, gpx.vH, gpx.vD, gpx.vU);
|
||||
if ((gpx.crc & crc_AUX)==0 && (gpx.aux[0] != 0 || gpx.aux[1] != 0 || gpx.aux[2] != 0 || gpx.aux[3] != 0)) {
|
||||
fprintf(stdout, ", \"aux\": \"%04x%04x%04x%04x\"", gpx.aux[0], gpx.aux[1], gpx.aux[2], gpx.aux[3]);
|
||||
}
|
||||
fprintf(stdout, " }\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!err1) {
|
||||
fprintf(stdout, "\n");
|
||||
//if (option_vergps == 8) fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
return err2;
|
||||
return err3;
|
||||
}
|
||||
|
||||
void print_frame(int len) {
|
||||
int i, ret = 0;
|
||||
int i, ec = 0;
|
||||
ui8_t byte;
|
||||
|
||||
gpx.crc = 0;
|
||||
|
||||
if (option_ecc) {
|
||||
ret = rs92_ecc(len);
|
||||
ec = rs92_ecc(len);
|
||||
}
|
||||
|
||||
for (i = len; i < FRAME_LEN; i++) {
|
||||
|
@ -1208,13 +1257,13 @@ void print_frame(int len) {
|
|||
}
|
||||
if (option_ecc && option_verbose) {
|
||||
fprintf(stdout, " ");
|
||||
if (ret >= 0) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
|
||||
fprintf(stdout, " errors: %d", ret);
|
||||
if (ec >= 0) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
|
||||
fprintf(stdout, " errors: %d", ec);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
// fprintf(stdout, "\n");
|
||||
}
|
||||
else print_position();
|
||||
else print_position(ec);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1343,7 +1392,13 @@ int main(int argc, char *argv[]) {
|
|||
else if (strcmp(*argv, "-g2") == 0) { option_vergps = 2; } // verbose2 GPS (bancroft)
|
||||
else if (strcmp(*argv, "-gg") == 0) { option_vergps = 8; } // vverbose GPS
|
||||
else if (strcmp(*argv, "--ecc") == 0) { option_ecc = 1; }
|
||||
else if (strcmp(*argv, "--json") == 0) {option_json = 1; option_ecc = 1; option_crc = 1; }
|
||||
else if (strcmp(*argv, "--ecc2") == 0) { option_ecc = 2; }
|
||||
else if (strcmp(*argv, "--json") == 0) {
|
||||
option_json = 1;
|
||||
option_ecc = 2;
|
||||
option_crc = 1;
|
||||
option_vel = 4;
|
||||
}
|
||||
else if (strcmp(*argv, "--ch2") == 0) { wav_channel = 1; } // right channel (default: 0=left)
|
||||
else if (strcmp(*argv, "--ths") == 0) {
|
||||
++argv;
|
||||
|
|
Ładowanie…
Reference in New Issue