Skip to content

Commit cf6b26c

Browse files
committed
mod: rem timeout logic. Catch PARSING_ERR and send $/bridgeError notification
1 parent 018b569 commit cf6b26c

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/bridge.h

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#define RESET_METHOD "$/reset"
1818
#define BIND_METHOD "$/register"
19-
#define BRIDGE_TIMEOUT "$/bridgeTimeout"
19+
#define BRIDGE_ERROR "$/bridgeError"
2020

2121
#define UPDATE_THREAD_STACK_SIZE 500
2222
#define UPDATE_THREAD_PRIORITY 5
@@ -34,27 +34,24 @@ class RpcResult {
3434
public:
3535
RpcError error;
3636

37-
RpcResult(uint32_t id, RPCClient* c, struct k_mutex* rm, struct k_mutex* wm, unsigned long timeout) : msg_id_wait(id), client(c), read_mutex(rm), write_mutex(wm), _timeout(timeout) {}
37+
RpcResult(uint32_t id, RPCClient* c, struct k_mutex* rm, struct k_mutex* wm) : msg_id_wait(id), client(c), read_mutex(rm), write_mutex(wm) {}
3838

3939
template<typename RType> bool result(RType& result) {
4040
if (_executed) return error.code == NO_ERR;
4141

42-
unsigned long start = millis();
4342
while(true) {
44-
if (_timeout > 0 && (millis() - start) > _timeout){
45-
error.code = GENERIC_ERR;
46-
error.traceback = "Timed out";
47-
k_mutex_lock(write_mutex, K_FOREVER);
48-
client->notify(BRIDGE_TIMEOUT);
49-
k_mutex_unlock(write_mutex);
50-
break;
51-
}
5243
if (k_mutex_lock(read_mutex, K_MSEC(10)) == 0 ) {
5344
if (client->get_response(msg_id_wait, result)) {
5445
error.code = client->lastError.code;
5546
error.traceback = client->lastError.traceback;
5647
k_mutex_unlock(read_mutex);
5748
break;
49+
} else if (client->lastError.code == PARSING_ERR) {
50+
error.code = client->lastError.code;
51+
error.traceback = client->lastError.traceback;
52+
k_mutex_lock(write_mutex, K_FOREVER);
53+
client->notify(BRIDGE_ERROR);
54+
k_mutex_unlock(write_mutex);
5855
}
5956
k_mutex_unlock(read_mutex);
6057
k_msleep(1);
@@ -77,7 +74,6 @@ class RpcResult {
7774
bool _executed = false;
7875
struct k_mutex* read_mutex;
7976
struct k_mutex* write_mutex;
80-
unsigned long _timeout = -1;
8177
};
8278

8379
class BridgeClass {
@@ -96,8 +92,6 @@ class BridgeClass {
9692

9793
bool started = false;
9894

99-
unsigned long _timeout = -1;
100-
10195
public:
10296

10397
explicit BridgeClass(HardwareSerial& serial) {
@@ -108,10 +102,6 @@ class BridgeClass {
108102
return started;
109103
}
110104

111-
void setTimeout(int t) {
112-
_timeout = t;
113-
}
114-
115105
// Initialize the bridge
116106
bool begin(unsigned long baud=DEFAULT_SERIAL_BAUD) {
117107
serial_ptr->begin(baud);
@@ -204,7 +194,7 @@ class BridgeClass {
204194
k_yield();
205195
}
206196
}
207-
return RpcResult{msg_id_wait, client, &read_mutex, &write_mutex, _timeout};
197+
return RpcResult{msg_id_wait, client, &read_mutex, &write_mutex};
208198
}
209199

210200

0 commit comments

Comments
 (0)