3737#include " shwg.h"
3838#include " shwg_button.h"
3939#include " shwg_factory_test.h"
40+ #include " streaming_tcp_client.h"
4041#include " streaming_tcp_server.h"
4142#include " streaming_udp_server.h"
4243#include " stringtokenizer_transform.h"
@@ -74,6 +75,9 @@ StreamingTCPServer *ydwg_raw_tcp_server;
7475StreamingUDPServer *nmea0183_udp_server;
7576StreamingUDPServer *ydwg_raw_udp_server;
7677
78+ StreamingTCPClient *ydwg_raw_tcp_client;
79+ StreamingTCPClient *nmea0183_tcp_client;
80+
7781// time elapsed since last system time update
7882elapsedMillis elapsed_since_last_system_time_update = kTimeUpdatePeriodMs ;
7983
@@ -85,10 +89,12 @@ Networking *networking;
8589
8690CheckboxConfig *checkbox_config_enable_firmware_updates;
8791BiDiPortConfig *port_config_ydwg_raw_tcp;
92+ HostPortConfig *port_config_ydwg_raw_tcp_client;
8893BiDiPortConfig *port_config_ydwg_raw_udp;
8994CheckboxConfig *checkbox_config_translate_to_seasmart;
9095CheckboxConfig *checkbox_config_translate_to_nmea0183;
9196PortConfig *port_config_nmea0183_tcp_tx;
97+ HostPortConfig *port_config_nmea0183_tcp_client;
9298PortConfig *port_config_nmea0183_udp_tx;
9399
94100UIOutput<String> ui_output_firmware_name (" Firmware name" , kFirmwareName ,
@@ -280,7 +286,7 @@ static void SetupYellowLEDBlinker(
280286 }));
281287}
282288
283- static void SetupTransmitters () {
289+ static void SetupConnections () {
284290 can_frame_clearinghouse = new LambdaTransform<CANFrame, CANFrame>(
285291 [](const CANFrame &frame) { return frame; });
286292
@@ -325,11 +331,14 @@ static void SetupTransmitters() {
325331 auto concatenate_ydwg_strings = new ConcatenateStrings (100 , 1000 );
326332 auto concatenate_n0183_strings = new ConcatenateStrings (100 , 1000 );
327333
334+ auto string_tokenizer = new StringTokenizer (" \r\n " );
335+
328336 auto n2k_to_0183_transform = new N2KTo0183Transform (nmea2000);
329337 auto n2k_to_seasmart_transform = new SeasmartTransform (nmea2000);
330338 auto ydwg_raw_to_can_transform = new YDWGRawToCANFrameTransform ();
331339
332340 can_to_ydwg_transform->connect_to (concatenate_ydwg_strings);
341+ string_tokenizer->connect_to (ydwg_raw_to_can_transform);
333342
334343 // ////
335344 // N2K message routing
@@ -390,7 +399,6 @@ static void SetupTransmitters() {
390399 int nmea0183_udp_port = port_config_nmea0183_udp_tx->get_port ();
391400 nmea0183_udp_server = new StreamingUDPServer (nmea0183_udp_port, networking);
392401 nmea0183_udp_server->set_enabled (port_config_nmea0183_udp_tx->get_enabled ());
393- concatenate_n0183_strings->connect_to (nmea0183_udp_server);
394402
395403 // send the generated NMEA 0183 message
396404 if (checkbox_config_translate_to_nmea0183->get_value ()) {
@@ -407,6 +415,27 @@ static void SetupTransmitters() {
407415 n2k_to_seasmart_transform->connect_to (concatenate_n0183_strings);
408416 }
409417
418+ // set up a YDWG RAW TCP client
419+ if (port_config_ydwg_raw_tcp_client->get_enabled ()) {
420+ String ydwg_raw_tcp_client_host =
421+ port_config_ydwg_raw_tcp_client->get_host ();
422+ int ydwg_raw_tcp_client_port = port_config_ydwg_raw_tcp_client->get_port ();
423+ ydwg_raw_tcp_client = new StreamingTCPClient (
424+ ydwg_raw_tcp_client_host, ydwg_raw_tcp_client_port, networking);
425+ can_to_ydwg_transform->connect_to (ydwg_raw_tcp_client);
426+ ydwg_raw_tcp_client->connect_to (string_tokenizer);
427+ }
428+
429+ // set up an NMEA 0183 TCP client
430+ if (port_config_nmea0183_tcp_client->get_enabled ()) {
431+ String nmea0183_tcp_client_host =
432+ port_config_nmea0183_tcp_client->get_host ();
433+ int nmea0183_tcp_client_port = port_config_nmea0183_tcp_client->get_port ();
434+ nmea0183_tcp_client = new StreamingTCPClient (
435+ nmea0183_tcp_client_host, nmea0183_tcp_client_port, networking);
436+ n2k_to_0183_transform->connect_to (nmea0183_tcp_client);
437+ }
438+
410439 // connect the CAN frame input to the YDWG raw transform
411440 debugD (" Connecting CAN input to YDWG raw transform" );
412441 can_frame_clearinghouse->connect_to (can_to_ydwg_transform);
@@ -430,9 +459,7 @@ static void SetupTransmitters() {
430459
431460 if (port_config_ydwg_raw_udp->get_rx_enabled ()) {
432461 debugD (" Connecting UDP RX to YDWG RAW" );
433- ydwg_raw_udp_server->connect_to (new StringTokenizer (" \r\n " ))
434- ->connect_to (ydwg_raw_to_can_transform);
435-
462+ ydwg_raw_udp_server->connect_to (string_tokenizer);
436463 }
437464}
438465
@@ -474,6 +501,13 @@ void SetupUIComponents() {
474501 " Enable TCP server for transmitting and/or receiving YDWG RAW data." ,
475502 1300 );
476503
504+ port_config_ydwg_raw_tcp_client = new HostPortConfig (
505+ false , " " , kDefaultYdwgRawTCPServerPort , " Enabled" , " Server hostname" ,
506+ " Server port" , " /Network/YDWG RAW TCP Client" ,
507+ " Connect to another TCP server for transmitting and receiving YDWG RAW "
508+ " data." ,
509+ 1350 );
510+
477511 port_config_ydwg_raw_udp = new BiDiPortConfig (
478512 true , false , " Transmit to WiFi" , " Receive from WiFi" ,
479513 kDefaultYdwgRawUDPServerPort , " /Network/YDWG RAW over UDP" ,
@@ -498,6 +532,13 @@ void SetupUIComponents() {
498532 " Enable a TCP server for transmitting NMEA 0183 and SeaSmart.Net data." ,
499533 1800 );
500534
535+ port_config_nmea0183_tcp_client = new HostPortConfig (
536+ false , " " , kDefaultNMEA0183TCPServerPort , " Enabled" , " Server hostname" ,
537+ " Server port" , " /Network/NMEA 0183 TCP Client" ,
538+ " Connect to another TCP server for transmitting NMEA 0183 and "
539+ " SeaSmart.Net data." ,
540+ 1850 );
541+
501542 port_config_nmea0183_udp_tx = new PortConfig (
502543 true , kDefaultNMEA0183UDPServerPort , " /Network/NMEA 0183 over UDP" ,
503544 " Broadcast NMEA 0183 and SeaSmart.Net data over UDP." , 1900 );
@@ -593,7 +634,7 @@ void setup() {
593634 n2k_msg_input.connect_to (new LambdaConsumer<tN2kMsg>(
594635 [](const tN2kMsg &n2k_msg) { SetSystemTime (n2k_msg); }));
595636
596- SetupTransmitters ();
637+ SetupConnections ();
597638
598639 app.onRepeat (1000 , []() {
599640 debugD (" Uptime: %lu, CAN RX: %d CAN TX: %d" , millis () / 1000 ,
0 commit comments