sforkowany z mirror/meshtastic-firmware
show real distances between nodes
rodzic
52b398083a
commit
4adddf4fd0
1
TODO.md
1
TODO.md
|
@ -4,7 +4,6 @@
|
||||||
* make debug info screen show real data (including battery level & charging)
|
* make debug info screen show real data (including battery level & charging)
|
||||||
* update build to generate both board types
|
* update build to generate both board types
|
||||||
* retest BLE software update for both board types
|
* retest BLE software update for both board types
|
||||||
* turn on screen when a new update arrives
|
|
||||||
* don't forward redundent pings or ping responses to the phone, it just wastes phone battery
|
* don't forward redundent pings or ping responses to the phone, it just wastes phone battery
|
||||||
|
|
||||||
# Medium priority
|
# Medium priority
|
||||||
|
|
|
@ -167,16 +167,15 @@ static int16_t packetnum = 0; // packet counter, we increment per xmission
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// A temporary buffer used for sending/receving packets, sized to hold the biggest buffer we might need
|
/// A temporary buffer used for sending/receving packets, sized to hold the biggest buffer we might need
|
||||||
static uint8_t radiobuf[SubPacket_size];
|
#define MAX_RHPACKETLEN 251
|
||||||
|
static uint8_t radiobuf[MAX_RHPACKETLEN];
|
||||||
uint8_t rxlen;
|
uint8_t rxlen;
|
||||||
uint8_t srcaddr, destaddr, id, flags;
|
uint8_t srcaddr, destaddr, id, flags;
|
||||||
|
|
||||||
assert(SubPacket_size < 251); // a hard limit from the radio stack (including 4 bytes of headers)
|
|
||||||
|
|
||||||
// Poll to see if we've received a packet
|
// Poll to see if we've received a packet
|
||||||
// if (manager.recvfromAckTimeout(radiobuf, &rxlen, 0, &srcaddr, &destaddr, &id, &flags))
|
// if (manager.recvfromAckTimeout(radiobuf, &rxlen, 0, &srcaddr, &destaddr, &id, &flags))
|
||||||
// prefill rxlen with the max length we can accept - very important
|
// prefill rxlen with the max length we can accept - very important
|
||||||
rxlen = sizeof(radiobuf);
|
rxlen = (uint8_t) MAX_RHPACKETLEN;
|
||||||
if (manager.recvfrom(radiobuf, &rxlen, &srcaddr, &destaddr, &id, &flags))
|
if (manager.recvfrom(radiobuf, &rxlen, &srcaddr, &destaddr, &id, &flags))
|
||||||
{
|
{
|
||||||
// We received a packet
|
// We received a packet
|
||||||
|
|
|
@ -41,8 +41,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Select which board is being used. If the outside build environment has sent a choice, just use that
|
// Select which board is being used. If the outside build environment has sent a choice, just use that
|
||||||
#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32)
|
#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32)
|
||||||
#define T_BEAM_V10 // AKA Rev1 (second board released)
|
//#define T_BEAM_V10 // AKA Rev1 (second board released)
|
||||||
//#define HELTEC_LORA32
|
#define HELTEC_LORA32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled)
|
// If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled)
|
||||||
|
|
|
@ -9,16 +9,16 @@
|
||||||
PB_BIND(Position, Position, AUTO)
|
PB_BIND(Position, Position, AUTO)
|
||||||
|
|
||||||
|
|
||||||
PB_BIND(Data, Data, AUTO)
|
PB_BIND(Data, Data, 2)
|
||||||
|
|
||||||
|
|
||||||
PB_BIND(User, User, AUTO)
|
PB_BIND(User, User, AUTO)
|
||||||
|
|
||||||
|
|
||||||
PB_BIND(SubPacket, SubPacket, AUTO)
|
PB_BIND(SubPacket, SubPacket, 2)
|
||||||
|
|
||||||
|
|
||||||
PB_BIND(MeshPacket, MeshPacket, AUTO)
|
PB_BIND(MeshPacket, MeshPacket, 2)
|
||||||
|
|
||||||
|
|
||||||
PB_BIND(ChannelSettings, ChannelSettings, AUTO)
|
PB_BIND(ChannelSettings, ChannelSettings, AUTO)
|
||||||
|
@ -39,10 +39,10 @@ PB_BIND(MyNodeInfo, MyNodeInfo, AUTO)
|
||||||
PB_BIND(DeviceState, DeviceState, 4)
|
PB_BIND(DeviceState, DeviceState, 4)
|
||||||
|
|
||||||
|
|
||||||
PB_BIND(FromRadio, FromRadio, AUTO)
|
PB_BIND(FromRadio, FromRadio, 2)
|
||||||
|
|
||||||
|
|
||||||
PB_BIND(ToRadio, ToRadio, AUTO)
|
PB_BIND(ToRadio, ToRadio, 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ typedef enum _ChannelSettings_ModemConfig {
|
||||||
|
|
||||||
typedef enum _DeviceState_Version {
|
typedef enum _DeviceState_Version {
|
||||||
DeviceState_Version_Unset = 0,
|
DeviceState_Version_Unset = 0,
|
||||||
DeviceState_Version_Minimum = 11,
|
DeviceState_Version_Minimum = 12,
|
||||||
DeviceState_Version_Current = 11
|
DeviceState_Version_Current = 12
|
||||||
} DeviceState_Version;
|
} DeviceState_Version;
|
||||||
|
|
||||||
/* Struct definitions */
|
/* Struct definitions */
|
||||||
|
@ -47,7 +47,7 @@ typedef struct _ChannelSettings {
|
||||||
char name[12];
|
char name[12];
|
||||||
} ChannelSettings;
|
} ChannelSettings;
|
||||||
|
|
||||||
typedef PB_BYTES_ARRAY_T(200) Data_payload_t;
|
typedef PB_BYTES_ARRAY_T(251) Data_payload_t;
|
||||||
typedef struct _Data {
|
typedef struct _Data {
|
||||||
Data_Type typ;
|
Data_Type typ;
|
||||||
Data_payload_t payload;
|
Data_payload_t payload;
|
||||||
|
@ -389,18 +389,18 @@ extern const pb_msgdesc_t ToRadio_msg;
|
||||||
|
|
||||||
/* Maximum encoded size of messages (where known) */
|
/* Maximum encoded size of messages (where known) */
|
||||||
#define Position_size 42
|
#define Position_size 42
|
||||||
#define Data_size 205
|
#define Data_size 256
|
||||||
#define User_size 72
|
#define User_size 72
|
||||||
#define SubPacket_size 208
|
#define SubPacket_size 259
|
||||||
#define MeshPacket_size 239
|
#define MeshPacket_size 290
|
||||||
#define ChannelSettings_size 50
|
#define ChannelSettings_size 50
|
||||||
#define RadioConfig_size 72
|
#define RadioConfig_size 72
|
||||||
#define RadioConfig_UserPreferences_size 18
|
#define RadioConfig_UserPreferences_size 18
|
||||||
#define NodeInfo_size 157
|
#define NodeInfo_size 157
|
||||||
#define MyNodeInfo_size 13
|
#define MyNodeInfo_size 13
|
||||||
#define DeviceState_size 13271
|
#define DeviceState_size 14954
|
||||||
#define FromRadio_size 248
|
#define FromRadio_size 299
|
||||||
#define ToRadio_size 242
|
#define ToRadio_size 293
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
@ -129,7 +129,7 @@ void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int1
|
||||||
/// Draw the last text message we received
|
/// Draw the last text message we received
|
||||||
void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
MeshPacket &mp = devicestate.rx_text_message;
|
MeshPacket &mp = devicestate.rx_text_message;
|
||||||
NodeInfo *node = nodeDB.getNode(mp.from);
|
NodeInfo *node = nodeDB.getNode(mp.from);
|
||||||
|
|
||||||
// Demo for drawStringMaxWidth:
|
// Demo for drawStringMaxWidth:
|
||||||
|
@ -140,7 +140,7 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
||||||
String sender = (node && node->has_user) ? node->user.short_name : "???";
|
String sender = (node && node->has_user) ? node->user.short_name : "???";
|
||||||
display->drawString(0 + x, 0 + y, sender);
|
display->drawString(0 + x, 0 + y, sender);
|
||||||
display->setFont(ArialMT_Plain_10);
|
display->setFont(ArialMT_Plain_10);
|
||||||
|
|
||||||
static char tempBuf[96];
|
static char tempBuf[96];
|
||||||
snprintf(tempBuf, sizeof(tempBuf), " %s", mp.payload.variant.data.payload.bytes); // the max length of this buffer is much longer than we can possibly print
|
snprintf(tempBuf, sizeof(tempBuf), " %s", mp.payload.variant.data.payload.bytes); // the max length of this buffer is much longer than we can possibly print
|
||||||
|
|
||||||
|
@ -196,6 +196,28 @@ uint32_t drawRows(OLEDDisplay *display, int16_t x, int16_t y, const char **field
|
||||||
return yo;
|
return yo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ported from my old java code, returns distance in meters along the globe surface (by magic?)
|
||||||
|
float latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b)
|
||||||
|
{
|
||||||
|
double pk = (180 / 3.14169);
|
||||||
|
double a1 = lat_a / pk;
|
||||||
|
double a2 = lng_a / pk;
|
||||||
|
double b1 = lat_b / pk;
|
||||||
|
double b2 = lng_b / pk;
|
||||||
|
double cos_b1 = cos(b1);
|
||||||
|
double cos_a1 = cos(a1);
|
||||||
|
double t1 =
|
||||||
|
cos_a1 * cos(a2) * cos_b1 * cos(b2);
|
||||||
|
double t2 =
|
||||||
|
cos_a1 * sin(a2) * cos_b1 * sin(b2);
|
||||||
|
double t3 = sin(a1) * sin(b1);
|
||||||
|
double tt = acos(t1 + t2 + t3);
|
||||||
|
if (isnan(tt))
|
||||||
|
tt = 0.0; // Must have been the same point?
|
||||||
|
|
||||||
|
return (float)(6366000 * tt);
|
||||||
|
}
|
||||||
|
|
||||||
/// A basic 2D point class for drawing
|
/// A basic 2D point class for drawing
|
||||||
class Point
|
class Point
|
||||||
{
|
{
|
||||||
|
@ -277,9 +299,22 @@ void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, in
|
||||||
else
|
else
|
||||||
snprintf(lastStr, sizeof(lastStr), "%d hours ago", agoSecs / 60 / 60);
|
snprintf(lastStr, sizeof(lastStr), "%d hours ago", agoSecs / 60 / 60);
|
||||||
|
|
||||||
|
static char distStr[20];
|
||||||
|
*distStr = 0; // might not have location data
|
||||||
|
NodeInfo *ourNode = nodeDB.getNode(nodeDB.getNodeNum());
|
||||||
|
if (ourNode && ourNode->has_position && node->has_position)
|
||||||
|
{
|
||||||
|
Position &op = ourNode->position, &p = node->position;
|
||||||
|
float d = latLongToMeter(p.latitude, p.longitude, op.latitude, op.longitude);
|
||||||
|
if (d < 2000)
|
||||||
|
snprintf(distStr, sizeof(distStr), "%.0f m", d);
|
||||||
|
else
|
||||||
|
snprintf(distStr, sizeof(distStr), "%.1f km", d / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
const char *fields[] = {
|
const char *fields[] = {
|
||||||
username,
|
username,
|
||||||
"2.1 mi",
|
distStr,
|
||||||
signalStr,
|
signalStr,
|
||||||
lastStr,
|
lastStr,
|
||||||
NULL};
|
NULL};
|
||||||
|
@ -549,7 +584,7 @@ void screen_set_frames()
|
||||||
size_t numframes = 0;
|
size_t numframes = 0;
|
||||||
|
|
||||||
// If we have a text message - show it first
|
// If we have a text message - show it first
|
||||||
if(devicestate.has_rx_text_message)
|
if (devicestate.has_rx_text_message)
|
||||||
nonBootFrames[numframes++] = drawTextMessageFrame;
|
nonBootFrames[numframes++] = drawTextMessageFrame;
|
||||||
|
|
||||||
// then all the nodes
|
// then all the nodes
|
||||||
|
|
Ładowanie…
Reference in New Issue