Libraries and firmware for OpenBCI Radio Modules.
The OpenBCI board has an on-board RFDuino radio module acting as a "Device". The OpenBCI system includes a USB dongle for the PC, which acts as the RFDuino "Host". The format of the OpenBCI data as seen on the PC is defined by a combination of the Arduino code on the OpenBCI board and of the RFDuino code running on the Host.
For a general discussion of the OpenBCI Radio firmware please refer to software section on the learning pages on openbci.com.
IMPORTANT: The channelNumber
will be stored into memory the first and only time from the begin()
function into memory. Why? As of firmware v2
channels can be changed over the air, that required us to retain the channel number during power cycle periods, i.e. turning the boards on and off. See our learning docs for the commands on how to change the channels over the air. Our main Processing GUI also contains tools to change channels along with a config utility just for this purpose.
For detailed installation and upload instructions please refer to our learning section on openbci.com.
Before we begin, let's declare there are two types of testing, functional and unit testing. The unit testing for this library uses the PTW-Arduino-Assert framework. The functional testing is completed with the OpenBCI_NodeJS libraries extensive automated testing that will functionally verify all components of the entire system.
This library is heavily dependent on automated testing. Thus this library uses the Push The World Arduino Test Framework which you must install to your libraries
folder in order to run the automated tests.
Contributions are more then welcomed, they are encouraged!
git checkout -b my-new-feature
git commit -m 'Add some feature'
git push origin my-new-feature
The function that the radio will call in setup()
mode - unint8_t
The mode the radio shall operate in, can be:
OPENBCI_MODE_DEVICE
- Radio operates in DEVICE
mode. Intended to be a RFduino on the OpenBCI Board when not in debug mode.OPENBCI_MODE_HOST
- Radio operates in HOST
mode. Intended to be an RFduino on an OpenBCI dongle.OPENBCI_MODE_PASS_THRU
- Pass through FTDI driver from Host to DeviceThe function that the radio will call in setup()
with radio channelNumber
. NOTE channelNumber
is stored to non-volatile memory! More about this in a couple lines.
mode - unint8_t
The mode the radio shall operate in, can be:
OPENBCI_MODE_DEVICE
- Radio operates in DEVICE
mode. Intended to be a RFduino on the OpenBCI Board when not in debug mode.OPENBCI_MODE_HOST
- Radio operates in HOST
mode. Intended to be an RFduino on an OpenBCI dongle.OPENBCI_MODE_PASS_THRU
- Pass through FTDI driver from Host to DevicechannelNumber - uint32_t
The channelNumber the RFduinoGZLL will use to communicate with the other RFduinoGZLL. NOTE can only be from 0
to 25
inclusive. Further, and this is really important channelNumber
will only be stored into memory on the first time this function is executed.
The function that the radio will call in setup()
with radio channelNumber
. This puts the system in dongle to dongle debug mode. During the development of this NOTE channelNumber
is stored to non-volatile memory! More about this in a couple lines.
mode - unint8_t
The mode the radio shall operate in, can be:
OPENBCI_MODE_DEVICE
- Radio operates in DEVICE
mode. Intended to be a RFduino on the OpenBCI Board when not in debug mode.OPENBCI_MODE_HOST
- Radio operates in HOST
mode. Intended to be an RFduino on an OpenBCI dongle.OPENBCI_MODE_PASS_THRU
- Pass through FTDI driver from Host to DevicechannelNumber - uint32_t
The channelNumber the RFduinoGZLL will use to communicate with the other RFduinoGZLL. NOTE can only be from 0
to 25
inclusive. Further, and this is really important channelNumber
will only be stored into memory on the first time this function is executed.
Moves bytes from StreamPacketBuffers to the main radio buffer.
buf - StreamPacketBuffer *
A buffer to read into the ring buffer
Used to fill the buffer with all zeros. Should be used as frequently as possible. This is very useful if you need to ensure that no bad data is sent over the serial port.
Called when all the packets have been received to flush the contents of the radio buffer to the serial port.
Used to flush any radio buffer that is ready to be flushed to the serial port. For now flushes just bufferRadio and bufferRadioBackUp on the Host.
Used to determine if there is data in the radio buffer. Most likely this data needs to be cleared.
Returns {boolean}
true
if the radio buffer has data, false
if not...
Used to reset the flags and positions of the radio buffer.
Stores a char to the serial buffer. Used by both the Device and the Host. Protects the system from buffer overflow.
newChar - {char}
The new char to store to the serial buffer.
Returns - {boolean}
true
if the new char was added to the serial buffer, false
if not.
If there are packets to be sent in the serial buffer.
Returns - {boolean}
true
if there are packets waiting to be sent from the serial buffer, false
if not...
Used to process the the serial buffer if the device fails to poll the host more than 3 * pollTime. This function should process the serial buffer for a Host channel change override and channel get request. Further this function should clear the serial buffer if there is anything inside it. In the special circumstances where the Host is waiting for either a channel change confirmation or a poll time change confirmation Should also revert to the pervious channel number
Function to clean (clear/reset) the bufferSerial.
n - uint8_t
The number of packets you want to clean, for example, on init, we would clean all packets, but on cleaning from the RFduinoGZLL_onReceive() we would only clean the number of packets actually used.
Based off the last time the serial port was read from, Determines if enough time has passed to qualify this data as a full serial page.
Returns - {boolean}
true
if enough time has passed, false
if not.
Process a char from the serial port on the Device. Enters the char into the stream state machine.
buf - StreamPacketBuffer *
The stream packet buffer to add the char to.
newChar - char
A new char to process.
Utility function to return true
if the the streamPacketBuffer is in the STREAM_STATE_READY. Normally used for determining if a stream packet is ready to be sent.
buf - StreamPacketBuffer *
The stream packet buffer to send to the Host.
Returns - {boolean}
true
is the buf
is in the ready state, false
otherwise.
Resets the first stream packet buffer to default settings.
Resets the stream packet buffer to default settings
buf - StreamPacketBuffer *
Pointer to a stream packet buffer to reset.
Sends the contents of the buf
to the HOST, sends as stream packet with the proper byteId.
buf - StreamPacketBuffer *
Pointer to a stream packet buffer to be sent to the Host.
Based off the last time the serial port was read from, Determines if enough time has passed to qualify this data as a stream packet.
Returns - {boolean}
true
if enough time has passed, false
if not.
The first line of defense against a system that has lost it's device. The timeout is 15ms longer than the longest poll time (255ms) possible.
Returns {boolean}
true
if enough time has passed since last poll, false
if not...
Private function to handle a request to read serial as a host
Returns {boolean}
true
if there is data to read, false
if not...
Used to reset the non-volatile memory back to it's factory state so the parameters in begin()
will be accepted.
Returns {boolean}
true
if the memory was successfully reset, false
if not...
Gets the channel number from non-volatile flash memory
Returns {uint32_t}
The channel number from non-volatile memory
Gets the poll time from non-volatile flash memory
Returns {uint32_t}
The poll time from non-volatile memory
Answers the question of if a packet is ready to be sent. need to check and there is no packet in the TX Radio Buffer, there are in fact packets to send and enough time has passed.
Returns {boolean}
true
if there is a packet ready to send on the Host
Used to flash the led to indicate to the user the device is in pass through mode.
Used to determine if there are packets in the serial buffer to be sent.
Returns {boolean}
true
if there are packets in the buffer and enough time has passed
Used to determine if there are packets in the serial buffer to be sent.
Returns {boolean}
true
if there are packets in the buffer
Reset the time since the last packet was sent to HOST. Very important with polling.
Writes to the serial port a message that matches a specific code.
code
_code_
{uint8_t} - The code to Serial.write().
HOST_MSG_COMMS_DOWN
- Print the comms down messageHOST_MESSAGE_COMMS_DOWN_CHAN
- Print the message when the comms when down trying to change channels.HOST_MESSAGE_COMMS_DOWN_POLL_TIME
- Print the message when the comms go down trying to change poll times.HOST_MSG_BAUD_FAST
- Baud rate switched to 230400HOST_MSG_BAUD_DEFAULT
- Baud rate switched to 115200HOST_MSG_BAUD_HYPER
- Baud rate switched to 921600HOST_MSG_SYS_UP
- Print the system up messageHOST_MSG_SYS_DOWN
- Print the system down messageHOST_MSG_CHAN
- Print the channel number messageHOST_MSG_CHAN_OVERRIDE
- Print the host over ride messageHOST_MSG_CHAN_VERIFY
- Print the need to verify the channel number you inputed messageHOST_MSG_CHAN_GET_FAILURE
- The message to print when there is a comms timeout and to print just the Host channel number.HOST_MSG_CHAN_GET_SUCCESS
- The message to print when the Host and Device are communicating.HOST_MSG_POLL_TIME
- Prints the poll time when there is no comms.HOST_MESSAGE_SERIAL_ACK
- Writes a serial ack (',') to the Driver/PCEntered from RFduinoGZLL_onReceive if the Device receives a packet of length greater than 1.
data - {volatile char * }
The data buffer to process.
len - {int}
The length of data
Returns - {boolean}
true
if there is a packet to send to the Host.
Entered from RFduinoGZLL_onReceive
if the Host receives a packet of length greater than 1.
device - {device_t}
The device that sent a packet to the Host.
data - {volatile char * }
The data buffer to process.
len - {int}
The length of data
Returns - {boolean}
true
if there is a packet to send to the Device.
Used to process a single char message received on the Device radio aka a private radio message. See OpenBCI_Radios_Definitions.h
for a full list of ORPM
s.
newChar - {char}
The char to be read in.
Returns - {boolean}
true
if a packet should be sent from the serial buffer.
Used to process a single char message received on the Host radio aka a private radio message. See OpenBCI_Radios_Definitions.h
for a full list of ORPM
s.
newChar - {char}
The char to be read in.
Returns - {boolean}
true
if a packet should be sent from the serial buffer.
Sends a soft reset command to the Pic 32 incase of an emergency.
Called from Host's RFduinoGZLL_onReceive
if a packet will be sent.
device - {device_t}
The device to send the packet to.
Called from Devices to send a packet to Host. Uses global variables to send the correct packet.
Returns - {int}
The packet number sent.
Sends a null byte to the host.
Used to see if enough time has passed since the last serial read. Useful to if a serial transmission from the PC/Driver has concluded.
Returns - {boolean}
true
if enough time has passed.