There are 3 micro-controller boards based on the STM32F105.
I have already configured the 64-pin devices with STM32CUBEMX.
Each has 2 DIP switches for ID and 2 DIP switches for RS232 receive / transmit speed (Only used on #1 & #3). #1 communicates with #2 via a variable baud rate RS485 / CAN (Driver only, not the protocol!). #2 communicates with #3 also via RS485 or CAN transceivers. During the initialization, #1 & #2 determine the maximum speed that the 100m cable can support reliably. Similarly, #2 & #3 determine their maximum reliable communication speed on their 200m cable.
Micro-controller #1 receives a string via RS232.
It also has 2 Pulse Inputs.
It encodes the Characters in the String, combined with the State of the 2 Pulse Inputs.
It transmits via RS-485 / CAN transceiver the encoded 7-bit word via #2 to #3 where it is decoded. During "unused frames on the 2 RS485 / CAN links, only frames are sent with the Pulse Status. #3 re-outputs the string and re-generated the pulses.
In the beginning the sending station and receiving station try different baud rates (not necessarily standard ones!) to determine the fastest reliable speed on the twisted pair using RS485 or CAN transceivers. If errors occur, the RS485 / CAN speed is reduced.
The Encode / Decode is already done, and there is sample code for the RS485 control pin. I basically need it all knitted together....
I have done projects with rs232 and rs485 protocols. If You use CAN driver without protocol, I suggest use pure RS485. Speed auto configuration would be made using error codes. If bit error has been detected speed would be reduced.