Skip to content

Commit

Permalink
Merge branch 'rejoe2-development03' into development03
Browse files Browse the repository at this point in the history
  • Loading branch information
lumapu committed Oct 2, 2023
2 parents 1bbe979 + 4cea0d2 commit ee6dbd6
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/hm/hmPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class HmPayload {
return false;

//requests to cause the next request to be executed immediately
if (mPayload[iv->id].gotFragment && ((mPayload[iv->id].txCmd < 11) || (mPayload[iv->id].txCmd > 18))) {
if (mPayload[iv->id].gotFragment && ((mPayload[iv->id].txCmd < RealTimeRunData_Debug) || (mPayload[iv->id].txCmd >= AlarmData))) {
*fastNext = true;
}

Expand Down
78 changes: 58 additions & 20 deletions src/hm/hmRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};

#define TX_REQ_DREDCONTROL 0x50
#define DRED_A5 0xa5
#define DRED_5A 0x5a
#define DRED_AA 0xaa
#define DRED_55 0x55

//-----------------------------------------------------------------------------
// HM Radio class
Expand Down Expand Up @@ -140,7 +145,7 @@ class HmRadio : public Radio {
return mNrf24.isChipConnected();
}

void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit, bool isNoMI = true, bool is4chMI = false) {
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit, bool isNoMI = true, uint16_t powerMax = 0) {
DPRINT(DBG_INFO, F("sendControlPacket cmd: 0x"));
DBGHEXLN(cmd);
initPacket(iv->radioId.u64, TX_REQ_DEVCONTROL, SINGLE_FRAME);
Expand All @@ -156,31 +161,64 @@ class HmRadio : public Radio {
}
} else { //MI 2nd gen. specific
switch (cmd) {
case Restart:
case TurnOn:
//mTxBuf[0] = 0x50;
mTxBuf[9] = 0x55;
mTxBuf[10] = 0xaa;
mTxBuf[9] = DRED_55;
mTxBuf[10] = DRED_AA;
break;
case TurnOff:
mTxBuf[9] = 0xaa;
mTxBuf[10] = 0x55;
mTxBuf[9] = DRED_AA;
mTxBuf[10] = DRED_55;
break;
case ActivePowerContr:
mTxBuf[9] = 0x5a;
mTxBuf[10] = 0x5a;
//Testing only! Original NRF24_DTUMIesp.ino code #L612-L613:
//UsrData[0]=0x5A;UsrData[1]=0x5A;UsrData[2]=100;//0x0a;// 10% limit
//UsrData[3]=((Limit*10) >> 8) & 0xFF; UsrData[4]= (Limit*10) & 0xFF; //WR needs 1 dec= zB 100.1 W
if (is4chMI) {
mTxBuf[cnt++] = 100; //10% limit, seems to be necessary to send sth. at all, but for MI-1500 this has no effect
//works (if ever!) only for absulute power limits!
mTxBuf[cnt++] = ((data[0] * 10) >> 8) & 0xff; // power limit
mTxBuf[cnt++] = ((data[0] * 10) ) & 0xff; // power limit
} else {
mTxBuf[cnt++] = data[0]*10; // power limit
if (data[1]<256) { // non persistent
mTxBuf[9] = DRED_5A;
mTxBuf[10] = DRED_5A;
//Testing only! Original NRF24_DTUMIesp.ino code #L612-L613:
//UsrData[0]=0x5A;UsrData[1]=0x5A;UsrData[2]=100;//0x0a;// 10% limit
//UsrData[3]=((Limit*10) >> 8) & 0xFF; UsrData[4]= (Limit*10) & 0xFF; //WR needs 1 dec= zB 100.1 W
if (!data[1]) { // AbsolutNonPersistent
mTxBuf[++cnt] = 100; //10% limit, seems to be necessary to send sth. at all, but for MI-1500 this has no effect
//works (if ever!) only for absulute power limits!
mTxBuf[++cnt] = ((data[0] * 10) >> 8) & 0xff; // power limit in W
mTxBuf[++cnt] = ((data[0] * 10) ) & 0xff; // power limit in W
} else if (powerMax) { //relative, but 4ch-MI (if ever) only accepts absolute values
mTxBuf[++cnt] = data[0]; // simple power limit in %, might be necessary to multiply by 10?
mTxBuf[++cnt] = ((data[0] * 10 * powerMax) >> 8) & 0xff; // power limit
mTxBuf[++cnt] = ((data[0] * 10 * powerMax) ) & 0xff; // power limit
} else { // might work for 1/2ch MI (if ever)
mTxBuf[++cnt] = data[0]; // simple power limit in %, might be necessary to multiply by 10?
}
} else { // persistent power limit needs to be translated in DRED command (?)
/* DRED instruction
Order Function
0x55AA Boot without DRM restrictions
0xA5A5 DRM0 shutdown
0x5A5A DRM5 power limit 0%
0xAA55 DRM6 power limit 50%
0x5A55 DRM8 unlimited power operation
*/
mTxBuf[0] = TX_REQ_DREDCONTROL;

if (data[1] == 256UL) { // AbsolutPersistent
if (data[0] == 0 && !powerMax) {
mTxBuf[9] = DRED_A5;
mTxBuf[10] = DRED_A5;
} else if (data[0] == 0 || !powerMax || data[0] < powerMax/4 ) {
mTxBuf[9] = DRED_5A;
mTxBuf[10] = DRED_5A;
} else if (data[0] <= powerMax/4*3) {
mTxBuf[9] = DRED_AA;
mTxBuf[10] = DRED_55;
} else if (data[0] <= powerMax) {
mTxBuf[9] = DRED_5A;
mTxBuf[10] = DRED_55;
} else if (data[0] > powerMax*2) {
mTxBuf[9] = DRED_55;
mTxBuf[10] = DRED_AA;
}
}
}


break;
default:
return;
Expand Down
Loading

0 comments on commit ee6dbd6

Please sign in to comment.