flipperzero-firmware/lib/subghz/protocols/subghz_protocol_common.h
Skorpionm 1cfa857f98
[FL-1610] SubGhz: scene based application, PT save and replay (#630)
* SubGhz: scene based application
* SubGhz: encoder/decoder separation, DMA streaming, update app and cli.
* SubGhz: 2 stage async tx complete, minor cleanup
* SubGhz: 2 stage async tx complete, FIX state pin end transmit
* SubGhz: Pricenton, receive TE signal
* SubGhz: Pricenton, add save data, add load data
* SubGhz: Add Read scene, Fix pricenton save, load funtion
* SubGhz: Add Read, Receiver, SaveName scene
* SubGhz: Read and Save (pricenton)
* SubGhz: add Load scence
* SubGhz: Fix select file scene, add load scene, add transmitter view, add send tx pricenton
* SubGhz: Fix pricenton encoder, fix transmitter send
* SubGhz: modified Pricenton Encoder (added guard time at the beginning), modified CC1101 config, code refactoring
* SubGhz: Fix pricenton encoder defalut TE
* Archive: Fix path and name SubGhz
* Archive: Fix name app SubGhz
* GubGhz: Came: add Save, Load key
* GubGhz: GateTX: add Save, Load key
* GubGhz: NeroSketch: add Save, Load key
* Github: better linters triggers
* SubGhz: adding fast loading keys Archive -> Run in app
* GubGhz: KeeLog: add Save, Load key, key generation from the serial number of the meter and the button
* SubGhz: format sources and fix compilation
* FuriHal: add subghz configuration description for AGC section
* SubGhz: save only protocols that can be saved. Cleanup.
* Github: lint on pull requests

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-12 17:42:56 +03:00

107 lines
3.1 KiB
C

#pragma once
#include <m-string.h>
#include <furi-hal.h>
#include <stdint.h>
#include "file-worker.h"
#define bit_read(value, bit) (((value) >> (bit)) & 0x01)
#define bit_set(value, bit) ((value) |= (1UL << (bit)))
#define bit_clear(value, bit) ((value) &= ~(1UL << (bit)))
#define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit))
#define SUBGHZ_TX_PIN_HIGTH()
#define SUBGHZ_TX_PIN_LOW()
#define DURATION_DIFF(x, y) ((x < y) ? (y - x) : (x - y))
//#define SUBGHZ_APP_PATH_FOLDER "/ext/subghz/saved"
#define SUBGHZ_APP_FOLDER "/any/subghz"
#define SUBGHZ_APP_PATH_FOLDER "/any/subghz/saved"
#define SUBGHZ_APP_EXTENSION ".sub"
typedef struct SubGhzProtocolCommon SubGhzProtocolCommon;
typedef void (*SubGhzProtocolCommonCallback)(SubGhzProtocolCommon* parser, void* context);
typedef void (*SubGhzProtocolCommonToStr)(SubGhzProtocolCommon* instance, string_t output);
//Save
typedef void (*SubGhzProtocolCommonGetStrSave)(SubGhzProtocolCommon* instance, string_t output);
//Load
typedef bool (*SubGhzProtocolCommonLoad)(FileWorker* file_worker, SubGhzProtocolCommon* instance);
struct SubGhzProtocolCommon {
const char* name;
uint16_t te_long;
uint16_t te_shot;
uint16_t te_delta;
uint8_t code_count_bit;
uint8_t code_last_count_bit;
uint64_t code_found;
uint64_t code_last_found;
uint8_t code_min_count_bit_for_found;
uint8_t parser_step;
uint32_t te_last;
uint8_t header_count;
uint16_t cnt;
uint32_t serial;
uint8_t btn;
/* Standard Callback for on rx complete event */
SubGhzProtocolCommonCallback callback;
void* context;
/* Dump To String */
SubGhzProtocolCommonToStr to_string;
/* Get string to save */
SubGhzProtocolCommonGetStrSave to_save_string;
/*Load protocol by file*/
SubGhzProtocolCommonLoad to_load_protocol;
};
/** Add data bit to code_found
*
* @param common - SubGhzProtocolCommon common
* @param bit - add bit
*/
void subghz_protocol_common_add_bit(SubGhzProtocolCommon* common, uint8_t bit);
/** Checking that the duration is included in the interval
*
* @param common - SubGhzProtocolCommon common
* @param duration duration reference
* @param duration_check duration checked
* @return true on success
*/
bool subghz_protocol_common_check_interval(
SubGhzProtocolCommon* common,
uint32_t duration,
uint16_t duration_check);
/** Bit-by-bit data mirroring
*
* @param key - data to mirror
* @param count_bit number of data bits
* @return mirrored data
*/
uint64_t subghz_protocol_common_reverse_key(uint64_t key, uint8_t count_bit);
/** Callback protocol
*
* @param instance - SubGhzProtocolCommon* instance
* @param callback
* @param context
*/
void subghz_protocol_common_set_callback(
SubGhzProtocolCommon* instance,
SubGhzProtocolCommonCallback callback,
void* context);
/** outputting information from the parser
*
* @param instance - SubGhzProtocolCommon* instance
* @param output - output string
*/
void subghz_protocol_common_to_str(SubGhzProtocolCommon* instance, string_t output);