unleashed-firmware/applications/irda/irda-app-file-parser.h
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

57 lines
1.8 KiB
C++

#pragma once
#include "irda-app-signal.h"
#include <irda.h>
#include <file-worker-cpp.h>
#include <memory>
#include <string>
#include <cstdint>
class IrdaAppFileParser {
public:
typedef struct {
char name[32];
IrdaAppSignal signal;
} IrdaFileSignal;
bool open_irda_file_read(const char* filename);
bool open_irda_file_write(const char* filename);
bool is_irda_file_exist(const char* filename, bool* exist);
bool rename_irda_file(const char* filename, const char* newname);
bool remove_irda_file(const char* name);
bool close();
bool check_errors();
std::unique_ptr<IrdaAppFileParser::IrdaFileSignal> read_signal();
bool save_signal(const IrdaAppSignal& signal, const char* name);
std::string file_select(const char* selected);
std::string make_name(const std::string& full_name) const;
private:
size_t stringify_message(
const IrdaAppSignal& signal,
const char* name,
char* content,
size_t content_len);
size_t stringify_raw_signal(
const IrdaAppSignal& signal,
const char* name,
char* content,
size_t content_len);
std::unique_ptr<IrdaFileSignal> parse_signal(const std::string& str) const;
std::unique_ptr<IrdaFileSignal> parse_signal_raw(const std::string& str) const;
std::string make_full_name(const std::string& name) const;
static inline const char* const irda_directory = "/any/irda";
static inline const char* const irda_extension = ".ir";
static inline const uint32_t max_raw_timings_in_signal = 512;
static inline const uint32_t max_line_length =
(9 + 1) * IrdaAppFileParser::max_raw_timings_in_signal + 100;
FileWorkerCpp file_worker;
char file_buf[128];
size_t file_buf_cnt = 0;
};