4
4
volatile static uint16_t dataHead = 0 ; // Head advances as data comes in from GNSS's UART
5
5
volatile int availableHandlerSpace = 0 ; // settings.gnssHandlerBufferSize - usedSpace
6
6
7
+ // Buffer the incoming Bluetooth stream so that it can be passed in bulk over I2C
8
+ uint8_t bluetoothOutgoingToZed[100 ];
9
+ uint16_t bluetoothOutgoingToZedHead = 0 ;
10
+ unsigned long lastZedI2CSend = 0 ; // Timestamp of the last time we sent RTCM ZED over I2C
11
+
7
12
// If the phone has any new data (NTRIP RTCM, etc), read it in over Bluetooth and pass along to ZED
8
13
// Scan for escape characters to enter config menu
9
14
void btReadTask (void *e)
@@ -41,7 +46,7 @@ void btReadTask(void *e)
41
46
if (USE_I2C_GNSS)
42
47
{
43
48
// serialGNSS.write(incoming);
44
- theGNSS. pushRawData (&incoming, 1 );
49
+ addToZedI2CBuffer (btEscapeCharacter );
45
50
}
46
51
else
47
52
theGNSS.pushRawData (&incoming, 1 );
@@ -55,8 +60,7 @@ void btReadTask(void *e)
55
60
if (USE_I2C_GNSS)
56
61
{
57
62
// serialGNSS.write(btEscapeCharacter);
58
- uint8_t escChar = btEscapeCharacter;
59
- theGNSS.pushRawData (&escChar, 1 );
63
+ addToZedI2CBuffer (btEscapeCharacter);
60
64
}
61
65
else
62
66
{
@@ -72,7 +76,7 @@ void btReadTask(void *e)
72
76
// UART RX can be corrupted by UART TX
73
77
// See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/469
74
78
// serialGNSS.write(incoming);
75
- theGNSS. pushRawData (& incoming, 1 );
79
+ addToZedI2CBuffer ( incoming);
76
80
}
77
81
else
78
82
theGNSS.pushRawData (&incoming, 1 );
@@ -87,6 +91,11 @@ void btReadTask(void *e)
87
91
88
92
} // End bluetoothGetState() == BT_CONNECTED
89
93
94
+ if (bluetoothOutgoingToZedHead > 0 && ((millis () - lastZedI2CSend) > 100 ))
95
+ {
96
+ sendZedI2CBuffer (); // Send any outstanding RTCM
97
+ }
98
+
90
99
if (settings.enableTaskReports == true )
91
100
systemPrintf (" SerialWriteTask High watermark: %d\r\n " , uxTaskGetStackHighWaterMark (nullptr ));
92
101
@@ -95,6 +104,35 @@ void btReadTask(void *e)
95
104
} // End while(true)
96
105
}
97
106
107
+ // Add byte to buffer that will be sent to ZED
108
+ // We cannot write single characters to the ZED over I2C (as this will change the address pointer)
109
+ void addToZedI2CBuffer (uint8_t incoming)
110
+ {
111
+ bluetoothOutgoingToZed[bluetoothOutgoingToZedHead] = incoming;
112
+
113
+ bluetoothOutgoingToZedHead++;
114
+ if (bluetoothOutgoingToZedHead == sizeof (bluetoothOutgoingToZed))
115
+ {
116
+ sendZedI2CBuffer ();
117
+ }
118
+ }
119
+
120
+ // Push the buffered data in bulk to the GNSS over I2C
121
+ bool sendZedI2CBuffer ()
122
+ {
123
+ bool response = theGNSS.pushRawData (bluetoothOutgoingToZed, bluetoothOutgoingToZedHead);
124
+
125
+ if (response == true )
126
+ {
127
+ // log_d("Pushed %d bytes RTCM to ZED", bluetoothOutgoingToZedHead);
128
+ }
129
+
130
+ // No matter the response, wrap the head and reset the timer
131
+ bluetoothOutgoingToZedHead = 0 ;
132
+ lastZedI2CSend = millis ();
133
+ return (response);
134
+ }
135
+
98
136
// Normally a delay(1) will feed the WDT but if we don't want to wait that long, this feeds the WDT without delay
99
137
void feedWdt ()
100
138
{
@@ -1247,7 +1285,7 @@ void sdSizeCheckTask(void *e)
1247
1285
sdCardSize = SD_MMC.cardSize ();
1248
1286
sdFreeSpace = SD_MMC.totalBytes () - SD_MMC.usedBytes ();
1249
1287
}
1250
- #endif // COMPILE_SD_MMC
1288
+ #endif // COMPILE_SD_MMC
1251
1289
1252
1290
xSemaphoreGive (sdCardSemaphore);
1253
1291
0 commit comments