kopia lustrzana https://github.com/projecthorus/radiosonde_auto_rx
Rebase M20 demod
rodzic
353193bf7e
commit
6b2ce1da94
|
@ -12,7 +12,7 @@ from queue import Queue
|
|||
# MINOR - New sonde type support, other fairly big changes that may result in telemetry or config file incompatability issus.
|
||||
# PATCH - Small changes, or minor feature additions.
|
||||
|
||||
__version__ = "1.6.1"
|
||||
__version__ = "1.6.2-beta1"
|
||||
|
||||
|
||||
# Global Variables
|
||||
|
|
|
@ -104,8 +104,10 @@ typedef struct {
|
|||
double vH; double vD; double vV;
|
||||
double vx; double vy; double vD2;
|
||||
float T; float RH; float TH; float P;
|
||||
float batV;
|
||||
ui8_t numSV;
|
||||
ui8_t utc_ofs;
|
||||
//ui8_t utc_ofs;
|
||||
ui8_t fwVer;
|
||||
char SN[12+4];
|
||||
ui8_t SNraw[3];
|
||||
ui8_t frame_bytes[FRAME_LEN+AUX_LEN+4];
|
||||
|
@ -193,12 +195,12 @@ frame[0x08..0x0A]: GPS altitude
|
|||
frame[0x0B..0x0E]: GPS hor.Vel. (velE,velN)
|
||||
frame[0x0F..0x11]: GPS TOW
|
||||
frame[0x15]: counter
|
||||
frame[0x16..0x17]: block check
|
||||
|
||||
frame[0x16..0x17]: block check (fwVer < 0x06) ; frame[0x16]: SPI1 P[0] (fwVer >= 0x07), frame[0x17]=0x00
|
||||
frame[0x18..0x19]: GPS ver.Vel. (velU)
|
||||
frame[0x1A..0x1B]: GPS week
|
||||
frame[0x1C..0x1F]: GPS latitude
|
||||
frame[0x20..0x23]: GPS longitude
|
||||
frame[0x24..0x25]: SPI1 P[1..2] (if pressure sensor)
|
||||
|
||||
frame[0x44..0x45]: frame check
|
||||
*/
|
||||
|
@ -218,7 +220,8 @@ frame[0x44..0x45]: frame check
|
|||
#define pos_SN 0x12 // 3 byte
|
||||
#define pos_CNT 0x15 // 1 byte
|
||||
#define pos_BlkChk 0x16 // 2 byte
|
||||
#define pos_Check (stdFLEN-1) // 2 byte
|
||||
#define pos_stdFW 0x43 // 1 byte
|
||||
#define pos_stdCheck (stdFLEN-1) // 2 byte
|
||||
|
||||
#define len_BlkChk 0x16 // frame[0x02..0x17] , incl. chk16
|
||||
|
||||
|
@ -250,6 +253,10 @@ frame[0x44..0x45]: frame check
|
|||
#define col_CSoo "\x1b[38;5;220m"
|
||||
#define col_CSno "\x1b[38;5;1m"
|
||||
#define col_CNST "\x1b[38;5;58m" // 3 byte
|
||||
#define col_ptuP "\x1b[38;5;180m"
|
||||
#define col_ptuT "\x1b[38;5;110m"
|
||||
#define col_ptuU "\x1b[38;5;120m"
|
||||
#define col_ptuTH "\x1b[38;5;115m"
|
||||
|
||||
/*
|
||||
$ for code in {0..255}
|
||||
|
@ -701,18 +708,33 @@ static float get_RH(gpx_t *gpx) {
|
|||
}
|
||||
|
||||
static float get_P(gpx_t *gpx) {
|
||||
// cf. DF9DQ
|
||||
//
|
||||
float hPa = 0.0f;
|
||||
ui16_t val = (gpx->frame_bytes[0x25] << 8) | gpx->frame_bytes[0x24];
|
||||
ui32_t val = (gpx->frame_bytes[0x25] << 8) | gpx->frame_bytes[0x24]; // cf. DF9DQ
|
||||
ui8_t p0 = 0x00;
|
||||
|
||||
if (gpx->fwVer >= 0x07) { // SPI1_P[0]
|
||||
p0 = gpx->frame_bytes[0x16];
|
||||
}
|
||||
val = (val << 8) | p0;
|
||||
|
||||
if (val > 0) {
|
||||
hPa = val/16.0f;
|
||||
hPa = val/(float)(16*256); // 4096=0x1000
|
||||
}
|
||||
|
||||
return hPa;
|
||||
}
|
||||
|
||||
static float get_BatV(gpx_t *gpx) {
|
||||
float batV = 0.0f;
|
||||
ui8_t val = gpx->frame_bytes[0x26]; // cf. DF9DQ
|
||||
|
||||
batV = val * (3.3f/255); // upper 8 bits ADC
|
||||
|
||||
return batV;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
|
||||
|
@ -741,6 +763,8 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
|
|||
gpx->P = get_P(gpx); // (optional) pressure
|
||||
}
|
||||
|
||||
gpx->batV = get_BatV(gpx); // battery V
|
||||
|
||||
if ( !gpx->option.slt )
|
||||
{
|
||||
if (gpx->option.col) {
|
||||
|
@ -763,10 +787,11 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
|
|||
}
|
||||
if (gpx->option.vbs >= 1) {
|
||||
fprintf(stdout, " # ");
|
||||
if (bcOK > 0) fprintf(stdout, " "col_CSok"(ok)"col_TXT);
|
||||
else if (bcOK < 0) fprintf(stdout, " "col_CSoo"(oo)"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"(no)"col_TXT);
|
||||
//
|
||||
if (gpx->fwVer < 0x07) {
|
||||
if (bcOK > 0) fprintf(stdout, " "col_CSok"(ok)"col_TXT);
|
||||
else if (bcOK < 0) fprintf(stdout, " "col_CSoo"(oo)"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"(no)"col_TXT);
|
||||
}
|
||||
if (csOK) fprintf(stdout, " "col_CSok"[OK]"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"[NO]"col_TXT);
|
||||
}
|
||||
|
@ -778,10 +803,14 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
|
|||
if (gpx->TH > -273.0f) fprintf(stdout, " TH:%.1fC", gpx->TH);
|
||||
}
|
||||
if (gpx->P > 0.0f) {
|
||||
if (gpx->P < 100.0f) fprintf(stdout, " P=%.2fhPa ", gpx->P);
|
||||
else fprintf(stdout, " P=%.1fhPa ", gpx->P);
|
||||
if (gpx->P < 10.0f) fprintf(stdout, " P=%.3fhPa ", gpx->P);
|
||||
else if (gpx->P < 100.0f) fprintf(stdout, " P=%.2fhPa ", gpx->P);
|
||||
else fprintf(stdout, " P=%.1fhPa ", gpx->P);
|
||||
}
|
||||
}
|
||||
if (gpx->option.vbs >= 3 && csOK) {
|
||||
fprintf(stdout, " (bat:%.2fV)", gpx->batV);
|
||||
}
|
||||
fprintf(stdout, ANSI_COLOR_RESET"");
|
||||
}
|
||||
else {
|
||||
|
@ -803,11 +832,12 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
|
|||
}
|
||||
if (gpx->option.vbs >= 1) {
|
||||
fprintf(stdout, " # ");
|
||||
//if (bcOK) fprintf(stdout, " (ok)"); else fprintf(stdout, " (no)");
|
||||
if (bcOK > 0) fprintf(stdout, " (ok)");
|
||||
else if (bcOK < 0) fprintf(stdout, " (oo)");
|
||||
else fprintf(stdout, " (no)");
|
||||
//
|
||||
if (gpx->fwVer < 0x07) {
|
||||
//if (bcOK) fprintf(stdout, " (ok)"); else fprintf(stdout, " (no)");
|
||||
if (bcOK > 0) fprintf(stdout, " (ok)");
|
||||
else if (bcOK < 0) fprintf(stdout, " (oo)");
|
||||
else fprintf(stdout, " (no)");
|
||||
}
|
||||
if (csOK) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
|
||||
}
|
||||
if (gpx->option.ptu && csOK) {
|
||||
|
@ -818,10 +848,14 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
|
|||
if (gpx->TH > -273.0f) fprintf(stdout, " TH:%.1fC", gpx->TH);
|
||||
}
|
||||
if (gpx->P > 0.0f) {
|
||||
if (gpx->P < 100.0f) fprintf(stdout, " P=%.2fhPa ", gpx->P);
|
||||
else fprintf(stdout, " P=%.1fhPa ", gpx->P);
|
||||
if (gpx->P < 10.0f) fprintf(stdout, " P=%.3fhPa ", gpx->P);
|
||||
else if (gpx->P < 100.0f) fprintf(stdout, " P=%.2fhPa ", gpx->P);
|
||||
else fprintf(stdout, " P=%.1fhPa ", gpx->P);
|
||||
}
|
||||
}
|
||||
if (gpx->option.vbs >= 3 && csOK) {
|
||||
fprintf(stdout, " (bat:%.2fV)", gpx->batV);
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
@ -846,6 +880,7 @@ static int print_pos(gpx_t *gpx, int bcOK, int csOK) {
|
|||
if (gpx->RH > -0.5f) fprintf(stdout, ", \"humidity\": %.1f", gpx->RH );
|
||||
if (gpx->P > 0.0f) fprintf(stdout, ", \"pressure\": %.2f", gpx->P );
|
||||
}
|
||||
fprintf(stdout, ", \"batt\": %.2f", gpx->batV);
|
||||
fprintf(stdout, ", \"rawid\": \"M20_%02X%02X%02X\"", gpx->frame_bytes[pos_SN], gpx->frame_bytes[pos_SN+1], gpx->frame_bytes[pos_SN+2]); // gpx->type
|
||||
fprintf(stdout, ", \"subtype\": \"0x%02X\"", gpx->type);
|
||||
if (gpx->jsn_freq > 0) {
|
||||
|
@ -876,6 +911,8 @@ static int print_frame(gpx_t *gpx, int pos, int b2B) {
|
|||
int cs1, cs2;
|
||||
int bc1, bc2, bc;
|
||||
int flen = stdFLEN; // stdFLEN=0x64, auxFLEN=0x76; M20:0x45 ?
|
||||
int pos_fw = pos_stdFW;
|
||||
int pos_check = pos_stdCheck;
|
||||
|
||||
if (b2B) {
|
||||
bits2bytes(gpx->frame_bits, gpx->frame_bytes);
|
||||
|
@ -885,10 +922,21 @@ static int print_frame(gpx_t *gpx, int pos, int b2B) {
|
|||
else {
|
||||
gpx->auxlen = flen - stdFLEN;
|
||||
//if (gpx->auxlen < 0 || gpx->auxlen > AUX_LEN) gpx->auxlen = 0; // 0x43,0x45
|
||||
if (gpx->auxlen < 0) {
|
||||
gpx->auxlen = 0;
|
||||
pos_fw = flen-2; // only if flen < stdFLEN
|
||||
}
|
||||
else if (gpx->auxlen > AUX_LEN) {
|
||||
gpx->auxlen = AUX_LEN;
|
||||
flen = stdFLEN+AUX_LEN;
|
||||
}
|
||||
}
|
||||
pos_check = flen-1;
|
||||
gpx->fwVer = gpx->frame_bytes[pos_fw];
|
||||
if (gpx->fwVer > 0x20) gpx->fwVer = 0;
|
||||
|
||||
cs1 = (gpx->frame_bytes[pos_Check+gpx->auxlen] << 8) | gpx->frame_bytes[pos_Check+gpx->auxlen+1];
|
||||
cs2 = checkM10(gpx->frame_bytes, pos_Check+gpx->auxlen);
|
||||
cs1 = (gpx->frame_bytes[pos_check] << 8) | gpx->frame_bytes[pos_check+1];
|
||||
cs2 = checkM10(gpx->frame_bytes, pos_check);
|
||||
|
||||
bc1 = (gpx->frame_bytes[pos_BlkChk] << 8) | gpx->frame_bytes[pos_BlkChk+1];
|
||||
bc2 = blk_checkM10(len_BlkChk, gpx->frame_bytes+2); // len(essentialBlock+chk16) = 0x16
|
||||
|
@ -921,16 +969,27 @@ static int print_frame(gpx_t *gpx, int pos, int b2B) {
|
|||
if ((i >= pos_GPSvU) && (i < pos_GPSvU+2)) fprintf(stdout, col_GPSvel);
|
||||
if ((i >= pos_SN) && (i < pos_SN+3)) fprintf(stdout, col_SN);
|
||||
if (i == pos_CNT) fprintf(stdout, col_CNT);
|
||||
if ((i >= pos_BlkChk) && (i < pos_BlkChk+2)) fprintf(stdout, col_Check);
|
||||
if ((i >= pos_Check+gpx->auxlen) && (i < pos_Check+gpx->auxlen+2)) fprintf(stdout, col_Check);
|
||||
if (gpx->fwVer < 0x07) {
|
||||
if ((i >= pos_BlkChk) && (i < pos_BlkChk+2)) fprintf(stdout, col_Check);
|
||||
} else {
|
||||
if ((i >= pos_BlkChk+1) && (i < pos_BlkChk+2)) fprintf(stdout, col_Check);
|
||||
}
|
||||
if (i >= 0x02 && i <= 0x03) fprintf(stdout, col_ptuU);
|
||||
if (i >= 0x04 && i <= 0x05) fprintf(stdout, col_ptuT);
|
||||
if (i >= 0x06 && i <= 0x07) fprintf(stdout, col_ptuTH);
|
||||
if (i == 0x16 && gpx->fwVer >= 0x07 || i >= 0x24 && i <= 0x25) fprintf(stdout, col_ptuP);
|
||||
|
||||
if ((i >= pos_check) && (i < pos_check+2)) fprintf(stdout, col_Check);
|
||||
fprintf(stdout, "%02x", byte);
|
||||
fprintf(stdout, col_FRTXT);
|
||||
}
|
||||
if (gpx->option.vbs) {
|
||||
fprintf(stdout, " # "col_Check"%04x"col_FRTXT, cs2);
|
||||
if (bc > 0) fprintf(stdout, " "col_CSok"(ok)"col_TXT);
|
||||
else if (bc < 0) fprintf(stdout, " "col_CSoo"(oo)"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"(no)"col_TXT);
|
||||
if (gpx->fwVer < 0x07) {
|
||||
if (bc > 0) fprintf(stdout, " "col_CSok"(ok)"col_TXT);
|
||||
else if (bc < 0) fprintf(stdout, " "col_CSoo"(oo)"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"(no)"col_TXT);
|
||||
}
|
||||
if (cs1 == cs2) fprintf(stdout, " "col_CSok"[OK]"col_TXT);
|
||||
else fprintf(stdout, " "col_CSno"[NO]"col_TXT);
|
||||
}
|
||||
|
@ -943,9 +1002,11 @@ static int print_frame(gpx_t *gpx, int pos, int b2B) {
|
|||
}
|
||||
if (gpx->option.vbs) {
|
||||
fprintf(stdout, " # %04x", cs2);
|
||||
if (bc > 0) fprintf(stdout, " (ok)");
|
||||
else if (bc < 0) fprintf(stdout, " (oo)");
|
||||
else fprintf(stdout, " (no)");
|
||||
if (gpx->fwVer < 0x07) {
|
||||
if (bc > 0) fprintf(stdout, " (ok)");
|
||||
else if (bc < 0) fprintf(stdout, " (oo)");
|
||||
else fprintf(stdout, " (no)");
|
||||
}
|
||||
if (cs1 == cs2) fprintf(stdout, " [OK]"); else fprintf(stdout, " [NO]");
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
|
Ładowanie…
Reference in New Issue