Class: TEF::FurComs::Serial
- Includes:
- XasLogger::Mix
- Defined in:
- lib/tef/furcoms/serial.rb
Overview
This class provides limited FurComs compatibility. Arbitration handling is not possible, which may cause frequent collisions in busy bus conditions. It is recommended to use a STM32 processor that provides translation between FurComs and the computer.
USB-To-Serial FurComs Bridge.
This class will handle connecting to a FurComs bus using a standard USB-To-UART adapter, such as an FTDI-Chip, in order to send and receive messages.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(port = '/dev/ttyACM0', baudrate = 115_200) ⇒ Serial
constructor
Initialize a Serial bridge class.
-
#send_message(topic, message, priority: 0, chip_id: 0) ⇒ Object
Send a message to the FurComs bus.
Methods inherited from Base
Constructor Details
#initialize(port = '/dev/ttyACM0', baudrate = 115_200) ⇒ Serial
Add graceful handling of controller disconnect/reconnect.
This class can not provide full arbitration handling. This may cause issues in busy bus conditions!
Initialize a Serial bridge class.
This will open the given Serial port and begin reading/writing onto the FurComs bus.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tef/furcoms/serial.rb', line 29 def initialize(port = '/dev/ttyACM0', baudrate = 115_200) super(); @port = SerialPort.new(port); @port.baud = baudrate; @port.sync = true; start_thread(); init_x_log("FurComs #{port}") x_logi('Ready!'); end |
Instance Method Details
#send_message(topic, message, priority: 0, chip_id: 0) ⇒ Object
Send a message to the FurComs bus.
This will send a message onto topic, using the given priority and chip_id (defaulting both to 0).
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/tef/furcoms/serial.rb', line 119 def (topic, , priority: 0, chip_id: 0) unless topic =~ /^[\w\s\/]*$/ raise ArgumentError, 'Topic includes invalid characters!' end if (topic.length + .length) > 250 raise ArgumentError, 'Message packet length exceeded!' end x_logd("Sending '#{topic}': '#{}'") escaped_str = slip_encode_data "#{topic}\0#{}" out_data = priority, chip_id, escaped_str; @port.write(out_data.pack('C2S<C*')) @port.flush end |