flipperzero-firmware/applications/irda/irda-app-signal.cpp
Albert Kharisov 5f6aff2255
[FL-1472, FL-1596, FL-1673] IRDA: stability improvements (#655)
- Restrict with 31 bytes length for remote and signal name
- Don't stuck for 0 PWM cycle timings
- Support timings > 65535 PWM cycles
- Fix remote file open error
- Add IRDA TX debug redirect
- Add remote parse error print, improve parsing, support tabs
- Fix stucks with uncorrect RAW signal values, long strings in remote file, etc
- Fix HAL signals capturing (save previous read value)
- Fix leak in case of failed parsing
2021-08-19 03:18:42 +03:00

96 lines
2.5 KiB
C++

#include "irda-app-signal.h"
#include <irda_transmit.h>
void IrdaAppSignal::copy_timings(const uint32_t* timings, size_t size) {
furi_assert(size);
furi_assert(timings);
payload.raw.timings_cnt = size;
if(size) {
payload.raw.timings = new uint32_t[size];
memcpy(payload.raw.timings, timings, size * sizeof(uint32_t));
}
}
void IrdaAppSignal::clear_timings() {
if(!decoded) {
delete[] payload.raw.timings;
payload.raw.timings_cnt = 0;
payload.raw.timings = nullptr;
}
}
IrdaAppSignal::IrdaAppSignal(const uint32_t* timings, size_t timings_cnt) {
decoded = false;
copy_timings(timings, timings_cnt);
}
IrdaAppSignal::IrdaAppSignal(const IrdaMessage* irda_message) {
decoded = true;
payload.message = *irda_message;
}
IrdaAppSignal& IrdaAppSignal::operator=(const IrdaAppSignal& other) {
clear_timings();
decoded = other.decoded;
if(decoded) {
payload.message = other.payload.message;
} else {
copy_timings(other.payload.raw.timings, other.payload.raw.timings_cnt);
}
return *this;
}
IrdaAppSignal::IrdaAppSignal(const IrdaAppSignal& other) {
decoded = other.decoded;
if(decoded) {
payload.message = other.payload.message;
} else {
copy_timings(other.payload.raw.timings, other.payload.raw.timings_cnt);
}
}
IrdaAppSignal::IrdaAppSignal(IrdaAppSignal&& other) {
clear_timings();
decoded = other.decoded;
if(decoded) {
payload.message = other.payload.message;
} else {
furi_assert(other.payload.raw.timings_cnt > 0);
payload.raw.timings = other.payload.raw.timings;
payload.raw.timings_cnt = other.payload.raw.timings_cnt;
other.payload.raw.timings = nullptr;
other.payload.raw.timings_cnt = 0;
}
}
void IrdaAppSignal::set_message(const IrdaMessage* irda_message) {
clear_timings();
decoded = true;
payload.message = *irda_message;
}
void IrdaAppSignal::set_raw_signal(uint32_t* timings, size_t timings_cnt) {
clear_timings();
decoded = false;
payload.raw.timings = timings;
payload.raw.timings_cnt = timings_cnt;
}
void IrdaAppSignal::copy_raw_signal(uint32_t* timings, size_t timings_cnt) {
clear_timings();
decoded = false;
copy_timings(timings, timings_cnt);
}
void IrdaAppSignal::transmit() const {
if(decoded) {
irda_send(&payload.message, 1);
} else {
irda_send_raw(payload.raw.timings, payload.raw.timings_cnt, true);
}
}