Add companion terminal mode and LoRa OTA tooling
This commit is contained in:
1 parent
cfdf33b7ca
commit
bf62afa240
16 files changed
+2956
-8
No files matched your search
@@ -5,12 +5,52 @@
|
||||
#define RECV_STATE_LEN1_FOUND 2
|
||||
#define RECV_STATE_LEN2_FOUND 3
|
||||
|
||||
void ArduinoSerialInterface::enable() {
|
||||
_isEnabled = true;
|
||||
void ArduinoSerialInterface::resetReceiveState() {
|
||||
_state = RECV_STATE_IDLE;
|
||||
_controlSequencePos = 0;
|
||||
_frame_len = 0;
|
||||
rx_len = 0;
|
||||
}
|
||||
|
||||
bool ArduinoSerialInterface::checkControlSequence(uint8_t c) {
|
||||
if (_controlSequence == nullptr || _controlSequence[0] == 0) return false;
|
||||
|
||||
if (c == (uint8_t)_controlSequence[_controlSequencePos]) {
|
||||
_controlSequencePos++;
|
||||
if (_controlSequence[_controlSequencePos] == 0) {
|
||||
_controlSequencePos = 0;
|
||||
_controlSequenceReceived = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// Preserve a possible new match when this byte is also the first byte of
|
||||
// the sequence (notably useful for sequences beginning with "+++").
|
||||
_controlSequencePos = c == (uint8_t)_controlSequence[0] ? 1 : 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ArduinoSerialInterface::setPassthroughMode(bool enabled) {
|
||||
_passthroughMode = enabled;
|
||||
_controlSequenceReceived = false;
|
||||
resetReceiveState();
|
||||
}
|
||||
|
||||
bool ArduinoSerialInterface::takeControlSequence() {
|
||||
bool received = _controlSequenceReceived;
|
||||
_controlSequenceReceived = false;
|
||||
return received;
|
||||
}
|
||||
|
||||
void ArduinoSerialInterface::enable() {
|
||||
_isEnabled = true;
|
||||
_controlSequenceReceived = false;
|
||||
resetReceiveState();
|
||||
}
|
||||
void ArduinoSerialInterface::disable() {
|
||||
_isEnabled = false;
|
||||
_controlSequenceReceived = false;
|
||||
resetReceiveState();
|
||||
}
|
||||
|
||||
bool ArduinoSerialInterface::isConnected() const {
|
||||
@@ -30,6 +70,7 @@ size_t ArduinoSerialInterface::writeFrame(const uint8_t src[], size_t len) {
|
||||
// frame is too big!
|
||||
return 0;
|
||||
}
|
||||
if (_passthroughMode) return len;
|
||||
|
||||
uint8_t hdr[3];
|
||||
hdr[0] = '>';
|
||||
@@ -41,12 +82,18 @@ size_t ArduinoSerialInterface::writeFrame(const uint8_t src[], size_t len) {
|
||||
}
|
||||
|
||||
size_t ArduinoSerialInterface::checkRecvFrame(uint8_t dest[]) {
|
||||
if (_passthroughMode) return 0;
|
||||
|
||||
while (_serial->available()) {
|
||||
int c = _serial->read();
|
||||
if (c < 0) break;
|
||||
|
||||
switch (_state) {
|
||||
case RECV_STATE_IDLE:
|
||||
if (checkControlSequence((uint8_t)c)) {
|
||||
// Leave any following bytes buffered for the passthrough consumer.
|
||||
return 0;
|
||||
}
|
||||
if (c == '<') {
|
||||
_state = RECV_STATE_HDR_FOUND;
|
||||
}
|
||||
|
||||
@@ -5,22 +5,46 @@
|
||||
|
||||
class ArduinoSerialInterface : public BaseSerialInterface {
|
||||
bool _isEnabled;
|
||||
bool _passthroughMode;
|
||||
bool _controlSequenceReceived;
|
||||
uint8_t _state;
|
||||
size_t _controlSequencePos;
|
||||
uint16_t _frame_len;
|
||||
uint16_t rx_len;
|
||||
Stream* _serial;
|
||||
const char* _controlSequence;
|
||||
uint8_t rx_buf[MAX_FRAME_SIZE];
|
||||
|
||||
public:
|
||||
ArduinoSerialInterface() { _isEnabled = false; _state = 0; }
|
||||
bool checkControlSequence(uint8_t c);
|
||||
void resetReceiveState();
|
||||
|
||||
void begin(Stream& serial) {
|
||||
_serial = &serial;
|
||||
public:
|
||||
ArduinoSerialInterface()
|
||||
: _isEnabled(false), _passthroughMode(false),
|
||||
_controlSequenceReceived(false), _state(0), _controlSequencePos(0),
|
||||
_frame_len(0), rx_len(0), _serial(nullptr),
|
||||
_controlSequence(nullptr) {}
|
||||
|
||||
void begin(Stream& serial, const char* controlSequence = nullptr) {
|
||||
_serial = &serial;
|
||||
_controlSequence = controlSequence;
|
||||
_passthroughMode = false;
|
||||
_controlSequenceReceived = false;
|
||||
resetReceiveState();
|
||||
#ifdef RAK_4631
|
||||
pinMode(WB_IO2, OUTPUT);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// In passthrough mode another line-oriented consumer owns the Stream. Binary
|
||||
// frames are neither read from nor written to this interface.
|
||||
void setPassthroughMode(bool enabled);
|
||||
bool isPassthroughMode() const { return _passthroughMode; }
|
||||
|
||||
// Returns true once for each complete control sequence received while the
|
||||
// binary frame parser was idle.
|
||||
bool takeControlSequence();
|
||||
|
||||
// BaseSerialInterface methods
|
||||
void enable() override;
|
||||
void disable() override;
|
||||
|
||||
Reference in new issue
Block a user