Open RTS
Full implementation of the Somfy RTS protocol
|
Core C library. More...
Data Structures | |
struct | rts_frame |
Represents the message "payload" sent by RTS remote controls. More... | |
struct | rts_frame_builder |
Assembles pulses received via rts_frame_builder_handle_pulse, into a complete rts_frame, and delivers them to the user-provided callback. More... | |
struct | rts_pulse_output |
Provides an interface for an output of RTS pulses, eg a GPIO or radio. More... | |
struct | rts_pulse_source |
Provides an interface for a source of RTS pulses, eg a GPIO or radio. More... | |
struct | rts_radio |
Abstraction layer which configures radio modules for RTS. More... | |
struct | rts_receiver |
Simulates a physical RTS receiver device, such as a shade or drapery motor. More... | |
struct | rts_remote |
Simulates a physical RTS remote control. More... | |
struct | rts_remote_store |
Provides an interface for a datastore which contains details about remote controls and rolling codes. More... | |
struct | rts_timings |
Timing definitions for encoding and decoding frames to pulses. More... | |
Enumerations | |
enum | rts_command { RTS_COMMAND_MY = 0x1 , RTS_COMMAND_UP = 0x2 , RTS_COMMAND_MY_UP = 0x3 , RTS_COMMAND_DOWN = 0x4 , RTS_COMMAND_MY_DOWN = 0x5 , RTS_COMMAND_UP_DOWN = 0x6 , RTS_COMMAND_MY_UP_DOWN = 0x7 , RTS_COMMAND_PROG = 0x8 , RTS_COMMAND_SUN_FLAG = 0x9 , RTS_COMMAND_FLAG = 0xA } |
Command sent by a remote, or received by a receiver as part of an rts_frame event. More... | |
enum | rts_radio_mode { RTS_RADIO_MODE_STANDBY , RTS_RADIO_MODE_RECEIVE , RTS_RADIO_MODE_TRANSMIT } |
The transceiver mode to enter. More... | |
enum | rts_receiver_event { RTS_RECEIVER_EVENT_NONE , RTS_RECEIVER_EVENT_PRESS , RTS_RECEIVER_EVENT_HOLD , RTS_RECEIVER_EVENT_HOLD_2 , RTS_RECEIVER_EVENT_HOLD_3 } |
De-duplicated "frame" events. More... | |
enum | rts_receiver_mode { RTS_RECEIVER_MODE_OFF , RTS_RECEIVER_MODE_PROGRAMMING , RTS_RECEIVER_MODE_COMMAND } |
Receiver modes. More... | |
Functions | |
const char * | rts_command_to_string (enum rts_command command) |
Get a string representation of the given rts_command. | |
void | rts_pulse_output_init_espidf_gpio (struct rts_pulse_output *pulse_output, uint8_t data_pin) |
Initialize an rts_pulse_output which sends pulses to the specified ESP-IDF GPIO pin. | |
void | rts_pulse_source_init_espidf_gpio (struct rts_pulse_source *pulse_source, uint8_t data_pin) |
Initialize an rts_pulse_source which receives pulses from the specified ESP-IDF GPIO pin. | |
void | rts_remote_store_init_nvs (struct rts_remote_store *store) |
Initialize an rts_remote_store which stores remotes and rolling codes in ESP-IDF's NVS (Non-volatile storage) on ESP8266 and ESP32 devices. | |
void | rts_pulse_output_init_gpiod (struct rts_pulse_output *pulse_output, char *device, uint8_t data_pin) |
Initialize an rts_pulse_output which sends pulses to the specified Linux gpiod device. | |
void | rts_pulse_source_init_gpiod (struct rts_pulse_source *pulse_source, char *device, uint8_t data_pin) |
Initialize an rts_pulse_source which receives pulses from the specified Linux gpiod device. | |
void | rts_remote_store_init_mmap (struct rts_remote_store *store, const char *filename) |
Initialize an rts_remote_store which stores remotes and rolling codes in a memory-mapped file on POSIX systems. | |
void | rts_frame_init (struct rts_frame *frame, enum rts_command command, uint16_t rolling_code, uint32_t remote_address) |
Initialize an rts_frame with typical payload. | |
void | rts_frame_from_bytes (struct rts_frame *frame, const uint8_t *bytes) |
Initialize an rts_frame from the raw (deobfuscated) bytes received. | |
void | rts_frame_to_bytes (struct rts_frame *frame, uint8_t *bytes, bool obfuscate) |
Convert an rts_frame to byte representation, and optionally apply XOR obfuscation to make it ready to send. | |
void | rts_frame_obfuscate_bytes (uint8_t *bytes) |
Apply in-place XOR obfuscation to a raw byte array representation of a frame. | |
void | rts_frame_deobfuscate_bytes (uint8_t *dest, const uint8_t *src) |
Apply XOR deobfuscation to a raw byte array representation of a frame. | |
uint8_t | rts_frame_generate_checksum (const uint8_t *bytes) |
Generate a checksum for the raw (deobfuscated) bytes of a frame. | |
void | rts_frame_builder_init (struct rts_frame_builder *builder, struct rts_timings *timings) |
Initialize an rts_frame_builder with the specified timings. | |
void | rts_frame_builder_handle_pulse (struct rts_frame_builder *builder, bool state, uint32_t micros) |
Inform the frame builder about a new pulse. | |
void | rts_frame_builder_set_callback (struct rts_frame_builder *builder, void(*callback)(struct rts_frame *frame, uint8_t count, uint32_t duration, void *user_data), void *user_data) |
Set a callback to call when new complete frames are received. | |
void | rts_pulse_output_enable (struct rts_pulse_output *pulse_output) |
Enable the pulse output. | |
void | rts_pulse_output_disable (struct rts_pulse_output *pulse_output) |
Disable the pulse output. | |
void | rts_pulse_output_send_pulse (struct rts_pulse_output *pulse_output, bool state, uint32_t micros) |
Instruct the rts_pulse_output to output a pulse. | |
void | rts_pulse_output_close (struct rts_pulse_output *pulse_output) |
Close and free resources allocated via a previous call to rts_pulse_output_init_*() | |
void | rts_pulse_source_enable (struct rts_pulse_source *pulse_source) |
Enable the pulse source. | |
void | rts_pulse_source_disable (struct rts_pulse_source *pulse_source) |
Disable the pulse source. | |
void | rts_pulse_source_update (struct rts_pulse_source *pulse_source) |
Check for new pulse data, should be called every loop() | |
void | rts_pulse_source_attach (struct rts_pulse_source *pulse_source, struct rts_frame_builder *frame_builder) |
Attach an observer. | |
void | rts_pulse_source_close (struct rts_pulse_source *pulse_source) |
Close and free any resources allocated via a previous call to rts_pulse_source_init_*() | |
struct rfm69 * | rts_radio_init_rfm69 (struct rts_radio *radio, struct spi_module *spi) |
Initialize an rts_radio to use an SX1231/RFM69 radio module. | |
struct sx1278 * | rts_radio_init_sx1278 (struct rts_radio *radio, struct spi_module *spi) |
Initialize an rts_radio to use an SX1278/RFM96 radio module. | |
void | rts_radio_set_mode (struct rts_radio *radio, enum rts_radio_mode mode) |
Set the radio mode for the specified rts_radio module, eg. | |
void | rts_receiver_init (struct rts_receiver *receiver, struct rts_pulse_source *pulse_source, struct rts_remote_store *remote_store) |
Initialize an rts_receiver. | |
void | rts_receiver_set_frame_callback (struct rts_receiver *receiver, void(*callback)(enum rts_receiver_event, struct rts_frame *frame, void *user_data), void *user_data) |
Set a callback function to call when new receiver events are received. | |
void | rts_receiver_set_mode_callback (struct rts_receiver *receiver, void(*callback)(enum rts_receiver_mode, void *user_data), void *user_data) |
Set a callback function to call when the receiver mode changes. | |
void | rts_receiver_set_mode (struct rts_receiver *receiver, uint8_t mode) |
Change the receiver mode. | |
void | rts_receiver_forget_all_remotes (struct rts_receiver *receiver) |
Convenience function to forget all paired remotes by clearing the receiver's rts_remote_store. | |
void | rts_receiver_update (struct rts_receiver *receiver) |
Instruct the receiver's rts_pulse_source to check for new pulse data, should be called every loop() if the pulse source does not keep itself updated (eg. | |
void | rts_remote_init (struct rts_remote *remote, struct rts_pulse_output *pulse_output, struct rts_remote_store *remote_store, struct rts_timings *timings) |
Initialize the rts_remote struct. | |
void | rts_remote_send_command (struct rts_remote *remote, uint32_t address, enum rts_command command, bool repeated) |
Send a "button press" command. | |
void | rts_remote_send_frame (struct rts_remote *remote, struct rts_frame *frame, bool repeated) |
Send an RTS frame. | |
void | rts_remote_send_pulse (struct rts_remote *remote, bool state, uint32_t micros) |
Send a single pulse to the internal rts_pulse_output. | |
void | rts_remote_store_set_code (struct rts_remote_store *store, uint32_t remote_address, uint16_t rolling_code) |
Set the rolling code for this remote, create if doesn't exist. | |
uint16_t | rts_remote_store_get_code (struct rts_remote_store *store, uint32_t remote_address) |
Get the rolling code for this remote. | |
uint16_t | rts_remote_store_next_code (struct rts_remote_store *store, uint32_t remote_address) |
Get the rolling code for this remote, then increment and persist. | |
bool | rts_remote_store_known_remote (struct rts_remote_store *store, uint32_t remote_address) |
Check if this is a known remote address. | |
void | rts_remote_store_forget (struct rts_remote_store *store, uint32_t remote_address) |
Forget a specific remote. | |
void | rts_remote_store_clear (struct rts_remote_store *store) |
Clear all remotes and rolling codes. | |
void | rts_remote_store_close (struct rts_remote_store *store) |
Close and free any resources allocated via a previous call to rts_remote_store_init*() | |
void | rts_remote_store_init_memory (struct rts_remote_store *store) |
Initialize an rts_remote_store which stores remotes and rolling codes in memory. | |
Variables | |
struct rts_timings | RTS_TIMINGS_SITUO5 |
Timings as measured from a physical Situio5 remote. | |
struct rts_timings * | RTS_TIMINGS_DEFAULT |
Default timings, suitable for most application. | |
Core C library.
enum rts_command |
Command sent by a remote, or received by a receiver as part of an rts_frame event.
Commands reflect buttons on a remote, eg "Up", "Down", "My", or certain combinations of button presses.
enum rts_radio_mode |
enum rts_receiver_event |
De-duplicated "frame" events.
enum rts_receiver_mode |
const char * rts_command_to_string | ( | enum rts_command | command | ) |
Get a string representation of the given rts_command.
command | the rts_command to convert |
|
related |
Initialize an rts_pulse_output which sends pulses to the specified ESP-IDF GPIO pin.
pulse_output | the rts_pulse_output struct to initialize |
data_pin | the GPIO pin number to output pulses to |
|
related |
Initialize an rts_pulse_source which receives pulses from the specified ESP-IDF GPIO pin.
pulse_source | the rts_pulse_source struct to initialize |
data_pin | the GPIO pin to monitor |
|
related |
Initialize an rts_remote_store which stores remotes and rolling codes in ESP-IDF's NVS (Non-volatile storage) on ESP8266 and ESP32 devices.
store | the rts_remote_store struct to initialize |
|
related |
Initialize an rts_pulse_output which sends pulses to the specified Linux gpiod device.
OPENRTS_HAS_GPIOD
macrosudo apt install libgpiod-dev
-lgpiod
)pulse_output | the rts_pulse_output struct to initialize |
device | the device file to use with gpiod, eg "/dev/gpiochip0" |
data_pin | the GPIO offset to output to, typically the GPIO pin number |
|
related |
Initialize an rts_pulse_source which receives pulses from the specified Linux gpiod device.
OPENRTS_HAS_GPIOD
macrosudo apt install libgpiod-dev
-lgpiod
)pulse_source | the rts_pulse_source struct to initialize |
device | the device file to use with gpiod, eg "/dev/gpiochip0" |
data_pin | the GPIO offset to monitor, typically the GPIO pin number |
|
related |
Initialize an rts_remote_store which stores remotes and rolling codes in a memory-mapped file on POSIX systems.
store | the rts_remote_store struct to initialize |
filename | the path of the filename to store remote data |
|
related |
Initialize an rts_frame with typical payload.
We'll generate a sensible encryption_key automatically.
frame | the frame to initialize |
command | the rts_command |
rolling_code | the rolling code |
remote_address | the remote address |
|
related |
Initialize an rts_frame from the raw (deobfuscated) bytes received.
frame | the frame to initialize |
bytes | the raw frame bytes to construct from |
|
related |
Convert an rts_frame to byte representation, and optionally apply XOR obfuscation to make it ready to send.
frame | the frame to convert |
bytes | the byte array to store the result in |
obfuscate | should we also apply obfuscation to the bytes |
|
related |
Apply in-place XOR obfuscation to a raw byte array representation of a frame.
bytes | the raw frame bytes to obfuscate |
|
related |
Apply XOR deobfuscation to a raw byte array representation of a frame.
dest | the destination byte array for the deobfuscated frame bytes |
src | the raw frame bytes to deobfuscate |
|
related |
Generate a checksum for the raw (deobfuscated) bytes of a frame.
Checksum for a valid frame is 0.
bytes | the raw deobfuscated frame bytes to check |
|
related |
Initialize an rts_frame_builder with the specified timings.
builder | the rts_frame_builder struct to initialize |
timings | the rts_timings struct to use for pulse decoding |
|
related |
Inform the frame builder about a new pulse.
This is typically called from an rts_pulse_source that has been attached using rts_pulse_source_attach.
builder | the rts_frame_builder struct |
state | boolean pulse logic state, true = HIGH, false = LOW |
micros | the time the pulse was in this state, in microseconds |
|
related |
Set a callback to call when new complete frames are received.
builder | the rts_frame_builder struct |
callback | the callback to fire |
user_data | optional custom user data pointer, will be included as the last parameter when callback is fired |
|
related |
Enable the pulse output.
pulse_output | the rts_pulse_output struct to enable |
|
related |
Disable the pulse output.
pulse_output | the rts_pulse_output struct to disable |
|
related |
Instruct the rts_pulse_output to output a pulse.
pulse_output | the rts_pulse_output struct |
state | boolean pulse logic state, true = HIGH, false = LOW |
micros | the time the pulse was in this state, in microseconds |
|
related |
Close and free resources allocated via a previous call to rts_pulse_output_init_*()
pulse_output | the rts_pulse_output to close |
|
related |
Enable the pulse source.
pulse_source | the rts_pulse_source struct to enable |
|
related |
Disable the pulse source.
pulse_source | the rts_pulse_source struct to disable |
|
related |
Check for new pulse data, should be called every loop()
pulse_source | the rts_pulse_source struct to update |
|
related |
Attach an observer.
pulse_source | the rts_pulse_source to be observed |
frame_builder | the rts_frame_builder observing this source. |
|
related |
Close and free any resources allocated via a previous call to rts_pulse_source_init_*()
pulse_source | the rts_pulse_source to close |
|
related |
|
related |
|
related |
|
related |
Initialize an rts_receiver.
receiver | the rts_receiver struct to initialize |
pulse_source | the rts_pulse_source to receive pulses from |
remote_store | the rts_remote_store to persist paired remotes to |
|
related |
Set a callback function to call when new receiver events are received.
receiver | the rts_receiver struct to set callback on |
callback | the callback function to call when new frame events are received. Frame events are fired after RTS frames are parsed and deduplicated. |
user_data | optional user_data pointer to pass to every callback. Set to NULL if not using. |
|
related |
Set a callback function to call when the receiver mode changes.
receiver | the rts_receiver struct to set callback on |
callback | the callback function to call when the mode changes |
user_data | optional user_data pointer top pass to every callback. Set to NULL if not using. |
|
related |
Change the receiver mode.
Receivers can be either "off", in "programming" mode or "command" mode.
receiver | the rts_receiver struct to change the mode of |
mode | the rts_receiver_mode to change to |
|
related |
Convenience function to forget all paired remotes by clearing the receiver's rts_remote_store.
receiver | the rts_receiver struct to forget remotes for |
|
related |
Instruct the receiver's rts_pulse_source to check for new pulse data, should be called every loop() if the pulse source does not keep itself updated (eg.
using interrupts).
receiver | the rts_receiver struct to update |
|
related |
Initialize the rts_remote struct.
remote | the rts_remote struct to initialize |
pulse_output | where to send pulses to |
remote_store | where to get/set remote rolling codes |
timings | the rts_timings struct to use for pulse encoding |
|
related |
Send a "button press" command.
This is the simplest way to use an rts_remote, which automatically creates an rts_frame struct under the hood, and handles the incrementing of rolling codes in the internal rts_remote_store.
The generated rts_frame is passed to rts_remote_send_frame.
remote | the rts_remote struct |
address | the remote address to send from |
command | the rts command to send (see rts_command enum) |
repeated | is this a "repeated" command, eg. from a button being held down? If so we won't increment the remote's rolling code |
|
related |
Send an RTS frame.
This function converts the provided rts_frame into a series of pulses, which are passed along to the internal rts_pulse_output by rts_remote_send_pulse.
remote | the rts_remote struct |
frame | the rts_frame to send |
repeated | is this a "repeated" command, eg. from a button being held down? If so we won't increment the remote's rolling code |
|
related |
Send a single pulse to the internal rts_pulse_output.
remote | the rts_remote struct |
state | boolean pulse logic state, true = HIGH, false = LOW |
micros | how long to set the pulse to this state, in microseconds |
|
related |
Set the rolling code for this remote, create if doesn't exist.
store | the rts_remote_store struct to set the code to |
remote_address | the address of the remote control |
rolling_code | the rolling code to set |
|
related |
Get the rolling code for this remote.
store | the rts_remote_store struct to get the code from |
remote_address | the address of the remote control |
|
related |
Get the rolling code for this remote, then increment and persist.
store | the rts_remote_store struct to get the code from |
remote_address | the address of the remote control |
|
related |
Check if this is a known remote address.
store | the rts_remote_store struct to check in |
remote_address | the address of the remote control |
|
related |
Forget a specific remote.
store | the rts_remote_store struct |
remote_address | the address of the remote control to forget |
|
related |
Clear all remotes and rolling codes.
store | the rts_remote_store struct to clear |
|
related |
Close and free any resources allocated via a previous call to rts_remote_store_init*()
store | the rts_remote_store to close |
|
related |
Initialize an rts_remote_store which stores remotes and rolling codes in memory.
store | the rts_remote_store struct to initialize |