added free memory to device status query

This commit is contained in:
Klaus K Wilting 2018-08-04 22:49:12 +02:00
parent 9b472780da
commit 0a52b16c78
5 changed files with 32 additions and 39 deletions

View File

@ -138,9 +138,10 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering.
**Port #2:** Device status query result
byte 1-2: Battery or USB Voltage [mV], 0 if unreadable
byte 1-2: Battery or USB Voltage [mV], 0 if no battery probe
byte 3-10: Uptime [seconds]
bytes 11-14: CPU temperature [°C]
bytes 15-18: Free RAM [bytes]
**Port #3:** Device configuration query result

View File

@ -18,7 +18,7 @@ function Decoder(bytes, port) {
if (port === 2) {
// device status data
return decode(bytes, [uint16, uptime, temperature], ['voltage', 'uptime', 'cputemp']);
return decode(bytes, [uint16, uptime, temperature, uint32], ['voltage', 'uptime', 'cputemp', 'memory']);
}
@ -66,7 +66,7 @@ uptime.BYTES = 4;
var uint8 = function (bytes) {
if (bytes.length !== uint8.BYTES) {
throw new Error('int must have exactly 1 byte');
throw new Error('uint8 must have exactly 1 byte');
}
return bytesToInt(bytes);
};
@ -74,12 +74,20 @@ uint8.BYTES = 1;
var uint16 = function (bytes) {
if (bytes.length !== uint16.BYTES) {
throw new Error('int must have exactly 2 bytes');
throw new Error('uint16 must have exactly 2 bytes');
}
return bytesToInt(bytes);
};
uint16.BYTES = 2;
var uint32 = function (bytes) {
if (bytes.length !== uint32.BYTES) {
throw new Error('uint32 must have exactly 4 bytes');
}
return bytesToInt(bytes);
};
uint32.BYTES = 4;
var latLng = function (bytes) {
if (bytes.length !== latLng.BYTES) {
throw new Error('Lat/Long must have exactly 4 bytes');

View File

@ -53,7 +53,7 @@ void PayloadConvert::addConfig(configData_t value) {
}
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
float cputemp) {
float cputemp, uint32_t mem) {
uint32_t temp = (uint32_t)cputemp;
buffer[cursor++] = highByte(voltage);
buffer[cursor++] = lowByte(voltage);
@ -69,6 +69,10 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
buffer[cursor++] = (byte)((temp & 0x00FF0000) >> 16);
buffer[cursor++] = (byte)((temp & 0x0000FF00) >> 8);
buffer[cursor++] = (byte)((temp & 0x000000FF));
buffer[cursor++] = (byte)((mem & 0xFF000000) >> 24);
buffer[cursor++] = (byte)((mem & 0x00FF0000) >> 16);
buffer[cursor++] = (byte)((mem & 0x0000FF00) >> 8);
buffer[cursor++] = (byte)((mem & 0x000000FF));
}
#ifdef HAS_GPS
@ -124,10 +128,11 @@ void PayloadConvert::addConfig(configData_t value) {
}
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
float cputemp) {
float cputemp, uint32_t mem) {
writeUint16(voltage);
writeUptime(uptime);
writeTemperature(cputemp);
writeUint32(mem);
}
#ifdef HAS_GPS
@ -159,6 +164,8 @@ void PayloadConvert::writeLatLng(double latitude, double longitude) {
intToBytes(cursor, longitude, 4);
}
void PayloadConvert::writeUint32(uint32_t i) { intToBytes(cursor, i, 4); }
void PayloadConvert::writeUint16(uint16_t i) { intToBytes(cursor, i, 2); }
void PayloadConvert::writeUint8(uint8_t i) { intToBytes(cursor, i, 1); }
@ -239,7 +246,7 @@ void PayloadConvert::addConfig(configData_t value) {
}
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
float celsius) {
float celsius, uint32_t mem) {
uint16_t temp = celsius * 10;
uint16_t volt = voltage / 10;
#ifdef HAS_BATTERY_PROBE

View File

@ -35,7 +35,7 @@ public:
uint8_t *getBuffer(void);
void addCount(uint16_t value1, uint16_t value2);
void addConfig(configData_t value);
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp);
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem);
void addAlarm(int8_t rssi, uint8_t message);
#ifdef HAS_GPS
void addGPS(gpsStatus_t value);
@ -59,6 +59,7 @@ private:
void intToBytes(uint8_t pos, int32_t i, uint8_t byteSize);
void writeUptime(uint64_t unixtime);
void writeLatLng(double latitude, double longitude);
void writeUint32(uint32_t i);
void writeUint16(uint16_t i);
void writeUint8(uint8_t i);
void writeHumidity(float humidity);

View File

@ -304,7 +304,7 @@ void get_status(uint8_t val[]) {
uint16_t voltage = 0;
#endif
payload.reset();
payload.addStatus(voltage, uptime() / 1000, temperatureRead());
payload.addStatus(voltage, uptime() / 1000, temperatureRead(), ESP.getFreeHeap());
SendData(STATUSPORT);
};
@ -350,6 +350,7 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) {
bool storeflag = false;
while (cursor < cmdlength) {
int i = cmdtablesize;
while (i--) {
if (cmd[cursor] == table[i].opcode) { // lookup command in opcode table
@ -368,36 +369,11 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) {
"Remote command x%02X called with missing parameter(s), skipped",
table[i].opcode);
break; // exit table lookup loop, command was found
} // lookup command
} // while loop table lookup
} // while loop parsing cmd
} // command validation
} // command table lookup loop
} // command parsing loop
if (storeflag)
saveConfig();
} // rcommand()
/*
// check and execute remote command
void rcommand(uint8_t cmd[], uint8_t cmdlength) {
if (cmdlength == 0)
return;
else
cmdlength--; // minus 1 byte for opcode
int i = cmdtablesize;
while (i--) {
if ((cmd[0] == table[i].opcode) &&
(table[i].params == cmdlength)) { // lookup command in opcode table
memmove(cmd, cmd + 1,
cmdlength); // strip opcode from cmd array
table[i].func(cmd); // execute assigned function with given parameters
if (table[i].store) // ceck if function needs to store configuration
saveConfig();
break; // exit while loop, command was found
} // lookup command
} // while
} // rcommand()
*/