mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Make linter happy
This commit is contained in:
@@ -16,24 +16,18 @@ static const SubGhzBlockConst pocsag_const = {
|
||||
};
|
||||
|
||||
// Minimal amount of sync bits (interleaving zeros and ones)
|
||||
#define POCSAG_MIN_SYNC_BITS 32
|
||||
#define POCSAG_CW_BITS 32
|
||||
#define POCSAG_CW_MASK 0xFFFFFFFF
|
||||
#define POCSAG_FRAME_SYNC_CODE 0x7CD215D8
|
||||
#define POCSAG_IDLE_CODE_WORD 0x7A89C197
|
||||
#define POCSAG_MIN_SYNC_BITS 32
|
||||
#define POCSAG_CW_BITS 32
|
||||
#define POCSAG_CW_MASK 0xFFFFFFFF
|
||||
#define POCSAG_FRAME_SYNC_CODE 0x7CD215D8
|
||||
#define POCSAG_IDLE_CODE_WORD 0x7A89C197
|
||||
|
||||
#define POCSAG_FUNC_NUM 0
|
||||
#define POCSAG_FUNC_ALERT1 1
|
||||
#define POCSAG_FUNC_ALERT2 2
|
||||
#define POCSAG_FUNC_ALPHANUM 3
|
||||
|
||||
static const char* func_msg[] = {
|
||||
"num: ",
|
||||
"alert",
|
||||
"alert: ",
|
||||
"msg: ",
|
||||
};
|
||||
#define POCSAG_FUNC_NUM 0
|
||||
#define POCSAG_FUNC_ALERT1 1
|
||||
#define POCSAG_FUNC_ALERT2 2
|
||||
#define POCSAG_FUNC_ALPHANUM 3
|
||||
|
||||
static const char* func_msg[] = {"num: ", "alert", "alert: ", "msg: "};
|
||||
static const char* bcd_chars = "*U -)(";
|
||||
|
||||
struct SubGhzProtocolDecoderPocsag {
|
||||
@@ -66,7 +60,6 @@ typedef enum {
|
||||
PocsagDecoderStepMessage,
|
||||
} PocsagDecoderStep;
|
||||
|
||||
|
||||
void* subghz_protocol_decoder_pocsag_alloc(SubGhzEnvironment* environment) {
|
||||
UNUSED(environment);
|
||||
|
||||
@@ -100,24 +93,21 @@ void subghz_protocol_decoder_pocsag_reset(void* context) {
|
||||
furi_string_reset(instance->done_msg);
|
||||
}
|
||||
|
||||
|
||||
static void pocsag_decode_address_word(SubGhzProtocolDecoderPocsag* instance, uint32_t data) {
|
||||
instance->ric = (data >> 13);
|
||||
instance->ric = (instance->ric << 3) | (instance->codeword_idx >> 1);
|
||||
instance->func = (data >> 11) & 0b11;
|
||||
}
|
||||
|
||||
|
||||
static bool decode_message_alphanumeric(SubGhzProtocolDecoderPocsag* instance, uint32_t data) {
|
||||
for (uint8_t i = 0; i < 20; i++) {
|
||||
for(uint8_t i = 0; i < 20; i++) {
|
||||
instance->char_data >>= 1;
|
||||
if (data & (1 << 30)) {
|
||||
instance->char_data |= 1<<6;
|
||||
if(data & (1 << 30)) {
|
||||
instance->char_data |= 1 << 6;
|
||||
}
|
||||
instance->char_bits++;
|
||||
if (instance->char_bits == 7) {
|
||||
if (instance->char_data == 0)
|
||||
return false;
|
||||
if(instance->char_bits == 7) {
|
||||
if(instance->char_data == 0) return false;
|
||||
furi_string_push_back(instance->msg, instance->char_data);
|
||||
instance->char_data = 0;
|
||||
instance->char_bits = 0;
|
||||
@@ -127,54 +117,47 @@ static bool decode_message_alphanumeric(SubGhzProtocolDecoderPocsag* instance, u
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void decode_message_numeric(SubGhzProtocolDecoderPocsag* instance, uint32_t data) {
|
||||
// 5 groups with 4 bits each
|
||||
uint8_t val;
|
||||
for (uint8_t i = 0; i < 5; i++) {
|
||||
val = (data >> (27 - i*4)) & 0b1111;
|
||||
for(uint8_t i = 0; i < 5; i++) {
|
||||
val = (data >> (27 - i * 4)) & 0b1111;
|
||||
// reverse the order of 4 bits
|
||||
val = (val & 0x5) << 1 | (val & 0xA) >> 1;
|
||||
val = (val & 0x3) << 2 | (val & 0xC) >> 2;
|
||||
|
||||
if (val <= 9)
|
||||
if(val <= 9)
|
||||
val += '0';
|
||||
else
|
||||
val = bcd_chars[val-10];
|
||||
val = bcd_chars[val - 10];
|
||||
furi_string_push_back(instance->msg, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// decode message word, maintaining instance state for partial decoding. Return true if more data
|
||||
// might follow or false if end of message reached.
|
||||
static bool pocsag_decode_message_word(SubGhzProtocolDecoderPocsag* instance, uint32_t data) {
|
||||
switch (instance->func) {
|
||||
case POCSAG_FUNC_ALERT2:
|
||||
case POCSAG_FUNC_ALPHANUM:
|
||||
return decode_message_alphanumeric(instance, data);
|
||||
switch(instance->func) {
|
||||
case POCSAG_FUNC_ALERT2:
|
||||
case POCSAG_FUNC_ALPHANUM:
|
||||
return decode_message_alphanumeric(instance, data);
|
||||
|
||||
case POCSAG_FUNC_NUM:
|
||||
decode_message_numeric(instance, data);
|
||||
return true;
|
||||
case POCSAG_FUNC_NUM:
|
||||
decode_message_numeric(instance, data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Function called when current message got decoded, but other messages might follow
|
||||
static void pocsag_message_done(SubGhzProtocolDecoderPocsag* instance) {
|
||||
// append the message to the long-term storage string
|
||||
furi_string_cat_printf(
|
||||
instance->done_msg,
|
||||
"RIC: %" PRIu32 ", ",
|
||||
instance->ric
|
||||
);
|
||||
|
||||
furi_string_cat_str(instance->done_msg, func_msg[instance->func]);
|
||||
if (instance->func != POCSAG_FUNC_ALERT1)
|
||||
furi_string_cat(instance->done_msg, instance->msg);
|
||||
furi_string_cat_str(instance->done_msg, "\r\n");
|
||||
furi_string_cat_printf(instance->done_msg, "RIC: %" PRIu32 ", ", instance->ric);
|
||||
furi_string_cat_str(instance->done_msg, func_msg[instance->func]);
|
||||
if(instance->func != POCSAG_FUNC_ALERT1) {
|
||||
furi_string_cat(instance->done_msg, instance->msg);
|
||||
}
|
||||
furi_string_cat_str(instance->done_msg, "\r\n");
|
||||
|
||||
// reset the state
|
||||
instance->char_bits = 0;
|
||||
@@ -182,22 +165,20 @@ static void pocsag_message_done(SubGhzProtocolDecoderPocsag* instance) {
|
||||
furi_string_reset(instance->msg);
|
||||
}
|
||||
|
||||
|
||||
void subghz_protocol_decoder_pocsag_feed(void* context, bool level, uint32_t duration) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderPocsag* instance = context;
|
||||
|
||||
// reset state - waiting for 32 bits of interleaving 1s and 0s
|
||||
if (instance->decoder.parser_step == PocsagDecoderStepReset) {
|
||||
if (DURATION_DIFF(duration, pocsag_const.te_short) < pocsag_const.te_delta) {
|
||||
if(instance->decoder.parser_step == PocsagDecoderStepReset) {
|
||||
if(DURATION_DIFF(duration, pocsag_const.te_short) < pocsag_const.te_delta) {
|
||||
// POCSAG signals are inverted
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, !level);
|
||||
|
||||
if (instance->decoder.decode_count_bit == POCSAG_MIN_SYNC_BITS) {
|
||||
if(instance->decoder.decode_count_bit == POCSAG_MIN_SYNC_BITS) {
|
||||
instance->decoder.parser_step = PocsagDecoderStepFoundSync;
|
||||
}
|
||||
}
|
||||
else if (instance->decoder.decode_count_bit > 0 ) {
|
||||
} else if(instance->decoder.decode_count_bit > 0) {
|
||||
subghz_protocol_decoder_pocsag_reset(context);
|
||||
}
|
||||
return;
|
||||
@@ -206,11 +187,11 @@ void subghz_protocol_decoder_pocsag_feed(void* context, bool level, uint32_t dur
|
||||
int bits_count = duration / pocsag_const.te_short;
|
||||
uint32_t extra = duration - pocsag_const.te_short * bits_count;
|
||||
|
||||
if (DURATION_DIFF(extra, pocsag_const.te_short) < pocsag_const.te_delta)
|
||||
if(DURATION_DIFF(extra, pocsag_const.te_short) < pocsag_const.te_delta)
|
||||
bits_count++;
|
||||
else if (extra > pocsag_const.te_delta) {
|
||||
else if(extra > pocsag_const.te_delta) {
|
||||
// in non-reset state we faced the error signal - we reached the end of the packet, flush data
|
||||
if (furi_string_size(instance->done_msg) > 0) {
|
||||
if(furi_string_size(instance->done_msg) > 0) {
|
||||
if(instance->base.callback)
|
||||
instance->base.callback(&instance->base, instance->base.context);
|
||||
}
|
||||
@@ -221,12 +202,12 @@ void subghz_protocol_decoder_pocsag_feed(void* context, bool level, uint32_t dur
|
||||
uint32_t codeword;
|
||||
|
||||
// handle state machine for every incoming bit
|
||||
while (bits_count-- > 0) {
|
||||
while(bits_count-- > 0) {
|
||||
subghz_protocol_blocks_add_bit(&instance->decoder, !level);
|
||||
|
||||
switch(instance->decoder.parser_step) {
|
||||
case PocsagDecoderStepFoundSync:
|
||||
if ((instance->decoder.decode_data & POCSAG_CW_MASK) == POCSAG_FRAME_SYNC_CODE) {
|
||||
if((instance->decoder.decode_data & POCSAG_CW_MASK) == POCSAG_FRAME_SYNC_CODE) {
|
||||
instance->decoder.parser_step = PocsagDecoderStepFoundPreamble;
|
||||
instance->decoder.decode_count_bit = 0;
|
||||
instance->decoder.decode_data = 0UL;
|
||||
@@ -234,9 +215,9 @@ void subghz_protocol_decoder_pocsag_feed(void* context, bool level, uint32_t dur
|
||||
break;
|
||||
case PocsagDecoderStepFoundPreamble:
|
||||
// handle codewords
|
||||
if (instance->decoder.decode_count_bit == POCSAG_CW_BITS) {
|
||||
if(instance->decoder.decode_count_bit == POCSAG_CW_BITS) {
|
||||
codeword = (uint32_t)(instance->decoder.decode_data & POCSAG_CW_MASK);
|
||||
switch (codeword) {
|
||||
switch(codeword) {
|
||||
case POCSAG_IDLE_CODE_WORD:
|
||||
instance->codeword_idx++;
|
||||
break;
|
||||
@@ -245,7 +226,7 @@ void subghz_protocol_decoder_pocsag_feed(void* context, bool level, uint32_t dur
|
||||
break;
|
||||
default:
|
||||
// Here we expect only address messages
|
||||
if (codeword >> 31 == 0) {
|
||||
if(codeword >> 31 == 0) {
|
||||
pocsag_decode_address_word(instance, codeword);
|
||||
instance->decoder.parser_step = PocsagDecoderStepMessage;
|
||||
}
|
||||
@@ -257,9 +238,9 @@ void subghz_protocol_decoder_pocsag_feed(void* context, bool level, uint32_t dur
|
||||
break;
|
||||
|
||||
case PocsagDecoderStepMessage:
|
||||
if (instance->decoder.decode_count_bit == POCSAG_CW_BITS) {
|
||||
if(instance->decoder.decode_count_bit == POCSAG_CW_BITS) {
|
||||
codeword = (uint32_t)(instance->decoder.decode_data & POCSAG_CW_MASK);
|
||||
switch (codeword) {
|
||||
switch(codeword) {
|
||||
case POCSAG_IDLE_CODE_WORD:
|
||||
// Idle during the message stops the message
|
||||
instance->codeword_idx++;
|
||||
@@ -271,11 +252,11 @@ void subghz_protocol_decoder_pocsag_feed(void* context, bool level, uint32_t dur
|
||||
break;
|
||||
default:
|
||||
// In this state, both address and message words can arrive
|
||||
if (codeword >> 31 == 0) {
|
||||
if(codeword >> 31 == 0) {
|
||||
pocsag_message_done(instance);
|
||||
pocsag_decode_address_word(instance, codeword);
|
||||
} else {
|
||||
if (!pocsag_decode_message_word(instance, codeword)) {
|
||||
if(!pocsag_decode_message_word(instance, codeword)) {
|
||||
instance->decoder.parser_step = PocsagDecoderStepFoundPreamble;
|
||||
pocsag_message_done(instance);
|
||||
}
|
||||
@@ -299,13 +280,15 @@ uint8_t subghz_protocol_decoder_pocsag_get_hash_data(void* context) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool subghz_protocol_decoder_pocsag_serialize(void* context, FlipperFormat* flipper_format, SubGhzRadioPreset* preset) {
|
||||
bool subghz_protocol_decoder_pocsag_serialize(
|
||||
void* context,
|
||||
FlipperFormat* flipper_format,
|
||||
SubGhzRadioPreset* preset) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderPocsag* instance = context;
|
||||
uint32_t msg_len;
|
||||
|
||||
if(!subghz_block_generic_serialize(&instance->generic, flipper_format, preset))
|
||||
return false;
|
||||
if(!subghz_block_generic_serialize(&instance->generic, flipper_format, preset)) return false;
|
||||
|
||||
msg_len = furi_string_size(instance->done_msg);
|
||||
if(!flipper_format_write_uint32(flipper_format, "MsgLen", &msg_len, 1)) {
|
||||
@@ -313,9 +296,8 @@ bool subghz_protocol_decoder_pocsag_serialize(void* context, FlipperFormat* flip
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!flipper_format_write_hex(flipper_format, "Msg", (uint8_t*)furi_string_get_cstr(instance->done_msg),
|
||||
msg_len))
|
||||
{
|
||||
uint8_t* s = (uint8_t*)furi_string_get_cstr(instance->done_msg);
|
||||
if(!flipper_format_write_hex(flipper_format, "Msg", s, msg_len)) {
|
||||
FURI_LOG_E(TAG, "Error adding Msg");
|
||||
return false;
|
||||
}
|
||||
@@ -356,11 +338,7 @@ bool subghz_protocol_decoder_pocsag_deserialize(void* context, FlipperFormat* fl
|
||||
void subhz_protocol_decoder_pocsag_get_string(void* context, FuriString* output) {
|
||||
furi_assert(context);
|
||||
SubGhzProtocolDecoderPocsag* instance = context;
|
||||
furi_string_cat_printf(
|
||||
output,
|
||||
"%s\r\n",
|
||||
instance->generic.protocol_name
|
||||
);
|
||||
furi_string_cat_printf(output, "%s\r\n", instance->generic.protocol_name);
|
||||
furi_string_cat(output, instance->done_msg);
|
||||
}
|
||||
|
||||
@@ -378,7 +356,8 @@ const SubGhzProtocolDecoder subghz_protocol_pocsag_decoder = {
|
||||
const SubGhzProtocol subghz_protocol_pocsag = {
|
||||
.name = SUBGHZ_PROTOCOL_POCSAG_NAME,
|
||||
.type = SubGhzProtocolTypeStatic,
|
||||
.flag = SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Load,
|
||||
.flag = SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save |
|
||||
SubGhzProtocolFlag_Load,
|
||||
|
||||
.decoder = &subghz_protocol_pocsag_decoder,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user