Skip to content

Commit

Permalink
Merge branch 've.direct-hex' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Apr 19, 2023
2 parents a1b3bdf + 943a0eb commit 84a6ed5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
36 changes: 28 additions & 8 deletions lib/VeDirectFrameHandler/VeDirectFrameHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ VeDirectFrameHandler::VeDirectFrameHandler() :
_state(IDLE),
_checksum(0),
_textPointer(0),
_hexSize(0),
_name(""),
_value(""),
_tmpFrame(),
Expand Down Expand Up @@ -99,7 +100,9 @@ void VeDirectFrameHandler::rxData(uint8_t inbyte)
{
//if (mStop) return;
if ( (inbyte == ':') && (_state != CHECKSUM) ) {
_state = RECORD_HEX;
_prevState = _state; //hex frame can interrupt TEXT
_state = RECORD_HEX;
_hexSize = 0;
}
if (_state != RECORD_HEX) {
_checksum += inbyte;
Expand Down Expand Up @@ -177,10 +180,7 @@ void VeDirectFrameHandler::rxData(uint8_t inbyte)
break;
}
case RECORD_HEX:
if (hexRxEvent(inbyte)) {
_checksum = 0;
_state = IDLE;
}
_state = hexRxEvent(inbyte);
break;
}
}
Expand Down Expand Up @@ -279,10 +279,27 @@ void VeDirectFrameHandler::logE(const char * module, const char * error) {

/*
* hexRxEvent
* This function included for continuity and possible future use.
* This function records hex answers or async messages
*/
bool VeDirectFrameHandler::hexRxEvent(uint8_t inbyte) {
return true; // stubbed out for future
int VeDirectFrameHandler::hexRxEvent(uint8_t inbyte) {
int ret=RECORD_HEX; // default - continue recording until end of frame

switch (inbyte) {
case '\n':
// restore previous state
ret=_prevState;
break;

default:
_hexSize++;
if (_hexSize>=VE_MAX_HEX_LEN) { // oops -buffer overflow - something went wrong, we abort
logE(MODULE,"hexRx buffer overflow - aborting read");
_hexSize=0;
ret=IDLE;
}
}

return ret;
}

bool VeDirectFrameHandler::isDataValid() {
Expand Down Expand Up @@ -510,6 +527,9 @@ String VeDirectFrameHandler::getPidAsString(uint16_t pid)
case 0XA10F:
strPID = "BlueSolar MPPT VE.Can 150|100";
break;
case 0XA110:
strPID = "SmartSolar MPPT RS 450|100";
break;
case 0XA112:
strPID = "BlueSolar MPPT VE.Can 250|70";
break;
Expand Down
6 changes: 5 additions & 1 deletion lib/VeDirectFrameHandler/VeDirectFrameHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#define VE_MAX_NAME_LEN 9 // VE.Direct Protocol: max name size is 9 including /0
#define VE_MAX_VALUE_LEN 33 // VE.Direct Protocol: max value size is 33 including /0
#define VE_MAX_HEX_LEN 100 // Maximum size of hex frame - max payload 34 byte (=68 char) + safe buffer


typedef struct {
uint16_t PID; // product id
Expand Down Expand Up @@ -69,12 +71,14 @@ class VeDirectFrameHandler {
void textRxEvent(char *, char *);
void frameEndEvent(bool); // copy temp struct to public struct
void logE(const char *, const char *);
bool hexRxEvent(uint8_t);
int hexRxEvent(uint8_t);

//bool mStop; // not sure what Victron uses this for, not using
int _state; // current state
int _prevState; // previous state
uint8_t _checksum; // checksum value
char * _textPointer; // pointer to the private buffer we're writing to, name or value
int _hexSize; // length of hex buffer
char _name[VE_MAX_VALUE_LEN]; // buffer for the field name
char _value[VE_MAX_VALUE_LEN]; // buffer for the field value
veStruct _tmpFrame{}; // private struct for received name and value pairs
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,10 @@
"InverterIdHint": "Wähle den Wechselrichter an dem die Batterie hängt.",
"InverterChannelId": "Kanal ID",
"InverterChannelIdHint": "Wähle den Kanal an dem die Batterie hängt.",
"TargetPowerConsumption": "Erlaubter Stromverbrauch",
"TargetPowerConsumptionHint": "Angestrebter erlaubter Stromverbrauch.",
"TargetPowerConsumptionHysteresis": "Hysterese für den Zielstromverbrauch",
"TargetPowerConsumptionHysteresisHint": "Wert um den der Zielstromverbrauch schwanken darf, ohne dass nachgeregelt wird.",
"TargetPowerConsumption": "Angestrebter Netzbezung",
"TargetPowerConsumptionHint": "Angestrebter erlaubter Stromverbrauch aus dem Netz.",
"TargetPowerConsumptionHysteresis": "Hysterese für den angestrebten Netzbezug",
"TargetPowerConsumptionHysteresisHint": "Wert um den der angestrebte Netzbezug schwanken darf, ohne dass nachgeregelt wird.",
"LowerPowerLimit": "Unteres Leistungslimit",
"UpperPowerLimit": "Oberes Leistungslimit",
"PowerMeters": "Leistungsmesser",
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@
"InverterIdHint": "Select proper inverter ID where battery is connected to.",
"InverterChannelId": "Channel ID",
"InverterChannelIdHint": "Select proper channel where battery is connected to.",
"TargetPowerConsumption": "Target power consumption",
"TargetPowerConsumption": "Target power consumption from grid",
"TargetPowerConsumptionHint": "Set the grid power consumption the limiter tries to achieve.",
"TargetPowerConsumptionHysteresis": "Hysteresis for power consumption",
"TargetPowerConsumptionHysteresisHint": "Value around which the target power consumption fluctuates without readjustment.",
"TargetPowerConsumptionHysteresis": "Hysteresis for power consumption from grid",
"TargetPowerConsumptionHysteresisHint": "Value around which the target grid power consumption fluctuates without readjustment.",
"LowerPowerLimit": "Lower power limit",
"UpperPowerLimit": "Upper power limit",
"PowerMeters": "Power meter",
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/views/PowerLimiterAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<div class="col-sm-10">
<div class="input-group">
<input type="number" class="form-control" id="targetPowerConsumption"
placeholder="75" min="0" v-model="powerLimiterConfigList.target_power_consumption"
placeholder="75" v-model="powerLimiterConfigList.target_power_consumption"
aria-describedby="targetPowerConsumptionDescription" required/>
<span class="input-group-text" id="targetPowerConsumptionDescription">W</span>
</div>
Expand Down

0 comments on commit 84a6ed5

Please sign in to comment.