Update RAK2560 code (#5844)

* * Update RAK9154 sensor to tx remote power telemetry
* remove uf2 script, pio run does that inline
* move sensor module to correct position
* disable LED and Accelerometer code on rak2560
* trunk fmt
* mention epaper variant
* attention, revert, revert
* Enable Environment Telemetry of these values
* fix float values
This commit is contained in:
Thomas Göttgens
2025-01-20 09:34:54 +01:00
committed by GitHub
parent 950341d1f9
commit 973b453d43
10 changed files with 76 additions and 147 deletions

View File

@@ -1,183 +0,0 @@
#ifdef HAS_RAKPROT
#include "../variants/rak2560/RAK9154Sensor.h"
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "../modules/Telemetry/Sensor/TelemetrySensor.h"
#include "configuration.h"
#include "concurrency/Periodic.h"
#include <RAK-OneWireSerial.h>
using namespace concurrency;
#define BOOT_DATA_REQ
RAK9154Sensor::RAK9154Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_SENSOR_UNSET, "RAK1954") {}
static Periodic *onewirePeriodic;
static SoftwareHalfSerial mySerial(HALF_UART_PIN); // Wire pin P0.15
static uint8_t buff[0x100];
static uint16_t bufflen = 0;
static int16_t dc_cur = 0;
static uint16_t dc_vol = 0;
static uint8_t dc_prec = 0;
static uint8_t provision = 0;
static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT_E eid, uint8_t *msg, uint16_t len)
{
switch (eid) {
case SNHUBAPI_EVT_RECV_REQ:
case SNHUBAPI_EVT_RECV_RSP:
break;
case SNHUBAPI_EVT_QSEND:
mySerial.write(msg, len);
break;
case SNHUBAPI_EVT_ADD_SID:
// LOG_INFO("+ADD:SID:[%02x]", msg[0]);
break;
case SNHUBAPI_EVT_ADD_PID:
// LOG_INFO("+ADD:PID:[%02x]", msg[0]);
#ifdef BOOT_DATA_REQ
provision = msg[0];
#endif
break;
case SNHUBAPI_EVT_GET_INTV:
break;
case SNHUBAPI_EVT_GET_ENABLE:
break;
case SNHUBAPI_EVT_SDATA_REQ:
// LOG_INFO("+EVT:PID[%02x],IPSO[%02x]",pid,msg[0]);
// for( uint16_t i=1; i<len; i++)
// {
// LOG_INFO("%02x,", msg[i]);
// }
// LOG_INFO("");
switch (msg[0]) {
case RAK_IPSO_CAPACITY:
dc_prec = msg[1];
if (dc_prec > 100) {
dc_prec = 100;
}
break;
case RAK_IPSO_DC_CURRENT:
dc_cur = (msg[2] << 8) + msg[1];
break;
case RAK_IPSO_DC_VOLTAGE:
dc_vol = (msg[2] << 8) + msg[1];
dc_vol *= 10;
break;
default:
break;
}
break;
case SNHUBAPI_EVT_REPORT:
// LOG_INFO("+EVT:PID[%02x],IPSO[%02x]",pid,msg[0]);
// for( uint16_t i=1; i<len; i++)
// {
// LOG_INFO("%02x,", msg[i]);
// }
// LOG_INFO("");
switch (msg[0]) {
case RAK_IPSO_CAPACITY:
dc_prec = msg[1];
if (dc_prec > 100) {
dc_prec = 100;
}
break;
case RAK_IPSO_DC_CURRENT:
dc_cur = (msg[1] << 8) + msg[2];
break;
case RAK_IPSO_DC_VOLTAGE:
dc_vol = (msg[1] << 8) + msg[2];
dc_vol *= 10;
break;
default:
break;
}
break;
case SNHUBAPI_EVT_CHKSUM_ERR:
LOG_INFO("+ERR:CHKSUM");
break;
case SNHUBAPI_EVT_SEQ_ERR:
LOG_INFO("+ERR:SEQUCE");
break;
default:
break;
}
}
static int32_t onewireHandle()
{
if (provision != 0) {
RakSNHub_Protocl_API.get.data(provision);
provision = 0;
}
while (mySerial.available()) {
char a = mySerial.read();
buff[bufflen++] = a;
delay(2); // continue data, timeout=2ms
}
if (bufflen != 0) {
RakSNHub_Protocl_API.process((uint8_t *)buff, bufflen);
bufflen = 0;
}
return 50;
}
int32_t RAK9154Sensor::runOnce()
{
onewirePeriodic = new Periodic("onewireHandle", onewireHandle);
mySerial.begin(9600);
RakSNHub_Protocl_API.init(onewire_evt);
status = true;
initialized = true;
return 0;
}
void RAK9154Sensor::setup()
{
// Set up oversampling and filter initialization
}
bool RAK9154Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
return true;
}
uint16_t RAK9154Sensor::getBusVoltageMv()
{
return dc_vol;
}
int RAK9154Sensor::getBusBatteryPercent()
{
return (int)dc_prec;
}
bool RAK9154Sensor::isCharging()
{
return (dc_cur > 0) ? true : false;
}
#endif // HAS_RAKPROT

View File

@@ -1,23 +0,0 @@
#ifdef HAS_RAKPROT
#ifndef _RAK9154SENSOR_H
#define _RAK9154SENSOR_H 1
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "../modules/Telemetry/Sensor/TelemetrySensor.h"
#include "../modules/Telemetry/Sensor/VoltageSensor.h"
class RAK9154Sensor : public TelemetrySensor, VoltageSensor
{
private:
protected:
virtual void setup() override;
public:
RAK9154Sensor();
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual uint16_t getBusVoltageMv() override;
int getBusBatteryPercent();
bool isCharging();
};
#endif // _RAK9154SENSOR_H
#endif // HAS_RAKPROT

View File

@@ -1,113 +0,0 @@
import struct
Import("env") # noqa: F821
# Parse input and create UF2 file
def create_uf2(source, target, env):
# source_hex = target[0].get_abspath()
source_hex = target[0].get_string(False)
source_hex = ".\\" + source_hex
print("#########################################################")
print("Create UF2 from " + source_hex)
print("#########################################################")
# print("Source: " + source_hex)
target = source_hex.replace(".hex", "")
target = target + ".uf2"
# print("Target: " + target)
with open(source_hex, mode="rb") as f:
inpbuf = f.read()
outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8"))
write_file(target, outbuf)
print("#########################################################")
print(target + " is ready to flash to target device")
print("#########################################################")
# Add callback after .hex file was created
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", create_uf2) # noqa: F821
# UF2 creation taken from uf2conv.py
UF2_MAGIC_START0 = 0x0A324655 # "UF2\n"
UF2_MAGIC_START1 = 0x9E5D5157 # Randomly selected
UF2_MAGIC_END = 0x0AB16F30 # Ditto
familyid = 0xADA52840
class Block:
def __init__(self, addr):
self.addr = addr
self.bytes = bytearray(256)
def encode(self, blockno, numblocks):
global familyid
flags = 0x0
if familyid:
flags |= 0x2000
hd = struct.pack(
"<IIIIIIII",
UF2_MAGIC_START0,
UF2_MAGIC_START1,
flags,
self.addr,
256,
blockno,
numblocks,
familyid,
)
hd += self.bytes[0:256]
while len(hd) < 512 - 4:
hd += b"\x00"
hd += struct.pack("<I", UF2_MAGIC_END)
return hd
def write_file(name, buf):
with open(name, "wb") as f:
f.write(buf)
# print("Wrote %d bytes to %s." % (len(buf), name))
def convert_from_hex_to_uf2(buf):
global appstartaddr
appstartaddr = None
upper = 0
currblock = None
blocks = []
for line in buf.split("\n"):
if line[0] != ":":
continue
i = 1
rec = []
while i < len(line) - 1:
rec.append(int(line[i : i + 2], 16))
i += 2
tp = rec[3]
if tp == 4:
upper = ((rec[4] << 8) | rec[5]) << 16
elif tp == 2:
upper = ((rec[4] << 8) | rec[5]) << 4
assert (upper & 0xFFFF) == 0
elif tp == 1:
break
elif tp == 0:
addr = upper | (rec[1] << 8) | rec[2]
if appstartaddr is None:
appstartaddr = addr
i = 4
while i < len(rec) - 1:
if not currblock or currblock.addr & ~0xFF != addr & ~0xFF:
currblock = Block(addr & ~0xFF)
blocks.append(currblock)
currblock.bytes[addr & 0xFF] = rec[i]
addr += 1
i += 1
numblocks = len(blocks)
resfile = b""
for i in range(0, numblocks):
resfile += blocks[i].encode(i, numblocks)
return resfile

View File

@@ -15,8 +15,6 @@ lib_deps =
${nrf52840_base.lib_deps}
${networking_base.lib_deps}
melopero/Melopero RV3028@^1.1.0
rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2
beegee-tokyo/RAKwireless RAK12034@^1.0.0
https://github.com/beegee-tokyo/RAK-OneWireSerial.git#0.0.2
debug_tool = jlink
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)