Skip to content

Commit

Permalink
[FL-3331] SubGhz: add subghz_protocol_registry external API (#2712)
Browse files Browse the repository at this point in the history
* [FL-3331] SubGhz: add subghz_protocol_registry external API

* F18: fix API version

---------

Co-authored-by: hedger <[email protected]>
  • Loading branch information
Skorpionm and hedger authored Jun 6, 2023
1 parent 3e1f209 commit dbd48a0
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion firmware/targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,28.4,,
Version,+,29.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down
8 changes: 5 additions & 3 deletions firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,28.4,,
Version,+,29.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -189,6 +189,7 @@ Header,+,lib/subghz/environment.h,,
Header,+,lib/subghz/protocols/raw.h,,
Header,+,lib/subghz/receiver.h,,
Header,+,lib/subghz/registry.h,,
Header,+,lib/subghz/subghz_protocol_registry.h,,
Header,+,lib/subghz/subghz_setting.h,,
Header,+,lib/subghz/subghz_tx_rx_worker.h,,
Header,+,lib/subghz/subghz_worker.h,,
Expand Down Expand Up @@ -2662,12 +2663,12 @@ Function,+,subghz_environment_get_came_atomo_rainbow_table_file_name,const char*
Function,+,subghz_environment_get_keystore,SubGhzKeystore*,SubGhzEnvironment*
Function,+,subghz_environment_get_nice_flor_s_rainbow_table_file_name,const char*,SubGhzEnvironment*
Function,+,subghz_environment_get_protocol_name_registry,const char*,"SubGhzEnvironment*, size_t"
Function,+,subghz_environment_get_protocol_registry,void*,SubGhzEnvironment*
Function,+,subghz_environment_get_protocol_registry,const SubGhzProtocolRegistry*,SubGhzEnvironment*
Function,+,subghz_environment_load_keystore,_Bool,"SubGhzEnvironment*, const char*"
Function,+,subghz_environment_set_alutech_at_4n_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*"
Function,+,subghz_environment_set_came_atomo_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*"
Function,+,subghz_environment_set_nice_flor_s_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*"
Function,+,subghz_environment_set_protocol_registry,void,"SubGhzEnvironment*, void*"
Function,+,subghz_environment_set_protocol_registry,void,"SubGhzEnvironment*, const SubGhzProtocolRegistry*"
Function,-,subghz_keystore_alloc,SubGhzKeystore*,
Function,-,subghz_keystore_free,void,SubGhzKeystore*
Function,-,subghz_keystore_get_data,SubGhzKeyArray_t*,SubGhzKeystore*
Expand Down Expand Up @@ -3361,6 +3362,7 @@ Variable,+,sequence_success,const NotificationSequence,
Variable,+,subghz_protocol_raw,const SubGhzProtocol,
Variable,+,subghz_protocol_raw_decoder,const SubGhzProtocolDecoder,
Variable,+,subghz_protocol_raw_encoder,const SubGhzProtocolEncoder,
Variable,+,subghz_protocol_registry,const SubGhzProtocolRegistry,
Variable,-,suboptarg,char*,
Variable,+,usb_cdc_dual,FuriHalUsbInterface,
Variable,+,usb_cdc_single,FuriHalUsbInterface,
Expand Down
1 change: 1 addition & 0 deletions lib/subghz/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env.Append(
File("blocks/generic.h"),
File("blocks/math.h"),
File("subghz_setting.h"),
File("subghz_protocol_registry.h"),
],
)

Expand Down
7 changes: 4 additions & 3 deletions lib/subghz/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ const char*

void subghz_environment_set_protocol_registry(
SubGhzEnvironment* instance,
void* protocol_registry_items) {
const SubGhzProtocolRegistry* protocol_registry_items) {
furi_assert(instance);
const SubGhzProtocolRegistry* protocol_registry = protocol_registry_items;
instance->protocol_registry = protocol_registry;
}

void* subghz_environment_get_protocol_registry(SubGhzEnvironment* instance) {
const SubGhzProtocolRegistry*
subghz_environment_get_protocol_registry(SubGhzEnvironment* instance) {
furi_assert(instance);
furi_assert(instance->protocol_registry);
return (void*)instance->protocol_registry;
return instance->protocol_registry;
}

const char*
Expand Down
7 changes: 5 additions & 2 deletions lib/subghz/environment.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <furi.h>
#include "registry.h"

#include "subghz_keystore.h"

Expand All @@ -9,6 +10,7 @@ extern "C" {
#endif

typedef struct SubGhzEnvironment SubGhzEnvironment;
typedef struct SubGhzProtocolRegistry SubGhzProtocolRegistry;

/**
* Allocate SubGhzEnvironment.
Expand Down Expand Up @@ -93,14 +95,15 @@ const char*
*/
void subghz_environment_set_protocol_registry(
SubGhzEnvironment* instance,
void* protocol_registry_items);
const SubGhzProtocolRegistry* protocol_registry_items);

/**
* Get list of protocols to work.
* @param instance Pointer to a SubGhzEnvironment instance
* @return Pointer to a SubGhzProtocolRegistry
*/
void* subghz_environment_get_protocol_registry(SubGhzEnvironment* instance);
const SubGhzProtocolRegistry*
subghz_environment_get_protocol_registry(SubGhzEnvironment* instance);

/**
* Get list of protocols names.
Expand Down
3 changes: 1 addition & 2 deletions lib/subghz/protocols/protocol_items.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "../registry.h"
#include "../subghz_protocol_registry.h"

#include "princeton.h"
#include "keeloq.h"
Expand Down Expand Up @@ -43,5 +44,3 @@
#include "alutech_at_4n.h"
#include "kinggates_stylo_4k.h"
#include "bin_raw.h"

extern const SubGhzProtocolRegistry subghz_protocol_registry;
1 change: 1 addition & 0 deletions lib/subghz/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {
typedef struct SubGhzEnvironment SubGhzEnvironment;

typedef struct SubGhzProtocolRegistry SubGhzProtocolRegistry;
typedef struct SubGhzProtocol SubGhzProtocol;

struct SubGhzProtocolRegistry {
const SubGhzProtocol** items;
Expand Down
13 changes: 13 additions & 0 deletions lib/subghz/subghz_protocol_registry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "registry.h"

#ifdef __cplusplus
extern "C" {
#endif

extern const SubGhzProtocolRegistry subghz_protocol_registry;

#ifdef __cplusplus
}
#endif
7 changes: 5 additions & 2 deletions lib/subghz/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#define SUBGHZ_RAW_FILE_VERSION 1
#define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File"

typedef struct SubGhzProtocolRegistry SubGhzProtocolRegistry;
typedef struct SubGhzEnvironment SubGhzEnvironment;

// Radio Preset
typedef struct {
FuriString* name;
Expand Down Expand Up @@ -115,11 +118,11 @@ typedef enum {
SubGhzProtocolFlag_BinRAW = (1 << 10),
} SubGhzProtocolFlag;

typedef struct {
struct SubGhzProtocol {
const char* name;
SubGhzProtocolType type;
SubGhzProtocolFlag flag;

const SubGhzProtocolEncoder* encoder;
const SubGhzProtocolDecoder* decoder;
} SubGhzProtocol;
};

0 comments on commit dbd48a0

Please sign in to comment.