diff --git a/segger/streaming/streaming_config.h b/segger/streaming/streaming_config.h index 1558676..fffb4f0 100644 --- a/segger/streaming/streaming_config.h +++ b/segger/streaming/streaming_config.h @@ -21,6 +21,10 @@ #ifndef _STREAMING_CONFIG_H_ #define _STREAMING_CONFIG_H_ +#ifndef WEBSOCKET_STREAMING + #define WEBSOCKET_STREAMING 1 +#endif + #ifndef JSONRPC_PORT #define JSONRPC_PORT "http" #endif @@ -69,4 +73,8 @@ #define STREAMING_TCP_PORT 7412 #endif +#ifndef STREAMING_PORT + #define STREAMING_PORT 7414 +#endif + #endif \ No newline at end of file diff --git a/segger/streaming/streaming_handler.c b/segger/streaming/streaming_handler.c index fcd5707..aa6b3e0 100644 --- a/segger/streaming/streaming_handler.c +++ b/segger/streaming/streaming_handler.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "RTOS.h" #include "streaming_handler.h" #include "IP.h" #include "IP_Webserver.h" @@ -31,6 +32,9 @@ struct streaming_callbacks *streaming_cbs; static char stream_id[9]; #if WEBSOCKET_STREAMING + +static OS_MAILBOX mb; // Mailbox to hand over connection handle from webserver task to streaming task + #define IP_WEBSOCKET_CLOSE_CODE_TRY_AGAIN_LATER 1013 static int websocket_acceptKey_generator(WEBS_OUTPUT *pOutput, void *pSecWebSocketKey, int SecWebSocketKeyLen, @@ -40,6 +44,8 @@ static int websocket_acceptKey_generator(WEBS_OUTPUT *pOutput, void *pSecWebSock return IP_WEBSOCKET_GenerateAcceptKey(pSecWebSocketKey, SecWebSocketKeyLen, pBuffer, BufferSize); } + + static void streaming_dispatch_handle(WEBS_OUTPUT *pOutput, void *pConnection) { WEBS_USE_PARA(pOutput); @@ -58,9 +64,8 @@ static void streaming_dispatch_handle(WEBS_OUTPUT *pOutput, void *pConnection) } } -static OS_MAILBOX mb; // Mailbox to hand over connection handle from webserver task to streaming task static long buff; -static webSocketHook; +static WEBS_WEBSOCKET_HOOK webSocketHook; static const IP_WEBS_WEBSOCKET_API StreamingWebSocketApi = {websocket_acceptKey_generator, streaming_dispatch_handle}; #endif @@ -121,7 +126,7 @@ void streaming_start(void) // Error might indicate we ran out of network buffers or the socket is closed signals_purge_stream(stream); stream_free(stream); -#ifdef WEBSOCKET_STREAMING +#if WEBSOCKET_STREAMING OS_MAILBOX_Purge(&mb); #endif } diff --git a/segger/streaming/streaming_packet.c b/segger/streaming/streaming_packet.c index 1b5cf8c..3eb4685 100644 --- a/segger/streaming/streaming_packet.c +++ b/segger/streaming/streaming_packet.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "streaming_config.h" #include "streaming_packet.h" #include "IP_WEBSOCKET.h" #include "SEGGER_UTIL.h" @@ -57,7 +58,7 @@ static int serialize_header(tl_packet_t *packet, unsigned char *dst, size_t buff // the streaming header size depends on the payload size size_t tl_header_size = (packet->payload_size) > UINT8_MAX ? 8 : 4; -#ifdef WEBSOCKET_STREAMING +#if WEBSOCKET_STREAMING // the websocket header size depends on the size of its payload, which contains the streaming header size_t websocket_payload_size = tl_header_size + packet->payload_size; size_t websocket_header_size = websocket_payload_size < 126 ? 2 : 4; @@ -71,7 +72,7 @@ static int serialize_header(tl_packet_t *packet, unsigned char *dst, size_t buff return -1; } -#ifdef WEBSOCKET_STREAMING +#if WEBSOCKET_STREAMING // serialize the websocket header *dst++ = 0x80 + IP_WEBSOCKET_FRAME_TYPE_BINARY; // FIN and binary packet if (websocket_payload_size < 126) { diff --git a/segger/streaming/streaming_signals.c b/segger/streaming/streaming_signals.c index b8bd98d..baf46e4 100644 --- a/segger/streaming/streaming_signals.c +++ b/segger/streaming/streaming_signals.c @@ -153,7 +153,7 @@ int signals_subscribe(const struct stream *stream, const char *signalId) streaming_cbs->on_subscribe(stream, &related_signal[i]); _signal_subscribe(stream, &related_signal[i], 0); // valueIndex is fixed to 0 and gets ignored } - if (!signal->subscribed && signal->definition.signaltype == signal_type_value) { + if (!signal->subscribed && signal->definition->signaltype == signal_type_value) { table->subscribed_value_signal_count++; } } diff --git a/segger/streaming/streaming_signals.h b/segger/streaming/streaming_signals.h index d0ed5d2..07d193f 100644 --- a/segger/streaming/streaming_signals.h +++ b/segger/streaming/streaming_signals.h @@ -84,7 +84,6 @@ void signals_init(void); void signals_send_all_avail(const struct stream *stream); int signals_subscribe(const struct stream *stream, const char *signalId); int signals_unsubscribe(const struct stream *stream, const char *signalId); -signal_t *signals_add_signal(signal_definition_t *def, signal_table_t *table); signal_table_t *signals_add_table(signal_definition_t *def, unsigned int count, const char *table_name); bool signal_has_subscription(signal_t *signal); unsigned int signal_get_signal_no(signal_t *signal); diff --git a/segger/streaming/streaming_websocket_rx.c b/segger/streaming/streaming_websocket_rx.c index 04b937e..a90d8d8 100644 --- a/segger/streaming/streaming_websocket_rx.c +++ b/segger/streaming/streaming_websocket_rx.c @@ -14,8 +14,9 @@ * limitations under the License. */ +#include "streaming_config.h" #include "streaming_websocket_rx.h" -#ifdef WEBSOCKET_STREAMING +#if WEBSOCKET_STREAMING #include "IP_WEBSOCKET.h" #endif #include @@ -39,7 +40,7 @@ int streaming_rx_callback(long Socket, IP_PACKET *pPacket, int code) goto CloseSocket; } -#ifdef WEBSOCKET_STREAMING +#if WEBSOCKET_STREAMING unsigned char *ptr = pPacket->pData; size_t paket_len = pPacket->NumBytes; U16 head = (ptr[0] << 8) + ptr[1];