formatting

This commit is contained in:
VerstreuteSeele
2023-01-27 02:09:42 +01:00
parent 0879f92e3d
commit a2b797fe01
44 changed files with 1735 additions and 1623 deletions

View File

@@ -9,9 +9,9 @@
#include "../app.h"
static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
if (numbits < 30) return false;
const char *sync_patterns[3] = {
static bool decode(uint8_t* bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo* info) {
if(numbits < 30) return false;
const char* sync_patterns[3] = {
"10000000000000000000000000000001", /* 30 zero bits. */
"100000000000000000000000000000001", /* 31 zero bits. */
"1000000000000000000000000000000001", /* 32 zero bits. */
@@ -19,70 +19,67 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
uint32_t off;
int j;
for (j = 0; j < 3; j++) {
off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_patterns[j]);
if (off != BITMAP_SEEK_NOT_FOUND) break;
for(j = 0; j < 3; j++) {
off = bitmap_seek_bits(bits, numbytes, 0, numbits, sync_patterns[j]);
if(off != BITMAP_SEEK_NOT_FOUND) break;
}
if (off == BITMAP_SEEK_NOT_FOUND) return false;
if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 preamble at: %lu",off);
if(off == BITMAP_SEEK_NOT_FOUND) return false;
if(DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 preamble at: %lu", off);
info->start_off = off;
// Seek data setction. Why -1? Last bit is data.
off += strlen(sync_patterns[j])-1;
off += strlen(sync_patterns[j]) - 1;
uint8_t d[3]; /* 24 bits of data. */
uint32_t decoded =
convert_from_line_code(d,sizeof(d),bits,numbytes,off,"1000","1110");
uint32_t decoded = convert_from_line_code(d, sizeof(d), bits, numbytes, off, "1000", "1110");
if (DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 decoded: %lu",decoded);
if (decoded < 24) return false;
if(DEBUG_MSG) FURI_LOG_E(TAG, "B4B1 decoded: %lu", decoded);
if(decoded < 24) return false;
off += 24*4; // seek to end symbol offset to calculate the length.
off += 24 * 4; // seek to end symbol offset to calculate the length.
off++; // In this protocol there is a final pulse as terminator.
info->pulses_count = off - info->start_off;
fieldset_add_bytes(info->fieldset,"id",d,5);
fieldset_add_uint(info->fieldset,"button",d[2]&0xf,4);
fieldset_add_bytes(info->fieldset, "id", d, 5);
fieldset_add_uint(info->fieldset, "button", d[2] & 0xf, 4);
return true;
}
/* Give fields and defaults for the signal creator. */
static void get_fields(ProtoViewFieldSet *fieldset) {
uint8_t default_id[3]= {0xAB, 0xCD, 0xE0};
fieldset_add_bytes(fieldset,"id",default_id,5);
fieldset_add_uint(fieldset,"button",1,4);
static void get_fields(ProtoViewFieldSet* fieldset) {
uint8_t default_id[3] = {0xAB, 0xCD, 0xE0};
fieldset_add_bytes(fieldset, "id", default_id, 5);
fieldset_add_uint(fieldset, "button", 1, 4);
}
/* Create a signal. */
static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fs)
{
static void build_message(RawSamplesBuffer* samples, ProtoViewFieldSet* fs) {
uint32_t te = 334; // Short pulse duration in microseconds.
// Sync: 1 te pulse, 31 te gap.
raw_samples_add(samples,true,te);
raw_samples_add(samples,false,te*31);
raw_samples_add(samples, true, te);
raw_samples_add(samples, false, te * 31);
// ID + button state
uint8_t data[3];
memcpy(data,fs->fields[0]->bytes,3);
data[2] = (data[2]&0xF0) | (fs->fields[1]->uvalue & 0xF);
for (uint32_t j = 0; j < 24; j++) {
if (bitmap_get(data,sizeof(data),j)) {
raw_samples_add(samples,true,te*3);
raw_samples_add(samples,false,te);
memcpy(data, fs->fields[0]->bytes, 3);
data[2] = (data[2] & 0xF0) | (fs->fields[1]->uvalue & 0xF);
for(uint32_t j = 0; j < 24; j++) {
if(bitmap_get(data, sizeof(data), j)) {
raw_samples_add(samples, true, te * 3);
raw_samples_add(samples, false, te);
} else {
raw_samples_add(samples,true,te);
raw_samples_add(samples,false,te*3);
raw_samples_add(samples, true, te);
raw_samples_add(samples, false, te * 3);
}
}
// Signal terminator. Just a single short pulse.
raw_samples_add(samples,true,te);
raw_samples_add(samples, true, te);
}
ProtoViewDecoder B4B1Decoder = {
.name = "PT/SC remote",
.decode = decode,
.get_fields = get_fields,
.build_message = build_message
};
.build_message = build_message};