1 #include <twr_radio_node.h>
3 __attribute__((weak))
void twr_radio_node_on_state_set(uint64_t *
id, uint8_t state_id,
bool *state) { (void)
id; (void) state_id; (void) state; }
4 __attribute__((weak))
void twr_radio_node_on_state_get(uint64_t *
id, uint8_t state_id) { (void)
id; (void) state_id; }
5 __attribute__((weak))
void twr_radio_node_on_buffer(uint64_t *
id,
void *buffer,
size_t length) { (void)
id; (void) buffer; (void) length; }
6 __attribute__((weak))
void twr_radio_node_on_led_strip_color_set(uint64_t *
id, uint32_t *color) { (void)
id; (void) color; }
7 __attribute__((weak))
void twr_radio_node_on_led_strip_brightness_set(uint64_t *
id, uint8_t *brightness) { (void)
id; (void) brightness; }
8 __attribute__((weak))
void twr_radio_node_on_led_strip_compound_set(uint64_t *
id, uint8_t *compound,
size_t length) { (void)
id; (void) compound; (void) length; }
9 __attribute__((weak))
void twr_radio_node_on_led_strip_effect_set(uint64_t *
id, twr_radio_node_led_strip_effect_t type, uint16_t wait, uint32_t *color) { (void)
id; (void) type; (void) wait; (void) color; }
10 __attribute__((weak))
void twr_radio_node_on_led_strip_thermometer_set(uint64_t *
id,
float *temperature, int8_t *min, int8_t *max, uint8_t *white_dots,
float *set_point, uint32_t *set_point_color) { (void)
id; (void) temperature; (void) min; (void) max; (void) white_dots; (void) set_point; (void) set_point_color; }
15 uint8_t buffer[1 + TWR_RADIO_ID_SIZE +
sizeof(state_id) +
sizeof(*state)];
17 buffer[0] = TWR_RADIO_HEADER_NODE_STATE_SET;
19 uint8_t *pbuffer = twr_radio_id_to_buffer(
id, buffer + 1);
21 pbuffer[0] = state_id;
23 twr_radio_bool_to_buffer(state, pbuffer + 1);
25 return twr_radio_pub_queue_put(buffer,
sizeof(buffer));
30 uint8_t buffer[1 + TWR_RADIO_ID_SIZE +
sizeof(state_id)];
32 buffer[0] = TWR_RADIO_HEADER_NODE_STATE_GET;
34 uint8_t *pbuffer = twr_radio_id_to_buffer(
id, buffer + 1);
36 pbuffer[0] = state_id;
38 return twr_radio_pub_queue_put(buffer,
sizeof(buffer));
43 uint8_t qbuffer[1 + TWR_RADIO_ID_SIZE + TWR_RADIO_NODE_MAX_BUFFER_SIZE];
45 if (length > TWR_RADIO_NODE_MAX_BUFFER_SIZE)
50 qbuffer[0] = TWR_RADIO_HEADER_NODE_BUFFER;
51 twr_radio_id_to_buffer(
id, qbuffer + 1);
53 memcpy(qbuffer + 1 + TWR_RADIO_ID_SIZE, buffer, length);
55 return twr_radio_pub_queue_put(qbuffer, length + 1 + TWR_RADIO_ID_SIZE);
60 uint8_t buffer[1 + TWR_RADIO_ID_SIZE +
sizeof(color)];
62 buffer[0] = TWR_RADIO_HEADER_NODE_LED_STRIP_COLOR_SET;
64 uint8_t *pbuffer = twr_radio_id_to_buffer(
id, buffer + 1);
66 twr_radio_data_to_buffer(&color,
sizeof(color), pbuffer);
68 return twr_radio_pub_queue_put(buffer,
sizeof(buffer));
73 uint8_t buffer[1 + TWR_RADIO_ID_SIZE +
sizeof(brightness)];
75 buffer[0] = TWR_RADIO_HEADER_NODE_LED_STRIP_BRIGHTNESS_SET;
77 uint8_t *pbuffer = twr_radio_id_to_buffer(
id, buffer + 1);
79 pbuffer[0] = brightness;
81 return twr_radio_pub_queue_put(buffer,
sizeof(buffer));
86 if ((length > TWR_RADIO_NODE_MAX_BUFFER_SIZE) || (length % 5 != 0))
91 uint8_t buffer[1 + TWR_RADIO_ID_SIZE + TWR_RADIO_NODE_MAX_BUFFER_SIZE];
93 buffer[0] = TWR_RADIO_HEADER_NODE_LED_STRIP_COMPOUND_SET;
95 uint8_t *pbuffer = twr_radio_id_to_buffer(
id, buffer + 1);
97 twr_radio_data_to_buffer(compound, length, pbuffer);
99 return twr_radio_pub_queue_put(buffer, 1 + TWR_RADIO_ID_SIZE + length);
104 uint8_t buffer[1 + TWR_RADIO_ID_SIZE + 1 +
sizeof(uint16_t) +
sizeof(uint32_t)];
106 buffer[0] = TWR_RADIO_HEADER_NODE_LED_STRIP_EFFECT_SET;
108 uint8_t *pbuffer = twr_radio_id_to_buffer(
id, buffer + 1);
112 *pbuffer++ = (uint16_t) wait;
113 *pbuffer++ = (uint16_t) wait >> 8;
115 twr_radio_data_to_buffer(&color,
sizeof(color), pbuffer);
117 return twr_radio_pub_queue_put(buffer,
sizeof(buffer));
122 uint8_t buffer[1 + TWR_RADIO_ID_SIZE +
sizeof(float) +
sizeof(int8_t) +
sizeof(int8_t) +
sizeof(uint8_t) +
sizeof(float) +
sizeof(uint32_t)];
124 buffer[0] = TWR_RADIO_HEADER_NODE_LED_STRIP_THERMOMETER_SET;
126 uint8_t *pbuffer = twr_radio_id_to_buffer(
id, buffer + 1);
128 pbuffer = twr_radio_float_to_buffer(&temperature, pbuffer);
134 *pbuffer++ = white_dots;
136 if ((set_point == NULL) || isnan(*set_point) || *set_point == TWR_RADIO_NULL_FLOAT)
138 return twr_radio_pub_queue_put(buffer,
sizeof(buffer) -
sizeof(
float) -
sizeof(uint32_t));
141 pbuffer = twr_radio_float_to_buffer(set_point, pbuffer);
143 pbuffer = twr_radio_data_to_buffer(&set_point_color,
sizeof(uint32_t), pbuffer);
145 return twr_radio_pub_queue_put(buffer,
sizeof(buffer));
154 if (length < TWR_RADIO_ID_SIZE + 1)
159 uint8_t *pbuffer = buffer + 1 + TWR_RADIO_ID_SIZE;
160 length = length - 1 - TWR_RADIO_ID_SIZE;
162 if (buffer[0] == TWR_RADIO_HEADER_NODE_STATE_SET)
167 twr_radio_bool_from_buffer(pbuffer + 1, &state, &pstate);
168 twr_radio_id_from_buffer(buffer + 1, &for_id);
169 twr_radio_node_on_state_set(&for_id, pbuffer[0], pstate);
171 else if (buffer[0] == TWR_RADIO_HEADER_NODE_STATE_GET)
173 twr_radio_id_from_buffer(buffer + 1, &for_id);
174 twr_radio_node_on_state_get(&for_id, pbuffer[0]);
176 else if (buffer[0] == TWR_RADIO_HEADER_NODE_BUFFER)
178 twr_radio_node_on_buffer(
id, pbuffer, length);
180 else if (buffer[0] == TWR_RADIO_HEADER_NODE_LED_STRIP_COLOR_SET)
184 twr_radio_data_from_buffer(pbuffer, &color,
sizeof(color));
186 twr_radio_node_on_led_strip_color_set(
id, &color);
188 else if (buffer[0] == TWR_RADIO_HEADER_NODE_LED_STRIP_BRIGHTNESS_SET)
190 twr_radio_node_on_led_strip_brightness_set(
id, pbuffer);
192 else if (buffer[0] == TWR_RADIO_HEADER_NODE_LED_STRIP_COMPOUND_SET)
194 twr_radio_node_on_led_strip_compound_set(
id, pbuffer, length);
196 else if (buffer[0] == TWR_RADIO_HEADER_NODE_LED_STRIP_EFFECT_SET)
198 twr_radio_node_led_strip_effect_t type = (twr_radio_node_led_strip_effect_t) *pbuffer++;
200 uint16_t wait = (uint16_t) *pbuffer++;
201 wait |= (uint16_t) *pbuffer++ >> 8;
205 twr_radio_data_from_buffer(pbuffer, &color,
sizeof(color));
207 twr_radio_node_on_led_strip_effect_set(
id, type, wait, &color);
209 else if (buffer[0] == TWR_RADIO_HEADER_NODE_LED_STRIP_THERMOMETER_SET)
214 float *pset_point = NULL;
217 pbuffer = twr_radio_float_from_buffer(pbuffer, &temperature, &ptemperature);
218 int8_t *min = (int8_t *) pbuffer;
219 int8_t *max = (int8_t *) pbuffer + 1;
220 uint8_t *white_dots = (uint8_t *) pbuffer + 2;
222 if (length ==
sizeof(
float) +
sizeof(int8_t) +
sizeof(int8_t) +
sizeof(uint8_t) +
sizeof(
float) +
sizeof(uint32_t))
224 pbuffer = twr_radio_float_from_buffer(pbuffer + 3, &set_point, &pset_point);
226 twr_radio_data_from_buffer(pbuffer, &color,
sizeof(color));
229 twr_radio_node_on_led_strip_thermometer_set(
id, ptemperature, min, max, white_dots, pset_point, &color);
bool twr_radio_node_state_set(uint64_t *id, uint8_t state_id, bool *state)
Send request for set new state.
bool twr_radio_node_led_strip_effect_set(uint64_t *id, twr_radio_node_led_strip_effect_t type, uint16_t wait, uint32_t color)
Send data to node.
bool twr_radio_node_buffer(uint64_t *id, void *buffer, size_t length)
Send data to node.
bool twr_radio_node_led_strip_compound_set(uint64_t *id, uint8_t *compound, size_t length)
Send data to node.
bool twr_radio_node_state_get(uint64_t *id, uint8_t state_id)
Send request for get actual state.
bool twr_radio_node_led_strip_color_set(uint64_t *id, uint32_t color)
Send data to node.
void twr_radio_node_decode(uint64_t *id, uint8_t *buffer, size_t length)
Internal decode function for twr_radio.c.
bool twr_radio_node_led_strip_brightness_set(uint64_t *id, uint8_t brightness)
Send data to node.
bool twr_radio_node_led_strip_thermometer_set(uint64_t *id, float temperature, int8_t min, int8_t max, uint8_t white_dots, float *set_point, uint32_t set_point_color)
Send data to node.