fix #269 see below

/**
 * Generate a short suffix used to disambiguate channels that might have the same "name" entered by the human but different PSKs.
 * The ideas is that the PSK changing should be visible to the user so that they see they probably messed up and that's why they
their nodes
 * aren't talking to each other.
 *
 * This string is of the form "#name-XY".
 *
 * Where X is a letter from A to Z (base26), and formed by xoring all the bytes of the PSK together.
 * Y is not yet used but should eventually indicate 'speed/range' of the link
 *
 * This function will also need to be implemented in GUI apps that talk to the radio.
 *
 * https://github.com/meshtastic/Meshtastic-device/issues/269
 */
const char *getChannelName();
This commit is contained in:
geeksville 2020-08-12 11:04:03 -07:00
parent 178958c165
commit 55dafcbecb
5 changed files with 82 additions and 46 deletions

View File

@ -25,13 +25,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "GPS.h" #include "GPS.h"
#include "MeshService.h" #include "MeshService.h"
#include "NodeDB.h" #include "NodeDB.h"
#include "Screen.h"
#include "configs.h"
#include "configuration.h" #include "configuration.h"
#include "graphics/images.h" #include "graphics/images.h"
#include "main.h" #include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "Screen.h"
#include "utils.h" #include "utils.h"
#include "configs.h"
using namespace meshtastic; /** @todo remove */ using namespace meshtastic; /** @todo remove */
@ -208,25 +208,20 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, NodeStatus *no
// Draw GPS status summary // Draw GPS status summary
static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps) static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps)
{ {
if (!gps->getIsConnected()) if (!gps->getIsConnected()) {
{
display->drawString(x, y - 2, "No GPS"); display->drawString(x, y - 2, "No GPS");
return; return;
} }
display->drawFastImage(x, y, 6, 8, gps->getHasLock() ? imgPositionSolid : imgPositionEmpty); display->drawFastImage(x, y, 6, 8, gps->getHasLock() ? imgPositionSolid : imgPositionEmpty);
if (!gps->getHasLock()) if (!gps->getHasLock()) {
{
display->drawString(x + 8, y - 2, "No sats"); display->drawString(x + 8, y - 2, "No sats");
return; return;
} } else {
else
{
char satsString[3]; char satsString[3];
uint8_t bar[2] = {0}; uint8_t bar[2] = {0};
// Draw DOP signal bars // Draw DOP signal bars
for(int i = 0; i < 5; i++) for (int i = 0; i < 5; i++) {
{
if (gps->getDOP() <= dopThresholds[i]) if (gps->getDOP() <= dopThresholds[i])
bar[0] = ~((1 << (5 - i)) - 1); bar[0] = ~((1 << (5 - i)) - 1);
else else
@ -390,7 +385,6 @@ static void drawNodeHeading(OLEDDisplay *display, int16_t compassX, int16_t comp
float arrowOffsetX = 0.2f, arrowOffsetY = 0.2f; float arrowOffsetX = 0.2f, arrowOffsetY = 0.2f;
Point leftArrow(tip.x - arrowOffsetX, tip.y - arrowOffsetY), rightArrow(tip.x + arrowOffsetX, tip.y - arrowOffsetY); Point leftArrow(tip.x - arrowOffsetX, tip.y - arrowOffsetY), rightArrow(tip.x + arrowOffsetX, tip.y - arrowOffsetY);
Point *arrowPoints[] = {&tip, &tail, &leftArrow, &rightArrow}; Point *arrowPoints[] = {&tip, &tail, &leftArrow, &rightArrow};
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -440,8 +434,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
displayedNodeNum = n->num; displayedNodeNum = n->num;
// We just changed to a new node screen, ask that node for updated state if it's older than 2 minutes // We just changed to a new node screen, ask that node for updated state if it's older than 2 minutes
if(sinceLastSeen(n) > 120) if (sinceLastSeen(n) > 120) {
{
service.sendNetworkPing(displayedNodeNum, true); service.sendNetworkPing(displayedNodeNum, true);
} }
} }
@ -477,14 +470,12 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
int16_t compassX = x + SCREEN_WIDTH - COMPASS_DIAM / 2 - 5, compassY = y + SCREEN_HEIGHT / 2; int16_t compassX = x + SCREEN_WIDTH - COMPASS_DIAM / 2 - 5, compassY = y + SCREEN_HEIGHT / 2;
bool hasNodeHeading = false; bool hasNodeHeading = false;
if(ourNode && hasPosition(ourNode)) if (ourNode && hasPosition(ourNode)) {
{
Position &op = ourNode->position; Position &op = ourNode->position;
float myHeading = estimatedHeading(DegD(op.latitude_i), DegD(op.longitude_i)); float myHeading = estimatedHeading(DegD(op.latitude_i), DegD(op.longitude_i));
drawCompassHeading(display, compassX, compassY, myHeading); drawCompassHeading(display, compassX, compassY, myHeading);
if(hasPosition(node)) if (hasPosition(node)) {
{
// display direction toward node // display direction toward node
hasNodeHeading = true; hasNodeHeading = true;
Position &p = node->position; Position &p = node->position;
@ -508,7 +499,6 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
display->drawString(compassX - FONT_HEIGHT / 4, compassY - FONT_HEIGHT / 2, "?"); display->drawString(compassX - FONT_HEIGHT / 4, compassY - FONT_HEIGHT / 2, "?");
display->drawCircle(compassX, compassY, COMPASS_DIAM / 2); display->drawCircle(compassX, compassY, COMPASS_DIAM / 2);
// Must be after distStr is populated // Must be after distStr is populated
drawColumns(display, x, y, fields); drawColumns(display, x, y, fields);
} }
@ -779,7 +769,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
char channelStr[20]; char channelStr[20];
{ {
concurrency::LockGuard guard(&lock); concurrency::LockGuard guard(&lock);
snprintf(channelStr, sizeof(channelStr), "#%s", channelName.c_str()); snprintf(channelStr, sizeof(channelStr), "%s", channelName.c_str());
// Display power status // Display power status
if (powerStatus->getHasBattery()) if (powerStatus->getHasBattery())
@ -827,8 +817,7 @@ void Screen::adjustBrightness()
int Screen::handleStatusUpdate(const meshtastic::Status *arg) int Screen::handleStatusUpdate(const meshtastic::Status *arg)
{ {
// DEBUG_MSG("Screen got status update %d\n", arg->getStatusType()); // DEBUG_MSG("Screen got status update %d\n", arg->getStatusType());
switch(arg->getStatusType()) switch (arg->getStatusType()) {
{
case STATUS_TYPE_NODE: case STATUS_TYPE_NODE:
if (nodeDB.updateTextMessage || nodeStatus->getLastNumTotal() != nodeStatus->getNumTotal()) if (nodeDB.updateTextMessage || nodeStatus->getLastNumTotal() != nodeStatus->getNumTotal())
setFrames(); setFrames();

View File

@ -364,7 +364,7 @@ void loop()
#endif #endif
// Update the screen last, after we've figured out what to show. // Update the screen last, after we've figured out what to show.
screen.debug_info()->setChannelNameStatus(channelSettings.name); screen.debug_info()->setChannelNameStatus(getChannelName());
// screen.debug()->setPowerStatus(powerStatus); // screen.debug()->setPowerStatus(powerStatus);
// No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in) // No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in)

View File

@ -66,6 +66,33 @@ static uint8_t ourMacAddr[6];
*/ */
NodeNum displayedNodeNum; NodeNum displayedNodeNum;
/**
* Generate a short suffix used to disambiguate channels that might have the same "name" entered by the human but different PSKs.
* The ideas is that the PSK changing should be visible to the user so that they see they probably messed up and that's why they
their nodes
* aren't talking to each other.
*
* This string is of the form "#name-XY".
*
* Where X is a letter from A to Z (base26), and formed by xoring all the bytes of the PSK together.
* Y is not yet used but should eventually indicate 'speed/range' of the link
*
* This function will also need to be implemented in GUI apps that talk to the radio.
*
* https://github.com/meshtastic/Meshtastic-device/issues/269
*/
const char *getChannelName()
{
static char buf[32];
uint8_t code = 0;
for (int i = 0; i < sizeof(channelSettings.psk.size); i++)
code ^= channelSettings.psk.bytes[i];
snprintf(buf, sizeof(buf), "#%s-%c", channelSettings.name, 'A' + (code % 26));
return buf;
}
NodeDB::NodeDB() : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count) {} NodeDB::NodeDB() : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count) {}
void NodeDB::resetRadioConfig() void NodeDB::resetRadioConfig()

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include "Observer.h"
#include <Arduino.h> #include <Arduino.h>
#include <assert.h> #include <assert.h>
#include "Observer.h"
#include "MeshTypes.h" #include "MeshTypes.h"
#include "mesh-pb-constants.h"
#include "NodeStatus.h" #include "NodeStatus.h"
#include "mesh-pb-constants.h"
extern DeviceState devicestate; extern DeviceState devicestate;
extern MyNodeInfo &myNodeInfo; extern MyNodeInfo &myNodeInfo;
@ -95,7 +95,8 @@ class NodeDB
NodeInfo *getOrCreateNode(NodeNum n); NodeInfo *getOrCreateNode(NodeNum n);
/// Notify observers of changes to the DB /// Notify observers of changes to the DB
void notifyObservers(bool forceUpdate = false) { void notifyObservers(bool forceUpdate = false)
{
// Notify observers of the current node state // Notify observers of the current node state
const meshtastic::NodeStatus status = meshtastic::NodeStatus(getNumOnlineNodes(), getNumNodes(), forceUpdate); const meshtastic::NodeStatus status = meshtastic::NodeStatus(getNumOnlineNodes(), getNumNodes(), forceUpdate);
newStatus.notifyObservers(&status); newStatus.notifyObservers(&status);
@ -115,3 +116,20 @@ class NodeDB
extern NodeNum displayedNodeNum; extern NodeNum displayedNodeNum;
extern NodeDB nodeDB; extern NodeDB nodeDB;
/**
* Generate a short suffix used to disambiguate channels that might have the same "name" entered by the human but different PSKs.
* The ideas is that the PSK changing should be visible to the user so that they see they probably messed up and that's why they
their nodes
* aren't talking to each other.
*
* This string is of the form "#name-XY".
*
* Where X is a letter from A to Z (base26), and formed by xoring all the bytes of the PSK together.
* Y is not yet used but should eventually indicate 'speed/range' of the link
*
* This function will also need to be implemented in GUI apps that talk to the radio.
*
* https://github.com/meshtastic/Meshtastic-device/issues/269
*/
const char *getChannelName();

View File

@ -115,6 +115,8 @@ unsigned long hash(char *str)
return hash; return hash;
} }
#define POWER_DEFAULT 17 #define POWER_DEFAULT 17
/** /**