mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 19:15:49 +00:00
* CommonCLI: "get " commands
This commit is contained in:
@@ -68,6 +68,35 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
||||
checkAdvertInterval();
|
||||
savePrefs();
|
||||
sprintf(reply, "password now: %s", _prefs->password); // echo back just to let admin know for sure!!
|
||||
} else if (memcmp(command, "get ", 4) == 0) {
|
||||
const char* config = &command[4];
|
||||
if (memcmp(config, "af", 2) == 0) {
|
||||
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->airtime_factor));
|
||||
} else if (memcmp(config, "advert.interval", 15) == 0) {
|
||||
sprintf(reply, "> %d", ((uint32_t) _prefs->advert_interval) * 2);
|
||||
} else if (memcmp(config, "guest.password", 14) == 0) {
|
||||
sprintf(reply, "> %s", _prefs->guest_password);
|
||||
} else if (memcmp(config, "name", 4) == 0) {
|
||||
sprintf(reply, "> %s", _prefs->node_name);
|
||||
} else if (memcmp(config, "repeat", 6) == 0) {
|
||||
sprintf(reply, "> %s", _prefs->disable_fwd ? "off" : "on");
|
||||
} else if (memcmp(config, "lat", 3) == 0) {
|
||||
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->node_lat));
|
||||
} else if (memcmp(config, "lon", 3) == 0) {
|
||||
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->node_lon));
|
||||
} else if (memcmp(config, "rxdelay", 7) == 0) {
|
||||
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->rx_delay_base));
|
||||
} else if (memcmp(config, "txdelay", 7) == 0) {
|
||||
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->tx_delay_factor));
|
||||
} else if (memcmp(config, "direct.txdelay", 14) == 0) {
|
||||
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->direct_tx_delay_factor));
|
||||
} else if (memcmp(config, "tx", 2) == 0 && (config[2] == 0 || config[2] == ' ')) {
|
||||
sprintf(reply, "> %d", (uint32_t) _prefs->tx_power_dbm);
|
||||
} else if (memcmp(config, "freq", 4) == 0) {
|
||||
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->freq));
|
||||
} else {
|
||||
sprintf(reply, "??: %s", config);
|
||||
}
|
||||
} else if (memcmp(command, "set ", 4) == 0) {
|
||||
const char* config = &command[4];
|
||||
if (memcmp(config, "af ", 3) == 0) {
|
||||
|
||||
@@ -18,3 +18,117 @@ void StrHelper::strzcpy(char* dest, const char* src, size_t buf_sz) {
|
||||
buf_sz--;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
union int32_Float_t
|
||||
{
|
||||
int32_t Long;
|
||||
float Float;
|
||||
};
|
||||
|
||||
#ifndef FLT_MIN_EXP
|
||||
#define FLT_MIN_EXP (-999)
|
||||
#endif
|
||||
|
||||
#ifndef FLT_MAX_EXP
|
||||
#define FLT_MAX_EXP (999)
|
||||
#endif
|
||||
|
||||
#define _FTOA_TOO_LARGE -2 // |input| > 2147483520
|
||||
#define _FTOA_TOO_SMALL -1 // |input| < 0.0000001
|
||||
|
||||
//precision 0-9
|
||||
#define PRECISION 7
|
||||
|
||||
//_ftoa function
|
||||
static void _ftoa(float f, char *p, int *status)
|
||||
{
|
||||
int32_t mantissa, int_part, frac_part;
|
||||
int16_t exp2;
|
||||
int32_Float_t x;
|
||||
|
||||
*status = 0;
|
||||
if (f == 0.0)
|
||||
{
|
||||
*p++ = '0';
|
||||
*p++ = '.';
|
||||
*p++ = '0';
|
||||
*p = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
x.Float = f;
|
||||
exp2 = (unsigned char)(x.Long>>23) - 127;
|
||||
mantissa = (x.Long&0xFFFFFF) | 0x800000;
|
||||
frac_part = 0;
|
||||
int_part = 0;
|
||||
|
||||
if (exp2 >= 31)
|
||||
{
|
||||
*status = _FTOA_TOO_LARGE;
|
||||
return;
|
||||
}
|
||||
else if (exp2 < -23)
|
||||
{
|
||||
*status = _FTOA_TOO_SMALL;
|
||||
return;
|
||||
}
|
||||
else if (exp2 >= 23)
|
||||
{
|
||||
int_part = mantissa<<(exp2 - 23);
|
||||
}
|
||||
else if (exp2 >= 0)
|
||||
{
|
||||
int_part = mantissa>>(23 - exp2);
|
||||
frac_part = (mantissa<<(exp2 + 1))&0xFFFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (exp2 < 0)
|
||||
frac_part = (mantissa&0xFFFFFF)>>-(exp2 + 1);
|
||||
}
|
||||
|
||||
if (x.Long < 0)
|
||||
*p++ = '-';
|
||||
if (int_part == 0)
|
||||
*p++ = '0';
|
||||
else
|
||||
{
|
||||
ltoa(int_part, p, 10);
|
||||
while (*p)
|
||||
p++;
|
||||
}
|
||||
*p++ = '.';
|
||||
if (frac_part == 0)
|
||||
*p++ = '0';
|
||||
else
|
||||
{
|
||||
char m;
|
||||
|
||||
for (m=0; m<PRECISION; m++)
|
||||
{
|
||||
//frac_part *= 10;
|
||||
frac_part = (frac_part<<3) + (frac_part<<1);
|
||||
*p++ = (frac_part>>24) + '0';
|
||||
frac_part &= 0xFFFFFF;
|
||||
}
|
||||
|
||||
//delete ending zeroes
|
||||
for (--p; p[0] == '0' && p[-1] != '.'; --p)
|
||||
;
|
||||
++p;
|
||||
}
|
||||
*p = 0;
|
||||
}
|
||||
|
||||
const char* StrHelper::ftoa(float f) {
|
||||
static char tmp[16];
|
||||
int status;
|
||||
_ftoa(f, tmp, &status);
|
||||
if (status) {
|
||||
tmp[0] = '0'; // fallback/error value
|
||||
tmp[1] = 0;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -11,4 +11,5 @@ class StrHelper {
|
||||
public:
|
||||
static void strncpy(char* dest, const char* src, size_t buf_sz);
|
||||
static void strzcpy(char* dest, const char* src, size_t buf_sz); // pads with trailing nulls
|
||||
static const char* ftoa(float f);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user