Browse Source

prototype webapi to get info, improved pwr limit

pull/134/head
Andreas Schiffler 3 years ago
parent
commit
028aedb788
  1. 200
      tools/esp8266/app.cpp
  2. 2
      tools/esp8266/app.h
  3. 37
      tools/esp8266/defines.h
  4. 5
      tools/esp8266/hmInverter.h
  5. 40
      tools/esp8266/hmRadio.h
  6. 3
      tools/esp8266/hmSystem.h

200
tools/esp8266/app.cpp

@ -9,6 +9,8 @@
#include "html/h/index_html.h" #include "html/h/index_html.h"
#include "html/h/setup_html.h" #include "html/h/setup_html.h"
#include "html/h/hoymiles_html.h" #include "html/h/hoymiles_html.h"
#include <ArduinoJson.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -53,17 +55,17 @@ void app::setup(uint32_t timeout) {
DPRINTLN(DBG_VERBOSE, F("app::setup")); DPRINTLN(DBG_VERBOSE, F("app::setup"));
Main::setup(timeout); Main::setup(timeout);
mWeb->on("/", std::bind(&app::showIndex, this)); mWeb->on("/", std::bind(&app::showIndex, this));
mWeb->on("/favicon.ico", std::bind(&app::showFavicon, this)); mWeb->on("/favicon.ico", std::bind(&app::showFavicon, this));
mWeb->on("/setup", std::bind(&app::showSetup, this)); mWeb->on("/setup", std::bind(&app::showSetup, this));
mWeb->on("/save", std::bind(&app::showSave, this)); mWeb->on("/save", std::bind(&app::showSave, this));
mWeb->on("/erase", std::bind(&app::showErase, this)); mWeb->on("/erase", std::bind(&app::showErase, this));
mWeb->on("/cmdstat", std::bind(&app::showStatistics, this)); mWeb->on("/cmdstat", std::bind(&app::showStatistics, this));
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this)); mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
mWeb->on("/livedata", std::bind(&app::showLiveData, this)); mWeb->on("/livedata", std::bind(&app::showLiveData, this));
mWeb->on("/json", std::bind(&app::showJSON, this)); mWeb->on("/json", std::bind(&app::showJSON, this));
mWeb->on("/devcontrol", std::bind(&app::devControl, this)); mWeb->on("/api",HTTP_POST, std::bind(&app::webapi, this));
if(mSettingsValid) { if(mSettingsValid) {
mEep->read(ADDR_INV_INTERVAL, &mSendInterval); mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
if(mSendInterval < MIN_SEND_INTERVAL) if(mSendInterval < MIN_SEND_INTERVAL)
@ -82,11 +84,12 @@ void app::setup(uint32_t timeout) {
if(0ULL != invSerial) { if(0ULL != invSerial) {
iv = mSys->addInverter(name, invSerial, modPwr); iv = mSys->addInverter(name, invSerial, modPwr);
if(NULL != iv) { if(NULL != iv) {
mEep->read(ADDR_INV_PWR_LIM + (i * 2),&iv->powerLimit); mEep->read(ADDR_INV_PWR_LIM + (i * 2),&iv->powerLimit[0]);
if (iv->powerLimit != 0xffff) { // only set it, if it is changed by user. Default value in the html setup page is -1 = 0xffff if (iv->powerLimit[0] != 0xffff) { // only set it, if it is changed by user. Default value in the html setup page is -1 = 0xffff
iv->powerLimit[1] = 0x0100; // set the limit as persistent
iv->devControlCmd = 11; // set active power limit iv->devControlCmd = 11; // set active power limit
iv->devControlRequest = true; // set to true to update the active power limit from setup html page iv->devControlRequest = true; // set to true to update the active power limit from setup html page
DPRINTLN(DBG_INFO, F("add inverter: ") + String(name) + ", SN: " + String(invSerial, HEX) + ", Power Limit: " + String(iv->powerLimit)); DPRINTLN(DBG_INFO, F("add inverter: ") + String(name) + ", SN: " + String(invSerial, HEX) + ", Power Limit: " + String(iv->powerLimit[0]));
} }
for(uint8_t j = 0; j < 4; j++) { for(uint8_t j = 0; j < 4; j++) {
mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH); mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH);
@ -232,52 +235,84 @@ void app::loop(void) {
// process buffer only on first occurrence // process buffer only on first occurrence
if(mSerialDebug) { if(mSerialDebug) {
DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | "); DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | ");
mSys->Radio.dumpBuf(NULL, p->packet, len); mSys->Radio.dumpBuf(NULL, p->packet, len);
} }
mFrameCnt++; mFrameCnt++;
if(0 != len) { if(0 != len) {
Inverter<> *iv = mSys->findInverter(&p->packet[1]); Inverter<> *iv = mSys->findInverter(&p->packet[1]);
if(NULL != iv && p->packet[0] == (0x15 + 0x80)) { // response from get all information command if(NULL != iv && p->packet[0] == (TX_REQ_INFO + 0x80)) { // response from get information command
uint8_t *pid = &p->packet[9]; DPRINTLN(DBG_DEBUG, F("Response from info request received"));
if (*pid == 0x00) { switch (mSys->InfoCmd){
DPRINT(DBG_DEBUG, "fragment number zero received and ignored"); case InverterDevInform_Simple:
} else { {
if((*pid & 0x7F) < 5) { DPRINT(DBG_INFO, "Response from inform simple\n");
memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], len-11); mSys->InfoCmd = RealTimeRunData_Debug; // Set back to default
mPayload[iv->id].len[(*pid & 0x7F) - 1] = len-11; break;
} }
case InverterDevInform_All:
{
DPRINT(DBG_INFO, "Response from inform all\n");
mSys->InfoCmd = RealTimeRunData_Debug; // Set back to default
break;
}
case GetLossRate:
{
DPRINT(DBG_INFO, "Response from get loss rate\n");
mSys->InfoCmd = RealTimeRunData_Debug; // Set back to default
break;
}
case RealTimeRunData_Debug:
{
uint8_t *pid = &p->packet[9];
if (*pid == 0x00) {
DPRINT(DBG_DEBUG, "fragment number zero received and ignored");
} else {
if((*pid & 0x7F) < 5) {
memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], len-11);
mPayload[iv->id].len[(*pid & 0x7F) - 1] = len-11;
}
if((*pid & 0x80) == 0x80) { if((*pid & 0x80) == 0x80) { // Last packet
if((*pid & 0x7f) > mPayload[iv->id].maxPackId) { if((*pid & 0x7f) > mPayload[iv->id].maxPackId) {
mPayload[iv->id].maxPackId = (*pid & 0x7f); mPayload[iv->id].maxPackId = (*pid & 0x7f);
if(*pid > 0x81) if(*pid > 0x81)
mLastPacketId = *pid; mLastPacketId = *pid;
}
}
} }
break;
} }
} }
} }
if(NULL != iv && p->packet[0] == (0x51 + 0x80)) { // response from dev control command if(NULL != iv && p->packet[0] == (TX_REQ_DEVCONTROL + 0x80)) { // response from dev control command
DPRINTLN(DBG_INFO, F("Response from devcontrol received")); DPRINTLN(DBG_DEBUG, F("Response from devcontrol request received"));
iv->devControlRequest = false; iv->devControlRequest = false;
if (p->packet[12] != 11 && iv->devControlCmd == 11){ switch (p->packet[12]){
// set back to last accpted limit case ActivePowerContr:
mEep->read(ADDR_INV_PWR_LIM + iv->id * 2, &iv->powerLimit); if (iv->devControlCmd == ActivePowerContr){ // ok inverter accepted the set point copy it to dtu eeprom
if (iv->powerLimit[1]>0){ // User want to have it persistent
mEep->write(ADDR_INV_PWR_LIM + iv->id * 2,iv->powerLimit[0]);
updateCrc();
mEep->commit();
DPRINTLN(DBG_INFO, F("Inverter has accepted power limit set point, written to dtu eeprom"));
}
DPRINTLN(DBG_INFO, F("Inverter has accepted power limit set point"));
iv->devControlCmd = Init;
}
break;
default:
if (iv->devControlCmd == ActivePowerContr){
//case inverter did not accept the sent limit; set back to last stored limit
mEep->read(ADDR_INV_PWR_LIM + iv->id * 2, &iv->powerLimit[0]);
DPRINTLN(DBG_INFO, F("Inverter has not accepted power limit set point")); DPRINTLN(DBG_INFO, F("Inverter has not accepted power limit set point"));
} }
if (p->packet[12] == 11 && iv->devControlCmd == 11){ // ok inverter accepted the set point copy it to dtu eeprom iv->devControlCmd = Init;
// on every reboot the dtu sets the power limit acc to the value in eeprom break;
mEep->write(ADDR_INV_PWR_LIM + iv->id * 2,iv->powerLimit);
updateCrc();
mEep->commit();
DPRINTLN(DBG_INFO, F("Inverter has accepted power limit set point, written to dtu eeprom"));
iv->devControlCmd = 0xff; // set to none known command.
} }
} }
} }
} }
mSys->BufCtrl.popBack(); mSys->BufCtrl.popBack();
} }
yield(); yield();
@ -384,10 +419,10 @@ void app::loop(void) {
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX)); DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
if(iv->devControlRequest){ if(iv->devControlRequest){
if(mSerialDebug) if(mSerialDebug)
DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit)); DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0]));
mSys->Radio.sendControlPacket(iv->radioId.u64,iv->devControlCmd ,uint16_t(iv->powerLimit)); mSys->Radio.sendControlPacket(iv->radioId.u64,iv->devControlCmd ,iv->powerLimit);
} else { } else {
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts); mSys->Radio.sendTimePacket(iv->radioId.u64, mSys->InfoCmd, mPayload[iv->id].ts);
mRxTicker = 0; mRxTicker = 0;
} }
} }
@ -449,7 +484,7 @@ void app::processPayload(bool retransmit) {
if(mPayload[iv->id].len[i] == 0) { if(mPayload[iv->id].len[i] == 0) {
if(mSerialDebug) if(mSerialDebug)
DPRINTLN(DBG_ERROR, F("while retrieving data: Frame ") + String(i+1) + F(" missing: Request Retransmit")); DPRINTLN(DBG_ERROR, F("while retrieving data: Frame ") + String(i+1) + F(" missing: Request Retransmit"));
mSys->Radio.sendCmdPacket(iv->radioId.u64, 0x15, (0x81+i), true); mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, (SINGLE_FRAME+i), true);
break; // only retransmit one frame per loop break; // only retransmit one frame per loop
} }
yield(); yield();
@ -459,9 +494,9 @@ void app::processPayload(bool retransmit) {
if(mSerialDebug) if(mSerialDebug)
DPRINTLN(DBG_ERROR, F("while retrieving data: last frame missing: Request Retransmit")); DPRINTLN(DBG_ERROR, F("while retrieving data: last frame missing: Request Retransmit"));
if(0x00 != mLastPacketId) if(0x00 != mLastPacketId)
mSys->Radio.sendCmdPacket(iv->radioId.u64, 0x15, mLastPacketId, true); mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, mLastPacketId, true);
else else
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts); mSys->Radio.sendTimePacket(iv->radioId.u64, mSys->InfoCmd, mPayload[iv->id].ts);
} }
mSys->Radio.switchRxCh(100); mSys->Radio.switchRxCh(100);
} }
@ -669,43 +704,44 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
if(NULL != iv) { if(NULL != iv) {
if (!iv->devControlRequest) { // still pending if (!iv->devControlRequest) { // still pending
token = strtok(NULL, "/"); token = strtok(NULL, "/");
uint8_t subcmd = std::stoi(token); switch ( std::stoi(token) ){
switch ( subcmd ){ case ActivePowerContr: // Active Power Control
case 11: // Active Power Control
if (true){ // if (std::stoi((char*)payload) > 0) error handling powerlimit needed? if (true){ // if (std::stoi((char*)payload) > 0) error handling powerlimit needed?
iv->devControlCmd = 11; iv->devControlCmd = ActivePowerContr;
iv->powerLimit = std::stoi((char*)payload); iv->powerLimit[0] = std::stoi((char*)payload);
DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit) + F("W") ); iv->powerLimit[1] = 0x0000; // if power limit is set via external interface --> set it temporay
DPRINTLN(DBG_DEBUG, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("W") );
} }
iv->devControlRequest = true; iv->devControlRequest = true;
break; break;
case 0: // Turn On case TurnOn: // Turn On
iv->devControlCmd = 0; iv->devControlCmd = TurnOn;
DPRINTLN(DBG_INFO, F("Turn on inverter ") + String(iv->id) ); DPRINTLN(DBG_INFO, F("Turn on inverter ") + String(iv->id) );
iv->devControlRequest = true; iv->devControlRequest = true;
break; break;
case 1: // Turn Off case TurnOff: // Turn Off
iv->devControlCmd = 1; iv->devControlCmd = TurnOff;
DPRINTLN(DBG_INFO, F("Turn off inverter ") + String(iv->id) ); DPRINTLN(DBG_INFO, F("Turn off inverter ") + String(iv->id) );
iv->devControlRequest = true; iv->devControlRequest = true;
break; break;
case 2: // Restart case Restart: // Restart
iv->devControlCmd = 2; iv->devControlCmd = Restart;
DPRINTLN(DBG_INFO, F("Restart inverter ") + String(iv->id) ); DPRINTLN(DBG_INFO, F("Restart inverter ") + String(iv->id) );
iv->devControlRequest = true; iv->devControlRequest = true;
break; break;
case 12: // Reactive Power Control case ReactivePowerContr: // Reactive Power Control
// iv->devControlCmd = 12; iv->devControlCmd = ReactivePowerContr;
// uint16_t reactive_power = std::stoi(strtok(NULL, "/")); if (true){ // if (std::stoi((char*)payload) > 0) error handling powerlimit needed?
// .../devcontrol/<inverter_id>/<subcmd in dec>/<value in dec> iv->devControlCmd = ReactivePowerContr;
// ^^^ iv->powerLimit[0] = std::stoi((char*)payload);
DPRINTLN(DBG_INFO, F("Reactive Power Control not implemented for inverter ") + String(iv->id) ); iv->powerLimit[1] = 0x0000; // if reactivepower limit is set via external interface --> set it temporay
DPRINTLN(DBG_DEBUG, F("Reactivepower limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("W") );
iv->devControlRequest = true;
}
break; break;
case 13: // Set Power Factor case PFSet: // Set Power Factor
// iv->devControlCmd = 13; // iv->devControlCmd = PFSet;
// uint16_t power_factor = std::stoi(strtok(NULL, "/")); // uint16_t power_factor = std::stoi(strtok(NULL, "/"));
// .../devcontrol/<inverter_id>/<subcmd in dec>/<value in dec>
// ^^^
DPRINTLN(DBG_INFO, F("Set Power Factor not implemented for inverter ") + String(iv->id) ); DPRINTLN(DBG_INFO, F("Set Power Factor not implemented for inverter ") + String(iv->id) );
break; break;
default: default:
@ -775,16 +811,20 @@ void app::showStatistics(void) {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::devControl(void) { // ToDo void app::webapi(void) { // ToDo
DPRINTLN(DBG_VERBOSE, F("app::devControl")); DPRINTLN(DBG_VERBOSE, F("app::api"));
if(mWeb->args() > 0) { DPRINTLN(DBG_DEBUG, mWeb->arg("plain"));
//mWeb->arg("ivid").toChar... const size_t capacity = 200; // Use arduinojson.org/assistant to compute the capacity.
// get iv DynamicJsonDocument payload(capacity);
// set devControl on/off/power limt --> integrate buttons in app::showLiveData
// ... // Parse JSON object
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Command sent</title><meta http-equiv=\"refresh\" content=\"2; URL=/hoymiles\"></head><body>" deserializeJson(payload, mWeb->arg("plain"));
"<p>sent</p></body></html>")); // ToDo: error handling for payload
if (payload["tx_request"] == TX_REQ_INFO){
mSys->InfoCmd = payload["cmd"];
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(mSys->InfoCmd));
} }
mWeb->send ( 200, "text/json", "{success:true}" );
} }
@ -826,7 +866,7 @@ void app::showLiveData(void) {
} }
modHtml += F("<div class=\"iv\">" modHtml += F("<div class=\"iv\">"
"<div class=\"ch-iv\"><span class=\"head\">") + String(iv->name) + F(" Limit ") + String(iv->powerLimit) + F(" W</span>"); "<div class=\"ch-iv\"><span class=\"head\">") + String(iv->name) + F(" Limit ") + String(iv->powerLimit[0]) + F(" W</span>");
uint8_t list[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PCT, FLD_T, FLD_YT, FLD_YD, FLD_PDC, FLD_EFF}; uint8_t list[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PCT, FLD_T, FLD_YT, FLD_YD, FLD_PDC, FLD_EFF};
for(uint8_t fld = 0; fld < 10; fld++) { for(uint8_t fld = 0; fld < 10; fld++) {

2
tools/esp8266/app.h

@ -71,7 +71,7 @@ class app : public Main {
void showHoymiles(void); void showHoymiles(void);
void showLiveData(void); void showLiveData(void);
void showJSON(void); void showJSON(void);
void devControl(void); void webapi(void);
void saveValues(bool webSend); void saveValues(bool webSend);

37
tools/esp8266/defines.h

@ -30,6 +30,43 @@ typedef struct {
uint8_t packet[MAX_RF_PAYLOAD_SIZE]; uint8_t packet[MAX_RF_PAYLOAD_SIZE];
} packet_t; } packet_t;
typedef enum
{
InverterDevInform_Simple = 0, // 0x00
InverterDevInform_All = 1, // 0x01
//GridOnProFilePara = 2, // 0x02
//HardWareConfig = 3, // 0x03
//SimpleCalibrationPara = 4, // 0x04
//SystemConfigPara = 5, // 0x05
RealTimeRunData_Debug = 11, // 0x0b
//RealTimeRunData_Reality = 12, // 0x0c
//RealTimeRunData_A_Phase = 13, // 0x0d
//RealTimeRunData_B_Phase = 14, // 0x0e
//RealTimeRunData_C_Phase = 15, // 0x0f
//AlarmData = 17, // 0x11 //Alarm data - all unsent alarms
//AlarmUpdate = 18, // 0x12 //Alarm data - all pending alarms
//RecordData = 19, // 0x13
//InternalData = 20, // 0x14
GetLossRate = 21, // 0x15
//GetSelfCheckState = 30, // 0x1e
//InitDataState = 0xff
} InfoCmdType;
typedef enum
{
TurnOn = 0, // 0x00
TurnOff = 1, // 0x01
Restart = 2, // 0x02
Lock = 3, // 0x03
Unlock = 4, // 0x04
ActivePowerContr = 11, // 0x0b
ReactivePowerContr = 12, // 0x0c
PFSet = 13, // 0x0d
CleanState_LockAndAlarm = 20, // 0x14
SelfInspection = 40, // 0x28 // self-inspection of grid-connected protection files
Init = 0xff
} DevControlCmdType;
// minimum serial interval // minimum serial interval
#define MIN_SERIAL_INTERVAL 5 #define MIN_SERIAL_INTERVAL 5

5
tools/esp8266/hmInverter.h

@ -69,7 +69,7 @@ class Inverter {
uint8_t type; // integer which refers to inverter type uint8_t type; // integer which refers to inverter type
byteAssign_t* assign; // type of inverter byteAssign_t* assign; // type of inverter
uint8_t listLen; // length of assignments uint8_t listLen; // length of assignments
uint16_t powerLimit; // limit power output uint16_t powerLimit[2]; // limit power output
uint8_t devControlCmd; // carries the requested cmd uint8_t devControlCmd; // carries the requested cmd
bool devControlRequest; // true if change needed bool devControlRequest; // true if change needed
serial_u serial; // serial number as on barcode serial_u serial; // serial number as on barcode
@ -82,7 +82,8 @@ class Inverter {
Inverter() { Inverter() {
ts = 0; ts = 0;
powerLimit = -1; // 65535 W Limit -> unlimited powerLimit[0] = -1; // 65535 W Limit -> unlimited
powerLimit[1] = 0x0100; // 0x0000 --> set temporary , 0x0100 --> set persistent
devControlRequest = false; devControlRequest = false;
devControlCmd = 0xff; devControlCmd = 0xff;
} }

40
tools/esp8266/hmRadio.h

@ -22,6 +22,10 @@
#define RF_CHANNELS 5 #define RF_CHANNELS 5
#define RF_LOOP_CNT 300 #define RF_LOOP_CNT 300
#define TX_REQ_INFO 0X15
#define TX_REQ_DEVCONTROL 0x51
#define ALL_FRAMES 0x80
#define SINGLE_FRAME 0x81
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"}; const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
@ -159,26 +163,25 @@ class HmRadio {
return mRfChLst[mTxChIdx]; return mRfChLst[mTxChIdx];
} }
void sendControlPacket(uint64_t invId, uint8_t cmd, uint16_t data) { void sendControlPacket(uint64_t invId, uint8_t cmd, uint16_t *data) {
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendControlPacket")); DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendControlPacket"));
sendCmdPacket(invId, 0x51, 0x80, false); // 0x80 implementation as original DTU code sendCmdPacket(invId, TX_REQ_DEVCONTROL, ALL_FRAMES, false); // 0x80 implementation as original DTU code
int cnt = 0; int cnt = 0;
mTxBuf[10] = cmd; // cmd --> 0x0b => Type_ActivePowerContr, 0 on, 1 off, 2 restart, 12 reactive power, 13 power factor mTxBuf[10] = cmd; // cmd --> 0x0b => Type_ActivePowerContr, 0 on, 1 off, 2 restart, 12 reactive power, 13 power factor
mTxBuf[10 + (++cnt)] = 0x00; mTxBuf[10 + (++cnt)] = 0x00;
if (cmd == 11){ if (cmd == ActivePowerContr){
// 4 bytes control data // 4 bytes control data
// Power Limit fix point 10 eg. 30 W --> 0d300 = 0x012c // Power Limit fix point 10 eg. 30 W --> 0d300 = 0x012c
// -1 = 0xffff --> no limit // -1 = 0xffff --> no limit
if (data == 0xffff){ if (data[0] == 0xffff){
data &= 0xffff; // ToDo: unlimit value is needed and is inverter specific! --> get it via RF from inverter or via user interface data[0] &= 0xffff; // ToDo: unlimit value is needed and is inverter specific! --> get it via RF from inverter or via user interface
} else { } else {
data*= 10; data[0] *= 10;
} }
mTxBuf[10 + (++cnt)] = (data >> 8) & 0xff; // 0x01 mTxBuf[10 + (++cnt)] = (data[0] >> 8) & 0xff; // power limit
mTxBuf[10 + (++cnt)] = (data ) & 0xff; // 0x2c mTxBuf[10 + (++cnt)] = (data[0] ) & 0xff; // power limit
mTxBuf[10 + (++cnt)] = 0x00; // not persistent mTxBuf[10 + (++cnt)] = (data[1] >> 8) & 0xff; // setting for persistens handling
//mTxBuf[10 + (++cnt)] = 0x01; // persistent mTxBuf[10 + (++cnt)] = (data[1] ) & 0xff; // setting for persistens handling
mTxBuf[10 + (++cnt)] = 0x00;
} }
// crc control data // crc control data
uint16_t crc = crc16(&mTxBuf[10], cnt+1); uint16_t crc = crc16(&mTxBuf[10], cnt+1);
@ -191,14 +194,17 @@ class HmRadio {
sendPacket(invId, mTxBuf, 10 + (++cnt), true); sendPacket(invId, mTxBuf, 10 + (++cnt), true);
} }
void sendTimePacket(uint64_t invId, uint32_t ts) { void sendTimePacket(uint64_t invId, uint8_t cmd, uint32_t ts) {
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket")); //DPRINTLN(DBG_VERBOSE, F("hmRadio.h:sendTimePacket"));
sendCmdPacket(invId, 0x15, 0x80, false); sendCmdPacket(invId, TX_REQ_INFO, ALL_FRAMES, false);
mTxBuf[10] = 0x0b; // cid mTxBuf[10] = cmd; // cid
mTxBuf[11] = 0x00; mTxBuf[11] = 0x00;
CP_U32_LittleEndian(&mTxBuf[12], ts); CP_U32_LittleEndian(&mTxBuf[12], ts);
mTxBuf[19] = 0x05; if (cmd == RealTimeRunData_Debug){
mTxBuf[19] = 0x05; // ToDo: Shall be the last received Alarm Index Number
} else {
mTxBuf[19] = 0x00;
}
uint16_t crc = crc16(&mTxBuf[10], 14); uint16_t crc = crc16(&mTxBuf[10], 14);
mTxBuf[24] = (crc >> 8) & 0xff; mTxBuf[24] = (crc >> 8) & 0xff;
mTxBuf[25] = (crc ) & 0xff; mTxBuf[25] = (crc ) & 0xff;
@ -341,6 +347,8 @@ class HmRadio {
BUFFER *mBufCtrl; BUFFER *mBufCtrl;
uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE]; uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE];
DevControlCmdType DevControlCmd;
volatile bool mIrqRcvd; volatile bool mIrqRcvd;
}; };

3
tools/esp8266/hmSystem.h

@ -19,9 +19,12 @@ class HmSystem {
RadioType Radio; RadioType Radio;
typedef BUFFER BufferType; typedef BUFFER BufferType;
BufferType BufCtrl; BufferType BufCtrl;
InfoCmdType InfoCmd;
//DevControlCmdType DevControlCmd;
HmSystem() { HmSystem() {
mNumInv = 0; mNumInv = 0;
InfoCmd = RealTimeRunData_Debug; // default case
} }
~HmSystem() { ~HmSystem() {
// TODO: cleanup // TODO: cleanup

Loading…
Cancel
Save