mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-10 05:59:08 -07:00
gangqi serial validator and fix add manually
This commit is contained in:
@@ -382,3 +382,28 @@ bool subghz_txrx_gen_secplus_v1_protocol(
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_txrx_gen_serial_gangqi(uint64_t* result_key) {
|
||||
uint64_t randkey = (uint64_t)rand();
|
||||
uint64_t only_required_bytes = (randkey & 0xFFFFF0000);
|
||||
uint16_t sum_of_3bytes = ((only_required_bytes >> 32) & 0xFF) +
|
||||
((only_required_bytes >> 24) & 0xFF) +
|
||||
((only_required_bytes >> 16) & 0xFF);
|
||||
|
||||
while(!((!(sum_of_3bytes & 0x3)) && ((0xb2 < sum_of_3bytes) && (sum_of_3bytes < 0x1ae)))) {
|
||||
randkey = (uint64_t)rand();
|
||||
only_required_bytes = (randkey & 0xFFFFF0000);
|
||||
sum_of_3bytes = ((only_required_bytes >> 32) & 0xFF) +
|
||||
((only_required_bytes >> 24) & 0xFF) +
|
||||
((only_required_bytes >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
// Serial 01 button 01
|
||||
uint64_t new_key = only_required_bytes | (0b01 << 14) | (0xD << 10) | (0b01 << 8);
|
||||
|
||||
uint8_t crc = -0xD7 - ((new_key >> 32) & 0xFF) - ((new_key >> 24) & 0xFF) -
|
||||
((new_key >> 16) & 0xFF) - ((new_key >> 8) & 0xFF);
|
||||
|
||||
// Add crc sum to the end
|
||||
*result_key = (new_key | crc);
|
||||
}
|
||||
|
||||
@@ -146,3 +146,10 @@ bool subghz_txrx_gen_secplus_v1_protocol(
|
||||
SubGhzTxRx* instance,
|
||||
const char* name_preset,
|
||||
uint32_t frequency);
|
||||
|
||||
/**
|
||||
* Generate valid serial number for GangQi protocol
|
||||
*
|
||||
* @return uint64_t if success
|
||||
*/
|
||||
void subghz_txrx_gen_serial_gangqi(uint64_t* result_key);
|
||||
|
||||
@@ -183,6 +183,10 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
|
||||
uint64_t key = (uint64_t)rand();
|
||||
|
||||
uint64_t gangqi_key;
|
||||
subghz_txrx_gen_serial_gangqi(&gangqi_key);
|
||||
|
||||
GenInfo gen_info = {0};
|
||||
switch(event.event) {
|
||||
case SetTypePricenton433:
|
||||
@@ -312,13 +316,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
.freq = 433920000,
|
||||
.data.name =
|
||||
SUBGHZ_PROTOCOL_GANGQI_NAME, // Add button 0xD arm and crc sum to the end
|
||||
.data.key =
|
||||
((key & 0x00FF00000) | 0x3400B7500 |
|
||||
((((-0xD7 - (((key & 0x00FF00000) | 0x3400B7500) >> 32)) & 0xFF) -
|
||||
((((key & 0x00FF00000) | 0x3400B7500) >> 24) & 0xFF) -
|
||||
((((key & 0x00FF00000) | 0x3400B7500) >> 16) & 0xFF) -
|
||||
((((key & 0x00FF00000) | 0x3400B7500) >> 8) & 0xFF)) &
|
||||
0xFF)),
|
||||
.data.key = gangqi_key,
|
||||
.data.bits = 34,
|
||||
.data.te = 0};
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user