Skip to content

Commit

Permalink
allow device to start with reset message, spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Feb 24, 2024
1 parent 6d49fd7 commit 3d62365
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
28 changes: 21 additions & 7 deletions src/lib/ebus/device_trans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ result_t PlainDevice::recv(unsigned int timeout, symbol_t* value, ArbitrationSta
}


/** the features requested. */
#define REQUEST_FEATURES 0x01

void EnhancedDevice::formatInfo(ostringstream* ostream, bool verbose, bool prefix) {
BaseDevice::formatInfo(ostream, verbose, prefix);
if (prefix) {
Expand Down Expand Up @@ -164,7 +167,7 @@ void EnhancedDevice::formatInfoJson(ostringstream* ostream) const {
}

result_t EnhancedDevice::requestEnhancedInfo(symbol_t infoId, bool wait) {
if (m_extraFatures == 0) {
if (m_extraFeatures == 0) {
return RESULT_ERR_INVALID_ARG;
}
if (wait) {
Expand Down Expand Up @@ -206,7 +209,7 @@ result_t EnhancedDevice::requestEnhancedInfo(symbol_t infoId, bool wait) {
}

string EnhancedDevice::getEnhancedInfos() {
if (m_extraFatures == 0) {
if (m_extraFeatures == 0) {
return "";
}
result_t res;
Expand Down Expand Up @@ -333,15 +336,17 @@ bool EnhancedDevice::cancelRunningArbitration(ArbitrationState* arbitrationState
result_t EnhancedDevice::notifyTransportStatus(bool opened) {
result_t result = BaseDevice::notifyTransportStatus(opened); // always OK
if (opened) {
symbol_t buf[2] = makeEnhancedSequence(ENH_REQ_INIT, 0x01); // extra feature: info
symbol_t buf[2] = makeEnhancedSequence(ENH_REQ_INIT, REQUEST_FEATURES); // extra feature: info
result = m_transport->write(buf, 2);
if (result != RESULT_OK) {
return result;
}
m_resetTime = time(NULL);
m_resetRequested = true;
} else {
// reset state
m_extraFatures = 0;
m_resetTime = 0;
m_extraFeatures = 0;
m_infoLen = 0;
m_enhInfoVersion = "";
m_enhInfoIsWifi = false;
Expand Down Expand Up @@ -439,13 +444,22 @@ symbol_t* value, ArbitrationState* arbitrationState) {
m_enhInfoSupplyVoltage = "";
m_enhInfoBusVoltage = "";
m_infoLen = 0;
m_extraFatures = data;
if (!m_resetRequested && m_resetTime+3 >= time(NULL)) {
if (data == m_extraFeatures) {
// skip explicit response to init request
valueSet = false;
break;
}
// response to init request had different feature flags
m_resetRequested = true;
}
m_extraFeatures = data;
if (m_listener != nullptr) {
m_listener->notifyDeviceStatus(false, (m_extraFatures&0x01) ? "reset, supports info" : "reset");
m_listener->notifyDeviceStatus(false, (m_extraFeatures&0x01) ? "reset, supports info" : "reset");
}
if (m_resetRequested) {
m_resetRequested = false;
if (m_extraFatures&0x01) {
if (m_extraFeatures&0x01) {
requestEnhancedInfo(0, false); // request version, ignore result
}
valueSet = false;
Expand Down
11 changes: 7 additions & 4 deletions src/lib/ebus/device_trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class EnhancedDevice : public BaseDevice, public EnhancedDeviceInterface {
* @param transport the @a Transport to use.
*/
explicit EnhancedDevice(Transport* transport)
: BaseDevice(transport), EnhancedDeviceInterface(), m_resetRequested(false),
m_extraFatures(0), m_infoReqTime(0), m_infoLen(0), m_infoPos(0), m_enhInfoIsWifi(false) {
: BaseDevice(transport), EnhancedDeviceInterface(), m_resetTime(0), m_resetRequested(false),
m_extraFeatures(0), m_infoReqTime(0), m_infoLen(0), m_infoPos(0), m_enhInfoIsWifi(false) {
}

// @copydoc
Expand All @@ -161,7 +161,7 @@ class EnhancedDevice : public BaseDevice, public EnhancedDeviceInterface {
virtual result_t notifyTransportStatus(bool opened);

// @copydoc
bool supportsUpdateCheck() const override { return m_extraFatures & 0x01; }
bool supportsUpdateCheck() const override { return m_extraFeatures & 0x01; }

// @copydoc
virtual result_t requestEnhancedInfo(symbol_t infoId, bool wait = true);
Expand Down Expand Up @@ -190,11 +190,14 @@ class EnhancedDevice : public BaseDevice, public EnhancedDeviceInterface {
*/
void notifyInfoRetrieved();

/** the time when the transport was resetted. */
time_t m_resetTime;

/** whether the reset of the device was already requested. */
bool m_resetRequested;

/** the extra features supported by the device. */
symbol_t m_extraFatures;
symbol_t m_extraFeatures;

/** the time of the last info request. */
time_t m_infoReqTime;
Expand Down

0 comments on commit 3d62365

Please sign in to comment.