Update came_atomo.c

working parcel counter ++
This commit is contained in:
r3df0xx 2022-06-08 18:52:37 +03:00
parent 6cb484375d
commit 9a15634705

View File

@ -132,27 +132,30 @@ static void subghz_protocol_encoder_came_atomo_get_upload(SubGhzProtocolEncoderC
manchester_encoder_reset(&enc_state); manchester_encoder_reset(&enc_state);
ManchesterEncoderResult result; ManchesterEncoderResult result;
instance->generic.cnt++;
FURI_LOG_I(TAG, "parcel counter: %4X\n\n", instance->generic.cnt);
uint8_t pack[8] = {}; uint8_t pack[8] = {};
pack[0] = (instance->generic.data_2 >> 56); pack[1] = ((instance->generic.data_2 >> 48) & 0xFF); pack[0] = (instance->generic.data_2 >> 56); pack[1] = (instance->generic.cnt >> 8);
pack[2] = ((instance->generic.data_2 >> 40) & 0xFF); pack[3] = ((instance->generic.data_2 >> 32) & 0xFF); pack[2] = (instance->generic.cnt & 0xFF); pack[3] = ((instance->generic.data_2 >> 32) & 0xFF);
pack[4] = ((instance->generic.data_2 >> 24) & 0xFF); pack[5] = ((instance->generic.data_2 >> 16) & 0xFF); pack[4] = ((instance->generic.data_2 >> 24) & 0xFF); pack[5] = ((instance->generic.data_2 >> 16) & 0xFF);
pack[6] = ((instance->generic.data_2 >> 8) & 0xFF); pack[7] = (instance->generic.data_2 & 0xFF); pack[6] = ((instance->generic.data_2 >> 8) & 0xFF); pack[7] = (instance->generic.data_2 & 0xFF);
FURI_LOG_I(TAG, "encoder prepared: %02X %02X %02X %02X %02X %02X %02X %02X\n", FURI_LOG_I(TAG, "encoder prepared: %02X %02X %02X %02X %02X %02X %02X %02X\n\n",
pack[0], pack[1], pack[2], pack[3], pack[4], pack[5], pack[6], pack[7]); pack[0], pack[1], pack[2], pack[3], pack[4], pack[5], pack[6], pack[7]);
atomo_encrypt(pack); atomo_encrypt(pack);
uint32_t hi = pack[0] << 24 | pack[1] << 16 | pack[2] << 8 | pack[3]; uint32_t hi = pack[0] << 24 | pack[1] << 16 | pack[2] << 8 | pack[3];
uint32_t lo = pack[4] << 24 | pack[5] << 16 | pack[6] << 8 | pack[7]; uint32_t lo = pack[4] << 24 | pack[5] << 16 | pack[6] << 8 | pack[7];
instance->generic.data = (uint64_t)hi << 32 | lo; instance->generic.data = (uint64_t)hi << 32 | lo;
FURI_LOG_I(TAG, "encrypted data: %02X %02X %02X %02X %02X %02X %02X %02X\n", FURI_LOG_I(TAG, "encrypted data: %02X %02X %02X %02X %02X %02X %02X %02X\n\n",
pack[0], pack[1], pack[2], pack[3], pack[4], pack[5], pack[6], pack[7]); pack[0], pack[1], pack[2], pack[3], pack[4], pack[5], pack[6], pack[7]);
uint64_t invert = instance->generic.data ^ 0xFFFFFFFFFFFFFFFF; instance->generic.data ^= 0xFFFFFFFFFFFFFFFF;
invert >>= 4; instance->generic.data >>= 4;
invert = (uint64_t)0x1 << 60 | invert; instance->generic.data = (uint64_t)0x1 << 60 | instance->generic.data;
hi = invert >> 32; hi = instance->generic.data >> 32;
lo = invert & 0xFFFFFFFF; lo = instance->generic.data & 0xFFFFFFFF;
FURI_LOG_I(TAG, "inverted to upload: %02X %02X %02X %02X %02X %02X %02X %02X\n", FURI_LOG_I(TAG, "inverted to upload: %02X %02X %02X %02X %02X %02X %02X %02X\n",
(hi >> 24), ((hi >> 16) & 0xFF), ((hi >> 8) & 0xFF), (hi & 0xFF), (hi >> 24), ((hi >> 16) & 0xFF), ((hi >> 8) & 0xFF), (hi & 0xFF),
(lo >> 24), ((lo >> 16) & 0xFF), ((lo >> 8) & 0xFF), (lo & 0xFF)); (lo >> 24), ((lo >> 16) & 0xFF), ((lo >> 8) & 0xFF), (lo & 0xFF));
@ -166,10 +169,10 @@ static void subghz_protocol_encoder_came_atomo_get_upload(SubGhzProtocolEncoderC
instance->encoder.upload[index++] = level_duration_make(true, 1); instance->encoder.upload[index++] = level_duration_make(true, 1);
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) { for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
if(!manchester_encoder_advance(&enc_state, !bit_read(invert, i - 1), &result)) { if(!manchester_encoder_advance(&enc_state, !bit_read(instance->generic.data, i - 1), &result)) {
instance->encoder.upload[index++] = instance->encoder.upload[index++] =
subghz_protocol_encoder_came_atomo_add_duration_to_upload(result); subghz_protocol_encoder_came_atomo_add_duration_to_upload(result);
manchester_encoder_advance(&enc_state, !bit_read(invert, i - 1), &result); manchester_encoder_advance(&enc_state, !bit_read(instance->generic.data, i - 1), &result);
} }
instance->encoder.upload[index++] = instance->encoder.upload[index++] =
subghz_protocol_encoder_came_atomo_add_duration_to_upload(result); subghz_protocol_encoder_came_atomo_add_duration_to_upload(result);
@ -202,6 +205,20 @@ bool subghz_protocol_encoder_came_atomo_deserialize(void* context, FlipperFormat
subghz_protocol_came_atomo_remote_controller(&instance->generic); subghz_protocol_came_atomo_remote_controller(&instance->generic);
subghz_protocol_encoder_came_atomo_get_upload(instance); subghz_protocol_encoder_came_atomo_get_upload(instance);
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_runing = true; instance->encoder.is_runing = true;
res = true; res = true;
@ -401,12 +418,16 @@ static void subghz_protocol_came_atomo_remote_controller(
* 0xEF3 ED0F7D9E F => 0xEF3 - CNT, 0xED0F7D9E - SN, 0xF - key * 0xEF3 ED0F7D9E F => 0xEF3 - CNT, 0xED0F7D9E - SN, 0xF - key
* *
* */ * */
instance->data ^= 0xFFFFFFFFFFFFFFFF;
instance->data <<= 4;
uint32_t hi = instance->data >> 32; uint32_t hi = instance->data >> 32;
uint32_t lo = instance->data & 0xFFFFFFFF; uint32_t lo = instance->data & 0xFFFFFFFF;
FURI_LOG_I(TAG, "inverted data: %02X %02X %02X %02X %02X %02X %02X %02X\n", FURI_LOG_I(TAG, "received data: %02X %02X %02X %02X %02X %02X %02X %02X\n\n",
(hi >> 24), ((hi >> 16) & 0xFF), ((hi >> 8) & 0xFF), (hi & 0xFF),
(lo >> 24), ((lo >> 16) & 0xFF), ((lo >> 8) & 0xFF), (lo & 0xFF));
instance->data ^= 0xFFFFFFFFFFFFFFFF;
instance->data <<= 4;
hi = instance->data >> 32;
lo = instance->data & 0xFFFFFFFF;
FURI_LOG_I(TAG, "inverted data: %02X %02X %02X %02X %02X %02X %02X %02X\n\n",
(hi >> 24), ((hi >> 16) & 0xFF), ((hi >> 8) & 0xFF), (hi & 0xFF), (hi >> 24), ((hi >> 16) & 0xFF), ((hi >> 8) & 0xFF), (hi & 0xFF),
(lo >> 24), ((lo >> 16) & 0xFF), ((lo >> 8) & 0xFF), (lo & 0xFF)); (lo >> 24), ((lo >> 16) & 0xFF), ((lo >> 8) & 0xFF), (lo & 0xFF));
uint8_t pack[8] = {}; uint8_t pack[8] = {};
@ -415,7 +436,7 @@ static void subghz_protocol_came_atomo_remote_controller(
pack[4] = ((instance->data >> 24) & 0xFF); pack[5] = ((instance->data >> 16) & 0xFF); pack[4] = ((instance->data >> 24) & 0xFF); pack[5] = ((instance->data >> 16) & 0xFF);
pack[6] = ((instance->data >> 8) & 0xFF); pack[7] = (instance->data & 0xFF); pack[6] = ((instance->data >> 8) & 0xFF); pack[7] = (instance->data & 0xFF);
atomo_decrypt(pack); atomo_decrypt(pack);
FURI_LOG_I(TAG, "decrypted data: %02X %02X %02X %02X %02X %02X %02X %02X\n", FURI_LOG_I(TAG, "decrypted data: %02X %02X %02X %02X %02X %02X %02X %02X\n\n",
pack[0], pack[1], pack[2], pack[3], pack[4], pack[5], pack[6], pack[7]); pack[0], pack[1], pack[2], pack[3], pack[4], pack[5], pack[6], pack[7]);
instance->cnt_2 = pack[0]; instance->cnt_2 = pack[0];
instance->cnt = (uint16_t)pack[1] << 8 | pack[2]; instance->cnt = (uint16_t)pack[1] << 8 | pack[2];