Skip to content

Commit 6bbdefc

Browse files
committed
mod: Monitor compatibility uses Bridge->call to write if router is older version
1 parent 87402b9 commit 6bbdefc

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/bridge.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#define RESET_METHOD "$/reset"
1818
#define BIND_METHOD "$/register"
19+
#define GET_VERSION_METHOD "$/version"
20+
1921
//#define BRIDGE_ERROR "$/bridgeLog"
2022

2123
#define UPDATE_THREAD_STACK_SIZE 500
@@ -157,6 +159,8 @@ class BridgeClass {
157159

158160
bool started = false;
159161

162+
MsgPack::str_t router_ver;
163+
160164
public:
161165

162166
explicit BridgeClass(HardwareSerial& serial) {
@@ -203,6 +207,10 @@ class BridgeClass {
203207
return res;
204208
}
205209

210+
bool getRouterVersion(MsgPack::str_t& version) {
211+
return call(GET_VERSION_METHOD).result(version);
212+
}
213+
206214
template<typename F>
207215
bool provide(const MsgPack::str_t& name, F&& func) {
208216
k_mutex_lock(&bridge_mutex, K_FOREVER);

src/monitor.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class BridgeMonitor: public Stream {
3131
RingBufferN<BufferSize> temp_buffer;
3232
struct k_mutex monitor_mutex{};
3333
bool _connected = false;
34+
bool _compatibility_mode;
3435

3536
public:
3637
explicit BridgeMonitor(BridgeClass& bridge): bridge(&bridge) {}
@@ -52,6 +53,8 @@ class BridgeMonitor: public Stream {
5253
k_mutex_lock(&monitor_mutex, K_FOREVER);
5354
bool out = false;
5455
_connected = bridge->call(MON_CONNECTED_METHOD).result(out) && out;
56+
MsgPack::str_t ver;
57+
_compatibility_mode = !bridge->call(GET_VERSION_METHOD).result(ver);
5558
k_mutex_unlock(&monitor_mutex);
5659
return out;
5760
}
@@ -114,10 +117,15 @@ class BridgeMonitor: public Stream {
114117
send_buffer += static_cast<char>(buffer[i]);
115118
}
116119

117-
size_t written;
118-
const bool ret = bridge->call(MON_WRITE_METHOD, send_buffer).result(written);
120+
size_t written = 0;
119121

120-
return ret? written : 0;
122+
if (_compatibility_mode) {
123+
bridge->call(MON_WRITE_METHOD, send_buffer).result(written);
124+
} else {
125+
bridge->notify(MON_WRITE_METHOD, send_buffer);
126+
}
127+
128+
return written;
121129
}
122130

123131
bool reset() {

0 commit comments

Comments
 (0)