injecting data into hardware serial


I'm facing quite a challenge.

I have a couple of Mega 2560s with RFM22 SparkFun RFM22 Shield - 434MHz - DEV-11018 - SparkFun Electronics 433Mhz radio shields on top of each.
I've established a serial bridge between the two - easy.

Now, it gets complicated then I'm trying to use serial event libraries, like CmdMessenger (GitHub - dreamcat4/CmdMessenger2: Fork of Neil Dudman's CmdMessenger. Serial messaging system for Arduino platform) or it's light weight version - SerialCommand (A Minimal Arduino Library for Processing Serial Commands – The inability to follow simple instructions)

Since RFM22 operates on SPI bus, serial events aren't processed, meaning radio packets bypass Hardware Serial library.

I wonder how difficult would it be to programatically inject every byte received from RFM22 chip (rf22.recvfrom()) into Hardware Serial's rx_buffer?
It looks like HardwareSerial.ccp doesn't have any public variables/methods to enable manipulation of the rx_buffer (Google Code Archive - Long-term storage for Google Code Project Hosting.)

I've currently physically interconnected Mega's Serial1->Serial0, and am writing RFM22 packets into Serial1, what fills Serial0 buffer and makes Serial event libraries to work, but that's a poor-man's approach

Any advices are welcome

I think you're screwed unless you modify HardwareSerial.cpp because all the variables you need are private.

Either that or write your own version and work directly with the UART.


I think it would be a lot simpler to clone the library that uses serial events and reads from the hardware serial buffer, to use different type(s) of events (that you generate) and reads from a buffer that you manage (containing radio data).

Did you ever find the solution to this problem? I’m trying to do pretty much the same thing and running into the same problem.

From what I’ve read I suspect it could be done by setting up a Stream to bridge between the radio library (which outputs a String) and the CmdMessenger library but I haven’t worked out how to do that yet.