m10dft: variable frame length like in m10ptu.c

pull/8/head
Zilog80 2019-01-16 17:04:48 +01:00
rodzic 8fe7ffff34
commit 5f6ab9f33b
1 zmienionych plików z 40 dodań i 25 usunięć

Wyświetl plik

@ -52,6 +52,7 @@ int option_verbose = 0, // ausfuehrliche Anzeige
wavloaded = 0;
int wav_channel = 0; // audio channel: left
/* -------------------------------------------------------------------------- */
/*
* Convert GPS Week and Seconds to Modified Julian Day.
@ -98,17 +99,23 @@ dduudduudduudduu duduudduuduudduu ddududuudduduudd uduuddududududud uudduduuddu
#define HEADLEN 32 // HEADLEN+HEADOFS=32 <= strlen(header)
#define HEADOFS 0
// Sync-Header (raw) // Sonde-Header (bits)
//char head[] = "11001100110011001010011001001100"; //"011001001001111100100000"; // M10: 64 9F 20 , M2K2: 64 8F 20
//"011101101001111100100000"; // M??: 76 9F 20
//"011001000100100100001001"; // M10-dop: 64 49 09
//char head[] = "11001100110011001010011001001100"; //"0110010010011111"; // M10: 64 9F , M2K2: 64 8F
//"0111011010011111"; // M10: 76 9F , w/ aux-data
//"0110010001001001"; // M10-dop: 64 49 09
//"0110010010101111"; // M10+: 64 AF w/ gtop-GPS
char rawheader[] = "10011001100110010100110010011001";
#define FRAME_LEN 102
#define FRAME_LEN (100+1) // 0x64+1
#define BITFRAME_LEN (FRAME_LEN*BITS)
ui8_t frame_bytes[FRAME_LEN+10];
#define AUX_LEN 20
#define BITAUX_LEN (AUX_LEN*BITS)
char frame_bits[BITFRAME_LEN+4];
ui8_t frame_bytes[FRAME_LEN+AUX_LEN+4];
char frame_bits[BITFRAME_LEN+BITAUX_LEN+8];
int auxlen = 0; // 0 .. 0x76-0x64
int bits2bytes(char *bitstr, ui8_t *bytes) {
@ -118,7 +125,7 @@ int bits2bytes(char *bitstr, ui8_t *bytes) {
bitpos = 0;
bytepos = 0;
while (bytepos < FRAME_LEN) {
while (bytepos < FRAME_LEN+AUX_LEN) {
byteval = 0;
d = 1;
@ -135,24 +142,25 @@ int bits2bytes(char *bitstr, ui8_t *bytes) {
}
//while (bytepos < FRAME_LEN) bytes[bytepos++] = 0;
//while (bytepos < FRAME_LEN+AUX_LEN) bytes[bytepos++] = 0;
return 0;
}
/* -------------------------------------------------------------------------- */
#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_GPSweek 0x20 // 2 byte
//Velocity East-North-Up (ENU)
#define pos_GPSvO 0x04 // 2 byte
#define pos_GPSvN 0x06 // 2 byte
#define pos_GPSvV 0x08 // 2 byte
#define pos_SN 0x5D // 2+3 byte
#define pos_Check 0x63 // 2 byte
#define pos_GPSvE 0x04 // 2 byte
#define pos_GPSvN 0x06 // 2 byte
#define pos_GPSvU 0x08 // 2 byte
#define pos_SN 0x5D // 2+3 byte
#define pos_Check (stdFLEN-1) // 2 byte
#define ANSI_COLOR_RED "\x1b[31m"
@ -315,7 +323,7 @@ int get_GPSvel() {
const double ms2kn100 = 2e2; // m/s -> knots: 1 m/s = 3.6/1.852 kn = 1.94 kn
for (i = 0; i < 2; i++) {
byte = frame_bytes[pos_GPSvO + i];
byte = frame_bytes[pos_GPSvE + i];
gpsVel_bytes[i] = byte;
}
vel16 = gpsVel_bytes[0] << 8 | gpsVel_bytes[1];
@ -342,7 +350,7 @@ int get_GPSvel() {
datum.vD = dir;
for (i = 0; i < 2; i++) {
byte = frame_bytes[pos_GPSvV + i];
byte = frame_bytes[pos_GPSvU + i];
gpsVel_bytes[i] = byte;
}
vel16 = gpsVel_bytes[0] << 8 | gpsVel_bytes[1];
@ -638,8 +646,8 @@ int print_pos(int csOK) {
if (option_verbose) {
err |= get_GPSvel();
if (!err) {
//if (option_verbose == 2) fprintf(stdout, " "col_GPSvel"(%.1f , %.1f : %.1f°)"col_TXT" ", datum.vx, datum.vy, datum.vD2);
fprintf(stdout, " vH: "col_GPSvel"%.1f"col_TXT" D: "col_GPSvel"%.1f°"col_TXT" vV: "col_GPSvel"%.1f"col_TXT" ", datum.vH, datum.vD, datum.vV);
//if (option_verbose == 2) fprintf(stdout, " "col_GPSvel"(%.1f , %.1f : %.1f)"col_TXT" ", datum.vx, datum.vy, datum.vD2);
fprintf(stdout, " vH: "col_GPSvel"%.1f"col_TXT" D: "col_GPSvel"%.1f"col_TXT"° vV: "col_GPSvel"%.1f"col_TXT" ", datum.vH, datum.vD, datum.vV);
}
if (option_verbose >= 2) {
get_SN();
@ -706,26 +714,33 @@ int print_frame(int pos) {
int i;
ui8_t byte;
int cs1, cs2;
int flen = stdFLEN; // stdFLEN=0x64, auxFLEN=0x76
bits2bytes(frame_bits, frame_bytes);
flen = frame_bytes[0];
if (flen == stdFLEN) auxlen = 0;
else {
auxlen = flen - stdFLEN;
if (auxlen < 0 || auxlen > AUX_LEN) auxlen = 0;
}
cs1 = (frame_bytes[pos_Check] << 8) | frame_bytes[pos_Check+1];
cs2 = checkM10(frame_bytes, pos_Check);
cs1 = (frame_bytes[pos_Check+auxlen] << 8) | frame_bytes[pos_Check+auxlen+1];
cs2 = checkM10(frame_bytes, pos_Check+auxlen);
if (option_raw) {
if (option_color && frame_bytes[1] != 0x49) {
fprintf(stdout, col_FRTXT);
for (i = 0; i < FRAME_LEN-1; i++) {
for (i = 0; i < FRAME_LEN+auxlen; i++) {
byte = frame_bytes[i];
if ((i >= pos_GPSTOW) && (i < pos_GPSTOW+4)) fprintf(stdout, col_GPSTOW);
if ((i >= pos_GPSlat) && (i < pos_GPSlat+4)) fprintf(stdout, col_GPSlat);
if ((i >= pos_GPSlon) && (i < pos_GPSlon+4)) fprintf(stdout, col_GPSlon);
if ((i >= pos_GPSalt) && (i < pos_GPSalt+4)) fprintf(stdout, col_GPSalt);
if ((i >= pos_GPSweek) && (i < pos_GPSweek+2)) fprintf(stdout, col_GPSweek);
if ((i >= pos_GPSvO) && (i < pos_GPSvO+6)) fprintf(stdout, col_GPSvel);
if ((i >= pos_GPSvE) && (i < pos_GPSvE+6)) fprintf(stdout, col_GPSvel);
if ((i >= pos_SN) && (i < pos_SN+5)) fprintf(stdout, col_SN);
if ((i >= pos_Check) && (i < pos_Check+2)) fprintf(stdout, col_Check);
if ((i >= pos_Check+auxlen) && (i < pos_Check+auxlen+2)) fprintf(stdout, col_Check);
fprintf(stdout, "%02x", byte);
fprintf(stdout, col_FRTXT);
}
@ -737,7 +752,7 @@ int print_frame(int pos) {
fprintf(stdout, ANSI_COLOR_RESET"\n");
}
else {
for (i = 0; i < FRAME_LEN-1; i++) {
for (i = 0; i < FRAME_LEN+auxlen; i++) {
byte = frame_bytes[i];
fprintf(stdout, "%02x", byte);
}
@ -751,7 +766,7 @@ int print_frame(int pos) {
}
else if (frame_bytes[1] == 0x49) {
if (option_verbose == 3) {
for (i = 0; i < FRAME_LEN-1; i++) {
for (i = 0; i < FRAME_LEN+auxlen; i++) {
byte = frame_bytes[i];
fprintf(stdout, "%02x", byte);
}
@ -907,7 +922,7 @@ int main(int argc, char **argv) {
pos /= 2;
bit0 = '0';
while ( pos < BITFRAME_LEN ) {
while ( pos < BITFRAME_LEN+BITAUX_LEN ) {
header_found = !(pos>=BITFRAME_LEN-10);
bitQ = read_sbit(fp, symlen, &bit, option_inv, bitofs, bitpos==0, !header_found); // symlen=2, return: zeroX/bit
if (bitQ == EOF) { break; }