tx: lowest documented PA table, test_burst, tx payload logging; 200ms delay improves SDR repeat decode 3%->30%
This commit is contained in:
+25
-13
@@ -97,13 +97,16 @@ uint32_t wmbus_hash(const uint8_t *data, size_t len)
|
||||
return h;
|
||||
}
|
||||
|
||||
int wmbus_build_test_frame(uint8_t *out, size_t maxlen, uint8_t access_nr)
|
||||
int wmbus_build_test_frame(uint8_t *out, size_t maxlen, uint8_t access_nr,
|
||||
uint8_t lfield)
|
||||
{
|
||||
// Format A frame: L C M(2) A(6) | CRC | CI ...data... | CRC
|
||||
// Format A frame: L C M(2) A(6) | CRC | CI ...data... | CRC per block
|
||||
// Manufacturer "SLN" = ((19)<<10)|(12<<5)|(14) = 0x4D8E (Solenos test)
|
||||
// ID 0x00000001 (BCD 00000001), version 0x01, device type 0x07 (water)
|
||||
uint8_t body[26];
|
||||
int L = 19; // C M A CI + 10 data bytes = 1+2+6+1+9... keep L=19: C(1)+M(2)+A(6)+CI(1)+data(9)
|
||||
uint8_t body[256];
|
||||
if (lfield < 19) lfield = 19;
|
||||
if (lfield > 200) lfield = 200;
|
||||
int L = lfield;
|
||||
body[0] = (uint8_t)L;
|
||||
body[1] = 0x44; // SND_NR
|
||||
body[2] = 0x8E; body[3] = 0x4D; // manufacturer, little endian
|
||||
@@ -111,13 +114,16 @@ int wmbus_build_test_frame(uint8_t *out, size_t maxlen, uint8_t access_nr)
|
||||
body[8] = 0x01; // version
|
||||
body[9] = 0x07; // device type
|
||||
body[10] = 0x78; // CI: response, no header
|
||||
// 9 data bytes: marker + access counter
|
||||
// data: marker + access counter + PRBS-ish padding
|
||||
body[11] = 0x53; body[12] = 0x4F; body[13] = 0x4C; body[14] = 0x54; // "SOLT"
|
||||
body[15] = 0x58; // "X"
|
||||
body[16] = access_nr;
|
||||
body[17] = 0xA5; body[18] = 0x5A; body[19] = access_nr ^ 0xFF;
|
||||
uint8_t x = 0xA5 ^ access_nr;
|
||||
for (int i = 17; i <= L; i++) {
|
||||
x = (uint8_t)(x * 197 + 31);
|
||||
body[i] = x;
|
||||
}
|
||||
|
||||
// assemble with block CRCs
|
||||
int total = wmbus_frame_total_len(WMBUS_FRAME_A, (uint8_t)L);
|
||||
if (total < 0 || (size_t)total > maxlen) return -1;
|
||||
|
||||
@@ -125,11 +131,17 @@ int wmbus_build_test_frame(uint8_t *out, size_t maxlen, uint8_t access_nr)
|
||||
for (int i = 0; i < 10; i++) out[i] = body[i];
|
||||
uint16_t c1 = wmbus_crc16(out, 10);
|
||||
out[10] = c1 >> 8; out[11] = c1 & 0xFF;
|
||||
// block 2: bytes 10..(L) of body (CI + data = L-9 bytes) + crc
|
||||
int n2 = L - 9;
|
||||
for (int i = 0; i < n2; i++) out[12 + i] = body[10 + i];
|
||||
uint16_t c2 = wmbus_crc16(out + 12, n2);
|
||||
out[12 + n2] = c2 >> 8; out[13 + n2] = c2 & 0xFF;
|
||||
|
||||
// blocks 2..n: 16 data bytes + crc each (last block short)
|
||||
int src = 10; // next body byte (CI onward), body holds L+1 bytes
|
||||
int dst = 12;
|
||||
while (src <= L) {
|
||||
int n = L + 1 - src;
|
||||
if (n > 16) n = 16;
|
||||
for (int i = 0; i < n; i++) out[dst + i] = body[src + i];
|
||||
uint16_t c = wmbus_crc16(out + dst, n);
|
||||
out[dst + n] = c >> 8; out[dst + n + 1] = c & 0xFF;
|
||||
src += n;
|
||||
dst += n + 2;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user