Skip to content

Commit

Permalink
Remove old DE specific OTA code
Browse files Browse the repository at this point in the history
This was used back in the day in some dresden elektronik networks.
  • Loading branch information
manup committed Oct 16, 2021
1 parent 89c145f commit a6bf48c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 159 deletions.
132 changes: 3 additions & 129 deletions de_otau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,14 @@ void DeRestPluginPrivate::initOtau()
{
otauIdleTicks = 0;
otauBusyTicks = 0;
otauNotifyIter = 0;
otauIdleTotalCounter = 0;
otauUnbindIdleTotalCounter = 0;
otauNotifyDelay = deCONZ::appArgumentNumeric("--otau-notify-delay", OTAU_IDLE_TICKS_NOTIFY);

otauTimer = new QTimer(this);
otauTimer->setSingleShot(false);
connect(otauTimer, SIGNAL(timeout()),
this, SLOT(otauTimerFired()));

if (otauNotifyDelay > 0)
{
otauTimer->start(1000);
}
}

/*! Handler for incoming otau packets.
Expand Down Expand Up @@ -120,16 +114,14 @@ void DeRestPluginPrivate::otauDataIndication(const deCONZ::ApsDataIndication &in
{
lightNode->setLastRead(READ_SWBUILD_ID, idleTotalCounter);
lightNode->enableRead(READ_SWBUILD_ID);
lightNode->setNextReadTime(READ_SWBUILD_ID, queryTime.addSecs(120));
lightNode->setNextReadTime(READ_SWBUILD_ID, queryTime.addSecs(160));
storeRecoverOnOffBri(lightNode);
}
}
else if ((ind.clusterId() == OTAU_CLUSTER_ID) && ((zclFrame.commandId() == OTAU_IMAGE_PAGE_REQUEST_CMD_ID) || (zclFrame.commandId() == OTAU_IMAGE_BLOCK_REQUEST_CMD_ID)))
else if (ind.clusterId() == OTAU_CLUSTER_ID && zclFrame.commandId() == OTAU_IMAGE_BLOCK_REQUEST_CMD_ID)
{
// remember last activity time
otauIdleTotalCounter = idleTotalCounter;

LightNode *lightNode = getLightNodeForAddress(ind.srcAddress(), ind.srcEndpoint());
storeRecoverOnOffBri(lightNode);
}

if (!isOtauActive())
Expand All @@ -155,52 +147,6 @@ void DeRestPluginPrivate::otauDataIndication(const deCONZ::ApsDataIndication &in
}
}

/*! Sends otau notifcation (std otau cluster) to \p node.
The node will then send a query next image request.
*/
void DeRestPluginPrivate::otauSendStdNotify(LightNode *node)
{
deCONZ::ApsDataRequest req;
deCONZ::ZclFrame zclFrame;

req.setProfileId(HA_PROFILE_ID);
req.setClusterId(OTAU_CLUSTER_ID);
req.setDstAddressMode(deCONZ::ApsExtAddress);
req.dstAddress().setExt(node->address().ext());
req.setDstEndpoint(node->haEndpoint().endpoint());
req.setSrcEndpoint(endpoint());
req.setState(deCONZ::FireAndForgetState);

zclFrame.setSequenceNumber(zclSeq++);
zclFrame.setCommandId(OTAU_IMAGE_NOTIFY_CMD_ID);

zclFrame.setFrameControl(deCONZ::ZclFCClusterCommand |
deCONZ::ZclFCDirectionServerToClient |
deCONZ::ZclFCDisableDefaultResponse);

{ // payload
QDataStream stream(&zclFrame.payload(), QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::LittleEndian);

uint8_t payloadType = 0x00; // query jitter
uint8_t queryJitter = 100;

stream << payloadType;
stream << queryJitter;
}

{ // ZCL frame
QDataStream stream(&req.asdu(), QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::LittleEndian);
zclFrame.writeToStream(stream);
}

if (apsCtrlWrapper.apsdeDataRequest(req) != deCONZ::Success)
{
DBG_Printf(DBG_INFO, "otau failed to send image notify request\n");
}
}

/*! Returns true if otau is busy with uploading data.
*/
bool DeRestPluginPrivate::isOtauBusy()
Expand Down Expand Up @@ -249,21 +195,11 @@ void DeRestPluginPrivate::otauTimerFired()
return;
}

if (otauNotifyDelay == 0)
{
return;
}

if (!isInNetwork())
{
return;
}

if (nodes.empty())
{
return;
}

if (otauIdleTicks < INT_MAX)
{
otauIdleTicks++;
Expand All @@ -279,67 +215,5 @@ void DeRestPluginPrivate::otauTimerFired()
}
}

if (otauIdleTicks < otauNotifyDelay)
{
return;
}

if (otauNotifyIter >= nodes.size())
{
otauNotifyIter = 0;
}

// dont do anything if sensors are triggering group commands
if ((idleTotalCounter - sensorIndIdleTotalCounter) < (60 * 10))
{
return;
}

LightNode *lightNode = &nodes[otauNotifyIter];
otauNotifyIter++;

if (!lightNode->isAvailable() &&
lightNode->otauClusterId() != OTAU_CLUSTER_ID)
{
return;
}

// filter vendor
if (lightNode->manufacturerCode() != VENDOR_DDEL)
{
return;
}

// whitelist active notify to some devices
if (lightNode->modelId().startsWith("FLS-NB"))
{ }
else if (lightNode->modelId().startsWith("FLS-PP3"))
{ }
else if (lightNode->modelId().startsWith("FLS-A"))
{ }
else
{
return;
}

QDateTime now = QDateTime::currentDateTime();
NodeValue &val = lightNode->getZclValue(OTAU_CLUSTER_ID, OTAU_SWVERSION_ID);

if (val.updateType == NodeValue::UpdateByZclRead)
{
if (val.timestamp.isValid() && val.timestamp.secsTo(now) < OTAU_NOTIFY_INTERVAL)
{
return;
}

if (val.timestampLastReadRequest.isValid() && val.timestampLastReadRequest.secsTo(now) < OTAU_NOTIFY_INTERVAL)
{
return;
}

val.timestampLastReadRequest = now;
}

otauSendStdNotify(lightNode);
otauIdleTicks = 0;
}
26 changes: 17 additions & 9 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,6 @@ DeRestPluginPrivate::DeRestPluginPrivate(QObject *parent) :
idleTotalCounter = IDLE_READ_LIMIT;
idleLastActivity = 0;
idleUpdateZigBeeConf = idleTotalCounter + 15;
sensorIndIdleTotalCounter = 0;
queryTime = QTime::currentTime();
udpSock = 0;
haEndpoint = 0;
Expand Down Expand Up @@ -12323,18 +12322,27 @@ void DeRestPluginPrivate::storeRecoverOnOffBri(LightNode *lightNode)

ResourceItem *onOff = lightNode->item(RStateOn);
ResourceItem *bri = lightNode->item(RStateBri);
std::vector<RecoverOnOff>::iterator i = recoverOnOff.begin();
std::vector<RecoverOnOff>::iterator end = recoverOnOff.end();

if (!onOff || !bri)
{
return;
}

if (!onOff->lastSet().isValid() || !bri->lastSet().isValid())
{
return;
}

auto i = recoverOnOff.begin();
auto end = recoverOnOff.end();

for (; i != end; ++i)
{
if (isSameAddress(i->address, lightNode->address()))
{
// update entry
i->onOff = onOff ? onOff->toBool() : false;
if (bri && bri->lastSet().isValid()) { i->bri = bri->toNumber(); }
else { i->bri = 0; }

i->onOff = onOff->toBool();
i->bri = bri->toNumber();
i->idleTotalCounterCopy = idleTotalCounter;
return;
}
Expand All @@ -12344,8 +12352,8 @@ void DeRestPluginPrivate::storeRecoverOnOffBri(LightNode *lightNode)
DBG_Printf(DBG_INFO, "New recover onOff entry 0x%016llX\n", lightNode->address().ext());
RecoverOnOff rc;
rc.address = lightNode->address();
rc.onOff = onOff ? onOff->toBool() : false;
rc.bri = bri ? bri->toNumber() : 0;
rc.onOff = onOff->toBool();
rc.bri = bri->toNumber();
rc.idleTotalCounterCopy = idleTotalCounter;
recoverOnOff.push_back(rc);
}
Expand Down
5 changes: 0 additions & 5 deletions de_web_plugin_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,6 @@ class DeRestPluginPrivate : public QObject
// Otau
void initOtau();
void otauDataIndication(const deCONZ::ApsDataIndication &ind, const deCONZ::ZclFrame &zclFrame);
void otauSendStdNotify(LightNode *node);
bool isOtauBusy();
bool isOtauActive();
int otauLastBusyTimeDelta() const;
Expand Down Expand Up @@ -1890,8 +1889,6 @@ public Q_SLOTS:
int otauBusyTicks;
int otauIdleTotalCounter;
int otauUnbindIdleTotalCounter;
uint otauNotifyIter; // iterator over nodes
int otauNotifyDelay;

// touchlink

Expand Down Expand Up @@ -2013,8 +2010,6 @@ public Q_SLOTS:
DeviceWidget *deviceWidget = nullptr;
RestDevices *restDevices;

int sensorIndIdleTotalCounter;

class SensorCommand
{
public:
Expand Down
16 changes: 0 additions & 16 deletions rest_gateways.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,22 +459,6 @@ void DeRestPluginPrivate::handleClusterIndicationGateways(const deCONZ::ApsDataI
return;
}

if (zclFrame.isClusterCommand())
{
if (ind.clusterId() == ONOFF_CLUSTER_ID)
{
if (zclFrame.commandId() == 0x00 || zclFrame.commandId() == 0x40 || // Off || Off with effect
zclFrame.commandId() == 0x01 || zclFrame.commandId() == 0x42) // On || On with timed off
{
sensorIndIdleTotalCounter = idleTotalCounter;
}
}
else if (ind.clusterId() == LEVEL_CLUSTER_ID)
{
sensorIndIdleTotalCounter = idleTotalCounter;
}
}

for (size_t i = 0; i < gateways.size(); i++)
{
Gateway *gw = gateways[i];
Expand Down

0 comments on commit a6bf48c

Please sign in to comment.