diff --git a/.semgrepignore b/.semgrepignore index 10fcb5f75..b4267ad23 100644 --- a/.semgrepignore +++ b/.semgrepignore @@ -1,2 +1,2 @@ .github/workflows/main_matrix.yml -src/mesh/compression/unishox2.c +src/mesh/compression/unishox2.cpp diff --git a/boards/tracker-t1000-e.json b/boards/tracker-t1000-e.json new file mode 100644 index 000000000..2be716e22 --- /dev/null +++ b/boards/tracker-t1000-e.json @@ -0,0 +1,58 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v7.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_WIO_WM1110 -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + ["0x239A", "0x8029"], + ["0x239A", "0x0029"], + ["0x239A", "0x002A"], + ["0x239A", "0x802A"] + ], + "usb_product": "T1000-E-BOOT", + "mcu": "nrf52840", + "variant": "Seeed_T1000-E", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "7.3.0", + "sd_fwid": "0x0123" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": ["bluetooth"], + "debug": { + "jlink_device": "nRF52840_xxAA", + "svd_path": "nrf52840.svd" + }, + "frameworks": ["arduino"], + "name": "Seeed T1000-E", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": [ + "jlink", + "nrfjprog", + "nrfutil", + "stlink", + "cmsis-dap", + "blackmagic" + ], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-E-for-Meshtastic-p-5913.html", + "vendor": "Seeed Studio" +} diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index a81518f31..914ff8e06 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -29,7 +29,6 @@ volatile ButtonThread::ButtonEventType ButtonThread::btnEvent = ButtonThread::BU #if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) OneButton ButtonThread::userButton; // Get reference to static member #endif - ButtonThread::ButtonThread() : OSThread("Button") { #if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) @@ -43,7 +42,7 @@ ButtonThread::ButtonThread() : OSThread("Button") int pin = config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN; // Resolved button pin #if defined(HELTEC_CAPSULE_SENSOR_V3) this->userButton = OneButton(pin, false, false); -#elif defined(BUTTON_ACTIVE_LOW) // change by WayenWeng +#elif defined(BUTTON_ACTIVE_LOW) this->userButton = OneButton(pin, BUTTON_ACTIVE_LOW, BUTTON_ACTIVE_PULLUP); #else this->userButton = OneButton(pin, true, true); @@ -53,7 +52,7 @@ ButtonThread::ButtonThread() : OSThread("Button") #ifdef INPUT_PULLUP_SENSE // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did -#ifdef BUTTON_SENSE_TYPE // change by WayenWeng +#ifdef BUTTON_SENSE_TYPE pinMode(pin, BUTTON_SENSE_TYPE); #else pinMode(pin, INPUT_PULLUP_SENSE); diff --git a/src/configuration.h b/src/configuration.h index 099ef17d8..f06966953 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -171,10 +171,6 @@ along with this program. If not, see . // ----------------------------------------------------------------------------- // GPS // ----------------------------------------------------------------------------- -#ifndef GPS_BAUDRATE -#define GPS_BAUDRATE 9600 -#endif - #ifndef GPS_THREAD_INTERVAL #define GPS_THREAD_INTERVAL 200 #endif @@ -185,6 +181,10 @@ along with this program. If not, see . /* Step #1: offer chance for variant-specific defines */ #include "variant.h" +#ifndef GPS_BAUDRATE +#define GPS_BAUDRATE 9600 +#endif + /* Step #2: follow with defines common to the architecture; also enable HAS_ option not specifically disabled by variant.h */ #include "architecture.h" @@ -316,4 +316,4 @@ along with this program. If not, see . #endif #include "DebugConfiguration.h" -#include "RF95Configuration.h" \ No newline at end of file +#include "RF95Configuration.h" diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 9628784d6..c50bc7b41 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -400,14 +400,21 @@ bool GPS::setup() int msglen = 0; if (!didSerialInit) { -#ifdef GNSS_Airoha // change by WayenWeng +#ifdef GNSS_AIROHA if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { probe(GPS_BAUDRATE); LOG_INFO("GPS setting to %d.\n", GPS_BAUDRATE); } #else #if !defined(GPS_UC6580) + if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { + + // if GPS_BAUDRATE is specified in variant (i.e. not 9600), skip to the specified rate. + if (speedSelect == 0 && GPS_BAUDRATE != serialSpeeds[speedSelect]) { + speedSelect = std::find(serialSpeeds, std::end(serialSpeeds), GPS_BAUDRATE) - serialSpeeds; + } + LOG_DEBUG("Probing for GPS at %d \n", serialSpeeds[speedSelect]); gnssModel = probe(serialSpeeds[speedSelect]); if (gnssModel == GNSS_MODEL_UNKNOWN) { @@ -777,7 +784,7 @@ bool GPS::setup() LOG_INFO("GNSS module configuration saved!\n"); } } -#endif // !GNSS_Airoha +#endif didSerialInit = true; } @@ -791,7 +798,6 @@ GPS::~GPS() // we really should unregister our sleep observer notifyDeepSleepObserver.unobserve(¬ifyDeepSleep); } - // Put the GPS hardware into a specified state void GPS::setPowerState(GPSPowerState newState, uint32_t sleepTime) { @@ -828,6 +834,11 @@ void GPS::setPowerState(GPSPowerState newState, uint32_t sleepTime) setPowerPMU(false); // Power (PMU): off writePinStandby(true); // Standby (pin): asleep (not awake) setPowerUBLOX(false, sleepTime); // Standby (UBLOX): asleep, timed +#ifdef GNSS_AIROHA + if (config.position.gps_update_interval * 1000 >= GPS_FIX_HOLD_TIME * 2) { + digitalWrite(PIN_GPS_EN, LOW); + } +#endif break; case GPS_OFF: @@ -837,6 +848,11 @@ void GPS::setPowerState(GPSPowerState newState, uint32_t sleepTime) setPowerPMU(false); // Power (PMU): off writePinStandby(true); // Standby (pin): asleep setPowerUBLOX(false, 0); // Standby (UBLOX): asleep, indefinitely +#ifdef GNSS_AIROHA + if (config.position.gps_update_interval * 1000 >= GPS_FIX_HOLD_TIME * 2) { + digitalWrite(PIN_GPS_EN, LOW); + } +#endif break; } } @@ -1175,7 +1191,8 @@ GnssModel_t GPS::probe(int serialSpeed) _serial_gps->updateBaudRate(serialSpeed); } #endif -#ifdef GNSS_Airoha // add by WayenWeng +#ifdef GNSS_AIROHA + return GNSS_MODEL_UNKNOWN; #else #ifdef GPS_DEBUG @@ -1191,6 +1208,15 @@ GnssModel_t GPS::probe(int serialSpeed) _serial_gps->write("$PCAS03,0,0,0,0,0,0,0,0,0,0,,,0,0*02\r\n"); delay(20); + // get version information from Unicore UFirebirdII Series + // Works for: UC6580, UM620, UM621, UM670A, UM680A, or UM681A + _serial_gps->write("$PDTINFO\r\n"); + delay(750); + if (getACK("UC6580", 500) == GNSS_RESPONSE_OK) { + LOG_INFO("UC6580 detected, using UC6580 Module\n"); + return GNSS_MODEL_UC6580; + } + // Get version information clearBuffer(); _serial_gps->write("$PCAS06,1*1A\r\n"); @@ -1398,13 +1424,6 @@ GPS *GPS::createGps() #else _serial_gps->begin(GPS_BAUDRATE); #endif - - /* - * T-Beam-S3-Core will be preset to use gps Probe here, and other boards will not be changed first - */ -#if defined(GPS_UC6580) - _serial_gps->updateBaudRate(115200); -#endif } return new_gps; } @@ -1486,11 +1505,25 @@ bool GPS::factoryReset() */ bool GPS::lookForTime() { -#ifdef GNSS_Airoha // add by WayenWeng + +#ifdef GNSS_AIROHA uint8_t fix = reader.fixQuality(); uint32_t now = millis(); + if (fix > 0) { + if (lastFixStartMsec > 0) { + if ((now - lastFixStartMsec) < GPS_FIX_HOLD_TIME) { + return false; + } else { + clearBuffer(); + } + } else { + lastFixStartMsec = now; + return false; + } + } else { + return false; + } #endif - auto ti = reader.time; auto d = reader.date; if (ti.isValid() && d.isValid()) { // Note: we don't check for updated, because we'll only be called if needed @@ -1525,13 +1558,26 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s */ bool GPS::lookForLocation() { -#ifdef GNSS_Airoha // add by WayenWeng +#ifdef GNSS_AIROHA if ((config.position.gps_update_interval * 1000) >= (GPS_FIX_HOLD_TIME * 2)) { uint8_t fix = reader.fixQuality(); uint32_t now = millis(); + if (fix > 0) { + if (lastFixStartMsec > 0) { + if ((now - lastFixStartMsec) < GPS_FIX_HOLD_TIME) { + return false; + } else { + clearBuffer(); + } + } else { + lastFixStartMsec = now; + return false; + } + } else { + return false; + } } #endif - // By default, TinyGPS++ does not parse GPGSA lines, which give us // the 2D/3D fixType (see NMEAGPS.h) // At a minimum, use the fixQuality indicator in GPGGA (FIXME?) @@ -1741,6 +1787,12 @@ void GPS::toggleGpsMode() if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) { config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED; LOG_INFO("User toggled GpsMode. Now DISABLED.\n"); +#ifdef GNSS_AIROHA + if (powerState == GPS_ACTIVE) { + LOG_DEBUG("User power Off GPS\n"); + digitalWrite(PIN_GPS_EN, LOW); + } +#endif disable(); } else if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED) { config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; @@ -1748,4 +1800,4 @@ void GPS::toggleGpsMode() enable(); } } -#endif // Exclude GPS \ No newline at end of file +#endif // Exclude GPS diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 7cbf771bc..87d03c592 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -69,7 +69,7 @@ class GPS : private concurrency::OSThread #endif private: const int serialSpeeds[6] = {9600, 4800, 38400, 57600, 115200, 9600}; - + uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastFixStartMsec = 0; uint32_t rx_gpio = 0; uint32_t tx_gpio = 0; uint32_t en_gpio = 0; diff --git a/src/mesh/LR11x0Interface.cpp b/src/mesh/LR11x0Interface.cpp index fc059ec16..1965eef89 100644 --- a/src/mesh/LR11x0Interface.cpp +++ b/src/mesh/LR11x0Interface.cpp @@ -100,7 +100,13 @@ template bool LR11x0Interface::init() // FIXME: May want to set depending on a definition, currently all LR1110 variant files use the DC-DC regulator option if (res == RADIOLIB_ERR_NONE) res = lora.setRegulatorDCDC(); - +#ifdef TRACKER_T1000_E +#ifdef LR11X0_DIO_RF_SWITCH_CONFIG + res = lora.setDioAsRfSwitch(LR11X0_DIO_RF_SWITCH_CONFIG); +#else + res = lora.setDioAsRfSwitch(0x03, 0x0, 0x01, 0x03, 0x02, 0x0, 0x0, 0x0); +#endif +#endif if (res == RADIOLIB_ERR_NONE) { if (config.lora.sx126x_rx_boosted_gain) { // the name is unfortunate but historically accurate res = lora.setRxBoostedGainMode(true); diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index c8c18ae6d..35536e714 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -92,22 +92,23 @@ void Router::enqueueReceivedMessage(meshtastic_MeshPacket *p) // FIXME, move this someplace better PacketId generatePacketId() { - static uint32_t i; // Note: trying to keep this in noinit didn't help for working across reboots + static uint32_t rollingPacketId; // Note: trying to keep this in noinit didn't help for working across reboots static bool didInit = false; - uint32_t numPacketId = UINT32_MAX; - if (!didInit) { didInit = true; // pick a random initial sequence number at boot (to prevent repeated reboots always starting at 0) // Note: we mask the high order bit to ensure that we never pass a 'negative' number to random - i = random(numPacketId & 0x7fffffff); - LOG_DEBUG("Initial packet id %u, numPacketId %u\n", i, numPacketId); + rollingPacketId = random(UINT32_MAX & 0x7fffffff); + LOG_DEBUG("Initial packet id %u\n", rollingPacketId); } - i++; - PacketId id = (i % numPacketId) + 1; // return number between 1 and numPacketId (ie - never zero) + rollingPacketId++; + + rollingPacketId &= UINT32_MAX >> 22; // Mask out the top 22 bits + PacketId id = rollingPacketId | random(UINT32_MAX & 0x7fffffff) << 10; // top 22 bits + LOG_DEBUG("Partially randomized packet id %u\n", id); return id; } diff --git a/src/mesh/compression/unishox2.c b/src/mesh/compression/unishox2.cpp similarity index 98% rename from src/mesh/compression/unishox2.c rename to src/mesh/compression/unishox2.cpp index 99c62f659..fcb12a222 100644 --- a/src/mesh/compression/unishox2.c +++ b/src/mesh/compression/unishox2.cpp @@ -15,6 +15,7 @@ * * @author Arundale Ramanathan * + * Port for Particle (particle.io) / Aruino - Jonathan Greenblatt */ /** * @file unishox2.c @@ -36,6 +37,14 @@ /// uint8_t is unsigned char typedef unsigned char uint8_t; +const char *USX_FREQ_SEQ_DFLT[] = {"\": \"", "\": ", ""}; +const char *USX_FREQ_SEQ_XML[] = {"", "" \ - } -/// Frequently occurring sequences in XML content -#define USX_FREQ_SEQ_XML \ - (const char *[]) \ - { \ - "", "has_contact) { - auto length = unishox2_compress_simple(t->contact.callsign, strlen(t->contact.callsign), compressed.contact.callsign); + auto length = unishox2_compress_lines(t->contact.callsign, strlen(t->contact.callsign), compressed.contact.callsign, + sizeof(compressed.contact.callsign) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Compression overflowed contact.callsign. Reverting to uncompressed packet\n"); + return; + } LOG_DEBUG("Compressed callsign: %d bytes\n", length); - - length = unishox2_compress_simple(t->contact.device_callsign, strlen(t->contact.device_callsign), - compressed.contact.device_callsign); + length = unishox2_compress_lines(t->contact.device_callsign, strlen(t->contact.device_callsign), + compressed.contact.device_callsign, sizeof(compressed.contact.device_callsign) - 1, + USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Compression overflowed contact.device_callsign. Reverting to uncompressed packet\n"); + return; + } LOG_DEBUG("Compressed device_callsign: %d bytes\n", length); } if (t->which_payload_variant == meshtastic_TAKPacket_chat_tag) { - auto length = unishox2_compress_simple(t->payload_variant.chat.message, strlen(t->payload_variant.chat.message), - compressed.payload_variant.chat.message); + auto length = unishox2_compress_lines(t->payload_variant.chat.message, strlen(t->payload_variant.chat.message), + compressed.payload_variant.chat.message, + sizeof(compressed.payload_variant.chat.message) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Compression overflowed chat.message. Reverting to uncompressed packet\n"); + return; + } LOG_DEBUG("Compressed chat message: %d bytes\n", length); if (t->payload_variant.chat.has_to) { compressed.payload_variant.chat.has_to = true; - length = unishox2_compress_simple(t->payload_variant.chat.to, strlen(t->payload_variant.chat.to), - compressed.payload_variant.chat.to); + length = unishox2_compress_lines(t->payload_variant.chat.to, strlen(t->payload_variant.chat.to), + compressed.payload_variant.chat.to, + sizeof(compressed.payload_variant.chat.to) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Compression overflowed chat.to. Reverting to uncompressed packet\n"); + return; + } LOG_DEBUG("Compressed chat to: %d bytes\n", length); } if (t->payload_variant.chat.has_to_callsign) { compressed.payload_variant.chat.has_to_callsign = true; - length = - unishox2_compress_simple(t->payload_variant.chat.to_callsign, strlen(t->payload_variant.chat.to_callsign), - compressed.payload_variant.chat.to_callsign); + length = unishox2_compress_lines(t->payload_variant.chat.to_callsign, strlen(t->payload_variant.chat.to_callsign), + compressed.payload_variant.chat.to_callsign, + sizeof(compressed.payload_variant.chat.to_callsign) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Compression overflowed chat.to_callsign. Reverting to uncompressed packet\n"); + return; + } LOG_DEBUG("Compressed chat to_callsign: %d bytes\n", length); } } @@ -102,7 +122,7 @@ void AtakPluginModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtast } else { if (!t->is_compressed) { // Not compressed. Something is wrong - LOG_ERROR("Received uncompressed TAKPacket over radio!\n"); + LOG_WARN("Received uncompressed TAKPacket over radio! Skipping\n"); return; } @@ -112,32 +132,55 @@ void AtakPluginModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtast uncompressed.is_compressed = false; if (t->has_contact) { auto length = - unishox2_decompress_simple(t->contact.callsign, strlen(t->contact.callsign), uncompressed.contact.callsign); - + unishox2_decompress_lines(t->contact.callsign, strlen(t->contact.callsign), uncompressed.contact.callsign, + sizeof(uncompressed.contact.callsign) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Decompression overflowed contact.callsign. Bailing out\n"); + return; + } LOG_DEBUG("Decompressed callsign: %d bytes\n", length); - length = unishox2_decompress_simple(t->contact.device_callsign, strlen(t->contact.device_callsign), - uncompressed.contact.device_callsign); - + length = unishox2_decompress_lines(t->contact.device_callsign, strlen(t->contact.device_callsign), + uncompressed.contact.device_callsign, + sizeof(uncompressed.contact.device_callsign) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Decompression overflowed contact.device_callsign. Bailing out\n"); + return; + } LOG_DEBUG("Decompressed device_callsign: %d bytes\n", length); } if (uncompressed.which_payload_variant == meshtastic_TAKPacket_chat_tag) { - auto length = unishox2_decompress_simple(t->payload_variant.chat.message, strlen(t->payload_variant.chat.message), - uncompressed.payload_variant.chat.message); + auto length = unishox2_decompress_lines(t->payload_variant.chat.message, strlen(t->payload_variant.chat.message), + uncompressed.payload_variant.chat.message, + sizeof(uncompressed.payload_variant.chat.message) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Decompression overflowed chat.message. Bailing out\n"); + return; + } LOG_DEBUG("Decompressed chat message: %d bytes\n", length); if (t->payload_variant.chat.has_to) { uncompressed.payload_variant.chat.has_to = true; - length = unishox2_decompress_simple(t->payload_variant.chat.to, strlen(t->payload_variant.chat.to), - uncompressed.payload_variant.chat.to); + length = unishox2_decompress_lines(t->payload_variant.chat.to, strlen(t->payload_variant.chat.to), + uncompressed.payload_variant.chat.to, + sizeof(uncompressed.payload_variant.chat.to) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Decompression overflowed chat.to. Bailing out\n"); + return; + } LOG_DEBUG("Decompressed chat to: %d bytes\n", length); } if (t->payload_variant.chat.has_to_callsign) { uncompressed.payload_variant.chat.has_to_callsign = true; length = - unishox2_decompress_simple(t->payload_variant.chat.to_callsign, strlen(t->payload_variant.chat.to_callsign), - uncompressed.payload_variant.chat.to_callsign); + unishox2_decompress_lines(t->payload_variant.chat.to_callsign, strlen(t->payload_variant.chat.to_callsign), + uncompressed.payload_variant.chat.to_callsign, + sizeof(uncompressed.payload_variant.chat.to_callsign) - 1, USX_PSET_DFLT, NULL); + if (length < 0) { + LOG_WARN("Decompression overflowed chat.to_callsign. Bailing out\n"); + return; + } LOG_DEBUG("Decompressed chat to_callsign: %d bytes\n", length); } } @@ -148,4 +191,4 @@ void AtakPluginModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtast service.sendToPhone(decompressedCopy); } return; -} \ No newline at end of file +} diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index b3294a866..228929e96 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -11,12 +11,12 @@ #include "configuration.h" #include "gps/GeoCoord.h" #include "main.h" +#include "mesh/compression/unishox2.h" #include "meshtastic/atak.pb.h" #include "sleep.h" #include "target_specific.h" extern "C" { -#include "mesh/compression/unishox2.h" #include } @@ -255,10 +255,12 @@ meshtastic_MeshPacket *PositionModule::allocAtakPli() .course = static_cast(localPosition.ground_track), }}}; - auto length = unishox2_compress_simple(owner.long_name, strlen(owner.long_name), takPacket.contact.device_callsign); + auto length = unishox2_compress_lines(owner.long_name, strlen(owner.long_name), takPacket.contact.device_callsign, + sizeof(takPacket.contact.device_callsign) - 1, USX_PSET_DFLT, NULL); LOG_DEBUG("Uncompressed device_callsign '%s' - %d bytes\n", owner.long_name, strlen(owner.long_name)); LOG_DEBUG("Compressed device_callsign '%s' - %d bytes\n", takPacket.contact.device_callsign, length); - length = unishox2_compress_simple(owner.long_name, strlen(owner.long_name), takPacket.contact.callsign); + length = unishox2_compress_lines(owner.long_name, strlen(owner.long_name), takPacket.contact.callsign, + sizeof(takPacket.contact.callsign) - 1, USX_PSET_DFLT, NULL); mp->decoded.payload.size = pb_encode_to_bytes(mp->decoded.payload.bytes, sizeof(mp->decoded.payload.bytes), &meshtastic_TAKPacket_msg, &takPacket); return mp; diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 92f90cfdd..fec1ee461 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -33,9 +33,7 @@ #include "Sensor/SHT31Sensor.h" #include "Sensor/SHT4XSensor.h" #include "Sensor/SHTC3Sensor.h" -#ifdef T1000X_SENSOR_EN #include "Sensor/T1000xSensor.h" -#endif #include "Sensor/TSL2591Sensor.h" #include "Sensor/VEML7700Sensor.h" @@ -98,7 +96,7 @@ int32_t EnvironmentTelemetryModule::runOnce() LOG_INFO("Environment Telemetry: Initializing\n"); // it's possible to have this module enabled, only for displaying values on the screen. // therefore, we should only enable the sensor loop if measurement is also enabled -#ifdef T1000X_SENSOR_EN // add by WayenWeng +#ifdef T1000X_SENSOR_EN result = t1000xSensor.runOnce(); #else if (dfRobotLarkSensor.hasSensor()) @@ -420,7 +418,11 @@ meshtastic_MeshPacket *EnvironmentTelemetryModule::allocReply() bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) { meshtastic_Telemetry m = meshtastic_Telemetry_init_zero; +#ifdef T1000X_SENSOR_EN + if (t1000xSensor.getMetrics(&m)) { +#else if (getEnvironmentTelemetry(&m)) { +#endif LOG_INFO("(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f\n", m.variant.environment_metrics.barometric_pressure, m.variant.environment_metrics.current, m.variant.environment_metrics.gas_resistance, m.variant.environment_metrics.relative_humidity, diff --git a/src/modules/Telemetry/Sensor/T1000xSensor.h b/src/modules/Telemetry/Sensor/T1000xSensor.h index 127d2630c..a1c771cfa 100644 --- a/src/modules/Telemetry/Sensor/T1000xSensor.h +++ b/src/modules/Telemetry/Sensor/T1000xSensor.h @@ -7,7 +7,6 @@ class T1000xSensor : public TelemetrySensor { - private: protected: virtual void setup() override; diff --git a/src/modules/TextMessageModule.cpp b/src/modules/TextMessageModule.cpp index 0f86a6470..2933718af 100644 --- a/src/modules/TextMessageModule.cpp +++ b/src/modules/TextMessageModule.cpp @@ -2,8 +2,8 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" +#include "buzz.h" #include "configuration.h" - TextMessageModule *textMessageModule; ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp) @@ -12,7 +12,6 @@ ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp auto &p = mp.decoded; LOG_INFO("Received text msg from=0x%0x, id=0x%x, msg=%.*s\n", mp.from, mp.id, p.payload.size, p.payload.bytes); #endif - // We only store/display messages destined for us. // Keep a copy of the most recent text message. devicestate.rx_text_message = mp; diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 5f7d6d902..a7085dffe 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -135,6 +135,10 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) LOG_ERROR("Invalid MQTT service envelope, topic %s, len %u!\n", topic, length); return; } else { + if (e.channel_id == NULL || e.gateway_id == NULL) { + LOG_ERROR("Invalid MQTT service envelope, topic %s, len %u!\n", topic, length); + return; + } meshtastic_Channel ch = channels.getByName(e.channel_id); if (strcmp(e.gateway_id, owner.id) == 0) { // Generate an implicit ACK towards ourselves (handled and processed only locally!) for this message. diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index aa51e810a..3910f718f 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -91,8 +91,12 @@ void enableSlowCLK() void esp32Setup() { + /* We explicitly don't want to do call randomSeed, + // as that triggers the esp32 core to use a less secure pseudorandom function. uint32_t seed = esp_random(); LOG_DEBUG("Setting random seed %u\n", seed); + randomSeed(seed); + */ LOG_DEBUG("Total heap: %d\n", ESP.getHeapSize()); LOG_DEBUG("Free heap: %d\n", ESP.getFreeHeap()); diff --git a/src/sleep.cpp b/src/sleep.cpp index 53c321d21..52839afa0 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -237,6 +237,25 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) #ifdef PIN_POWER_EN pinMode(PIN_POWER_EN, INPUT); // power off peripherals // pinMode(PIN_POWER_EN1, INPUT_PULLDOWN); +#endif + +#ifdef TRACKER_T1000_E +#ifdef GNSS_AIROHA + digitalWrite(GPS_VRTC_EN, LOW); + digitalWrite(PIN_GPS_RESET, LOW); + digitalWrite(GPS_SLEEP_INT, LOW); + digitalWrite(GPS_RTC_INT, LOW); + pinMode(GPS_RESETB_OUT, OUTPUT); + digitalWrite(GPS_RESETB_OUT, LOW); +#endif + +#ifdef BUZZER_EN_PIN + digitalWrite(BUZZER_EN_PIN, LOW); +#endif + +#ifdef PIN_3V3_EN + digitalWrite(PIN_3V3_EN, LOW); +#endif #endif setLed(false); diff --git a/variants/diy/nrf52_promicro_diy_tcxo/variant.cpp b/variants/diy/nrf52_promicro_diy_tcxo/variant.cpp index 4030122e5..5869ed1d4 100644 --- a/variants/diy/nrf52_promicro_diy_tcxo/variant.cpp +++ b/variants/diy/nrf52_promicro_diy_tcxo/variant.cpp @@ -28,4 +28,11 @@ const uint32_t g_ADigitalPinMap[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, // P1 - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; \ No newline at end of file + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // 3V3 Power Rail + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); +} diff --git a/variants/diy/nrf52_promicro_diy_xtal/variant.cpp b/variants/diy/nrf52_promicro_diy_xtal/variant.cpp index 4030122e5..5869ed1d4 100644 --- a/variants/diy/nrf52_promicro_diy_xtal/variant.cpp +++ b/variants/diy/nrf52_promicro_diy_xtal/variant.cpp @@ -28,4 +28,11 @@ const uint32_t g_ADigitalPinMap[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, // P1 - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; \ No newline at end of file + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // 3V3 Power Rail + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); +} diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index f0ee0631d..685c9f079 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -52,6 +52,7 @@ #define GPS_RESET_MODE LOW #define GPS_UC6580 +#define GPS_BAUDRATE 115200 #define USE_SX1262 #define LORA_DIO0 -1 // a No connect on the SX1262 module diff --git a/variants/heltec_wireless_tracker_V1_0/variant.h b/variants/heltec_wireless_tracker_V1_0/variant.h index 1b4751a57..23987adf0 100644 --- a/variants/heltec_wireless_tracker_V1_0/variant.h +++ b/variants/heltec_wireless_tracker_V1_0/variant.h @@ -49,6 +49,7 @@ #define GPS_RESET_MODE LOW #define GPS_UC6580 +#define GPS_BAUDRATE 115200 #define USE_SX1262 #define LORA_DIO0 -1 // a No connect on the SX1262 module diff --git a/variants/tracker-t1000-e/platformio.ini b/variants/tracker-t1000-e/platformio.ini new file mode 100644 index 000000000..1db57ca29 --- /dev/null +++ b/variants/tracker-t1000-e/platformio.ini @@ -0,0 +1,16 @@ +; tracker-t1000-e v0.9.1 +[env:tracker-t1000-e] +extends = nrf52840_base +board = tracker-t1000-e +; board_level = extra +; platform = https://github.com/maxgerhardt/platform-nordicnrf52#cac6fcf943a41accd2aeb4f3659ae297a73f422e +build_flags = ${nrf52840_base.build_flags} -Ivariants/tracker-t1000-e -Isrc/platform/nrf52/softdevice -Isrc/platform/nrf52/softdevice/nrf52 -DTRACKER_T1000_E -DRADIOLIB_GODMODE + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" + -DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. +board_build.ldscript = src/platform/nrf52/nrf52840_s140_v7.ld +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/tracker-t1000-e> +lib_deps = + ${nrf52840_base.lib_deps} +debug_tool = jlink +; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) +upload_protocol = nrfutil diff --git a/variants/tracker-t1000-e/variant.cpp b/variants/tracker-t1000-e/variant.cpp new file mode 100644 index 000000000..85e0c44f3 --- /dev/null +++ b/variants/tracker-t1000-e/variant.cpp @@ -0,0 +1,64 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const uint32_t g_ADigitalPinMap[] = { + // P0 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, LOW); + + pinMode(PIN_3V3_EN, OUTPUT); + digitalWrite(PIN_3V3_EN, HIGH); + + pinMode(PIN_3V3_ACC_EN, OUTPUT); + digitalWrite(PIN_3V3_ACC_EN, LOW); + + pinMode(BUZZER_EN_PIN, OUTPUT); + digitalWrite(BUZZER_EN_PIN, HIGH); + + pinMode(PIN_GPS_EN, OUTPUT); + digitalWrite(PIN_GPS_EN, LOW); + + pinMode(GPS_VRTC_EN, OUTPUT); + digitalWrite(GPS_VRTC_EN, HIGH); + + pinMode(PIN_GPS_RESET, OUTPUT); + digitalWrite(PIN_GPS_RESET, LOW); + + pinMode(GPS_SLEEP_INT, OUTPUT); + digitalWrite(GPS_SLEEP_INT, HIGH); + + pinMode(GPS_RTC_INT, OUTPUT); + digitalWrite(GPS_RTC_INT, LOW); + + pinMode(GPS_RESETB_OUT, INPUT); +} \ No newline at end of file diff --git a/variants/tracker-t1000-e/variant.h b/variants/tracker-t1000-e/variant.h new file mode 100644 index 000000000..75d8ddffc --- /dev/null +++ b/variants/tracker-t1000-e/variant.h @@ -0,0 +1,150 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_TRACKER_T1000_E_ +#define _VARIANT_TRACKER_T1000_E_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Number of pins defined in PinDescription array +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (6) +#define NUM_ANALOG_OUTPUTS (0) + +#define PIN_3V3_EN (32 + 6) // P1.6, Power to Sensors +#define PIN_3V3_ACC_EN (32 + 7) // P1.7, Power to Acc + +#define PIN_LED1 (0 + 24) // P0.24 +#define LED_PIN PIN_LED1 +#define LED_BUILTIN -1 +#define LED_BLUE -1 // Actually green +#define LED_STATE_ON 1 // State when LED is lit + +#define BUTTON_PIN (0 + 6) // P0.6 +#define BUTTON_ACTIVE_LOW false +#define BUTTON_ACTIVE_PULLUP false +#define BUTTON_SENSE_TYPE 0x6 + +#define HAS_WIRE 1 + +#define WIRE_INTERFACES_COUNT 1 + +// unused pins +#define PIN_WIRE_SDA (0 + 9) // P0.26 +#define PIN_WIRE_SCL (0 + 10) // P0.27 + +/* + * Serial interfaces + */ +#define PIN_SERIAL1_RX (0 + 14) // P0.14 +#define PIN_SERIAL1_TX (0 + 13) // P0.13 + +#define PIN_SERIAL2_RX (0 + 17) // P0.17 +#define PIN_SERIAL2_TX (0 + 16) // P0.16 + +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (32 + 8) // P1.08 +#define PIN_SPI_MOSI (32 + 9) // P1.09 +#define PIN_SPI_SCK (0 + 11) // P0.11 +#define PIN_SPI_NSS (0 + 12) // P0.12 + +#define LORA_RESET (32 + 10) // P1.10 // RST +#define LORA_DIO1 (32 + 1) // P1.01 // IRQ +#define LORA_DIO2 (0 + 7) // P0.07 // BUSY +#define LORA_SCK PIN_SPI_SCK +#define LORA_MISO PIN_SPI_MISO +#define LORA_MOSI PIN_SPI_MOSI +#define LORA_CS PIN_SPI_NSS + +// supported modules list +#define USE_LR1110 + +#define LR1110_IRQ_PIN LORA_DIO1 +#define LR1110_NRESER_PIN LORA_RESET +#define LR1110_BUSY_PIN LORA_DIO2 +#define LR1110_SPI_NSS_PIN LORA_CS +#define LR1110_SPI_SCK_PIN LORA_SCK +#define LR1110_SPI_MOSI_PIN LORA_MOSI +#define LR1110_SPI_MISO_PIN LORA_MISO + +#define LR11X0_DIO3_TCXO_VOLTAGE 1.6 +#define LR11X0_DIO_AS_RF_SWITCH +#define LR11X0_DIO_RF_SWITCH_CONFIG 0x0f, 0x0, 0x09, 0x0B, 0x0A, 0x0, 0x4, 0x0 + +#define HAS_GPS 1 +#define GNSS_AIROHA +#define GPS_RX_PIN PIN_SERIAL1_RX +#define GPS_TX_PIN PIN_SERIAL1_TX + +#define GPS_BAUDRATE 115200 + +#define PIN_GPS_EN (32 + 11) // P1.11 +#define GPS_EN_ACTIVE HIGH + +#define PIN_GPS_RESET (32 + 15) // P1.15 +#define GPS_RESET_MODE HIGH + +#define GPS_VRTC_EN (0 + 8) // P0.8, awlays high +#define GPS_SLEEP_INT (32 + 12) // P1.12, awlays high +#define GPS_RTC_INT (0 + 15) // P0.15, normal is LOW, wake by HIGH +#define GPS_RESETB_OUT (32 + 14) // P1.14, awlays input pull_up + +#define GPS_FIX_HOLD_TIME 15000 // ms +#define BATTERY_PIN 2 +#define ADC_MULTIPLIER (2.0F) + +#define ADC_RESOLUTION 14 +#define BATTERY_SENSE_RESOLUTION_BITS 12 + +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 + +// Buzzer +#define BUZZER_EN_PIN (32 + 5) // P1.05, awlays high +#define PIN_BUZZER (0 + 25) // P0.25, pwm output + +#define T1000X_SENSOR_EN +#define T1000X_VCC_PIN (0 + 4) // P0.4 +#define T1000X_NTC_PIN (0 + 31) // P0.31 +#define T1000X_LUX_PIN (0 + 29) // P0.29 + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif // _VARIANT_TRACKER_T1000_E_ diff --git a/variants/tracksenger/internal/variant.h b/variants/tracksenger/internal/variant.h index e63cecd7b..929c38793 100644 --- a/variants/tracksenger/internal/variant.h +++ b/variants/tracksenger/internal/variant.h @@ -48,6 +48,7 @@ #define GPS_RESET_MODE LOW #define GPS_UC6580 +#define GPS_BAUDRATE 115200 #define USE_SX1262 #define LORA_DIO0 -1 // a No connect on the SX1262 module @@ -87,4 +88,4 @@ { \ 26, 37, 17, 16, 15, 7 \ } -// #end keyboard \ No newline at end of file +// #end keyboard diff --git a/variants/tracksenger/lcd/variant.h b/variants/tracksenger/lcd/variant.h index 0f3423d52..3f952361b 100644 --- a/variants/tracksenger/lcd/variant.h +++ b/variants/tracksenger/lcd/variant.h @@ -72,6 +72,7 @@ #define GPS_RESET_MODE LOW #define GPS_UC6580 +#define GPS_BAUDRATE 115200 #define USE_SX1262 #define LORA_DIO0 -1 // a No connect on the SX1262 module @@ -111,4 +112,4 @@ { \ 26, 37, 17, 16, 15, 7 \ } -// #end keyboard \ No newline at end of file +// #end keyboard diff --git a/variants/tracksenger/oled/variant.h b/variants/tracksenger/oled/variant.h index d6bacf139..99f12bd23 100644 --- a/variants/tracksenger/oled/variant.h +++ b/variants/tracksenger/oled/variant.h @@ -50,6 +50,7 @@ #define GPS_RESET_MODE LOW #define GPS_UC6580 +#define GPS_BAUDRATE 115200 #define USE_SX1262 #define LORA_DIO0 -1 // a No connect on the SX1262 module @@ -89,4 +90,4 @@ { \ 26, 37, 17, 16, 15, 7 \ } -// #end keyboard \ No newline at end of file +// #end keyboard diff --git a/variants/wio-t1000-s/variant.h b/variants/wio-t1000-s/variant.h index 86bd34f62..fa6ea4abc 100644 --- a/variants/wio-t1000-s/variant.h +++ b/variants/wio-t1000-s/variant.h @@ -106,7 +106,7 @@ extern "C" { #define LR11X0_DIO_RF_SWITCH_CONFIG 0x0f, 0x0, 0x09, 0x0B, 0x0A, 0x0, 0x4, 0x0 #define HAS_GPS 1 -#define GNSS_Airoha +#define GNSS_AIROHA #define GPS_RX_PIN PIN_SERIAL1_RX #define GPS_TX_PIN PIN_SERIAL1_TX