initial Somfy Telis Encoder (doesnt work)

This commit is contained in:
TQMatvey
2023-01-11 19:47:45 +07:00
parent 78c64737aa
commit b30aa890e6
3 changed files with 142 additions and 7 deletions
+6 -1
View File
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,11.6,,
Version,+,11.7,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
@@ -3061,6 +3061,11 @@ Function,-,subghz_protocol_encoder_smc5326_deserialize,_Bool,"void*, FlipperForm
Function,-,subghz_protocol_encoder_smc5326_free,void,void*
Function,-,subghz_protocol_encoder_smc5326_stop,void,void*
Function,-,subghz_protocol_encoder_smc5326_yield,LevelDuration,void*
Function,-,subghz_protocol_encoder_somfy_telis_alloc,void*,SubGhzEnvironment*
Function,-,subghz_protocol_encoder_somfy_telis_deserialize,_Bool,"void*, FlipperFormat*"
Function,-,subghz_protocol_encoder_somfy_telis_free,void,void*
Function,-,subghz_protocol_encoder_somfy_telis_stop,void,void*
Function,-,subghz_protocol_encoder_somfy_telis_yield,LevelDuration,void*
Function,-,subghz_protocol_encoder_star_line_alloc,void*,SubGhzEnvironment*
Function,-,subghz_protocol_encoder_star_line_deserialize,_Bool,"void*, FlipperFormat*"
Function,-,subghz_protocol_encoder_star_line_free,void,void*
1 entry status name type params
2 Version + 11.6 11.7
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
3061 Function - subghz_protocol_encoder_smc5326_free void void*
3062 Function - subghz_protocol_encoder_smc5326_stop void void*
3063 Function - subghz_protocol_encoder_smc5326_yield LevelDuration void*
3064 Function - subghz_protocol_encoder_somfy_telis_alloc void* SubGhzEnvironment*
3065 Function - subghz_protocol_encoder_somfy_telis_deserialize _Bool void*, FlipperFormat*
3066 Function - subghz_protocol_encoder_somfy_telis_free void void*
3067 Function - subghz_protocol_encoder_somfy_telis_stop void void*
3068 Function - subghz_protocol_encoder_somfy_telis_yield LevelDuration void*
3069 Function - subghz_protocol_encoder_star_line_alloc void* SubGhzEnvironment*
3070 Function - subghz_protocol_encoder_star_line_deserialize _Bool void*, FlipperFormat*
3071 Function - subghz_protocol_encoder_star_line_free void void*
+90 -6
View File
@@ -31,6 +31,8 @@ struct SubGhzProtocolEncoderSomfyTelis {
SubGhzProtocolBlockEncoder encoder;
SubGhzBlockGeneric generic;
SubGhzKeystore* keystore;
};
typedef enum {
@@ -55,24 +57,106 @@ const SubGhzProtocolDecoder subghz_protocol_somfy_telis_decoder = {
};
const SubGhzProtocolEncoder subghz_protocol_somfy_telis_encoder = {
.alloc = NULL,
.free = NULL,
.alloc = subghz_protocol_encoder_somfy_telis_alloc,
.free = subghz_protocol_encoder_somfy_telis_free,
.deserialize = NULL,
.stop = NULL,
.yield = NULL,
.deserialize = subghz_protocol_encoder_somfy_telis_deserialize,
.stop = subghz_protocol_encoder_somfy_telis_stop,
.yield = subghz_protocol_encoder_somfy_telis_yield,
};
const SubGhzProtocol subghz_protocol_somfy_telis = {
.name = SUBGHZ_PROTOCOL_SOMFY_TELIS_NAME,
.type = SubGhzProtocolTypeDynamic,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_868 | SubGhzProtocolFlag_AM |
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save,
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
.decoder = &subghz_protocol_somfy_telis_decoder,
.encoder = &subghz_protocol_somfy_telis_encoder,
};
void* subghz_protocol_encoder_somfy_telis_alloc(SubGhzEnvironment* environment) {
SubGhzProtocolEncoderSomfyTelis* instance = malloc(sizeof(SubGhzProtocolEncoderSomfyTelis));
instance->base.protocol = &subghz_protocol_somfy_telis;
instance->generic.protocol_name = instance->base.protocol->name;
instance->keystore = subghz_environment_get_keystore(environment);
instance->encoder.repeat = 10;
instance->encoder.size_upload = 256;
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
instance->encoder.is_running = false;
return instance;
}
void subghz_protocol_encoder_somfy_telis_free(void* context) {
furi_assert(context);
SubGhzProtocolEncoderSomfyTelis* instance = context;
free(instance->encoder.upload);
free(instance);
}
bool subghz_protocol_encoder_somfy_telis_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolEncoderSomfyTelis* instance = context;
bool res = false;
do {
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
FURI_LOG_E(TAG, "Deserialize error");
break;
}
//optional parameter parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
//TODO: subghz_protocol_encoder_star_line_get_upload(instance, instance->generic.btn);
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
break;
}
uint8_t key_data[sizeof(uint64_t)] = {0};
for(size_t i = 0; i < sizeof(uint64_t); i++) {
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF;
}
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to add Key");
break;
}
instance->encoder.is_running = true;
res = true;
} while(false);
return res;
}
void subghz_protocol_encoder_somfy_telis_stop(void* context) {
SubGhzProtocolEncoderSomfyTelis* instance = context;
instance->encoder.is_running = false;
}
LevelDuration subghz_protocol_encoder_somfy_telis_yield(void* context) {
SubGhzProtocolEncoderSomfyTelis* instance = context;
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
instance->encoder.is_running = false;
return level_duration_reset();
}
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
if(++instance->encoder.front == instance->encoder.size_upload) {
instance->encoder.repeat--;
instance->encoder.front = 0;
}
return ret;
}
void* subghz_protocol_decoder_somfy_telis_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolDecoderSomfyTelis* instance = malloc(sizeof(SubGhzProtocolDecoderSomfyTelis));
+46
View File
@@ -11,6 +11,52 @@ extern const SubGhzProtocolDecoder subghz_protocol_somfy_telis_decoder;
extern const SubGhzProtocolEncoder subghz_protocol_somfy_telis_encoder;
extern const SubGhzProtocol subghz_protocol_somfy_telis;
/**
* Allocate SubGhzProtocolEncoderSomfyTelis.
* @param environment Pointer to a SubGhzEnvironment instance
* @return SubGhzProtocolEncoderSomfyTelis* pointer to a SubGhzProtocolEncoderSSomfyTelis instance
*/
void* subghz_protocol_encoder_somfy_telis_alloc(SubGhzEnvironment* environment);
/**
* Free SubGhzProtocolEncoderSomfyTelis.
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
*/
void subghz_protocol_encoder_somfy_telis_free(void* context);
/**
* Key generation from simple data.
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
* @param flipper_format Pointer to a FlipperFormat instance
* @param serial Serial number, 24 bit
* @param btn Button number, 8 bit
* @param cnt Counter value, 16 bit
* @param manufacture_name Name of manufacturer's key
* @param preset Modulation, SubGhzRadioPreset
* @return true On success
*/
/**
* Deserialize and generating an upload to send.
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
* @param flipper_format Pointer to a FlipperFormat instance
* @return true On success
*/
bool subghz_protocol_encoder_somfy_telis_deserialize(void* context, FlipperFormat* flipper_format);
/**
* Forced transmission stop.
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
*/
void subghz_protocol_encoder_somfy_telis_stop(void* context);
/**
* Getting the level and duration of the upload to be loaded into DMA.
* @param context Pointer to a SubGhzProtocolEncoderSomfyTelis instance
* @return LevelDuration
*/
LevelDuration subghz_protocol_encoder_somfy_telis_yield(void* context);
/**
* Allocate SubGhzProtocolDecoderSomfyTelis.
* @param environment Pointer to a SubGhzEnvironment instance