From 28588f6730ae29c62800ec59ccf00b932764e012 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 3 Mar 2020 08:23:58 -0800 Subject: [PATCH] send hw version info via protobufs --- TODO.md | 1 - bin/regen-protos.sh | 7 +++- proto | 2 +- src/NodeDB.cpp | 3 ++ src/configuration.h | 81 ++++++++++++++++++++++----------------------- src/main.cpp | 9 ++--- src/mesh.pb.h | 19 ++++++++--- 7 files changed, 66 insertions(+), 56 deletions(-) diff --git a/TODO.md b/TODO.md index 689433d5a..73bdd492a 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ Items to complete soon (next couple of alpha releases). -* Serious but rare bug: after light sleep sometimes protocol bufs sent to phone are corrupted!!! * text messages are not showing on local screen if screen was on * The following three items are all the same: diff --git a/bin/regen-protos.sh b/bin/regen-protos.sh index af98aee9a..bc6bc9b72 100755 --- a/bin/regen-protos.sh +++ b/bin/regen-protos.sh @@ -1 +1,6 @@ -/home/kevinh/packages/nanopb-0.4.1-linux-x86/generator-bin/protoc --nanopb_out=-v:src -I=proto mesh.proto +#!/bin/bash + +echo "This script requires https://jpa.kapsi.fi/nanopb/download/ version 0.4.1" +# the nanopb tool seems to require that the .options file be in the current directory! +cd proto +../../nanopb-0.4.1-linux-x86/generator-bin/protoc --nanopb_out=-v:../src -I=../proto mesh.proto diff --git a/proto b/proto index c4ee1448e..e1a48b6e7 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit c4ee1448ea99058fe45c6738e547197e4a4c1887 +Subproject commit e1a48b6e75c2ec3ad3995165a7b4fb64ce597e02 diff --git a/src/NodeDB.cpp b/src/NodeDB.cpp index 8071d58d7..55996a1e0 100644 --- a/src/NodeDB.cpp +++ b/src/NodeDB.cpp @@ -64,6 +64,9 @@ void NodeDB::init() // some hardware defaults to have a built in GPS myNodeInfo.has_gps = true; #endif + strncpy(myNodeInfo.region, xstr(HW_VERSION), sizeof(myNodeInfo.region)); + strncpy(myNodeInfo.firmware_version, xstr(APP_VERSION), sizeof(myNodeInfo.firmware_version)); + strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model)); // Init our blank owner info to reasonable defaults esp_efuse_mac_get_default(ourMacAddr); diff --git a/src/configuration.h b/src/configuration.h index d27c9009b..01f368053 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -31,11 +31,10 @@ along with this program. If not, see . // If app version is not specified we assume we are not being invoked by the build script #ifndef APP_VERSION -#define APP_VERSION 0.0.0 // this def normally comes from build-all.sh -#define HW_VERSION 1.0-US // normally comes from build-all.sh and contains the region code +#define APP_VERSION 0.0.0 // this def normally comes from build-all.sh +#define HW_VERSION 1.0 - US // normally comes from build-all.sh and contains the region code #endif - // ----------------------------------------------------------------------------- // Configuration // ----------------------------------------------------------------------------- @@ -54,18 +53,20 @@ along with this program. If not, see . //#define USE_JTAG #endif -#define DEBUG_PORT Serial // Serial debug port -#define SERIAL_BAUD 115200 // Serial debug baud rate +#define DEBUG_PORT Serial // Serial debug port +#define SERIAL_BAUD 115200 // Serial debug baud rate -#define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found +#define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found +#define xstr(s) str(s) +#define str(s) #s // ----------------------------------------------------------------------------- // DEBUG // ----------------------------------------------------------------------------- #ifdef DEBUG_PORT -#define DEBUG_MSG(...) DEBUG_PORT.printf( __VA_ARGS__ ) +#define DEBUG_MSG(...) DEBUG_PORT.printf(__VA_ARGS__) #else #define DEBUG_MSG(...) #endif @@ -80,15 +81,15 @@ along with this program. If not, see . // GPS // ----------------------------------------------------------------------------- -#define GPS_SERIAL_NUM 1 -#define GPS_BAUDRATE 9600 +#define GPS_SERIAL_NUM 1 +#define GPS_BAUDRATE 9600 #if defined(T_BEAM_V10) -#define GPS_RX_PIN 34 +#define GPS_RX_PIN 34 #ifdef USE_JTAG -#define GPS_TX_PIN -1 +#define GPS_TX_PIN -1 #else -#define GPS_TX_PIN 12 +#define GPS_TX_PIN 12 #endif #endif @@ -96,61 +97,59 @@ along with this program. If not, see . // LoRa SPI // ----------------------------------------------------------------------------- -#define SCK_GPIO 5 -#define MISO_GPIO 19 -#define MOSI_GPIO 27 -#define NSS_GPIO 18 +#define SCK_GPIO 5 +#define MISO_GPIO 19 +#define MOSI_GPIO 27 +#define NSS_GPIO 18 #if defined(T_BEAM_V10) // This string must exactly match the case used in release file names or the android updater won't work -#define HW_VENDOR "TBEAM" +#define HW_VENDOR "TBEAM" #define BICOLOR_DISPLAY // we have yellow at the top 16 lines -#define I2C_SDA 21 -#define I2C_SCL 22 +#define I2C_SDA 21 +#define I2C_SCL 22 -#define BUTTON_PIN 38 +#define BUTTON_PIN 38 #ifndef USE_JTAG -#define RESET_GPIO 14 +#define RESET_GPIO 14 #endif -#define DIO0_GPIO 26 -#define DIO1_GPIO 33 // Note: not really used on this board -#define DIO2_GPIO 32 // Note: not really used on this board +#define DIO0_GPIO 26 +#define DIO1_GPIO 33 // Note: not really used on this board +#define DIO2_GPIO 32 // Note: not really used on this board -// Leave undefined to disable our PMU IRQ handler -#define PMU_IRQ 35 +// Leave undefined to disable our PMU IRQ handler +#define PMU_IRQ 35 #elif defined(HELTEC_LORA32) // This string must exactly match the case used in release file names or the android updater won't work -#define HW_VENDOR "HELTEC" +#define HW_VENDOR "HELTEC" #ifndef USE_JTAG // gpio15 is TDO for JTAG, so no I2C on this board while doing jtag -#define I2C_SDA 4 -#define I2C_SCL 15 +#define I2C_SDA 4 +#define I2C_SCL 15 #endif -#define RESET_OLED 16 +#define RESET_OLED 16 -#define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost -#define LED_PIN 25 -#define BUTTON_PIN 0 +#define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost +#define LED_PIN 25 +#define BUTTON_PIN 0 #ifndef USE_JTAG -#define RESET_GPIO 14 +#define RESET_GPIO 14 #endif -#define DIO0_GPIO 26 -#define DIO1_GPIO 35 -#define DIO2_GPIO 34 +#define DIO0_GPIO 26 +#define DIO1_GPIO 35 +#define DIO2_GPIO 34 #endif - // ----------------------------------------------------------------------------- // AXP192 (Rev1-specific options) // ----------------------------------------------------------------------------- // #define AXP192_SLAVE_ADDRESS 0x34 // Now defined in axp20x.h -#define GPS_POWER_CTRL_CH 3 -#define LORA_POWER_CTRL_CH 2 - +#define GPS_POWER_CTRL_CH 3 +#define LORA_POWER_CTRL_CH 2 diff --git a/src/main.cpp b/src/main.cpp index 9ba9023f2..f016eb740 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,10 +52,7 @@ bool isUSBPowered; bool ssd1306_found; bool axp192_found; -bool bluetoothOn; - -#define xstr(s) str(s) -#define str(s) #s +bool bluetoothOn; // ----------------------------------------------------------------------------- // Application @@ -201,8 +198,6 @@ const char *getDeviceName() return name; } - - void setup() { // Debug @@ -288,7 +283,7 @@ void setBluetoothEnable(bool on) { Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap()); //ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); - initBluetooth(); + initBluetooth(); } else { diff --git a/src/mesh.pb.h b/src/mesh.pb.h index 84e411e9d..08825f252 100644 --- a/src/mesh.pb.h +++ b/src/mesh.pb.h @@ -56,6 +56,9 @@ typedef struct _MyNodeInfo { int32_t my_node_num; bool has_gps; int32_t num_channels; + char region[12]; + char hw_model[12]; + char firmware_version[12]; } MyNodeInfo; typedef struct _Position { @@ -184,7 +187,7 @@ typedef struct _ToRadio { #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default} #define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0} -#define MyNodeInfo_init_default {0, 0, 0} +#define MyNodeInfo_init_default {0, 0, 0, "", "", ""} #define DeviceState_init_default {false, RadioConfig_init_default, false, MyNodeInfo_init_default, false, User_init_default, 0, {NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default}, 0, {MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default}, _DeviceState_Version_MIN, false, MeshPacket_init_default} #define FromRadio_init_default {0, 0, {MeshPacket_init_default}} #define ToRadio_init_default {0, {MeshPacket_init_default}} @@ -197,7 +200,7 @@ typedef struct _ToRadio { #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero} #define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0} -#define MyNodeInfo_init_zero {0, 0, 0} +#define MyNodeInfo_init_zero {0, 0, 0, "", "", ""} #define DeviceState_init_zero {false, RadioConfig_init_zero, false, MyNodeInfo_init_zero, false, User_init_zero, 0, {NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero}, 0, {MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero}, _DeviceState_Version_MIN, false, MeshPacket_init_zero} #define FromRadio_init_zero {0, 0, {MeshPacket_init_zero}} #define ToRadio_init_zero {0, {MeshPacket_init_zero}} @@ -213,6 +216,9 @@ typedef struct _ToRadio { #define MyNodeInfo_my_node_num_tag 1 #define MyNodeInfo_has_gps_tag 2 #define MyNodeInfo_num_channels_tag 3 +#define MyNodeInfo_region_tag 4 +#define MyNodeInfo_hw_model_tag 5 +#define MyNodeInfo_firmware_version_tag 6 #define Position_latitude_tag 1 #define Position_longitude_tag 2 #define Position_altitude_tag 3 @@ -353,7 +359,10 @@ X(a, STATIC, SINGULAR, INT32, frequency_error, 6) #define MyNodeInfo_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, INT32, my_node_num, 1) \ X(a, STATIC, SINGULAR, BOOL, has_gps, 2) \ -X(a, STATIC, SINGULAR, INT32, num_channels, 3) +X(a, STATIC, SINGULAR, INT32, num_channels, 3) \ +X(a, STATIC, SINGULAR, STRING, region, 4) \ +X(a, STATIC, SINGULAR, STRING, hw_model, 5) \ +X(a, STATIC, SINGULAR, STRING, firmware_version, 6) #define MyNodeInfo_CALLBACK NULL #define MyNodeInfo_DEFAULT NULL @@ -426,8 +435,8 @@ extern const pb_msgdesc_t ToRadio_msg; #define RadioConfig_size 126 #define RadioConfig_UserPreferences_size 72 #define NodeInfo_size 155 -#define MyNodeInfo_size 24 -#define DeviceState_size 15021 +#define MyNodeInfo_size 63 +#define DeviceState_size 15060 #define FromRadio_size 301 #define ToRadio_size 295