Porównaj commity

...

2 Commity

Autor SHA1 Wiadomość Data
Zilog80 4fa98b637a rs41: cal/conf via JSON, jsncal/conf option implies JSON output 2023-10-03 00:04:16 +02:00
Zilog80 f462e760dd rs41: cal/conf via JSON 2023-10-02 23:36:34 +02:00
1 zmienionych plików z 60 dodań i 5 usunięć

Wyświetl plik

@ -65,6 +65,7 @@ typedef struct {
i8_t aut;
i8_t jsn; // JSON output (auto_rx)
i8_t slt; // silent (only raw/json)
i8_t cal; // json cal/conf
} option_t;
typedef struct {
@ -117,6 +118,9 @@ typedef struct {
ui8_t dfrm_bitscore[FRAME_LEN];
ui8_t calibytes[51*16];
ui8_t calfrchk[51];
ui8_t calconf_complete;
ui8_t calconf_sent;
ui8_t *calconf_subfrm; // 1+16 byte cal/conf subframe
float ptu_Rf1; // ref-resistor f1 (750 Ohm)
float ptu_Rf2; // ref-resistor f2 (1100 Ohm)
float ptu_co1[3]; // { -243.911 , 0.187654 , 8.2e-06 }
@ -267,15 +271,15 @@ float r4(ui8_t *bytes) {
}
*/
static int crc16(gpx_t *gpx, int start, int len) {
static int crc16(ui8_t data[], int len) {
int crc16poly = 0x1021;
int rem = 0xFFFF, i, j;
int byte;
if (start+len+2 > FRAME_LEN) return -1;
//if (start+len+2 > FRAME_LEN) return -1;
for (i = 0; i < len; i++) {
byte = gpx->frame[start+i];
byte = data[i];
rem = rem ^ (byte << 8);
for (j = 0; j < 8; j++) {
if (rem & 0x8000) {
@ -298,7 +302,7 @@ static int check_CRC(gpx_t *gpx, ui32_t pos, ui32_t pck) {
crclen = gpx->frame[pos+1];
if (pos + crclen + 4 > FRAME_LEN) return -1;
crcdat = u2(gpx->frame+pos+2+crclen);
if ( crcdat != crc16(gpx, pos+2, crclen) ) {
if ( crcdat != crc16(gpx->frame+pos+2, crclen) ) {
return 1; // CRC NO
}
else return 0; // CRC OK
@ -451,6 +455,8 @@ static int get_SondeID(gpx_t *gpx, int crc, int ofs) {
// reset conf data
memset(gpx->rstyp, 0, 9);
memset(gpx->rsm, 0, 10);
gpx->calconf_complete = 0;
gpx->calconf_sent = 0;
gpx->freq = 0;
gpx->conf_fw = 0;
gpx->conf_bt = 0;
@ -504,6 +510,19 @@ static int get_FrameConf(gpx_t *gpx, int ofs) {
gpx->ecdat.last_calfrm = calfr;
gpx->ecdat.last_calfrm_ts = gpx->ecdat.ts;
if ( !gpx->calconf_complete ) {
int sum = 0;
for (i = 0; i < 51; i++) { // 0x00..0x32
sum += gpx->calfrchk[i];
}
if (sum == 51) { // count all subframes
int calconf_dat = gpx->calibytes[0] | (gpx->calibytes[1]<<8);
int calconf_crc = crc16(gpx->calibytes+2, 50*16-2); // subframe 0x32 not included (variable)
if (calconf_dat == calconf_crc) gpx->calconf_complete = 1;
}
}
}
return err;
@ -1299,7 +1318,7 @@ static int get_Aux(gpx_t *gpx, int out, int pos) {
auxlen = gpx->frame[pos+1];
auxcrc = gpx->frame[pos+2+auxlen] | (gpx->frame[pos+2+auxlen+1]<<8);
if ( auxcrc == crc16(gpx, pos+2, auxlen) ) {
if ( pos + auxlen + 4 <= FRAME_LEN && auxcrc == crc16(gpx->frame+pos+2, auxlen) ) {
if (count7E == 0) {
if (out) fprintf(stdout, "\n # xdata = ");
}
@ -1372,6 +1391,8 @@ static int get_Calconf(gpx_t *gpx, int out, int ofs) {
char rsmtyp[10];
int err = 0;
gpx->calconf_subfrm = gpx->frame+pos_CalData+ofs;
byte = gpx->frame[pos_CalData+ofs];
calfr = byte;
err = check_CRC(gpx, pos_FRAME+ofs, pck_FRAME);
@ -2110,6 +2131,31 @@ static int print_position(gpx_t *gpx, int ec) {
fprintf(stdout, ", \"rs41_mainboard_fw\": %d", gpx->conf_fw);
}
if (gpx->option.cal == 1) { // cal/conf
if ( !gpx->calconf_sent && gpx->calconf_complete ) {
fprintf(stdout, ", \"rs41_calconf320\": \"");
for (int _j = 0; _j < 50*16; _j++) {
fprintf(stdout, "%02X", gpx->calibytes[_j]);
}
fprintf(stdout, "\"");
gpx->calconf_sent = 1;
}
if (gpx->calconf_subfrm[0] == 0x32) {
fprintf(stdout, ", \"rs41_conf0x32\": \"");
for (int _j = 0; _j < 16; _j++) {
fprintf(stdout, "%02X", gpx->calconf_subfrm[1+_j]);
}
fprintf(stdout, "\"");
}
}
if (gpx->option.cal == 2) { // cal/conf
fprintf(stdout, ", \"rs41_subfrm\": \"0x%02X:", gpx->calconf_subfrm[0]);
for (int _j = 0; _j < 16; _j++) {
fprintf(stdout, "%02X", gpx->calconf_subfrm[1+_j]);
}
fprintf(stdout, "\"");
}
// Include frequency derived from subframe information if available.
if (gpx->freq > 0) {
fprintf(stdout, ", \"tx_frequency\": %d", gpx->freq );
@ -2444,6 +2490,8 @@ int main(int argc, char *argv[]) {
if (frq < 300000000) frq = -1;
cfreq = frq;
}
else if (strcmp(*argv, "--jsnsubfrm1") == 0) { gpx.option.cal = 1; } // json cal/conf
else if (strcmp(*argv, "--jsnsubfrm2") == 0) { gpx.option.cal = 2; } // json cal/conf
else if (strcmp(*argv, "--rawhex") == 0) { rawhex = 2; } // raw hex input
else if (strcmp(*argv, "--xorhex") == 0) { rawhex = 2; xorhex = 1; } // raw xor input
else if (strcmp(*argv, "-") == 0) {
@ -2495,6 +2543,13 @@ int main(int argc, char *argv[]) {
// init gpx
memcpy(gpx.frame, rs41_header_bytes, sizeof(rs41_header_bytes)); // 8 header bytes
gpx.calconf_subfrm = gpx.frame+pos_CalData;
if (gpx.option.cal) {
gpx.option.jsn = 1;
gpx.option.ecc = 2;
gpx.option.crc = 1;
}
if (cfreq > 0) gpx.jsn_freq = (cfreq+500)/1000;