|
15 | 15 | #define NEXWATCH_US_PER_BIT (255) |
16 | 16 | #define NEXWATCH_ENCODER_PULSES_PER_BIT (16) |
17 | 17 |
|
18 | | -typedef struct { |
19 | | - uint8_t magic; |
20 | | - char desc[13]; |
21 | | - uint8_t chk; |
22 | | -} ProtocolNexwatchMagic; |
23 | | - |
24 | | -static ProtocolNexwatchMagic magic_items[] = { |
25 | | - {0xBE, "Quadrakey", 0}, |
26 | | - {0x88, "Nexkey", 0}, |
27 | | - {0x86, "Honeywell", 0}}; |
28 | | - |
29 | 18 | typedef struct { |
30 | 19 | uint8_t data_index; |
31 | 20 | uint8_t bit_clock_index; |
@@ -143,10 +132,10 @@ static bool protocol_nexwatch_decoder_feed_internal(bool polarity, uint32_t time |
143 | 132 | return result; |
144 | 133 | } |
145 | 134 |
|
146 | | -static void protocol_nexwatch_descramble(uint32_t* id, uint32_t* scrambled) { |
| 135 | +static void protocol_nexwatch_descramble(uint32_t* id, const uint32_t* scrambled) { |
147 | 136 | // 255 = Not used/Unknown other values are the bit offset in the ID/FC values |
148 | | - const uint8_t hex_2_id[] = {31, 27, 23, 19, 15, 11, 7, 3, 30, 26, 22, 18, 14, 10, 6, 2, |
149 | | - 29, 25, 21, 17, 13, 9, 5, 1, 28, 24, 20, 16, 12, 8, 4, 0}; |
| 137 | + static const uint8_t hex_2_id[] = {31, 27, 23, 19, 15, 11, 7, 3, 30, 26, 22, 18, 14, 10, 6, 2, |
| 138 | + 29, 25, 21, 17, 13, 9, 5, 1, 28, 24, 20, 16, 12, 8, 4, 0}; |
150 | 139 |
|
151 | 140 | *id = 0; |
152 | 141 | for(uint8_t idx = 0; idx < 32; idx++) { |
@@ -264,27 +253,33 @@ LevelDuration protocol_nexwatch_encoder_yield(ProtocolNexwatch* protocol) { |
264 | 253 | } |
265 | 254 |
|
266 | 255 | static void protocol_nexwatch_render_data_internal( |
267 | | - ProtocolNexwatch* protocol, |
| 256 | + const ProtocolNexwatch* protocol, |
268 | 257 | FuriString* result, |
269 | 258 | bool brief) { |
270 | 259 | uint32_t id = 0; |
271 | | - uint32_t scrambled = bit_lib_get_bits_32(protocol->data, 8, 32); |
| 260 | + const uint32_t scrambled = bit_lib_get_bits_32(protocol->data, 8, 32); |
272 | 261 | protocol_nexwatch_descramble(&id, &scrambled); |
273 | 262 |
|
274 | | - uint8_t m_idx; |
275 | | - uint8_t mode = bit_lib_get_bits(protocol->data, 40, 4); |
276 | | - uint8_t parity = bit_lib_get_bits(protocol->data, 44, 4); |
277 | | - uint8_t chk = bit_lib_get_bits(protocol->data, 48, 8); |
| 263 | + const uint8_t mode = bit_lib_get_bits(protocol->data, 40, 4); |
| 264 | + const uint8_t parity = bit_lib_get_bits(protocol->data, 44, 4); |
| 265 | + const uint8_t chk = bit_lib_get_bits(protocol->data, 48, 8); |
278 | 266 |
|
279 | | - for(m_idx = 0; m_idx < COUNT_OF(magic_items); m_idx++) { |
280 | | - magic_items[m_idx].chk = protocol_nexwatch_checksum(magic_items[m_idx].magic, id, parity); |
281 | | - if(magic_items[m_idx].chk == chk) { |
| 267 | + typedef struct { |
| 268 | + const char* desc; |
| 269 | + uint8_t magic; |
| 270 | + } ProtocolNexwatchMagic; |
| 271 | + |
| 272 | + static const ProtocolNexwatchMagic magic_items[] = { |
| 273 | + {"Quadrakey", 0xBE}, {"Nexkey", 0x88}, {"Honeywell", 0x86}}; |
| 274 | + |
| 275 | + const char* type = "Unknown"; |
| 276 | + for(size_t idx = 0; idx < COUNT_OF(magic_items); idx++) { |
| 277 | + if(protocol_nexwatch_checksum(magic_items[idx].magic, id, parity) == chk) { |
| 278 | + type = magic_items[idx].desc; |
282 | 279 | break; |
283 | 280 | } |
284 | 281 | } |
285 | 282 |
|
286 | | - const char* type = m_idx < COUNT_OF(magic_items) ? magic_items[m_idx].desc : "Unknown"; |
287 | | - |
288 | 283 | if(brief) { |
289 | 284 | furi_string_printf( |
290 | 285 | result, |
|
0 commit comments