Skip to content

Commit 5f37fad

Browse files
author
Nathan Seidle
committed
Add test menu
1 parent 2061dfa commit 5f37fad

File tree

5 files changed

+153
-66
lines changed

5 files changed

+153
-66
lines changed

Firmware/RTK_Enclosed/RTK_Enclosed.ino

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
Set static position based on user input
2828
Wait for better pos accuracy before starting a survey in
2929
Can we add NTRIP reception over Wifi to the ESP32 to aid in survey in time?
30-
30+
Test lots of bt switching from setup switch. Test for null handles: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html
31+
3132
BT cast batt, RTK status, etc
3233
3334
Menu System:
@@ -129,6 +130,7 @@ const int resolution = 8;
129130
//Setup hardware serial and BT buffers
130131
#include "BluetoothSerial.h"
131132
BluetoothSerial SerialBT;
133+
char deviceName[20]; //The serial string that is broadcast. Ex: 'Surveyor Base-BC61'
132134

133135
HardwareSerial GPS(2);
134136
#define RXD2 16
@@ -178,6 +180,8 @@ enum returnStatus {
178180
//Global variables
179181
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
180182
const byte menuTimeout = 15; //Menus will exit/timeout after this number of seconds
183+
bool inTestMode = false; //Used to re-route BT traffic while in test sub menu
184+
181185
uint32_t lastBluetoothLEDBlink = 0;
182186
uint32_t lastRoverUpdate = 0;
183187
uint32_t lastBaseUpdate = 0;
@@ -289,7 +293,11 @@ void setup()
289293
Serial.println(F("GPS configuration complete"));
290294

291295
beginSD(); //Test if SD is present
292-
296+
if(online.microSD == true)
297+
{
298+
Serial.println(F("microSD card online"));
299+
}
300+
293301
danceLEDs(); //Turn on LEDs like a car dashboard
294302

295303
//myGPS.enableDebugging(); //Enable debug messages over Serial (default)
@@ -368,27 +376,15 @@ void beginSD()
368376

369377
if (settings.enableSD == true)
370378
{
371-
// For reasons I don't understand, we seem to have to wait for at least 1ms after SPI.begin before we call microSDPowerOn.
372-
// If you comment the next line, the Artemis resets at microSDPowerOn when beginSD is called from wakeFromSleep...
373-
// But only on one of my V10 red boards. The second one I have doesn't seem to need the delay!?
374-
delay(1);
375-
376-
// microSDPowerOn();
377-
378379
//Max power up time is 250ms: https://www.kingston.com/datasheets/SDCIT-specsheet-64gb_en.pdf
379380
//Max current is 200mA average across 1s, peak 300mA
380-
for (int i = 0; i < 10; i++) //Wait
381-
{
382-
delay(1);
383-
}
381+
delay(10);
384382

385383
if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat
386384
{
387385
printDebug("SD init failed (first attempt). Trying again...\r\n");
388-
for (int i = 0; i < 250; i++) //Give SD more time to power up, then try again
389-
{
390-
delay(1);
391-
}
386+
//Give SD more time to power up, then try again
387+
delay(250);
392388
if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat
393389
{
394390
Serial.println(F("SD init failed (second attempt). Is card present? Formatted?"));

Firmware/RTK_Enclosed/System.ino

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11

22
uint8_t settingPayload[MAX_PAYLOAD_SIZE]; //This array holds the payload data bytes. Global so that we can use between config functions.
33

4+
//Tack device's MAC address to end of friendly broadcast name
5+
//This allows multiple units to be on at same time
6+
bool startBluetooth()
7+
{
8+
uint8_t mac[6];
9+
esp_read_mac(mac, ESP_MAC_WIFI_STA);
10+
mac[5] += 2; //Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
11+
12+
if (digitalRead(baseSwitch) == HIGH)
13+
{
14+
//Rover mode
15+
sprintf(deviceName, "Surveyor Rover-%02X%02X", mac[4], mac[5]);
16+
}
17+
else
18+
{
19+
//Base mode
20+
sprintf(deviceName, "Surveyor Base-%02X%02X", mac[4], mac[5]);
21+
}
22+
23+
if (SerialBT.begin(deviceName) == false)
24+
return (false);
25+
Serial.print("Bluetooth broadcasting as: ");
26+
Serial.println(deviceName);
27+
28+
//Start the tasks for handling incoming and outgoing BT bytes to/from ZED-F9P
29+
xTaskCreate(F9PSerialReadTask, "F9Read", 10000, NULL, 0, NULL);
30+
xTaskCreate(F9PSerialWriteTask, "F9Write", 10000, NULL, 0, NULL);
31+
32+
SerialBT.setTimeout(1);
33+
34+
return (true);
35+
}
36+
437
//If the phone has any new data (NTRIP RTCM, etc), read it in over Bluetooth and pass along to ZED
538
//Task for writing to the GNSS receiver
639
void F9PSerialWriteTask(void *e)
@@ -9,19 +42,26 @@ void F9PSerialWriteTask(void *e)
942
{
1043
//Receive corrections from either the ESP32 USB or bluetooth
1144
//and write to the GPS
12-
if (Serial.available())
13-
{
14-
auto s = Serial.readBytes(wBuffer, SERIAL_SIZE_RX);
15-
GPS.write(wBuffer, s);
16-
}
17-
// else if (SerialBT.connected() && SerialBT.available())
45+
// if (Serial.available())
46+
// {
47+
// auto s = Serial.readBytes(wBuffer, SERIAL_SIZE_RX);
48+
// GPS.write(wBuffer, s);
49+
// }
1850

1951
if (SerialBT.available())
2052
{
2153
while (SerialBT.available())
2254
{
23-
auto s = SerialBT.readBytes(wBuffer, SERIAL_SIZE_RX);
24-
GPS.write(wBuffer, s);
55+
if (inTestMode == false)
56+
{
57+
//Pass bytes tp GNSS receiver
58+
auto s = SerialBT.readBytes(wBuffer, SERIAL_SIZE_RX);
59+
GPS.write(wBuffer, s);
60+
}
61+
else
62+
{
63+
Serial.printf("I heard: %c\n", SerialBT.read());
64+
}
2565
}
2666
}
2767

@@ -344,42 +384,6 @@ void danceLEDs()
344384
digitalWrite(bluetoothStatusLED, LOW);
345385
}
346386

347-
//Tack device's MAC address to end of friendly broadcast name
348-
//This allows multiple units to be on at same time
349-
bool startBluetooth()
350-
{
351-
uint8_t mac[6];
352-
esp_read_mac(mac, ESP_MAC_WIFI_STA);
353-
mac[5] += 2; //Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
354-
355-
char deviceName[20];
356-
if (digitalRead(baseSwitch) == HIGH)
357-
{
358-
//Rover mode
359-
sprintf(deviceName, "Surveyor Rover-%02X%02X", mac[4], mac[5]);
360-
}
361-
else
362-
{
363-
//Base mode
364-
sprintf(deviceName, "Surveyor Base-%02X%02X", mac[4], mac[5]);
365-
}
366-
367-
if (SerialBT.begin(deviceName) == false)
368-
return (false);
369-
Serial.print("Bluetooth broadcasting as: ");
370-
Serial.println(deviceName);
371-
372-
//Start the tasks.
373-
//Can also use xTaskCreatePinnedToCore to pin a task to one of the two cores
374-
//on the ESP32
375-
xTaskCreate(F9PSerialReadTask, "F9Read", 10000, NULL, 0, NULL);
376-
xTaskCreate(F9PSerialWriteTask, "F9Write", 10000, NULL, 0, NULL);
377-
378-
SerialBT.setTimeout(1);
379-
380-
return (true);
381-
}
382-
383387
boolean SFE_UBLOX_GPS_ADD::getModuleInfo(uint16_t maxWait)
384388
{
385389
myGPS.minfo.hwVersion[0] = 0;

Firmware/RTK_Enclosed/menuMain.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ void menuMain()
77
Serial.println();
88
Serial.println(F("Menu: Main Menu"));
99

10-
Serial.println(F("1) Configure Terminal Output"));
10+
Serial.println(F("1) Configure Data Logging"));
1111

12-
Serial.println(F("2) Configure Time Stamp"));
13-
14-
if (settings.enableSD && online.microSD)
15-
Serial.println(F("s) SD Card File Transfer"));
12+
if (settings.enableSD && online.microSD)
13+
Serial.println(F("s) SD Card File Transfer"));
1614

1715
Serial.println(F("r) Reset all settings to default"));
1816

17+
Serial.println(F("t) Test menu"));
18+
1919
Serial.println(F("x) Exit"));
2020

2121
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
@@ -43,6 +43,8 @@ void menuMain()
4343
// else
4444
// Serial.println(F("Reset aborted"));
4545
}
46+
else if (incoming == 't')
47+
menuTest();
4648
else if (incoming == 'x')
4749
break;
4850
else if (incoming == STATUS_GETBYTE_TIMEOUT)

Firmware/RTK_Enclosed/menuTest.ino

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//Production testing
2+
//Allow operator to output NMEA on radio port for connector testing
3+
//Scan for display
4+
void menuTest()
5+
{
6+
inTestMode = true; //Reroutes bluetooth bytes
7+
8+
//Enable RTCM
9+
myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_UART2, 1); //Enable message 1005 to output through UART2, message every second
10+
myGPS.enableRTCMmessage(UBX_RTCM_1074, COM_PORT_UART2, 1);
11+
myGPS.enableRTCMmessage(UBX_RTCM_1084, COM_PORT_UART2, 1);
12+
myGPS.enableRTCMmessage(UBX_RTCM_1094, COM_PORT_UART2, 1);
13+
myGPS.enableRTCMmessage(UBX_RTCM_1124, COM_PORT_UART2, 1);
14+
myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_UART2, 10); //Enable message every 10 seconds
15+
16+
while (1)
17+
{
18+
Serial.println();
19+
Serial.println(F("Menu: Test Menu"));
20+
21+
Serial.print("Bluetooth broadcasting as: ");
22+
Serial.println(deviceName);
23+
24+
Serial.println("Radio Port is now outputting RTCM");
25+
26+
if (settings.enableSD && online.microSD)
27+
{
28+
Serial.println("microSD card is successfully detected");
29+
}
30+
31+
//0x3D is default on Qwiic board
32+
if (isConnected(0x3D) == true || isConnected(0x3C) == true)
33+
Serial.println("Qwiic Good. Display detected.");
34+
else
35+
Serial.println("Qwiic port failed! No display detected.");
36+
37+
Serial.println(F("Any character received over Blueooth connection will be displayed here"));
38+
39+
Serial.println(F("1) Display microSD contents"));
40+
41+
Serial.println(F("2) Scan for Qwiic OLED display"));
42+
43+
Serial.println(F("x) Exit"));
44+
45+
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
46+
47+
if (incoming == '1')
48+
{
49+
if (settings.enableSD && online.microSD)
50+
{
51+
Serial.println(F("Files found (date time size name):\n"));
52+
sd.ls(LS_R | LS_DATE | LS_SIZE);
53+
}
54+
}
55+
else if (incoming == 'x')
56+
break;
57+
else if (incoming == STATUS_GETBYTE_TIMEOUT)
58+
{
59+
Serial.println("time out");
60+
// break;
61+
}
62+
else
63+
printUnknown(incoming);
64+
}
65+
66+
inTestMode = false; //Reroutes bluetooth bytes
67+
68+
//Disable RTCM sentences
69+
myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_UART2, 0);
70+
myGPS.enableRTCMmessage(UBX_RTCM_1074, COM_PORT_UART2, 0);
71+
myGPS.enableRTCMmessage(UBX_RTCM_1084, COM_PORT_UART2, 0);
72+
myGPS.enableRTCMmessage(UBX_RTCM_1094, COM_PORT_UART2, 0);
73+
myGPS.enableRTCMmessage(UBX_RTCM_1124, COM_PORT_UART2, 0);
74+
myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_UART2, 0);
75+
76+
while (Serial.available()) Serial.read(); //Empty buffer of any newline chars
77+
}
78+
79+
bool isConnected(uint8_t deviceAddress)
80+
{
81+
Wire.beginTransmission(deviceAddress);
82+
if (Wire.endTransmission() == 0)
83+
return true;
84+
return false;
85+
}

Programming/RTK_Enclosed.ino.bin

15.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)