@@ -56,12 +56,13 @@ enum RingBufferConsumers
56
56
RBC_TCP_SERVER,
57
57
RBC_SD_CARD,
58
58
RBC_UDP_SERVER,
59
+ RBC_USB_SERIAL,
59
60
// Insert new consumers here
60
61
RBC_MAX
61
62
};
62
63
63
64
const char *const ringBufferConsumer[] = {
64
- " Bluetooth" , " TCP Client" , " TCP Server" , " SD Card" , " UDP Server" ,
65
+ " Bluetooth" , " TCP Client" , " TCP Server" , " SD Card" , " UDP Server" , " USB Serial " ,
65
66
};
66
67
67
68
const int ringBufferConsumerEntries = sizeof (ringBufferConsumer) / sizeof (ringBufferConsumer[0 ]);
@@ -101,6 +102,7 @@ unsigned long lastGnssSend; // Timestamp of the last time we sent RTCM to GNSS
101
102
// Ring buffer tails
102
103
static RING_BUFFER_OFFSET btRingBufferTail; // BT Tail advances as it is sent over BT
103
104
static RING_BUFFER_OFFSET sdRingBufferTail; // SD Tail advances as it is recorded to SD
105
+ static RING_BUFFER_OFFSET usbRingBufferTail; // USB Tail advances as it is sent over USB serial
104
106
105
107
// Ring buffer offsets
106
108
static uint16_t rbOffsetHead;
@@ -898,6 +900,58 @@ void handleGnssDataTask(void *e)
898
900
}
899
901
}
900
902
903
+ // ----------------------------------------------------------------------
904
+ // Send data over USB serial
905
+ // ----------------------------------------------------------------------
906
+
907
+ startMillis = millis ();
908
+
909
+ // Determine USB serial connection state
910
+ if (!forwardGnssDataToUsbSerial)
911
+ // Discard the data
912
+ usbRingBufferTail = dataHead;
913
+ else
914
+ {
915
+ // Determine the amount of USB serial data in the buffer
916
+ bytesToSend = dataHead - usbRingBufferTail;
917
+ if (bytesToSend < 0 )
918
+ bytesToSend += settings.gnssHandlerBufferSize ;
919
+ if (bytesToSend > 0 )
920
+ {
921
+ // Reduce bytes to send if we have more to send then the end of
922
+ // the buffer, we'll wrap next loop
923
+ if ((usbRingBufferTail + bytesToSend) > settings.gnssHandlerBufferSize )
924
+ bytesToSend = settings.gnssHandlerBufferSize - usbRingBufferTail;
925
+
926
+ // Send data over USB serial to the PC
927
+ bytesToSend = systemWriteGnssDataToUsbSerial (&ringBuffer[usbRingBufferTail], bytesToSend);
928
+
929
+ // Account for the data that was sent
930
+ if (bytesToSend > 0 )
931
+ {
932
+ // Account for the sent or dropped data
933
+ usbRingBufferTail += bytesToSend;
934
+ if (usbRingBufferTail >= settings.gnssHandlerBufferSize )
935
+ usbRingBufferTail -= settings.gnssHandlerBufferSize ;
936
+
937
+ // Remember the maximum transfer time
938
+ deltaMillis = millis () - startMillis;
939
+ if (maxMillis[RBC_USB_SERIAL] < deltaMillis)
940
+ maxMillis[RBC_USB_SERIAL] = deltaMillis;
941
+ }
942
+
943
+ // Determine the amount of data that remains in the buffer
944
+ bytesToSend = dataHead - usbRingBufferTail;
945
+ if (bytesToSend < 0 )
946
+ bytesToSend += settings.gnssHandlerBufferSize ;
947
+ if (usedSpace < bytesToSend)
948
+ {
949
+ usedSpace = bytesToSend;
950
+ slowConsumer = " USB Serial" ;
951
+ }
952
+ }
953
+ }
954
+
901
955
// ----------------------------------------------------------------------
902
956
// Send data to the network clients
903
957
// ----------------------------------------------------------------------
0 commit comments