From 803d2dfefbd6605c6fd90c7ce080ac82db8830df Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 28 Apr 2020 17:06:00 -0700 Subject: [PATCH 1/2] add note about python API --- docs/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/README.md b/docs/README.md index 850ea89de..a10ff9f6a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,6 +13,7 @@ Note: Questions after reading this? See our new [forum](https://meshtastic.disco - Applications where closed source GPS communicators just won't cut it (it is easy to add features for glider pilots etc...) - Secure long-range communication within groups without depending on cellular providers - Finding your lost kids ;-) +- Through our [python API](https://pypi.org/project/meshtastic/) use these inexpensive radios to easily add mesh networking to your own projects. [![Youtube video demo](desk-video-screenshot.png)](https://www.youtube.com/watch?v=WlNbMbVZlHI "Meshtastic early demo") @@ -38,6 +39,7 @@ This software is 100% open source and developed by a group of hobbyist experimen Note: Updates are happening almost daily, only major updates are listed below. For more details see our forum. +- 04/28/2020 - 0.6.0 [Python API](https://pypi.org/project/meshtastic/) released. Makes it easy to use meshtastic devices as "zero config / just works" mesh transport adapters for other projects. - 04/20/2020 - 0.4.3 Pretty solid now both for the android app and the device code. Many people have donated translations and code. Probably going to call it a beta soon. - 03/03/2020 - 0.0.9 of the Android app and device code is released. Still an alpha but fairly functional. - 02/25/2020 - 0.0.4 of the Android app is released. This is a very early alpha, see below to join the alpha-testers group. From 2ab34357d5922c94055c74c227494f0e075acff3 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 28 Apr 2020 17:43:16 -0700 Subject: [PATCH 2/2] emit FromRadio.rebooted to serial test harness can detect reboots --- proto | 2 +- src/SerialConsole.cpp | 1 + src/mesh/PhoneAPI.h | 6 +++--- src/mesh/StreamAPI.cpp | 36 ++++++++++++++++++++++++++++-------- src/mesh/StreamAPI.h | 15 +++++++++++++-- src/mesh/mesh.pb.h | 5 ++++- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/proto b/proto index 8427b2301..e570ee983 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 8427b23016dc96fc78885f05de5172e9eec5fe6d +Subproject commit e570ee9836949d9f420fd19cc59a2595c8669a6e diff --git a/src/SerialConsole.cpp b/src/SerialConsole.cpp index 3a8917fd3..861219037 100644 --- a/src/SerialConsole.cpp +++ b/src/SerialConsole.cpp @@ -17,6 +17,7 @@ void SerialConsole::init() { Port.begin(SERIAL_BAUD); StreamAPI::init(); + emitRebooted(); } /** diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 337408246..cb4ba1c34 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -45,9 +45,6 @@ class PhoneAPI /// We temporarily keep the nodeInfo here between the call to available and getFromRadio const NodeInfo *nodeInfoForPhone = NULL; - /// Our fromradio packet while it is being assembled - FromRadio fromRadioScratch; - ToRadio toRadioScratch; // this is a static scratch object, any data must be copied elsewhere before returning /// Use to ensure that clients don't get confused about old messages from the radio @@ -85,6 +82,9 @@ class PhoneAPI void handleSetRadio(const RadioConfig &r); protected: + /// Our fromradio packet while it is being assembled + FromRadio fromRadioScratch; + /** * Subclasses can use this as a hook to provide custom notifications for their transport (i.e. bluetooth notifies) */ diff --git a/src/mesh/StreamAPI.cpp b/src/mesh/StreamAPI.cpp index 674e758c9..00434f90b 100644 --- a/src/mesh/StreamAPI.cpp +++ b/src/mesh/StreamAPI.cpp @@ -1,4 +1,5 @@ #include "StreamAPI.h" +#include "configuration.h" #define START1 0x94 #define START2 0xc3 @@ -58,14 +59,33 @@ void StreamAPI::writeStream() do { // Send every packet we can len = getFromRadio(txBuf + HEADER_LEN); - if (len != 0) { - txBuf[0] = START1; - txBuf[1] = START2; - txBuf[2] = (len >> 8) & 0xff; - txBuf[3] = len & 0xff; - - stream->write(txBuf, len + HEADER_LEN); - } + emitTxBuffer(len); } while (len); } +} + +/** + * Send the current txBuffer over our stream + */ +void StreamAPI::emitTxBuffer(size_t len) +{ + if (len != 0) { + txBuf[0] = START1; + txBuf[1] = START2; + txBuf[2] = (len >> 8) & 0xff; + txBuf[3] = len & 0xff; + + stream->write(txBuf, len + HEADER_LEN); + } +} + +void StreamAPI::emitRebooted() +{ + // In case we send a FromRadio packet + memset(&fromRadioScratch, 0, sizeof(fromRadioScratch)); + fromRadioScratch.which_variant = FromRadio_rebooted_tag; + fromRadioScratch.variant.rebooted = true; + + DEBUG_MSG("Emitting reboot packet for serial shell\n"); + emitTxBuffer(pb_encode_to_bytes(txBuf + HEADER_LEN, FromRadio_size, FromRadio_fields, &fromRadioScratch)); } \ No newline at end of file diff --git a/src/mesh/StreamAPI.h b/src/mesh/StreamAPI.h index ec8e55946..ed0a5fbd4 100644 --- a/src/mesh/StreamAPI.h +++ b/src/mesh/StreamAPI.h @@ -37,8 +37,6 @@ class StreamAPI : public PhoneAPI uint8_t rxBuf[MAX_STREAM_BUF_SIZE]; size_t rxPtr = 0; - uint8_t txBuf[MAX_STREAM_BUF_SIZE]; - public: StreamAPI(Stream *_stream) : stream(_stream) {} @@ -61,6 +59,19 @@ class StreamAPI : public PhoneAPI void writeStream(); protected: + /** + * Send a FromRadio.rebooted = true packet to the phone + */ + void emitRebooted(); + + /** + * Send the current txBuffer over our stream + */ + void emitTxBuffer(size_t len); + /// Are we allowed to write packets to our output stream (subclasses can turn this off - i.e. SerialConsole) bool canWrite = true; + + /// Subclasses can use this scratch buffer if they wish + uint8_t txBuf[MAX_STREAM_BUF_SIZE]; }; \ No newline at end of file diff --git a/src/mesh/mesh.pb.h b/src/mesh/mesh.pb.h index 9e639ac7e..fdc266cdb 100644 --- a/src/mesh/mesh.pb.h +++ b/src/mesh/mesh.pb.h @@ -159,6 +159,7 @@ typedef struct _FromRadio { RadioConfig radio; DebugString debug_string; uint32_t config_complete_id; + bool rebooted; } variant; } FromRadio; @@ -289,6 +290,7 @@ typedef struct _ToRadio { #define FromRadio_radio_tag 6 #define FromRadio_debug_string_tag 7 #define FromRadio_config_complete_id_tag 8 +#define FromRadio_rebooted_tag 9 #define FromRadio_num_tag 1 #define ToRadio_packet_tag 1 #define ToRadio_want_config_id_tag 100 @@ -432,7 +434,8 @@ X(a, STATIC, ONEOF, MESSAGE, (variant,my_info,variant.my_info), 3) \ X(a, STATIC, ONEOF, MESSAGE, (variant,node_info,variant.node_info), 4) \ X(a, STATIC, ONEOF, MESSAGE, (variant,radio,variant.radio), 6) \ X(a, STATIC, ONEOF, MESSAGE, (variant,debug_string,variant.debug_string), 7) \ -X(a, STATIC, ONEOF, UINT32, (variant,config_complete_id,variant.config_complete_id), 8) +X(a, STATIC, ONEOF, UINT32, (variant,config_complete_id,variant.config_complete_id), 8) \ +X(a, STATIC, ONEOF, BOOL, (variant,rebooted,variant.rebooted), 9) #define FromRadio_CALLBACK NULL #define FromRadio_DEFAULT NULL #define FromRadio_variant_packet_MSGTYPE MeshPacket