-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RAKwireless WisMesh Hub (RAK2560/RAK9154) #4117
Changes from 2 commits
d7c52c3
5e01b42
85d621d
0c45c99
f50073e
e546220
ceb884c
11c3ca5
4fe281c
aca0807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
#ifdef HAS_RAKPROT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the RAK9154 support is places correctly. The Telemetry folder is for devices that actually transmit values over Lora. This looks more like gathering values for internal processing. If this is only ever used once for this particular device, you can as well put it in the variant folder and skip deriving it from TelemetryModule. If you add the OSThread class to inheritance you can use the runOnce model without having to define it as a sensor (which it isn't in the meshtastic sense) |
||
#include "RAK9154Sensor.h" | ||
#include "../mesh/generated/meshtastic/telemetry.pb.h" | ||
#include "TelemetrySensor.h" | ||
#include "configuration.h" | ||
|
||
#include <RAK-OneWireSerial.h> | ||
#include "concurrency/Periodic.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]\r\n", msg[0]); | ||
break; | ||
|
||
case SNHUBAPI_EVT_ADD_PID: | ||
// LOG_INFO("+ADD:PID:[%02x]\r\n", 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]\r\n",pid,msg[0]); | ||
// for( uint16_t i=1; i<len; i++) | ||
// { | ||
// LOG_INFO("%02x,", msg[i]); | ||
// } | ||
// LOG_INFO("\r\n"); | ||
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]\r\n",pid,msg[0]); | ||
// for( uint16_t i=1; i<len; i++) | ||
// { | ||
// LOG_INFO("%02x,", msg[i]); | ||
// } | ||
// LOG_INFO("\r\n"); | ||
|
||
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\r\n"); | ||
break; | ||
|
||
case SNHUBAPI_EVT_SEQ_ERR: | ||
LOG_INFO("+ERR:SEQUCE\r\n"); | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively if the values really should be able to go out over the mesh, you need to implementthese functions :-) |
||
} | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifdef HAS_RAKPROT | ||
#include "../mesh/generated/meshtastic/telemetry.pb.h" | ||
#include "TelemetrySensor.h" | ||
#include "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 // HAS_RAKPROT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't check in the vscode files. This will cause merge conflicts all over the place.