[FL-1912, FL-1939] Sub-GHz frequency analyzer and add new protocol (#746)

* ToolBox: add manchester-decoder and manchester-encoder
* SubGhz: add new FM config cc1101
* Subghz: add protocol Kia
* SubGhz: fix receiving the last packet Nero Radio
* SubGhz: app protocol CAME Twin (TW2EE/TW4EE)
* SubGhz: add protocol CAME Atomo (AT03EV/ AT04EV)
* F7: sync with F6
* SubGhz: add frequency analyzer
* SubGhz: remove space from file name 
* SubGhz: frequency analyzer add filter and fix view
* [FL-1939] GubGhz: Frequency analyzer redesign
* SubGhz: fix incorrect subghz api call sequence in frequency analyzer worker

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Skorpionm 2021-10-10 18:35:10 +04:00 committed by GitHub
parent 5dbfe3d90a
commit 4418e73b26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 2082 additions and 316 deletions

View file

@ -115,6 +115,8 @@ void canvas_set_font(Canvas* canvas, Font font) {
u8g2_SetFont(&canvas->fb, u8g2_font_haxrcorp4089_tr);
} else if(font == FontKeyboard) {
u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mf);
} else if(font == FontBigNumbers) {
u8g2_SetFont(&canvas->fb, u8g2_font_profont22_tn);
} else {
furi_crash(NULL);
}

View file

@ -20,7 +20,7 @@ typedef enum {
} Color;
/** Fonts enumeration */
typedef enum { FontPrimary, FontSecondary, FontKeyboard } Font;
typedef enum { FontPrimary, FontSecondary, FontKeyboard, FontBigNumbers } Font;
/** Alignment enumeration */
typedef enum {

View file

@ -1,7 +1,7 @@
#pragma once
#include <stdint.h>
#include <atomic>
#include "manchester-decoder.h"
#include <lib/toolbox/manchester-decoder.h>
#include "protocols/protocol-emmarin.h"
class DecoderEMMarin {
public:

View file

@ -0,0 +1,171 @@
#include "subghz_frequency_analyzer_worker.h"
#include <furi.h>
#include "../subghz_i.h"
struct SubGhzFrequencyAnalyzerWorker {
FuriThread* thread;
volatile bool worker_running;
uint8_t count_repet;
FrequencyRSSI frequency_rssi_buf;
float filVal;
SubGhzFrequencyAnalyzerWorkerPairCallback pair_callback;
void* context;
};
// running average with adaptive coefficient
static uint32_t subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
SubGhzFrequencyAnalyzerWorker* instance,
uint32_t newVal) {
float k;
float newValFloat = newVal;
// the sharpness of the filter depends on the absolute value of the difference
if(abs(newValFloat - instance->filVal) > 500000)
k = 0.9;
else
k = 0.03;
instance->filVal += (newValFloat - instance->filVal) * k;
return (uint32_t)instance->filVal;
}
/** Worker thread
*
* @param context
* @return exit code
*/
static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
SubGhzFrequencyAnalyzerWorker* instance = context;
FrequencyRSSI frequency_rssi;
float rssi;
uint32_t frequency;
uint32_t frequency_start;
//Start CC1101
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
furi_hal_subghz_set_frequency(433920000);
furi_hal_subghz_flush_rx();
furi_hal_subghz_rx();
while(instance->worker_running) {
osDelay(10);
frequency_rssi.rssi = -127.0f;
for(size_t i = 0; i < subghz_frequencies_count; i++) {
if(furi_hal_subghz_is_frequency_valid(subghz_frequencies[i])) {
furi_hal_subghz_idle();
frequency = furi_hal_subghz_set_frequency(subghz_frequencies[i]);
furi_hal_subghz_rx();
osDelay(3);
rssi = furi_hal_subghz_get_rssi();
if(frequency_rssi.rssi < rssi) {
frequency_rssi.rssi = rssi;
frequency_rssi.frequency = frequency;
}
}
}
if(frequency_rssi.rssi > -90.0) {
// -0.5 ... 433.92 ... +0.5
frequency_start = frequency_rssi.frequency - 250000;
//step 10KHz
for(uint32_t i = frequency_start; i < frequency_start + 500000; i += 10000) {
if(furi_hal_subghz_is_frequency_valid(i)) {
furi_hal_subghz_idle();
frequency = furi_hal_subghz_set_frequency(i);
furi_hal_subghz_rx();
osDelay(3);
rssi = furi_hal_subghz_get_rssi();
if(frequency_rssi.rssi < rssi) {
frequency_rssi.rssi = rssi;
frequency_rssi.frequency = frequency;
}
}
}
}
if(frequency_rssi.rssi > -90.0) {
instance->count_repet = 20;
if(instance->filVal) {
frequency_rssi.frequency =
subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
instance, frequency_rssi.frequency);
}
if(instance->pair_callback)
instance->pair_callback(
instance->context, frequency_rssi.frequency, frequency_rssi.rssi);
} else {
if(instance->count_repet > 0) {
instance->count_repet--;
} else {
instance->filVal = 0;
if(instance->pair_callback) instance->pair_callback(instance->context, 0, 0);
}
}
}
//Stop CC1101
furi_hal_subghz_idle();
furi_hal_subghz_sleep();
return 0;
}
SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc() {
SubGhzFrequencyAnalyzerWorker* instance = furi_alloc(sizeof(SubGhzFrequencyAnalyzerWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "subghz_frequency_analyzer_worker");
furi_thread_set_stack_size(instance->thread, 2048);
furi_thread_set_context(instance->thread, instance);
furi_thread_set_callback(instance->thread, subghz_frequency_analyzer_worker_thread);
return instance;
}
void subghz_frequency_analyzer_worker_free(SubGhzFrequencyAnalyzerWorker* instance) {
furi_assert(instance);
furi_thread_free(instance->thread);
free(instance);
}
void subghz_frequency_analyzer_worker_set_pair_callback(
SubGhzFrequencyAnalyzerWorker* instance,
SubGhzFrequencyAnalyzerWorkerPairCallback callback,
void* context) {
furi_assert(instance);
furi_assert(context);
instance->pair_callback = callback;
instance->context = context;
}
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance) {
furi_assert(instance);
furi_assert(!instance->worker_running);
instance->worker_running = true;
furi_thread_start(instance->thread);
}
void subghz_frequency_analyzer_worker_stop(SubGhzFrequencyAnalyzerWorker* instance) {
furi_assert(instance);
furi_assert(instance->worker_running);
instance->worker_running = false;
furi_thread_join(instance->thread);
}
bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker* instance) {
furi_assert(instance);
return instance->worker_running;
}

View file

@ -0,0 +1,54 @@
#pragma once
#include <furi-hal.h>
typedef struct SubGhzFrequencyAnalyzerWorker SubGhzFrequencyAnalyzerWorker;
typedef void (
*SubGhzFrequencyAnalyzerWorkerPairCallback)(void* context, uint32_t frequency, float rssi);
typedef struct {
uint32_t frequency;
float rssi;
} FrequencyRSSI;
/** Allocate SubGhzFrequencyAnalyzerWorker
*
* @return SubGhzFrequencyAnalyzerWorker*
*/
SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc();
/** Free SubGhzFrequencyAnalyzerWorker
*
* @param instance SubGhzFrequencyAnalyzerWorker instance
*/
void subghz_frequency_analyzer_worker_free(SubGhzFrequencyAnalyzerWorker* instance);
/** Pair callback SubGhzFrequencyAnalyzerWorker
*
* @param instance SubGhzFrequencyAnalyzerWorker instance
* @param callback SubGhzFrequencyAnalyzerWorkerOverrunCallback callback
* @param context
*/
void subghz_frequency_analyzer_worker_set_pair_callback(
SubGhzFrequencyAnalyzerWorker* instance,
SubGhzFrequencyAnalyzerWorkerPairCallback callback,
void* context);
/** Start SubGhzFrequencyAnalyzerWorker
*
* @param instance SubGhzFrequencyAnalyzerWorker instance
*/
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance);
/** Stop SubGhzFrequencyAnalyzerWorker
*
* @param instance SubGhzFrequencyAnalyzerWorker instance
*/
void subghz_frequency_analyzer_worker_stop(SubGhzFrequencyAnalyzerWorker* instance);
/** Check if worker is running
* @param instance SubGhzFrequencyAnalyzerWorker instance
* @return bool - true if running
*/
bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker* instance);

View file

@ -16,3 +16,4 @@ ADD_SCENE(subghz, test_static, TestStatic)
ADD_SCENE(subghz, test_carrier, TestCarrier)
ADD_SCENE(subghz, test_packet, TestPacket)
ADD_SCENE(subghz, set_type, SetType)
ADD_SCENE(subghz, frequency_analyzer, FrequencyAnalyzer)

View file

@ -28,7 +28,9 @@ void subghz_scene_delete_on_enter(void* context) {
if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
snprintf(buffer_str, sizeof(buffer_str), "AM");
} else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
} else if(
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async ||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
snprintf(buffer_str, sizeof(buffer_str), "FM");
} else {
furi_crash(NULL);

View file

@ -0,0 +1,30 @@
#include "../subghz_i.h"
#include "../views/subghz_frequency_analyzer.h"
void subghz_scene_frequency_analyzer_callback(SubghzFrequencyAnalyzerEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}
void subghz_scene_frequency_analyzer_on_enter(void* context) {
SubGhz* subghz = context;
subghz_frequency_analyzer_set_callback(
subghz->subghz_frequency_analyzer, subghz_scene_frequency_analyzer_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewFrequencyAnalyzer);
}
bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzFrequencyAnalyzerEventOnlyRx) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
return true;
}
}
return false;
}
void subghz_scene_frequency_analyzer_on_exit(void* context) {
// SubGhz* subghz = context;
}

View file

@ -17,7 +17,9 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
snprintf(preset_str, sizeof(preset_str), "AM");
} else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
} else if(
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async ||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
snprintf(preset_str, sizeof(preset_str), "FM");
} else {
furi_crash(NULL);

View file

@ -1,15 +1,17 @@
#include "../subghz_i.h"
#define PRESET_COUNT 3
#define PRESET_COUNT 4
const char* const preset_text[PRESET_COUNT] = {
"AM270",
"AM650",
"FM",
"FM238",
"FM476",
};
const uint32_t preset_value[PRESET_COUNT] = {
FuriHalSubGhzPresetOok270Async, /** OOK, bandwidth 270kHz, asynchronous */
FuriHalSubGhzPresetOok650Async, /** OOK, bandwidth 650kHz, asynchronous */
FuriHalSubGhzPreset2FSKAsync, /** FM, asynchronous */
FuriHalSubGhzPreset2FSKDev238Async, /** FM, deviation 2.380371 kHz, asynchronous */
FuriHalSubGhzPreset2FSKDev476Async, /** FM, deviation 4.760742 kHz, asynchronous */
};
#define HOPPING_COUNT 2

View file

@ -57,7 +57,9 @@ void subghz_scene_receiver_info_on_enter(void* context) {
if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
snprintf(buffer_str, sizeof(buffer_str), "AM");
} else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
} else if(
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async ||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
snprintf(buffer_str, sizeof(buffer_str), "FM");
} else {
furi_crash(NULL);

View file

@ -7,6 +7,7 @@ enum SubmenuIndex {
SubmenuIndexNiceFlo24bit,
SubmenuIndexCAME12bit,
SubmenuIndexCAME24bit,
SubmenuIndexCAMETwee,
SubmenuIndexNeroSketch,
SubmenuIndexNeroRadio,
SubmenuIndexGateTX,
@ -62,6 +63,12 @@ void subghz_scene_set_type_on_enter(void* context) {
SubmenuIndexCAME24bit,
subghz_scene_set_type_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu,
"CAME TWEE",
SubmenuIndexCAMETwee,
subghz_scene_set_type_submenu_callback,
subghz);
// submenu_add_item(
// subghz->submenu, "Nero Sketch", SubmenuIndexNeroSketch, subghz_scene_set_type_submenu_callback, subghz);
// submenu_add_item(
@ -132,6 +139,15 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
generated_protocol = true;
}
break;
case SubmenuIndexCAMETwee:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "CAME TWEE")) {
subghz->txrx->protocol_result->code_last_count_bit = 54;
key = (key & 0x0FFFFFF0);
subghz->txrx->protocol_result->code_last_found = 0x003FFF7200000000 |
(key ^ 0xE0E0E0EE);
generated_protocol = true;
}
break;
// case SubmenuIndexNeroSketch:
// /* code */
// break;

View file

@ -5,6 +5,7 @@ enum SubmenuIndex {
SubmenuIndexSaved,
SubmenuIndexTest,
SubmenuIndexAddManualy,
SubmenuIndexFrequencyAnalyzer,
};
void subghz_scene_start_submenu_callback(void* context, uint32_t index) {
@ -27,6 +28,12 @@ void subghz_scene_start_on_enter(void* context) {
SubmenuIndexAddManualy,
subghz_scene_start_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu,
"Frequency Analyzer",
SubmenuIndexFrequencyAnalyzer,
subghz_scene_start_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz);
@ -55,6 +62,11 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexAddManualy);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetType);
return true;
} else if(event.event == SubmenuIndexFrequencyAnalyzer) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexFrequencyAnalyzer);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneFrequencyAnalyzer);
return true;
} else if(event.event == SubmenuIndexTest) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexTest);

View file

@ -36,7 +36,9 @@ static void subghz_scene_transmitter_update_data_show(void* context) {
if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
snprintf(preset_str, sizeof(preset_str), "AM");
} else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
} else if(
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async ||
subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
snprintf(preset_str, sizeof(preset_str), "FM");
} else {
furi_crash(NULL);

View file

@ -133,6 +133,13 @@ SubGhz* subghz_alloc() {
SubGhzViewVariableItemList,
variable_item_list_get_view(subghz->variable_item_list));
// Frequency Analyzer
subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewFrequencyAnalyzer,
subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer));
// Carrier Test Module
subghz->subghz_test_carrier = subghz_test_carrier_alloc();
view_dispatcher_add_view(
@ -215,6 +222,10 @@ void subghz_free(SubGhz* subghz) {
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewVariableItemList);
variable_item_list_free(subghz->variable_item_list);
// Frequency Analyzer
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewFrequencyAnalyzer);
subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer);
// Submenu
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewMenu);
submenu_free(subghz->submenu);

View file

@ -3,6 +3,7 @@
#include "subghz.h"
#include "views/subghz_receiver.h"
#include "views/subghz_transmitter.h"
#include "views/subghz_frequency_analyzer.h"
#include "views/subghz_test_static.h"
#include "views/subghz_test_carrier.h"
@ -98,6 +99,7 @@ struct SubGhz {
SubghzTransmitter* subghz_transmitter;
VariableItemList* variable_item_list;
SubghzFrequencyAnalyzer* subghz_frequency_analyzer;
SubghzTestStatic* subghz_test_static;
SubghzTestCarrier* subghz_test_carrier;
SubghzTestPacket* subghz_test_packet;
@ -113,6 +115,7 @@ typedef enum {
SubGhzViewWidget,
SubGhzViewTransmitter,
SubGhzViewVariableItemList,
SubGhzViewFrequencyAnalyzer,
SubGhzViewStatic,
SubGhzViewTestCarrier,
SubGhzViewTestPacket,

View file

@ -0,0 +1,170 @@
#include "subghz_frequency_analyzer.h"
#include "../subghz_i.h"
#include <math.h>
#include <furi.h>
#include <furi-hal.h>
#include <input/input.h>
#include <notification/notification-messages.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include "../helpers/subghz_frequency_analyzer_worker.h"
#include <assets_icons.h>
typedef enum {
SubghzFrequencyAnalyzerStatusIDLE,
} SubghzFrequencyAnalyzerStatus;
struct SubghzFrequencyAnalyzer {
View* view;
SubGhzFrequencyAnalyzerWorker* worker;
SubghzFrequencyAnalyzerCallback callback;
void* context;
};
typedef struct {
uint32_t frequency;
float rssi;
} SubghzFrequencyAnalyzerModel;
void subghz_frequency_analyzer_set_callback(
SubghzFrequencyAnalyzer* subghz_frequency_analyzer,
SubghzFrequencyAnalyzerCallback callback,
void* context) {
furi_assert(subghz_frequency_analyzer);
furi_assert(callback);
subghz_frequency_analyzer->callback = callback;
subghz_frequency_analyzer->context = context;
}
void subghz_frequency_analyzer_draw_rssi(Canvas* canvas, float rssi) {
uint8_t x = 48;
uint8_t y = 56;
uint8_t column_number = 0;
if(rssi) {
rssi = (rssi + 90) / 3;
for(size_t i = 1; i < (uint8_t)rssi; i++) {
if(i > 20) break;
if(i % 4) {
column_number++;
canvas_draw_box(canvas, x + 2 * i, y - column_number, 2, 4 + column_number);
}
}
}
}
void subghz_frequency_analyzer_draw(Canvas* canvas, SubghzFrequencyAnalyzerModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 20, 8, "Frequency Analyzer");
canvas_draw_str(canvas, 28, 60, "RSSI");
subghz_frequency_analyzer_draw_rssi(canvas, model->rssi);
//Frequency
canvas_set_font(canvas, FontBigNumbers);
snprintf(
buffer,
sizeof(buffer),
"%03ld.%03ld",
model->frequency / 1000000 % 1000,
model->frequency / 1000 % 1000);
canvas_draw_str(canvas, 8, 35, buffer);
canvas_draw_icon(canvas, 96, 24, &I_MHz_25x11);
}
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
furi_assert(context);
//SubghzFrequencyAnalyzer* instance = context;
if(event->key == InputKeyBack) {
return false;
}
return true;
}
void subghz_frequency_analyzer_pair_callback(void* context, uint32_t frequency, float rssi) {
SubghzFrequencyAnalyzer* instance = context;
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
model->rssi = rssi;
model->frequency = frequency;
return true;
});
}
void subghz_frequency_analyzer_enter(void* context) {
furi_assert(context);
SubghzFrequencyAnalyzer* instance = context;
//Start worker
instance->worker = subghz_frequency_analyzer_worker_alloc();
subghz_frequency_analyzer_worker_set_pair_callback(
instance->worker,
(SubGhzFrequencyAnalyzerWorkerPairCallback)subghz_frequency_analyzer_pair_callback,
instance);
subghz_frequency_analyzer_worker_start(instance->worker);
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
model->rssi = 0;
model->frequency = 0;
return true;
});
}
void subghz_frequency_analyzer_exit(void* context) {
furi_assert(context);
SubghzFrequencyAnalyzer* instance = context;
//Stop worker
if(subghz_frequency_analyzer_worker_is_running(instance->worker)) {
subghz_frequency_analyzer_worker_stop(instance->worker);
}
subghz_frequency_analyzer_worker_free(instance->worker);
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
model->rssi = 0;
return true;
});
}
SubghzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
SubghzFrequencyAnalyzer* instance = furi_alloc(sizeof(SubghzFrequencyAnalyzer));
// View allocation and configuration
instance->view = view_alloc();
view_allocate_model(
instance->view, ViewModelTypeLocking, sizeof(SubghzFrequencyAnalyzerModel));
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_frequency_analyzer_draw);
view_set_input_callback(instance->view, subghz_frequency_analyzer_input);
view_set_enter_callback(instance->view, subghz_frequency_analyzer_enter);
view_set_exit_callback(instance->view, subghz_frequency_analyzer_exit);
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
model->rssi = 0;
return true;
});
return instance;
}
void subghz_frequency_analyzer_free(SubghzFrequencyAnalyzer* instance) {
furi_assert(instance);
view_free(instance->view);
free(instance);
}
View* subghz_frequency_analyzer_get_view(SubghzFrequencyAnalyzer* instance) {
furi_assert(instance);
return instance->view;
}

View file

@ -0,0 +1,22 @@
#pragma once
#include <gui/view.h>
typedef enum {
SubghzFrequencyAnalyzerEventOnlyRx,
} SubghzFrequencyAnalyzerEvent;
typedef struct SubghzFrequencyAnalyzer SubghzFrequencyAnalyzer;
typedef void (*SubghzFrequencyAnalyzerCallback)(SubghzFrequencyAnalyzerEvent event, void* context);
void subghz_frequency_analyzer_set_callback(
SubghzFrequencyAnalyzer* subghz_frequency_analyzer,
SubghzFrequencyAnalyzerCallback callback,
void* context);
SubghzFrequencyAnalyzer* subghz_frequency_analyzer_alloc();
void subghz_frequency_analyzer_free(SubghzFrequencyAnalyzer* subghz_static);
View* subghz_frequency_analyzer_get_view(SubghzFrequencyAnalyzer* subghz_static);

File diff suppressed because one or more lines are too long

View file

@ -5,64 +5,64 @@ extern const Icon I_Certification1_103x23;
extern const Icon I_Certification2_119x30;
extern const Icon A_WatchingTV_128x64;
extern const Icon A_Wink_128x64;
extern const Icon I_125_10px;
extern const Icon I_ble_10px;
extern const Icon I_dir_10px;
extern const Icon I_ibutt_10px;
extern const Icon I_ir_10px;
extern const Icon I_Nfc_10px;
extern const Icon I_sub1_10px;
extern const Icon I_ir_10px;
extern const Icon I_ibutt_10px;
extern const Icon I_unknown_10px;
extern const Icon I_ble_10px;
extern const Icon I_125_10px;
extern const Icon I_ButtonRightSmall_3x5;
extern const Icon I_ButtonLeft_4x7;
extern const Icon I_ButtonCenter_7x7;
extern const Icon I_ButtonLeftSmall_3x5;
extern const Icon I_ButtonLeft_4x7;
extern const Icon I_ButtonRightSmall_3x5;
extern const Icon I_ButtonRight_4x7;
extern const Icon I_DFU_128x50;
extern const Icon I_Warning_30x23;
extern const Icon I_ButtonRight_4x7;
extern const Icon I_ButtonCenter_7x7;
extern const Icon I_DolphinOkay_41x43;
extern const Icon I_DolphinFirstStart4_67x53;
extern const Icon I_DolphinFirstStart2_59x51;
extern const Icon I_DolphinFirstStart5_54x49;
extern const Icon I_DolphinFirstStart0_70x53;
extern const Icon I_DolphinFirstStart6_58x54;
extern const Icon I_DolphinFirstStart1_59x53;
extern const Icon I_DolphinFirstStart8_56x51;
extern const Icon I_DolphinFirstStart7_61x51;
extern const Icon I_Flipper_young_80x60;
extern const Icon I_DolphinFirstStart2_59x51;
extern const Icon I_DolphinFirstStart3_57x48;
extern const Icon I_PassportBottom_128x17;
extern const Icon I_DolphinFirstStart4_67x53;
extern const Icon I_DolphinFirstStart5_54x49;
extern const Icon I_DolphinFirstStart6_58x54;
extern const Icon I_DolphinFirstStart7_61x51;
extern const Icon I_DolphinFirstStart8_56x51;
extern const Icon I_DolphinOkay_41x43;
extern const Icon I_Flipper_young_80x60;
extern const Icon I_DoorLeft_70x55;
extern const Icon I_DoorLeft_8x56;
extern const Icon I_DoorLocked_10x56;
extern const Icon I_DoorRight_8x56;
extern const Icon I_DoorLeft_70x55;
extern const Icon I_PassportLeft_6x47;
extern const Icon I_DoorRight_70x55;
extern const Icon I_DoorRight_8x56;
extern const Icon I_LockPopup_100x49;
extern const Icon I_Mute_25x27;
extern const Icon I_IrdaArrowUp_4x8;
extern const Icon I_Up_hvr_25x27;
extern const Icon I_Mute_hvr_25x27;
extern const Icon I_Vol_down_25x27;
extern const Icon I_PassportBottom_128x17;
extern const Icon I_PassportLeft_6x47;
extern const Icon I_Back_15x10;
extern const Icon I_Down_25x27;
extern const Icon I_Power_hvr_25x27;
extern const Icon I_IrdaLearnShort_128x31;
extern const Icon I_IrdaArrowDown_4x8;
extern const Icon I_Vol_down_hvr_25x27;
extern const Icon I_IrdaLearn_128x64;
extern const Icon I_Down_hvr_25x27;
extern const Icon I_Fill_marker_7x7;
extern const Icon I_Power_25x27;
extern const Icon I_Vol_up_25x27;
extern const Icon I_Up_25x27;
extern const Icon I_Back_15x10;
extern const Icon I_IrdaSend_128x64;
extern const Icon I_IrdaArrowDown_4x8;
extern const Icon I_IrdaArrowUp_4x8;
extern const Icon I_IrdaLearnShort_128x31;
extern const Icon I_IrdaLearn_128x64;
extern const Icon I_IrdaSendShort_128x34;
extern const Icon I_IrdaSend_128x64;
extern const Icon I_Mute_25x27;
extern const Icon I_Mute_hvr_25x27;
extern const Icon I_Power_25x27;
extern const Icon I_Power_hvr_25x27;
extern const Icon I_Up_25x27;
extern const Icon I_Up_hvr_25x27;
extern const Icon I_Vol_down_25x27;
extern const Icon I_Vol_down_hvr_25x27;
extern const Icon I_Vol_up_25x27;
extern const Icon I_Vol_up_hvr_25x27;
extern const Icon I_KeySave_24x11;
extern const Icon I_KeyBackspaceSelected_16x9;
extern const Icon I_KeySaveSelected_24x11;
extern const Icon I_KeyBackspace_16x9;
extern const Icon I_KeySaveSelected_24x11;
extern const Icon I_KeySave_24x11;
extern const Icon A_125khz_14;
extern const Icon A_Bluetooth_14;
extern const Icon A_Debug_14;
@ -81,42 +81,43 @@ extern const Icon A_U2F_14;
extern const Icon A_iButton_14;
extern const Icon I_Detailed_chip_17x13;
extern const Icon I_Medium_chip_22x21;
extern const Icon I_Health_16x16;
extern const Icon I_FaceCharging_29x14;
extern const Icon I_BatteryBody_52x28;
extern const Icon I_Voltage_16x16;
extern const Icon I_Temperature_16x16;
extern const Icon I_Battery_16x16;
extern const Icon I_FaceCharging_29x14;
extern const Icon I_FaceConfused_29x14;
extern const Icon I_FaceNopower_29x14;
extern const Icon I_FaceNormal_29x14;
extern const Icon I_Battery_16x16;
extern const Icon I_FaceConfused_29x14;
extern const Icon I_RFIDDolphinSuccess_108x57;
extern const Icon I_Health_16x16;
extern const Icon I_Temperature_16x16;
extern const Icon I_Voltage_16x16;
extern const Icon I_RFIDBigChip_37x36;
extern const Icon I_RFIDDolphinSend_97x61;
extern const Icon I_RFIDDolphinReceive_97x61;
extern const Icon I_SDQuestion_35x43;
extern const Icon I_RFIDDolphinSend_97x61;
extern const Icon I_RFIDDolphinSuccess_108x57;
extern const Icon I_SDError_43x35;
extern const Icon I_SDQuestion_35x43;
extern const Icon I_Cry_dolph_55x52;
extern const Icon I_BadUsb_9x8;
extern const Icon I_PlaceholderR_30x13;
extern const Icon I_Background_128x8;
extern const Icon I_Lock_8x8;
extern const Icon I_Battery_26x8;
extern const Icon I_PlaceholderL_11x13;
extern const Icon I_Battery_19x8;
extern const Icon I_SDcardMounted_11x8;
extern const Icon I_SDcardFail_11x8;
extern const Icon I_USBConnected_15x8;
extern const Icon I_Bluetooth_5x8;
extern const Icon I_Background_128x11;
extern const Icon I_Scanning_123x52;
extern const Icon I_Quest_7x8;
extern const Icon I_Unlock_7x8;
extern const Icon I_Background_128x8;
extern const Icon I_BadUsb_9x8;
extern const Icon I_Battery_19x8;
extern const Icon I_Battery_26x8;
extern const Icon I_Bluetooth_5x8;
extern const Icon I_Lock_8x8;
extern const Icon I_PlaceholderL_11x13;
extern const Icon I_PlaceholderR_30x13;
extern const Icon I_SDcardFail_11x8;
extern const Icon I_SDcardMounted_11x8;
extern const Icon I_USBConnected_15x8;
extern const Icon I_Lock_7x8;
extern const Icon I_DolphinMafia_115x62;
extern const Icon I_MHz_25x11;
extern const Icon I_Quest_7x8;
extern const Icon I_Scanning_123x52;
extern const Icon I_Unlock_7x8;
extern const Icon I_DolphinExcited_64x63;
extern const Icon I_DolphinMafia_115x62;
extern const Icon I_DolphinNice_96x59;
extern const Icon I_DolphinWait_61x59;
extern const Icon I_iButtonDolphinSuccess_109x60;
extern const Icon I_iButtonDolphinVerySuccess_108x52;
extern const Icon I_iButtonKey_49x44;
extern const Icon I_DolphinNice_96x59;
extern const Icon I_DolphinWait_61x59;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -132,7 +132,7 @@ static const uint8_t furi_hal_subghz_preset_ook_650khz_async_regs[][2] = {
/* End */
{0, 0},
};
static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
static const uint8_t furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs[][2] = {
/* GPIO GD0 */
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
@ -146,11 +146,10 @@ static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
// // Modem Configuration
{CC1101_MDMCFG0, 0x00},
{CC1101_MDMCFG1, 0x2},
{CC1101_MDMCFG2, 0x4}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
{CC1101_MDMCFG1, 0x02},
{CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
{CC1101_MDMCFG3, 0x83}, // Data rate is 4.79794 kBaud
{CC1101_MDMCFG4, 0x67}, //Rx BW filter is 270.833333 kHz
//{ CC1101_DEVIATN, 0x14 }, //Deviation 4.760742 kHz
{CC1101_DEVIATN, 0x04}, //Deviation 2.380371 kHz
/* Main Radio Control State Machine */
@ -188,6 +187,61 @@ static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
/* End */
{0, 0},
};
static const uint8_t furi_hal_subghz_preset_2fsk_dev4_76khz_async_regs[][2] = {
/* GPIO GD0 */
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
/* Frequency Synthesizer Control */
{CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
/* Packet engine */
{CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
{CC1101_PKTCTRL1, 0x04},
// // Modem Configuration
{CC1101_MDMCFG0, 0x00},
{CC1101_MDMCFG1, 0x02},
{CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
{CC1101_MDMCFG3, 0x83}, // Data rate is 4.79794 kBaud
{CC1101_MDMCFG4, 0x67}, //Rx BW filter is 270.833333 kHz
{CC1101_DEVIATN, 0x14}, //Deviation 4.760742 kHz
/* Main Radio Control State Machine */
{CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
/* Frequency Offset Compensation Configuration */
{CC1101_FOCCFG,
0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
/* Automatic Gain Control */
{CC1101_AGCCTRL0,
0x91}, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
{CC1101_AGCCTRL1,
0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
{CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
/* Wake on radio and timeouts control */
{CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
/* Frontend configuration */
{CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
{CC1101_FREND1, 0x56},
/* Frequency Synthesizer Calibration, valid for 433.92 */
{CC1101_FSCAL3, 0xE9},
{CC1101_FSCAL2, 0x2A},
{CC1101_FSCAL1, 0x00},
{CC1101_FSCAL0, 0x1F},
/* Magic f4ckery */
{CC1101_TEST2, 0x81}, // FIFOTHR ADC_RETENTION=1 matched value
{CC1101_TEST1, 0x35}, // FIFOTHR ADC_RETENTION=1 matched value
{CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
/* End */
{0, 0},
};
static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
0x00,
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
@ -282,8 +336,11 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
} else if(preset == FuriHalSubGhzPresetOok270Async) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_270khz_async_regs);
furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
} else if(preset == FuriHalSubGhzPreset2FSKAsync) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
} else if(preset == FuriHalSubGhzPreset2FSKDev238Async) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs);
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
} else if(preset == FuriHalSubGhzPreset2FSKDev476Async) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_dev4_76khz_async_regs);
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
} else {
furi_crash(NULL);

View file

@ -132,7 +132,7 @@ static const uint8_t furi_hal_subghz_preset_ook_650khz_async_regs[][2] = {
/* End */
{0, 0},
};
static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
static const uint8_t furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs[][2] = {
/* GPIO GD0 */
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
@ -146,11 +146,10 @@ static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
// // Modem Configuration
{CC1101_MDMCFG0, 0x00},
{CC1101_MDMCFG1, 0x2},
{CC1101_MDMCFG2, 0x4}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
{CC1101_MDMCFG1, 0x02},
{CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
{CC1101_MDMCFG3, 0x83}, // Data rate is 4.79794 kBaud
{CC1101_MDMCFG4, 0x67}, //Rx BW filter is 270.833333 kHz
//{ CC1101_DEVIATN, 0x14 }, //Deviation 4.760742 kHz
{CC1101_DEVIATN, 0x04}, //Deviation 2.380371 kHz
/* Main Radio Control State Machine */
@ -188,6 +187,61 @@ static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
/* End */
{0, 0},
};
static const uint8_t furi_hal_subghz_preset_2fsk_dev4_76khz_async_regs[][2] = {
/* GPIO GD0 */
{CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
/* Frequency Synthesizer Control */
{CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
/* Packet engine */
{CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
{CC1101_PKTCTRL1, 0x04},
// // Modem Configuration
{CC1101_MDMCFG0, 0x00},
{CC1101_MDMCFG1, 0x02},
{CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
{CC1101_MDMCFG3, 0x83}, // Data rate is 4.79794 kBaud
{CC1101_MDMCFG4, 0x67}, //Rx BW filter is 270.833333 kHz
{CC1101_DEVIATN, 0x14}, //Deviation 4.760742 kHz
/* Main Radio Control State Machine */
{CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
/* Frequency Offset Compensation Configuration */
{CC1101_FOCCFG,
0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
/* Automatic Gain Control */
{CC1101_AGCCTRL0,
0x91}, //10 - Medium hysteresis, medium asymmetric dead zone, medium gain ; 01 - 16 samples agc; 00 - Normal AGC, 01 - 8dB boundary
{CC1101_AGCCTRL1,
0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
{CC1101_AGCCTRL2, 0x07}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAIN_TARGET 42 dB
/* Wake on radio and timeouts control */
{CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
/* Frontend configuration */
{CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
{CC1101_FREND1, 0x56},
/* Frequency Synthesizer Calibration, valid for 433.92 */
{CC1101_FSCAL3, 0xE9},
{CC1101_FSCAL2, 0x2A},
{CC1101_FSCAL1, 0x00},
{CC1101_FSCAL0, 0x1F},
/* Magic f4ckery */
{CC1101_TEST2, 0x81}, // FIFOTHR ADC_RETENTION=1 matched value
{CC1101_TEST1, 0x35}, // FIFOTHR ADC_RETENTION=1 matched value
{CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
/* End */
{0, 0},
};
static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
0x00,
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
@ -282,8 +336,11 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
} else if(preset == FuriHalSubGhzPresetOok270Async) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_270khz_async_regs);
furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
} else if(preset == FuriHalSubGhzPreset2FSKAsync) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
} else if(preset == FuriHalSubGhzPreset2FSKDev238Async) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs);
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
} else if(preset == FuriHalSubGhzPreset2FSKDev476Async) {
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_dev4_76khz_async_regs);
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
} else {
furi_crash(NULL);

View file

@ -18,7 +18,8 @@ extern "C" {
typedef enum {
FuriHalSubGhzPresetOok270Async, /**< OOK, bandwidth 270kHz, asynchronous */
FuriHalSubGhzPresetOok650Async, /**< OOK, bandwidth 650kHz, asynchronous */
FuriHalSubGhzPreset2FSKAsync, /**< FM, asynchronous */
FuriHalSubGhzPreset2FSKDev238Async, /**< FM, deviation 2.380371 kHz, asynchronous */
FuriHalSubGhzPreset2FSKDev476Async, /**< FM, deviation 4.760742 kHz, asynchronous */
} FuriHalSubGhzPreset;
/** Switchable Radio Paths */

View file

@ -0,0 +1,231 @@
#include "subghz_protocol_came_atomo.h"
#include "subghz_protocol_common.h"
#include <lib/toolbox/manchester-decoder.h>
struct SubGhzProtocolCameAtomo {
SubGhzProtocolCommon common;
ManchesterState manchester_saved_state;
};
typedef enum {
CameAtomoDecoderStepReset = 0,
CameAtomoDecoderStepDecoderData,
} CameAtomoDecoderStep;
SubGhzProtocolCameAtomo* subghz_protocol_came_atomo_alloc() {
SubGhzProtocolCameAtomo* instance = furi_alloc(sizeof(SubGhzProtocolCameAtomo));
instance->common.name = "CAME Atomo";
instance->common.code_min_count_bit_for_found = 62;
instance->common.te_short = 600;
instance->common.te_long = 1200;
instance->common.te_delta = 250;
instance->common.type_protocol = SubGhzProtocolCommonTypeStatic;
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_came_atomo_to_str;
// instance->common.to_save_string =
// (SubGhzProtocolCommonGetStrSave)subghz_protocol_came_atomo_to_save_str;
//instance->common.to_load_protocol_from_file =
// (SubGhzProtocolCommonLoadFromFile)subghz_protocol_came_atomo_to_load_protocol_from_file;
instance->common.to_load_protocol =
(SubGhzProtocolCommonLoadFromRAW)subghz_decoder_came_atomo_to_load_protocol;
// instance->common.get_upload_protocol =
// (SubGhzProtocolCommonEncoderGetUpLoad)subghz_protocol_came_atomo_send_key;
return instance;
}
void subghz_protocol_came_atomo_free(SubGhzProtocolCameAtomo* instance) {
furi_assert(instance);
free(instance);
}
/** Analysis of received data
*
* @param instance SubGhzProtocolCameAtomo instance
*/
void subghz_protocol_came_atomo_remote_controller(SubGhzProtocolCameAtomo* instance) {
}
void subghz_protocol_came_atomo_reset(SubGhzProtocolCameAtomo* instance) {
instance->common.parser_step = CameAtomoDecoderStepReset;
manchester_advance(
instance->manchester_saved_state,
ManchesterEventReset,
&instance->manchester_saved_state,
NULL);
}
void subghz_protocol_came_atomo_parse(
SubGhzProtocolCameAtomo* instance,
bool level,
uint32_t duration) {
ManchesterEvent event = ManchesterEventReset;
switch(instance->common.parser_step) {
case CameAtomoDecoderStepReset:
if((!level) && (DURATION_DIFF(duration, instance->common.te_long * 65) <
instance->common.te_delta * 20)) {
//Found header CAME
instance->common.parser_step = CameAtomoDecoderStepDecoderData;
instance->common.code_found = 0;
instance->common.code_count_bit = 1;
manchester_advance(
instance->manchester_saved_state,
ManchesterEventReset,
&instance->manchester_saved_state,
NULL);
manchester_advance(
instance->manchester_saved_state,
ManchesterEventShortLow,
&instance->manchester_saved_state,
NULL);
} else {
instance->common.parser_step = CameAtomoDecoderStepReset;
}
break;
case CameAtomoDecoderStepDecoderData:
if(!level) {
if(DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta) {
event = ManchesterEventShortLow;
} else if(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta) {
event = ManchesterEventLongLow;
} else if(duration >= (instance->common.te_long * 2 + instance->common.te_delta)) {
if(instance->common.code_count_bit >=
instance->common.code_min_count_bit_for_found) {
instance->common.code_last_found = instance->common.code_found;
instance->common.code_last_count_bit = instance->common.code_count_bit;
// uint32_t code_found_hi = instance->common.code_last_found >> 32;
// uint32_t code_found_lo = instance->common.code_last_found & 0x00000000ffffffff;
// uint64_t code_found_reverse = subghz_protocol_common_reverse_key(
// instance->common.code_last_found, instance->common.code_last_count_bit);
// uint32_t code_found_reverse_hi = code_found_reverse >> 32;
// uint32_t code_found_reverse_lo = code_found_reverse & 0x00000000ffffffff;
// FURI_LOG_I(
// "ATOMO",
// "%08lX%08lX %08lX%08lX %d",
// code_found_hi,
// code_found_lo,
// code_found_reverse_hi,
// code_found_reverse_lo,
// instance->common.code_last_count_bit);
if(instance->common.callback)
instance->common.callback(
(SubGhzProtocolCommon*)instance, instance->common.context);
}
instance->common.code_found = 0;
instance->common.code_count_bit = 1;
manchester_advance(
instance->manchester_saved_state,
ManchesterEventReset,
&instance->manchester_saved_state,
NULL);
manchester_advance(
instance->manchester_saved_state,
ManchesterEventShortLow,
&instance->manchester_saved_state,
NULL);
} else {
instance->common.parser_step = CameAtomoDecoderStepReset;
}
} else {
if(DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta) {
event = ManchesterEventShortHigh;
} else if(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta) {
event = ManchesterEventLongHigh;
} else {
instance->common.parser_step = CameAtomoDecoderStepReset;
}
}
if(event != ManchesterEventReset) {
bool data;
bool data_ok = manchester_advance(
instance->manchester_saved_state, event, &instance->manchester_saved_state, &data);
if(data_ok) {
instance->common.code_found = (instance->common.code_found << 1) | !data;
instance->common.code_count_bit++;
}
}
break;
}
}
void subghz_protocol_came_atomo_to_str(SubGhzProtocolCameAtomo* instance, string_t output) {
uint32_t code_found_hi = instance->common.code_last_found >> 32;
uint32_t code_found_lo = instance->common.code_last_found & 0x00000000ffffffff;
string_cat_printf(
output,
"%s %dbit\r\n"
"Key:0x%lX%08lX\r\n",
instance->common.name,
instance->common.code_last_count_bit,
code_found_hi,
code_found_lo);
}
// void subghz_protocol_came_atomo_to_save_str(SubGhzProtocolCameAtomo* instance, string_t output) {
// string_printf(
// output,
// "Protocol: %s\n"
// "Bit: %d\n"
// "Key: %08lX%08lX\r\n",
// instance->common.name,
// instance->common.code_last_count_bit,
// (uint32_t)(instance->common.code_last_found >> 32),
// (uint32_t)(instance->common.code_last_found & 0xFFFFFFFF));
// }
// bool subghz_protocol_came_atomo_to_load_protocol_from_file(
// FileWorker* file_worker,
// SubGhzProtocolCameAtomo* instance) {
// bool loaded = false;
// string_t temp_str;
// string_init(temp_str);
// int res = 0;
// int data = 0;
// do {
// // Read and parse bit data from 2nd line
// if(!file_worker_read_until(file_worker, temp_str, '\n')) {
// break;
// }
// res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data);
// if(res != 1) {
// break;
// }
// instance->common.code_last_count_bit = (uint8_t)data;
// // Read and parse key data from 3nd line
// if(!file_worker_read_until(file_worker, temp_str, '\n')) {
// break;
// }
// // strlen("Key: ") = 5
// string_right(temp_str, 5);
// uint8_t buf_key[8] = {0};
// if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) {
// break;
// }
// for(uint8_t i = 0; i < 8; i++) {
// instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i];
// }
// loaded = true;
// } while(0);
// string_clear(temp_str);
// subghz_protocol_came_atomo_remote_controller(instance);
// return loaded;
// }
void subghz_decoder_came_atomo_to_load_protocol(SubGhzProtocolCameAtomo* instance, void* context) {
furi_assert(context);
furi_assert(instance);
SubGhzProtocolCommonLoad* data = context;
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_came_atomo_remote_controller(instance);
}

View file

@ -0,0 +1,73 @@
#pragma once
#include "subghz_protocol_common.h"
typedef struct SubGhzProtocolCameAtomo SubGhzProtocolCameAtomo;
/** Allocate SubGhzProtocolCameAtomo
*
* @return SubGhzProtocolCameAtomo*
*/
SubGhzProtocolCameAtomo* subghz_protocol_came_atomo_alloc();
/** Free SubGhzProtocolCameAtomo
*
* @param instance
*/
void subghz_protocol_came_atomo_free(SubGhzProtocolCameAtomo* instance);
// /** Get upload protocol
// *
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param encoder - SubGhzProtocolCommonEncoder encoder
// * @return bool
// */
// bool subghz_protocol_came_atomo_send_key(
// SubGhzProtocolCameAtomo* instance,
// SubGhzProtocolCommonEncoder* encoder);
/** Reset internal state
* @param instance - SubGhzProtocolCameAtomo instance
*/
void subghz_protocol_came_atomo_reset(SubGhzProtocolCameAtomo* instance);
/** Parse accepted duration
*
* @param instance - SubGhzProtocolCameAtomo instance
* @param data - LevelDuration level_duration
*/
void subghz_protocol_came_atomo_parse(
SubGhzProtocolCameAtomo* instance,
bool level,
uint32_t duration);
/** Outputting information from the parser
*
* @param instance - SubGhzProtocolCameAtomo* instance
* @param output - output string
*/
void subghz_protocol_came_atomo_to_str(SubGhzProtocolCameAtomo* instance, string_t output);
// /** Get a string to save the protocol
// *
// * @param instance - SubGhzProtocolCameAtomo instance
// * @param output - the resulting string
// */
// void subghz_protocol_came_atomo_to_save_str(SubGhzProtocolCameAtomo* instance, string_t output);
// /** Loading protocol from file
// *
// * @param file_worker - FileWorker file_worker
// * @param instance - SubGhzProtocolCameAtomo instance
// * @return bool
// */
// bool subghz_protocol_came_atomo_to_load_protocol_from_file(
// FileWorker* file_worker,
// SubGhzProtocolCameAtomo* instance);
/** Loading protocol from bin data
*
* @param instance - SubGhzProtocolCameAtomo instance
* @param context - SubGhzProtocolCommonLoad context
*/
void subghz_decoder_came_atomo_to_load_protocol(SubGhzProtocolCameAtomo* instance, void* context);

View file

@ -0,0 +1,394 @@
#include "subghz_protocol_came_twee.h"
#include "subghz_protocol_common.h"
#include <lib/toolbox/manchester-decoder.h>
#include <lib/toolbox/manchester-encoder.h>
/*
* Help
* https://phreakerclub.com/forum/showthread.php?t=635&highlight=came+twin
*
*/
#define DIP_PATTERN "%c%c%c%c%c%c%c%c%c%c"
#define CNT_TO_DIP(dip) \
(dip & 0x0200 ? '1' : '0'), (dip & 0x0100 ? '1' : '0'), (dip & 0x0080 ? '1' : '0'), \
(dip & 0x0040 ? '1' : '0'), (dip & 0x0020 ? '1' : '0'), (dip & 0x0010 ? '1' : '0'), \
(dip & 0x0008 ? '1' : '0'), (dip & 0x0004 ? '1' : '0'), (dip & 0x0002 ? '1' : '0'), \
(dip & 0x0001 ? '1' : '0')
struct SubGhzProtocolCameTwee {
SubGhzProtocolCommon common;
ManchesterState manchester_saved_state;
};
typedef enum {
CameTweeDecoderStepReset = 0,
CameTweeDecoderStepDecoderData,
} CameTweeDecoderStep;
SubGhzProtocolCameTwee* subghz_protocol_came_twee_alloc() {
SubGhzProtocolCameTwee* instance = furi_alloc(sizeof(SubGhzProtocolCameTwee));
instance->common.name = "CAME TWEE";
instance->common.code_min_count_bit_for_found = 54;
instance->common.te_short = 500;
instance->common.te_long = 1000;
instance->common.te_delta = 250;
instance->common.type_protocol = SubGhzProtocolCommonTypeStatic;
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_came_twee_to_str;
instance->common.to_save_string =
(SubGhzProtocolCommonGetStrSave)subghz_protocol_came_twee_to_save_str;
instance->common.to_load_protocol_from_file =
(SubGhzProtocolCommonLoadFromFile)subghz_protocol_came_twee_to_load_protocol_from_file;
instance->common.to_load_protocol =
(SubGhzProtocolCommonLoadFromRAW)subghz_decoder_came_twee_to_load_protocol;
instance->common.get_upload_protocol =
(SubGhzProtocolCommonEncoderGetUpLoad)subghz_protocol_came_twee_send_key;
return instance;
}
void subghz_protocol_came_twee_free(SubGhzProtocolCameTwee* instance) {
furi_assert(instance);
free(instance);
}
LevelDuration subghz_protocol_came_twee_add_duration_to_upload(
SubGhzProtocolCameTwee* instance,
ManchesterEncoderResult result) {
LevelDuration data;
switch(result) {
case ManchesterEncoderResultShortLow:
data.duration = instance->common.te_short;
data.level = false;
break;
case ManchesterEncoderResultLongLow:
data.duration = instance->common.te_long;
data.level = false;
break;
case ManchesterEncoderResultLongHigh:
data.duration = instance->common.te_long;
data.level = true;
break;
case ManchesterEncoderResultShortHigh:
data.duration = instance->common.te_short;
data.level = true;
break;
default:
printf("DO CRASH HERE\r\n");
// furi_crash
break;
}
return level_duration_make(data.level, data.duration);
}
bool subghz_protocol_came_twee_send_key(
SubGhzProtocolCameTwee* instance,
SubGhzProtocolCommonEncoder* encoder) {
furi_assert(instance);
furi_assert(encoder);
const uint32_t magic_numbers_xor[15] = {
0x0E0E0E00,
0x1D1D1D11,
0x2C2C2C22,
0x3B3B3B33,
0x4A4A4A44,
0x59595955,
0x68686866,
0x77777777,
0x86868688,
0x95959599,
0xA4A4A4AA,
0xB3B3B3BB,
0xC2C2C2CC,
0xD1D1D1DD,
0xE0E0E0EE,
};
size_t index = 0;
ManchesterEncoderState enc_state;
manchester_encoder_reset(&enc_state);
ManchesterEncoderResult result;
// encoder->size_upload = (instance->common.code_last_count_bit * 2) + 2;
// if(encoder->size_upload > SUBGHZ_ENCODER_UPLOAD_MAX_SIZE) return false;
uint64_t temp_parcel = 0x003FFF7200000000; //parcel mask
for(int i = 14; i >= 0; i--) {
temp_parcel = (temp_parcel & 0xFFFFFFFF00000000) |
(instance->common.serial ^ magic_numbers_xor[i]);
for(uint8_t i = instance->common.code_last_count_bit; i > 0; i--) {
if(!manchester_encoder_advance(&enc_state, !bit_read(temp_parcel, i - 1), &result)) {
encoder->upload[index++] =
subghz_protocol_came_twee_add_duration_to_upload(instance, result);
manchester_encoder_advance(&enc_state, !bit_read(temp_parcel, i - 1), &result);
}
encoder->upload[index++] =
subghz_protocol_came_twee_add_duration_to_upload(instance, result);
}
encoder->upload[index] = subghz_protocol_came_twee_add_duration_to_upload(
instance, manchester_encoder_finish(&enc_state));
if(level_duration_get_level(encoder->upload[index])) {
index++;
}
encoder->upload[index++] =
level_duration_make(false, (uint32_t)instance->common.te_long * 51);
}
encoder->size_upload = index;
return true;
}
/** Analysis of received data
*
* @param instance SubGhzProtocolCameTwee instance
*/
void subghz_protocol_came_twee_remote_controller(SubGhzProtocolCameTwee* instance) {
/* Came Twee 54 bit, rolling code 15 parcels with
* a decreasing counter from 0xE to 0x0
* with originally coded dip switches on the console 10 bit code
*
* 0x003FFF72E04A6FEE
* 0x003FFF72D17B5EDD
* 0x003FFF72C2684DCC
* 0x003FFF72B3193CBB
* 0x003FFF72A40E2BAA
* 0x003FFF72953F1A99
* 0x003FFF72862C0988
* 0x003FFF7277DDF877
* 0x003FFF7268C2E766
* 0x003FFF7259F3D655
* 0x003FFF724AE0C544
* 0x003FFF723B91B433
* 0x003FFF722C86A322
* 0x003FFF721DB79211
* 0x003FFF720EA48100
*
* decryption
* the last 32 bits, do XOR by the desired number, divide the result by 4,
* convert the first 16 bits of the resulting 32-bit number to bin and do
* bit-by-bit mirroring, adding up to 10 bits
*
* Example
* Step 1. 0x003FFF721DB79211 => 0x1DB79211
* Step 4. 0x1DB79211 xor 0x1D1D1D11 => 0x00AA8F00
* Step 4. 0x00AA8F00 / 4 => 0x002AA3C0
* Step 5. 0x002AA3C0 => 0x002A
* Step 6. 0x002A bin => b101010
* Step 7. b101010 => b0101010000
* Step 8. b0101010000 => (Dip) Off ON Off ON Off ON Off Off Off Off
*/
const uint32_t magic_numbers_xor[15] = {
0x0E0E0E00,
0x1D1D1D11,
0x2C2C2C22,
0x3B3B3B33,
0x4A4A4A44,
0x59595955,
0x68686866,
0x77777777,
0x86868688,
0x95959599,
0xA4A4A4AA,
0xB3B3B3BB,
0xC2C2C2CC,
0xD1D1D1DD,
0xE0E0E0EE,
};
uint8_t cnt_parcel = (uint8_t)(instance->common.code_last_found & 0xF);
uint32_t data = (uint32_t)(instance->common.code_last_found & 0x0FFFFFFFF);
data = (data ^ magic_numbers_xor[cnt_parcel]);
instance->common.serial = data;
data /= 4;
instance->common.btn = (data >> 4) & 0x0F;
data >>= 16;
data = (uint16_t)subghz_protocol_common_reverse_key(data, 16);
instance->common.cnt = data >> 6;
}
void subghz_protocol_came_twee_reset(SubGhzProtocolCameTwee* instance) {
instance->common.parser_step = CameTweeDecoderStepReset;
manchester_advance(
instance->manchester_saved_state,
ManchesterEventReset,
&instance->manchester_saved_state,
NULL);
}
void subghz_protocol_came_twee_parse(
SubGhzProtocolCameTwee* instance,
bool level,
uint32_t duration) {
ManchesterEvent event = ManchesterEventReset;
switch(instance->common.parser_step) {
case CameTweeDecoderStepReset:
if((!level) && (DURATION_DIFF(duration, instance->common.te_long * 51) <
instance->common.te_delta * 20)) {
//Found header CAME
instance->common.parser_step = CameTweeDecoderStepDecoderData;
instance->common.code_found = 0;
instance->common.code_count_bit = 0;
manchester_advance(
instance->manchester_saved_state,
ManchesterEventLongLow,
&instance->manchester_saved_state,
NULL);
manchester_advance(
instance->manchester_saved_state,
ManchesterEventLongHigh,
&instance->manchester_saved_state,
NULL);
manchester_advance(
instance->manchester_saved_state,
ManchesterEventShortLow,
&instance->manchester_saved_state,
NULL);
} else {
instance->common.parser_step = CameTweeDecoderStepReset;
}
break;
case CameTweeDecoderStepDecoderData:
if(!level) {
if(DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta) {
event = ManchesterEventShortLow;
} else if(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta) {
event = ManchesterEventLongLow;
} else if(duration >= (instance->common.te_long * 2 + instance->common.te_delta)) {
if(instance->common.code_count_bit >=
instance->common.code_min_count_bit_for_found) {
instance->common.code_last_found = instance->common.code_found;
instance->common.code_last_count_bit = instance->common.code_count_bit;
if(instance->common.callback)
instance->common.callback(
(SubGhzProtocolCommon*)instance, instance->common.context);
}
instance->common.code_found = 0;
instance->common.code_count_bit = 0;
manchester_advance(
instance->manchester_saved_state,
ManchesterEventLongLow,
&instance->manchester_saved_state,
NULL);
manchester_advance(
instance->manchester_saved_state,
ManchesterEventLongHigh,
&instance->manchester_saved_state,
NULL);
manchester_advance(
instance->manchester_saved_state,
ManchesterEventShortLow,
&instance->manchester_saved_state,
NULL);
} else {
instance->common.parser_step = CameTweeDecoderStepReset;
}
} else {
if(DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta) {
event = ManchesterEventShortHigh;
} else if(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta) {
event = ManchesterEventLongHigh;
} else {
instance->common.parser_step = CameTweeDecoderStepReset;
}
}
if(event != ManchesterEventReset) {
bool data;
bool data_ok = manchester_advance(
instance->manchester_saved_state, event, &instance->manchester_saved_state, &data);
if(data_ok) {
instance->common.code_found = (instance->common.code_found << 1) | !data;
instance->common.code_count_bit++;
}
}
break;
}
}
void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t output) {
uint32_t code_found_hi = instance->common.code_last_found >> 32;
uint32_t code_found_lo = instance->common.code_last_found & 0x00000000ffffffff;
string_cat_printf(
output,
"%s %dbit\r\n"
"Key:0x%lX%08lX\r\n"
"Btn:%lX\r\n"
"DIP:" DIP_PATTERN,
instance->common.name,
instance->common.code_last_count_bit,
code_found_hi,
code_found_lo,
instance->common.btn,
CNT_TO_DIP(instance->common.cnt));
}
void subghz_protocol_came_twee_to_save_str(SubGhzProtocolCameTwee* instance, string_t output) {
string_printf(
output,
"Protocol: %s\n"
"Bit: %d\n"
"Key: %08lX%08lX\r\n",
instance->common.name,
instance->common.code_last_count_bit,
(uint32_t)(instance->common.code_last_found >> 32),
(uint32_t)(instance->common.code_last_found & 0xFFFFFFFF));
}
bool subghz_protocol_came_twee_to_load_protocol_from_file(
FileWorker* file_worker,
SubGhzProtocolCameTwee* instance) {
bool loaded = false;
string_t temp_str;
string_init(temp_str);
int res = 0;
int data = 0;
do {
// Read and parse bit data from 2nd line
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
break;
}
res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data);
if(res != 1) {
break;
}
instance->common.code_last_count_bit = (uint8_t)data;
// Read and parse key data from 3nd line
if(!file_worker_read_until(file_worker, temp_str, '\n')) {
break;
}
// strlen("Key: ") = 5
string_right(temp_str, 5);
uint8_t buf_key[8] = {0};
if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) {
break;
}
for(uint8_t i = 0; i < 8; i++) {
instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i];
}
loaded = true;
} while(0);
string_clear(temp_str);
subghz_protocol_came_twee_remote_controller(instance);
return loaded;
}
void subghz_decoder_came_twee_to_load_protocol(SubGhzProtocolCameTwee* instance, void* context) {
furi_assert(context);
furi_assert(instance);
SubGhzProtocolCommonLoad* data = context;
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_came_twee_remote_controller(instance);
}

View file

@ -0,0 +1,73 @@
#pragma once
#include "subghz_protocol_common.h"
typedef struct SubGhzProtocolCameTwee SubGhzProtocolCameTwee;
/** Allocate SubGhzProtocolCameTwee
*
* @return SubGhzProtocolCameTwee*
*/
SubGhzProtocolCameTwee* subghz_protocol_came_twee_alloc();
/** Free SubGhzProtocolCameTwee
*
* @param instance
*/
void subghz_protocol_came_twee_free(SubGhzProtocolCameTwee* instance);
/** Get upload protocol
*
* @param instance - SubGhzProtocolCameTwee instance
* @param encoder - SubGhzProtocolCommonEncoder encoder
* @return bool
*/
bool subghz_protocol_came_twee_send_key(
SubGhzProtocolCameTwee* instance,
SubGhzProtocolCommonEncoder* encoder);
/** Reset internal state
* @param instance - SubGhzProtocolCameTwee instance
*/
void subghz_protocol_came_twee_reset(SubGhzProtocolCameTwee* instance);
/** Parse accepted duration
*
* @param instance - SubGhzProtocolCameTwee instance
* @param data - LevelDuration level_duration
*/
void subghz_protocol_came_twee_parse(
SubGhzProtocolCameTwee* instance,
bool level,
uint32_t duration);
/** Outputting information from the parser
*
* @param instance - SubGhzProtocolCameTwee* instance
* @param output - output string
*/
void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t output);
/** Get a string to save the protocol
*
* @param instance - SubGhzProtocolCameTwee instance
* @param output - the resulting string
*/
void subghz_protocol_came_twee_to_save_str(SubGhzProtocolCameTwee* instance, string_t output);
/** Loading protocol from file
*
* @param file_worker - FileWorker file_worker
* @param instance - SubGhzProtocolCameTwee instance
* @return bool
*/
bool subghz_protocol_came_twee_to_load_protocol_from_file(
FileWorker* file_worker,
SubGhzProtocolCameTwee* instance);
/** Loading protocol from bin data
*
* @param instance - SubGhzProtocolCameTwee instance
* @param context - SubGhzProtocolCommonLoad context
*/
void subghz_decoder_came_twee_to_load_protocol(SubGhzProtocolCameTwee* instance, void* context);

View file

@ -17,13 +17,13 @@
#define SUBGHZ_APP_FOLDER "/any/subghz"
#define SUBGHZ_APP_PATH_FOLDER "/any/subghz/saved"
#define SUBGHZ_APP_EXTENSION ".sub"
#define SUBGHZ_ENCODER_UPLOAD_MAX_SIZE 512
#define SUBGHZ_ENCODER_UPLOAD_MAX_SIZE 2048
typedef enum {
SubGhzProtocolCommonTypeUnknown,
SubGhzProtocolCommonTypeStatic,
SubGhzProtocolCommonTypeDynamic,
}SubGhzProtocolCommonType;
} SubGhzProtocolCommonType;
typedef struct SubGhzProtocolCommon SubGhzProtocolCommon;
typedef struct SubGhzProtocolCommonEncoder SubGhzProtocolCommonEncoder;

View file

@ -0,0 +1,190 @@
#include "subghz_protocol_kia.h"
struct SubGhzProtocolKIA {
SubGhzProtocolCommon common;
};
typedef enum {
KIADecoderStepReset = 0,
KIADecoderStepCheckPreambula,
KIADecoderStepSaveDuration,
KIADecoderStepCheckDuration,
} KIADecoderStep;
SubGhzProtocolKIA* subghz_protocol_kia_alloc(void) {
SubGhzProtocolKIA* instance = furi_alloc(sizeof(SubGhzProtocolKIA));
instance->common.name = "KIA";
instance->common.code_min_count_bit_for_found = 60;
instance->common.te_short = 250;
instance->common.te_long = 500;
instance->common.te_delta = 100;
instance->common.type_protocol = SubGhzProtocolCommonTypeDynamic;
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_kia_to_str;
instance->common.to_load_protocol =
(SubGhzProtocolCommonLoadFromRAW)subghz_decoder_kia_to_load_protocol;
return instance;
}
void subghz_protocol_kia_free(SubGhzProtocolKIA* instance) {
furi_assert(instance);
free(instance);
}
void subghz_protocol_kia_reset(SubGhzProtocolKIA* instance) {
instance->common.parser_step = KIADecoderStepReset;
}
uint8_t subghz_protocol_kia_crc8(uint8_t* data, size_t len) {
uint8_t crc = 0x08;
size_t i, j;
for(i = 0; i < len; i++) {
crc ^= data[i];
for(j = 0; j < 8; j++) {
if((crc & 0x80) != 0)
crc = (uint8_t)((crc << 1) ^ 0x7F);
else
crc <<= 1;
}
}
return crc;
}
/** Analysis of received data
*
* @param instance SubGhzProtocolKIA instance
*/
void subghz_protocol_kia_check_remote_controller(SubGhzProtocolKIA* instance) {
/*
* 0x0F 0112 43B04EC 1 7D
* 0x0F 0113 43B04EC 1 DF
* 0x0F 0114 43B04EC 1 30
* 0x0F 0115 43B04EC 2 13
* 0x0F 0116 43B04EC 3 F5
* CNT Serial K CRC8 Kia (CRC8, poly 0x7f, start_crc 0x08)
*/
instance->common.serial = (uint32_t)((instance->common.code_last_found >> 12) & 0x0FFFFFFF);
instance->common.btn = (instance->common.code_last_found >> 8) & 0x0F;
instance->common.cnt = (instance->common.code_last_found >> 40) & 0xFFFF;
}
void subghz_protocol_kia_parse(SubGhzProtocolKIA* instance, bool level, uint32_t duration) {
switch(instance->common.parser_step) {
case KIADecoderStepReset:
if((!level) &&
(DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta)) {
instance->common.parser_step = KIADecoderStepCheckPreambula;
instance->common.te_last = duration;
instance->common.header_count = 0;
} else {
instance->common.parser_step = KIADecoderStepReset;
}
break;
case KIADecoderStepCheckPreambula:
if(!level) {
if((DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta) ||
(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta)) {
instance->common.te_last = duration;
} else {
instance->common.parser_step = KIADecoderStepReset;
}
} else if(
(DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta) &&
(DURATION_DIFF(instance->common.te_last, instance->common.te_short) <
instance->common.te_delta)) {
// Found header
instance->common.header_count++;
break;
} else if(
(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta) &&
(DURATION_DIFF(instance->common.te_last, instance->common.te_long) <
instance->common.te_delta)) {
// Found start bit
if(instance->common.header_count > 15) {
instance->common.parser_step = KIADecoderStepSaveDuration;
instance->common.code_found = 0;
instance->common.code_count_bit = 1;
subghz_protocol_common_add_bit(&instance->common, 1);
} else {
instance->common.parser_step = KIADecoderStepReset;
}
} else {
instance->common.parser_step = KIADecoderStepReset;
}
break;
case KIADecoderStepSaveDuration:
if(!level) {
if(duration >= (instance->common.te_long + instance->common.te_delta * 2)) {
//Found stop bit
instance->common.parser_step = KIADecoderStepReset;
if(instance->common.code_count_bit >=
instance->common.code_min_count_bit_for_found) {
instance->common.code_last_found = instance->common.code_found;
instance->common.code_last_count_bit = instance->common.code_count_bit;
if(instance->common.callback)
instance->common.callback(
(SubGhzProtocolCommon*)instance, instance->common.context);
}
instance->common.code_found = 0;
instance->common.code_count_bit = 0;
break;
} else {
instance->common.te_last = duration;
instance->common.parser_step = KIADecoderStepCheckDuration;
}
} else {
instance->common.parser_step = KIADecoderStepReset;
}
break;
case KIADecoderStepCheckDuration:
if(level) {
if((DURATION_DIFF(instance->common.te_last, instance->common.te_short) <
instance->common.te_delta) &&
(DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta)) {
subghz_protocol_common_add_bit(&instance->common, 0);
instance->common.parser_step = KIADecoderStepSaveDuration;
} else if(
(DURATION_DIFF(instance->common.te_last, instance->common.te_long) <
instance->common.te_delta) &&
(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta)) {
subghz_protocol_common_add_bit(&instance->common, 1);
instance->common.parser_step = KIADecoderStepSaveDuration;
} else {
instance->common.parser_step = KIADecoderStepReset;
}
} else {
instance->common.parser_step = KIADecoderStepReset;
}
break;
}
}
void subghz_protocol_kia_to_str(SubGhzProtocolKIA* instance, string_t output) {
uint32_t code_found_hi = instance->common.code_last_found >> 32;
uint32_t code_found_lo = instance->common.code_last_found & 0x00000000ffffffff;
string_cat_printf(
output,
"%s %dbit\r\n"
"Key:%08lX%08lX\r\n"
"Sn:%07lX Btn:%lX Cnt:%04X\r\n",
instance->common.name,
instance->common.code_last_count_bit,
code_found_hi,
code_found_lo,
instance->common.serial,
instance->common.btn,
instance->common.cnt);
}
void subghz_decoder_kia_to_load_protocol(SubGhzProtocolKIA* instance, void* context) {
furi_assert(context);
furi_assert(instance);
SubGhzProtocolCommonLoad* data = context;
instance->common.code_last_found = data->code_found;
instance->common.code_last_count_bit = data->code_count_bit;
subghz_protocol_kia_check_remote_controller(instance);
}

View file

@ -0,0 +1,56 @@
#pragma once
#include "subghz_protocol_common.h"
typedef struct SubGhzProtocolKIA SubGhzProtocolKIA;
/** Allocate SubGhzProtocolKIA
*
* @return SubGhzProtocolKIA*
*/
SubGhzProtocolKIA* subghz_protocol_kia_alloc();
/** Free SubGhzProtocolKIA
*
* @param instance
*/
void subghz_protocol_kia_free(SubGhzProtocolKIA* instance);
/** Reset internal state
* @param instance - SubGhzProtocolKIA instance
*/
void subghz_protocol_kia_reset(SubGhzProtocolKIA* instance);
/** Analysis of received data
*
* @param instance SubGhzProtocolKIA instance
*/
void subghz_protocol_kia_check_remote_controller(SubGhzProtocolKIA* instance);
/** Parse accepted duration
*
* @param instance - SubGhzProtocolKIA instance
* @param data - LevelDuration level_duration
*/
void subghz_protocol_kia_parse(SubGhzProtocolKIA* instance, bool level, uint32_t duration);
/** Outputting information from the parser
*
* @param instance - SubGhzProtocolKIA* instance
* @param output - output string
*/
void subghz_protocol_kia_to_str(SubGhzProtocolKIA* instance, string_t output);
/** Get a string to save the protocol
*
* @param instance - SubGhzProtocolKIA instance
* @param output - the resulting string
*/
void subghz_protocol_kia_to_save_str(SubGhzProtocolKIA* instance, string_t output);
/** Loading protocol from bin data
*
* @param instance - SubGhzProtocolKIA instance
* @param context - SubGhzProtocolCommonLoad context
*/
void subghz_decoder_kia_to_load_protocol(SubGhzProtocolKIA* instance, void* context);

View file

@ -161,11 +161,20 @@ void subghz_protocol_nero_radio_parse(
if(!level) {
if(duration >= (instance->common.te_short * 10 + instance->common.te_delta * 2)) {
//Found stop bit
if(DURATION_DIFF(instance->common.te_last, instance->common.te_short) <
instance->common.te_delta) {
subghz_protocol_common_add_bit(&instance->common, 0);
} else if(
DURATION_DIFF(instance->common.te_last, instance->common.te_long) <
instance->common.te_delta) {
subghz_protocol_common_add_bit(&instance->common, 1);
}
instance->common.parser_step = NeroRadioDecoderStepReset;
if(instance->common.code_count_bit >=
instance->common.code_min_count_bit_for_found) {
instance->common.code_last_found = instance->common.code_found;
instance->common.code_last_count_bit = instance->common.code_count_bit;
if(instance->common.callback)
instance->common.callback(
(SubGhzProtocolCommon*)instance, instance->common.context);

View file

@ -1,6 +1,8 @@
#include "subghz_parser.h"
#include "protocols/subghz_protocol_came.h"
#include "protocols/subghz_protocol_came_twee.h"
#include "protocols/subghz_protocol_came_atomo.h"
#include "protocols/subghz_protocol_cfm.h"
#include "protocols/subghz_protocol_keeloq.h"
#include "protocols/subghz_protocol_nice_flo.h"
@ -13,6 +15,7 @@
#include "protocols/subghz_protocol_star_line.h"
#include "protocols/subghz_protocol_nero_radio.h"
#include "protocols/subghz_protocol_scher_khan.h"
#include "protocols/subghz_protocol_kia.h"
#include "subghz_keystore.h"
@ -21,6 +24,8 @@
typedef enum {
SubGhzProtocolTypeCame,
SubGhzProtocolTypeCameTwee,
SubGhzProtocolTypeCameAtomo,
SubGhzProtocolTypeKeeloq,
SubGhzProtocolTypeNiceFlo,
SubGhzProtocolTypeNiceFlorS,
@ -32,6 +37,7 @@ typedef enum {
SubGhzProtocolTypeStarLine,
SubGhzProtocolTypeNeroRadio,
SubGhzProtocolTypeScherKhan,
SubGhzProtocolTypeKIA,
SubGhzProtocolTypeMax,
} SubGhzProtocolType;
@ -75,6 +81,10 @@ SubGhzParser* subghz_parser_alloc() {
instance->protocols[SubGhzProtocolTypeCame] =
(SubGhzProtocolCommon*)subghz_protocol_came_alloc();
instance->protocols[SubGhzProtocolTypeCameTwee] =
(SubGhzProtocolCommon*)subghz_protocol_came_twee_alloc();
instance->protocols[SubGhzProtocolTypeCameAtomo] =
(SubGhzProtocolCommon*)subghz_protocol_came_atomo_alloc();
instance->protocols[SubGhzProtocolTypeKeeloq] =
(SubGhzProtocolCommon*)subghz_protocol_keeloq_alloc(instance->keystore);
instance->protocols[SubGhzProtocolTypePrinceton] =
@ -97,6 +107,8 @@ SubGhzParser* subghz_parser_alloc() {
(SubGhzProtocolCommon*)subghz_protocol_nero_radio_alloc();
instance->protocols[SubGhzProtocolTypeScherKhan] =
(SubGhzProtocolCommon*)subghz_protocol_scher_khan_alloc();
instance->protocols[SubGhzProtocolTypeKIA] =
(SubGhzProtocolCommon*)subghz_protocol_kia_alloc();
return instance;
}
@ -105,6 +117,10 @@ void subghz_parser_free(SubGhzParser* instance) {
furi_assert(instance);
subghz_protocol_came_free((SubGhzProtocolCame*)instance->protocols[SubGhzProtocolTypeCame]);
subghz_protocol_came_twee_free(
(SubGhzProtocolCameTwee*)instance->protocols[SubGhzProtocolTypeCameTwee]);
subghz_protocol_came_atomo_free(
(SubGhzProtocolCameAtomo*)instance->protocols[SubGhzProtocolTypeCameAtomo]);
subghz_protocol_keeloq_free(
(SubGhzProtocolKeeloq*)instance->protocols[SubGhzProtocolTypeKeeloq]);
subghz_decoder_princeton_free(
@ -126,6 +142,7 @@ void subghz_parser_free(SubGhzParser* instance) {
(SubGhzProtocolNeroRadio*)instance->protocols[SubGhzProtocolTypeNeroRadio]);
subghz_protocol_scher_khan_free(
(SubGhzProtocolScherKhan*)instance->protocols[SubGhzProtocolTypeScherKhan]);
subghz_protocol_kia_free((SubGhzProtocolKIA*)instance->protocols[SubGhzProtocolTypeKIA]);
subghz_keystore_free(instance->keystore);
@ -186,6 +203,10 @@ void subghz_parser_load_keeloq_file(SubGhzParser* instance, const char* file_nam
void subghz_parser_reset(SubGhzParser* instance) {
subghz_protocol_came_reset((SubGhzProtocolCame*)instance->protocols[SubGhzProtocolTypeCame]);
subghz_protocol_came_twee_reset(
(SubGhzProtocolCameTwee*)instance->protocols[SubGhzProtocolTypeCameTwee]);
subghz_protocol_came_atomo_reset(
(SubGhzProtocolCameAtomo*)instance->protocols[SubGhzProtocolTypeCameAtomo]);
subghz_protocol_keeloq_reset(
(SubGhzProtocolKeeloq*)instance->protocols[SubGhzProtocolTypeKeeloq]);
subghz_decoder_princeton_reset(
@ -207,11 +228,18 @@ void subghz_parser_reset(SubGhzParser* instance) {
(SubGhzProtocolNeroRadio*)instance->protocols[SubGhzProtocolTypeNeroRadio]);
subghz_protocol_scher_khan_reset(
(SubGhzProtocolScherKhan*)instance->protocols[SubGhzProtocolTypeScherKhan]);
subghz_protocol_kia_reset((SubGhzProtocolKIA*)instance->protocols[SubGhzProtocolTypeKIA]);
}
void subghz_parser_parse(SubGhzParser* instance, bool level, uint32_t duration) {
subghz_protocol_came_parse(
(SubGhzProtocolCame*)instance->protocols[SubGhzProtocolTypeCame], level, duration);
subghz_protocol_came_twee_parse(
(SubGhzProtocolCameTwee*)instance->protocols[SubGhzProtocolTypeCameTwee], level, duration);
subghz_protocol_came_atomo_parse(
(SubGhzProtocolCameAtomo*)instance->protocols[SubGhzProtocolTypeCameAtomo],
level,
duration);
subghz_protocol_keeloq_parse(
(SubGhzProtocolKeeloq*)instance->protocols[SubGhzProtocolTypeKeeloq], level, duration);
subghz_decoder_princeton_parse(
@ -244,4 +272,6 @@ void subghz_parser_parse(SubGhzParser* instance, bool level, uint32_t duration)
(SubGhzProtocolScherKhan*)instance->protocols[SubGhzProtocolTypeScherKhan],
level,
duration);
subghz_protocol_kia_parse(
(SubGhzProtocolKIA*)instance->protocols[SubGhzProtocolTypeKIA], level, duration);
}

View file

@ -20,6 +20,8 @@ typedef enum {
ManchesterStateStart0 = 3
} ManchesterState;
bool manchester_advance(
ManchesterState state,
ManchesterEvent event,

View file

@ -0,0 +1,54 @@
#include "manchester-encoder.h"
#include <stdio.h>
void manchester_encoder_reset(ManchesterEncoderState* state) {
state->step = 0;
}
bool manchester_encoder_advance(
ManchesterEncoderState* state,
const bool curr_bit,
ManchesterEncoderResult* result) {
bool advance = false;
switch(state->step) {
case 0:
state->prev_bit = curr_bit;
if(state->prev_bit) {
*result = ManchesterEncoderResultShortLow;
} else {
*result = ManchesterEncoderResultShortHigh;
}
state->step = 1;
advance = true;
break;
case 1:
*result = (state->prev_bit << 1) + curr_bit;
if(curr_bit == state->prev_bit) {
state->step = 2;
} else {
state->prev_bit = curr_bit;
advance = true;
}
break;
case 2:
if(curr_bit) {
*result = ManchesterEncoderResultShortLow;
} else {
*result = ManchesterEncoderResultShortHigh;
}
state->prev_bit = curr_bit;
state->step = 1;
advance = true;
break;
default:
printf("DO CRASH HERE\r\n");
// furi_crash
break;
}
return advance;
}
ManchesterEncoderResult manchester_encoder_finish(ManchesterEncoderState* state) {
state->step = 0;
return (state->prev_bit << 1) + state->prev_bit;
}

View file

@ -0,0 +1,32 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
bool prev_bit;
uint8_t step;
} ManchesterEncoderState;
typedef enum {
ManchesterEncoderResultShortLow = 0b00,
ManchesterEncoderResultLongLow = 0b01,
ManchesterEncoderResultLongHigh = 0b10,
ManchesterEncoderResultShortHigh = 0b11,
} ManchesterEncoderResult;
void manchester_encoder_reset(ManchesterEncoderState* state);
bool manchester_encoder_advance(
ManchesterEncoderState* state,
const bool curr_bit,
ManchesterEncoderResult* result);
ManchesterEncoderResult manchester_encoder_finish(ManchesterEncoderState* state);
#ifdef __cplusplus
}
#endif