added free memory to device status query
This commit is contained in:
parent
9b472780da
commit
0a52b16c78
@ -138,9 +138,10 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering.
|
|||||||
|
|
||||||
**Port #2:** Device status query result
|
**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]
|
byte 3-10: Uptime [seconds]
|
||||||
bytes 11-14: CPU temperature [°C]
|
bytes 11-14: CPU temperature [°C]
|
||||||
|
bytes 15-18: Free RAM [bytes]
|
||||||
|
|
||||||
**Port #3:** Device configuration query result
|
**Port #3:** Device configuration query result
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ function Decoder(bytes, port) {
|
|||||||
|
|
||||||
if (port === 2) {
|
if (port === 2) {
|
||||||
// device status data
|
// 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) {
|
var uint8 = function (bytes) {
|
||||||
if (bytes.length !== uint8.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);
|
return bytesToInt(bytes);
|
||||||
};
|
};
|
||||||
@ -74,12 +74,20 @@ uint8.BYTES = 1;
|
|||||||
|
|
||||||
var uint16 = function (bytes) {
|
var uint16 = function (bytes) {
|
||||||
if (bytes.length !== uint16.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);
|
return bytesToInt(bytes);
|
||||||
};
|
};
|
||||||
uint16.BYTES = 2;
|
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) {
|
var latLng = function (bytes) {
|
||||||
if (bytes.length !== latLng.BYTES) {
|
if (bytes.length !== latLng.BYTES) {
|
||||||
throw new Error('Lat/Long must have exactly 4 bytes');
|
throw new Error('Lat/Long must have exactly 4 bytes');
|
||||||
|
@ -53,7 +53,7 @@ void PayloadConvert::addConfig(configData_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||||
float cputemp) {
|
float cputemp, uint32_t mem) {
|
||||||
uint32_t temp = (uint32_t)cputemp;
|
uint32_t temp = (uint32_t)cputemp;
|
||||||
buffer[cursor++] = highByte(voltage);
|
buffer[cursor++] = highByte(voltage);
|
||||||
buffer[cursor++] = lowByte(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 & 0x00FF0000) >> 16);
|
||||||
buffer[cursor++] = (byte)((temp & 0x0000FF00) >> 8);
|
buffer[cursor++] = (byte)((temp & 0x0000FF00) >> 8);
|
||||||
buffer[cursor++] = (byte)((temp & 0x000000FF));
|
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
|
#ifdef HAS_GPS
|
||||||
@ -124,10 +128,11 @@ void PayloadConvert::addConfig(configData_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||||
float cputemp) {
|
float cputemp, uint32_t mem) {
|
||||||
writeUint16(voltage);
|
writeUint16(voltage);
|
||||||
writeUptime(uptime);
|
writeUptime(uptime);
|
||||||
writeTemperature(cputemp);
|
writeTemperature(cputemp);
|
||||||
|
writeUint32(mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
@ -159,6 +164,8 @@ void PayloadConvert::writeLatLng(double latitude, double longitude) {
|
|||||||
intToBytes(cursor, longitude, 4);
|
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::writeUint16(uint16_t i) { intToBytes(cursor, i, 2); }
|
||||||
|
|
||||||
void PayloadConvert::writeUint8(uint8_t i) { intToBytes(cursor, i, 1); }
|
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,
|
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
|
||||||
float celsius) {
|
float celsius, uint32_t mem) {
|
||||||
uint16_t temp = celsius * 10;
|
uint16_t temp = celsius * 10;
|
||||||
uint16_t volt = voltage / 10;
|
uint16_t volt = voltage / 10;
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef HAS_BATTERY_PROBE
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
uint8_t *getBuffer(void);
|
uint8_t *getBuffer(void);
|
||||||
void addCount(uint16_t value1, uint16_t value2);
|
void addCount(uint16_t value1, uint16_t value2);
|
||||||
void addConfig(configData_t value);
|
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);
|
void addAlarm(int8_t rssi, uint8_t message);
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
void addGPS(gpsStatus_t value);
|
void addGPS(gpsStatus_t value);
|
||||||
@ -59,6 +59,7 @@ private:
|
|||||||
void intToBytes(uint8_t pos, int32_t i, uint8_t byteSize);
|
void intToBytes(uint8_t pos, int32_t i, uint8_t byteSize);
|
||||||
void writeUptime(uint64_t unixtime);
|
void writeUptime(uint64_t unixtime);
|
||||||
void writeLatLng(double latitude, double longitude);
|
void writeLatLng(double latitude, double longitude);
|
||||||
|
void writeUint32(uint32_t i);
|
||||||
void writeUint16(uint16_t i);
|
void writeUint16(uint16_t i);
|
||||||
void writeUint8(uint8_t i);
|
void writeUint8(uint8_t i);
|
||||||
void writeHumidity(float humidity);
|
void writeHumidity(float humidity);
|
||||||
|
@ -304,7 +304,7 @@ void get_status(uint8_t val[]) {
|
|||||||
uint16_t voltage = 0;
|
uint16_t voltage = 0;
|
||||||
#endif
|
#endif
|
||||||
payload.reset();
|
payload.reset();
|
||||||
payload.addStatus(voltage, uptime() / 1000, temperatureRead());
|
payload.addStatus(voltage, uptime() / 1000, temperatureRead(), ESP.getFreeHeap());
|
||||||
SendData(STATUSPORT);
|
SendData(STATUSPORT);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -350,6 +350,7 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) {
|
|||||||
bool storeflag = false;
|
bool storeflag = false;
|
||||||
|
|
||||||
while (cursor < cmdlength) {
|
while (cursor < cmdlength) {
|
||||||
|
|
||||||
int i = cmdtablesize;
|
int i = cmdtablesize;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
if (cmd[cursor] == table[i].opcode) { // lookup command in opcode table
|
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",
|
"Remote command x%02X called with missing parameter(s), skipped",
|
||||||
table[i].opcode);
|
table[i].opcode);
|
||||||
break; // exit table lookup loop, command was found
|
break; // exit table lookup loop, command was found
|
||||||
} // lookup command
|
} // command validation
|
||||||
} // while loop table lookup
|
} // command table lookup loop
|
||||||
} // while loop parsing cmd
|
|
||||||
|
} // command parsing loop
|
||||||
|
|
||||||
if (storeflag)
|
if (storeflag)
|
||||||
saveConfig();
|
saveConfig();
|
||||||
} // rcommand()
|
} // 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()
|
|
||||||
*/
|
|
Loading…
Reference in New Issue
Block a user