Skip to content

Commit

Permalink
0.8.69
Browse files Browse the repository at this point in the history
* fix brackets
  • Loading branch information
lumapu committed Jan 31, 2024
1 parent ac58f2f commit 349184a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/hm/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Communication : public CommQueue<> {
mIsRetransmit = false;
if(NULL == q->iv->radio)
cmdDone(false); // can't communicate while radio is not defined!
mFirstTry = INV_RADIO_TYPE_NRF == q->iv->ivRadioType && q->iv->isAvailable();
mFirstTry = (INV_RADIO_TYPE_NRF == q->iv->ivRadioType) && (q->iv->isAvailable());
q->iv->mCmd = q->cmd;
q->iv->mIsSingleframeReq = false;
mFramesExpected = getFramesExpected(q); // function to get expected frame count.
Expand Down Expand Up @@ -116,7 +116,7 @@ class Communication : public CommQueue<> {
//q->iv->radioStatistics.txCnt++;
q->iv->radio->mRadioWaitTime.startTimeMonitor(mTimeout);
if(!mIsRetransmit && (q->cmd == AlarmData) || (q->cmd == GridOnProFilePara))
incrAttempt(q->cmd == AlarmData? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA);
incrAttempt((q->cmd == AlarmData)? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA);

mIsRetransmit = false;
setAttempt();
Expand Down Expand Up @@ -184,7 +184,7 @@ class Communication : public CommQueue<> {
if (p->packet[0] == (TX_REQ_INFO + ALL_FRAMES)) { // response from get information command
if(parseFrame(p)) {
q->iv->curFrmCnt++;
if(!mIsRetransmit && (p->packet[9] == 0x02 || p->packet[9] == 0x82) && p->millis < LIMIT_FAST_IV)
if(!mIsRetransmit && ((p->packet[9] == 0x02) || (p->packet[9] == 0x82)) && (p->millis < LIMIT_FAST_IV))
mHeu.setIvRetriesGood(q->iv,p->millis < LIMIT_VERYFAST_IV);
}
} else if (p->packet[0] == (TX_REQ_DEVCONTROL + ALL_FRAMES)) { // response from dev control command
Expand Down Expand Up @@ -257,13 +257,13 @@ class Communication : public CommQueue<> {
return;
}
//count missing frames
if(!q->iv->mIsSingleframeReq && q->iv->ivRadioType == INV_RADIO_TYPE_NRF) { // already checked?
if(!q->iv->mIsSingleframeReq && (q->iv->ivRadioType == INV_RADIO_TYPE_NRF)) { // already checked?
uint8_t missedFrames = 0;
for(uint8_t i = 0; i < q->iv->radio->mFramesExpected; i++) {
if(mLocalBuf[i].len == 0)
missedFrames++;
}
if(missedFrames > 3 || (q->cmd == RealTimeRunData_Debug && missedFrames > 1) || (missedFrames > 1 && missedFrames + 2 > q->attempts)) {
if(missedFrames > 3 || (q->cmd == RealTimeRunData_Debug && missedFrames > 1) || ((missedFrames > 1) && ((missedFrames + 2) > q->attempts))) {
if(*mSerialDebug) {
DPRINT_IVID(DBG_INFO, q->iv->id);
DBGPRINT(String(missedFrames));
Expand Down Expand Up @@ -435,7 +435,7 @@ class Communication : public CommQueue<> {
}

inline bool parseMiFrame(packet_t *p, const queue_s *q) {
if(!mIsRetransmit && p->packet[9] == 0x00 && p->millis < LIMIT_FAST_IV_MI) //first frame is fast?
if((!mIsRetransmit && p->packet[9] == 0x00) && (p->millis < LIMIT_FAST_IV_MI)) //first frame is fast?
mHeu.setIvRetriesGood(q->iv,p->millis < LIMIT_VERYFAST_IV_MI);
if ((p->packet[0] == MI_REQ_CH1 + ALL_FRAMES)
|| (p->packet[0] == MI_REQ_CH2 + ALL_FRAMES)
Expand Down
2 changes: 1 addition & 1 deletion src/hm/Heuristic.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------------
// 2023 Ahoy, https://github.com/lumpapu/ahoy
// 2024 Ahoy, https://github.com/lumpapu/ahoy
// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed
//-----------------------------------------------------------------------------

Expand Down
10 changes: 7 additions & 3 deletions src/hm/HeuristicInv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class HeuristicInv {
testChId = 0;
saveOldTestQuality = -6;
lastRxFragments = 0;

rxSpeeds[0] = false;
rxSpeeds[1] = false;
rxSpeedCnt[0] = 0;
rxSpeedCnt[1] = 0;
}

bool isTxAtMax(void) const {
Expand All @@ -42,9 +47,8 @@ class HeuristicInv {
uint8_t testChId = 0;
int8_t saveOldTestQuality = -6;
uint8_t lastRxFragments = 0;
bool rxSpeeds[2] = {false,false}; // is inverter responding very fast respective fast?
uint8_t rxSpeedCnt[2] = {0,0}; // count how many messages had been received very fast respective fast (10 max)

bool rxSpeeds[2] = {false, false}; // is inverter responding very fast respective fast?
uint8_t rxSpeedCnt[2] = {0, 0}; // count how many messages had been received very fast respective fast (10 max)
};

#endif /*__HEURISTIC_INV_H__*/
2 changes: 1 addition & 1 deletion src/hm/hmDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ enum {INV_RADIO_TYPE_NRF = 0, INV_RADIO_TYPE_CMT};
#define DURATION_TXFRAME 85 // timeout parameter for first transmission and first expected frame (time to first channel switch from tx start!) (ms)
#define DURATION_LISTEN_MIN 5 // time to stay at least on a listening channel (ms)
#define DURATION_PAUSE_LASTFR 45 // how long to pause after last frame (ms)
const uint8_t duration_reserve[2] = {65,115};
const uint8_t duration_reserve[2] = {65, 115};

#define LIMIT_FAST_IV 85 // time limit to qualify an inverter as very fast answering inverter
#define LIMIT_VERYFAST_IV 70 // time limit to qualify an inverter as very fast answering inverter
Expand Down
2 changes: 1 addition & 1 deletion src/hm/hmInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class Inverter {
status = InverterStatus::OFF;
actPowerLimit = 0xffff; // power limit will be read once inverter becomes available
alarmMesIndex = 0;
if(ivRadioType == INV_RADIO_TYPE_NRF) {
if(INV_RADIO_TYPE_NRF == ivRadioType) {
heuristics.clear();
#ifdef DYNAMIC_OFFSET
rxOffset = ivGen == IV_HM ? 13 : 12; // effective 3 (or 2), but can easily be recognized as default setting
Expand Down
9 changes: 5 additions & 4 deletions src/hm/hmRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,13 @@ class HmRadio : public Radio {
isLastPackage = (p.packet[9] > ALL_FRAMES); // > ALL_FRAMES indicates last packet received
if(mLastIv->mIsSingleframeReq) // we only expect one frame here...
isRetransmitAnswer = true;

if(isLastPackage)
setExpectedFrames(p.packet[9] - ALL_FRAMES);
#ifdef DYNAMIC_OFFSET
if(p.packet[9] == 1 && p.millis < DURATION_ONEFRAME)
if((p.packet[9] == 1) && (p.millis < DURATION_ONEFRAME))
mLastIv->rxOffset = (RF_CHANNELS + mTxChIdx - tempRxChIdx + 1) % RF_CHANNELS;
else if(mNRFloopChannels && mLastIv->rxOffset > RF_CHANNELS) { // unsure setting?
else if(mNRFloopChannels && (mLastIv->rxOffset > RF_CHANNELS)) { // unsure setting?
mLastIv->rxOffset = (RF_CHANNELS + mTxChIdx - tempRxChIdx + (isLastPackage ? mFramesExpected : p.packet[9])); // make clear it's not sure, start with one more offset
mNRFloopChannels = false;
}
Expand All @@ -346,7 +347,7 @@ class HmRadio : public Radio {
else if ((p.packet[0] != 0x88) && (p.packet[0] != 0x92)) // ignore MI status messages //#0 was p.packet[0] != 0x00 &&
isLastPackage = true; // response from dev control command
#ifdef DYNAMIC_OFFSET
if(p.packet[9] == 0x00 && p.millis < DURATION_ONEFRAME)
if((p.packet[9] == 0x00) && (p.millis < DURATION_ONEFRAME))
mLastIv->rxOffset = (RF_CHANNELS + mTxChIdx - tempRxChIdx - 1) % RF_CHANNELS;
#endif
}
Expand Down Expand Up @@ -408,7 +409,7 @@ class HmRadio : public Radio {

mNrf24->stopListening();
mNrf24->flush_rx();
if(!isRetransmit && mTxRetries != mTxRetriesNext) {
if(!isRetransmit && (mTxRetries != mTxRetriesNext)) {
mNrf24->setRetries(3, mTxRetriesNext);
mTxRetries = mTxRetriesNext;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hm/hmSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ class HmSystem {
DPRINTLN(DBG_WARN, F("MI Inverter, has some restrictions!"));

#ifdef DYNAMIC_OFFSET
iv->rxOffset = iv->ivGen == IV_HM ? 13 : 12; // effective 3 (or 2), but can easily be recognized as default setting
iv->rxOffset = (iv->ivGen == IV_HM) ? 13 : 12; // effective 3 (or 2), but can easily be recognized as default setting
#else
iv->rxOffset = (iv->ivGen == IV_HM && iv->type == INV_TYPE_4CH) ? 3 : 2;
iv->rxOffset = iv->ivGen == IV_HM ? 3 : 2;
iv->rxOffset = ((iv->ivGen == IV_HM) && (iv->type == INV_TYPE_4CH)) ? 3 : 2;
iv->rxOffset = (iv->ivGen == IV_HM) ? 3 : 2;
#endif

cb(iv);
Expand Down

0 comments on commit 349184a

Please sign in to comment.