@@ -41,31 +41,33 @@ class RPCClient {
4141 MsgPack::object::nil_t nil;
4242 RpcError rpc_error;
4343
44- MsgPack::arr_size_t resp_size (4 );
45-
46- if (!unpacker.deserialize (resp_size, r_msg_type, r_msg_id, nil, result)){
47- // Try to deserialize for a RpcError
48- if (!unpacker.deserialize (resp_size, r_msg_type, r_msg_id, rpc_error, nil)){
49- Serial.println (" Unable to deserialize" );
50- Serial.print (" buf len " );
51- Serial.print (raw_buffer_fill);
52- Serial.print (" : " );
53- for (size_t i = 0 ; i<raw_buffer_fill; i++){
54- Serial.print (raw_buffer[i], HEX);
55- Serial.print (" -" );
56- }
57- flush_buffer ();
58- return false ;
59- } else {
60- Serial.print (" RPC produced an error: " );
61- Serial.println (rpc_error.code );
62- Serial.println (rpc_error.traceback );
63- }
44+ MsgPack::arr_size_t resp_size;
6445
46+ if (!unpacker.deserialize (resp_size, r_msg_type, r_msg_id)){
47+ Serial.println (" malformed response" );
48+ };
49+
50+ if ((resp_size.size () != 4 ) || (r_msg_type != 1 ) || (r_msg_id != msg_id)){
51+ Serial.println (" wrong msg received" );
52+ flush_buffer ();
53+ return false ;
6554 }
6655
67- if (r_msg_id != msg_id){
68- // Serial.println("msg_id mismatch");
56+ if (!unpacker.unpackNil ()){
57+ Serial.print (" RPC error - " );
58+ int error_code;
59+ MsgPack::str_t error_str;
60+ unpacker.deserialize (error_code, error_str);
61+ Serial.print (" error code: " );
62+ Serial.print (error_code);
63+ Serial.print (" error str: " );
64+ Serial.println (error_str);
65+ unpacker.unpackNil ();
66+ msg_id += 1 ;
67+ flush_buffer ();
68+ return false ;
69+ } else if (!unpacker.deserialize (result)){
70+ Serial.println (" Unexpected result" );
6971 flush_buffer ();
7072 return false ;
7173 }
0 commit comments