7#include "cueos_config.h"
30static uint8_t _i_to_len(uint16_t i){
31 return floor(log10((
double)i) + 1);
40static uint8_t _roundup_4(uint8_t val){
41 return ((val + 4 - 1) / 4) * 4;
51static void _osc_packet_cat(
OSC_packet_s *osc_packet,
const void *data,
size_t size){
52 memmove(osc_packet->
sp, data, size);
53 osc_packet->
sp += size;
62static void _osc_packet_roundup4(
OSC_packet_s *osc_packet){
64 uint8_t cur_size = osc_packet->
sp - osc_packet->
data;
65 uint8_t new_size = _roundup_4(cur_size);
67 for(
size_t i=0; i<(new_size - cur_size);i++){
68 _osc_packet_cat(osc_packet, OSC_PACKET_NULL_CHAR, 1);
82static void _osc_server_receive(
void *arg,
struct udp_pcb *pcb,
struct pbuf *p,
const ip_addr_t *addr, u16_t port){
102 osc_server.
_pcb = udp_new();
103 udp_bind(osc_server.
_pcb, IP_ADDR_ANY, cueOS_CONFIG_OSC_IN_PORT);
104 udp_recv(osc_server.
_pcb, _osc_server_receive, NULL);
119 uint32_t swapped_ctrl_val = ((ctrl_val>>24)&0xff) | ((ctrl_val<<8)&0xff0000) | ((ctrl_val>>8)&0xff00) | ((ctrl_val<<24)&0xff000000);
120 uint8_t uri_len = _i_to_len(media_type) + _i_to_len(ctrl_type) + _i_to_len(ctrl_id) + 3;
121 uint8_t tot_len = OSC_PACKET_PAYLOAD_LEN + _roundup_4(uri_len);
123 osc_packet.
data = pvPortMalloc(tot_len *
sizeof(uint8_t));
124 osc_packet.
sp = osc_packet.
data;
130 osc_packet.
sp += sprintf(osc_packet.
sp,OSC_PACKET_URI_FORMAT, media_type, ctrl_type, ctrl_id);
131 _osc_packet_roundup4(&osc_packet);
132 _osc_packet_cat(&osc_packet,
",i", 2);
133 _osc_packet_cat(&osc_packet, &swapped_ctrl_val, 4);
134 _osc_packet_roundup4(&osc_packet);
136 osc_server.
_p_tx = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL);
137 pbuf_take(osc_server.
_p_tx, osc_packet.
data, tot_len);
138 udp_sendto(osc_server.
_pcb, osc_server.
_p_tx, IP_ADDR_BROADCAST, cueOS_CONFIG_OSC_OUT_PORT);
140 vPortFree(osc_packet.
data);
142 pbuf_free(osc_server.
_p_tx);
void osc_packet_send(osc_media_type_e media_type, osc_control_type_e ctrl_type, uint16_t ctrl_id, uint32_t ctrl_val)
Prepares and send an OSC packet over UDP.
void osc_server_init(void)
Initialises the OSC server instance.
osc_control_type_e
List of OSC control types (As implemented by ASLS)
osc_media_type_e
List of OSC-controllable media types (As implemented by ASLS)
DEfines en OSC packet instance. TODO: this is not a RAM-efficient implementation.....
Defines an OSC server instance. Open Sound Control (OSC) is a protocol for networking sound synthesiz...