jfjlaros / simpleRPC

Simple RPC implementation for Arduino.
MIT License
50 stars 17 forks source link

simple_rpc: error: invalid protocol header #24

Closed cdupont closed 2 years ago

cdupont commented 2 years ago

Hello, thanks for this awesome library! I get this error when using simple_rpc:

$ simple_rpc call /dev/ttyUSB0 foo 1
usage: simple_rpc [-h] [-v] {list,call} ...
simple_rpc: error: invalid protocol header

I suspect it's because I use it with another library that outputs a lot of traces on Serial port. If I comment out that other library, it works fine. Any idea how to manage that? I could go and remove the traces in the other library, but it's heavy and not really under my control...

Thanks

cdupont commented 2 years ago

Anyway, the question is: how to mix this library and traces? Is it possible?

jfjlaros commented 2 years ago

I don't think so. A basic serial connection has no notion of multiple channels, there are some higher level protocols that could be used to accomplish this, but if the other library does not conform to that particular standard, you are still out of luck.

Do you perhaps have other communication devices on your board, like a second serial port, Bluetooth or WiFi?

cdupont commented 2 years ago

No, there is only the USB serial port... Guess I will just modify that library to remove the traces. But it's a pity to lose the traces of course...

jfjlaros commented 2 years ago

Can that particular library be configured to use interfaces other than HardwareSerial?

I ask because it may be possible to use something like PacketSerial to multiplex two connections over the same serial line.

cdupont commented 2 years ago

That library simple outputs traces with Serial.print. Do I need to change it?

jfjlaros commented 2 years ago

Not for the moment, I have to figure out whether this multiplexing idea is feasible first.

cdupont commented 2 years ago

So do you think multiplexing is feasible? With all traces disabled, it's very hard to debug my system now :)

jfjlaros commented 2 years ago

Yes, I think so.

You might want to check out this post.

Please note that this is all very experimental, it will take some time before we have a stable library that works.

jfjlaros commented 2 years ago

I have something that seems to be working reasonably, at least on my system.

See the Arduino library and the host library if you want to try it yourself.

cdupont commented 2 years ago

Hello, I was wondering if you manage to make traces work finally?

jfjlaros commented 2 years ago

Yes, I have a proof of concept working, I shared the links to this project in a previous message.

cdupont commented 2 years ago

So, I suppose I can use your library serialMux together with simpleRPC?

#include <simpleRPC.h>
#include <serialMux.h>

SerialMux mux(Serial);
VSerial serialRPC(mux);
VSerial serialTrace(mux);

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  //Start RPC lib on multiplexed serial port
  interface(serialRPC, digitalRead, "", digitalWrite, "");
  //Use Serial traces anyway
  serialTrace.printLn("Test");

}

Is this correct?

jfjlaros commented 2 years ago

Yes, that is the idea.

Also, if your other library uses Serial.print() hardcoded, you can try the following workaround.

cdupont commented 2 years ago

That is great, thanks!

jfjlaros commented 2 years ago

Note that I have only tested the host side on Linux, I don't expect it to work under any other OS, except maybe for macOS.