1
0

before threading

This commit is contained in:
Daniel Tartavel 2023-04-27 12:36:03 +02:00
parent 50621141bf
commit 2b430512e5
11 changed files with 715 additions and 268 deletions

View File

@ -8,19 +8,14 @@ int debugLevel = DEBUG | INFO | WARNING | ERROR;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("zigbeemanager");
QCoreApplication::setApplicationName("zigbeemanager");
initBackends();
zigateBkd.connect(&zigateBkd, SIGNAL(readyRead()), &zigateBkd, SLOT(getData()));
QObject::connect(&zigateBkd, SIGNAL(readyRead()), &zigateBkd, SLOT(getData()));
cout << "sending command 0x0010" << endl;
zigateBkd.sendCmd("0010", "");
zigateBkd.getResponse();
return a.exec();
}

View File

@ -1,7 +1,9 @@
#include "serial.inc.h"
#include <unistd.h>
#include "zigateBackend.h"
extern QApplication a;
extern ZigateBackend zigateBkd;
using namespace std;
ZigbeeMgr::ZigbeeMgr()
@ -13,7 +15,7 @@ ZigbeeMgr::~ZigbeeMgr()
this->close();
}
void ZigbeeMgr::init()
void ZigbeeMgr::initSerial()
{
//QMessageBox::StandardButton reply;
bool test;
@ -37,19 +39,19 @@ void ZigbeeMgr::init()
void ZigbeeMgr::getData()
{
cout << "getData()" << endl;
//if (this->waitForReadyRead(20000))
//{
if (this->waitForReadyRead(20000))
{
while (!atEnd())
{
//cout << "reading datas" << endl;
this->dataRead += this->readAll();
//cout << this->dataRead.toHex().toStdString() << endl;
}
//}else
//{
// cout << "Reading datas has timed out" << endl;
//}
//emit(interpretResult(this->dataRead));
}else
{
cout << "Reading datas has timed out" << endl;
}
zigateBkd.interpretResult(this->dataRead);
}
void ZigbeeMgr::write(QByteArray msg)

View File

@ -29,11 +29,13 @@ class ZigbeeMgr : public QSerialPort
void write(QByteArray datas);
ZigbeeMgr();
~ZigbeeMgr();
void init();
void getData();
void initSerial();
bool findSerialDevice();
signals:
public slots:
void getData();
};

View File

@ -1,6 +0,0 @@
#ifndef VERSION_H
#define VERSION_H
QString version = "0.1";
#endif // VERSION_H

View File

@ -24,7 +24,8 @@ ZigateBackend::ZigateBackend()
sleep(10);
}
}
this->init();
this->initSerial();
qtc
// this->resultCodes.insert(0x8000, "Status");
// resultCodes.insert();
@ -139,11 +140,11 @@ void ZigateBackend::sendCmd(QByteArray cmd, QByteArray datas)
void ZigateBackend::getResponse()
{
this->getData();
//this->getData();
this->interpretResult(this->dataRead);
this->dataRead.clear();
}
int ZigateBackend::interpretResult(QByteArray payload)
{
uint tab = 0;
@ -158,7 +159,6 @@ int ZigateBackend::interpretResult(QByteArray payload)
QByteArray datasResult;
QByteArray quality;
QByteArray payloadD;
uint typeA;
payloadD = unTranscode(payload);
length = payloadD.count();
@ -168,7 +168,7 @@ int ZigateBackend::interpretResult(QByteArray payload)
//type de message
type = payloadD.mid(0, 2);
ln = payloadD.mid(2, 2).toHex().toUInt(nullptr, 16);
if (type[0] == 0x80 or type[0] == 0X00 or type[0] == 0X99)
if (type[0] == 0x80 or type[0] == 0x00 or type[0] == 0x99)
{
crctmp = crctmp ^ payloadD.at(0) ^ payloadD.at(1);
crctmp = crctmp ^ payloadD.at(2) ^ payloadD.at(3);
@ -209,3 +209,236 @@ int ZigateBackend::interpretResult(QByteArray payload)
}
return tab;
}
void defaultManager(Response *responseObject)
{
int nbyte;
int isValue;
int offset = 0;
QByteArray datas = responseObject->datas;
QByteArray result;
QByteArray code = responseObject->code.toHex();
cout << responseObject->code.toStdString() << endl;
QMap <uint, QList<QVariant>>::iterator i = zigateBkd.responseListIndex[code]->properties.begin();
QList <QVariant> propertyList;
QMap <uint, QString> propertyDetail;
QMap<uint,QString> var;
infoOutput(responseObject);
while (i != zigateBkd.responseListIndex[code]->properties.end())
{
propertyList = i.value();
propertyDetail = zigateBkd.responseListIndex[code]->propertyDetail.value(i.key());
cout << propertyList.at(0).toString().toStdString() << ": ";
nbyte = propertyList.at(1).toInt();
isValue = propertyList.at(2).toInt();
result = datas.mid(offset, nbyte);
offset += nbyte;
switch (isValue)
{
case 0:
cout << result.toHex().toStdString() << endl;
break;
case 1:
cout << result.toHex().toStdString() << endl;
//foreach (var, propertyDetail)
//{
//}
break;
case 2:
if (propertyDetail.contains(result.toUInt()))
{
cout << propertyDetail.value(result.toUInt()).toStdString() << endl;
}else if (propertyDetail.contains(-1))
{
cout << propertyDetail.value(-1).toStdString() << endl;
}
break;
case 3:
zigateBkd.responseListIndex[responseObject->code]->propertyManagerList[i.key()](result);
break;
case 4:
cout << "Liste" << endl;
break;
case 5:
cout << result.toStdString() << endl;
break;
}
i++;
}
}
void macCapabilityManager(QByteArray mac)
{
cout << "macCapabilityManger" << mac.toStdString() << endl;
}
/* void deviceAnnounceManager()
{
infoOutput(responseListIndex(""));
}
*/
void dataIndicationManager(Response * response)
{
infoOutput(response);
}
void clustersListManager(Response * response)
{
infoOutput(response);
}
/*
void attributesListManager()
{
infoOutput(attributesList);
}
void commandsListManager()
{
infoOutput(commandsList);
}
void statusManager()
{
infoOutput(status);
}
void status2Manager()
{
}
void versionListManager()
{
infoOutput(versionList);
}
// ****************************************************************************
// 0 - Off
// 1 - On
// *******************************************************************************
void permitJoinManager()
{
infoOutput(permitJoin);
}
void networkJoinedFormedManager()
{
infoOutput(networkJoinedFormed);
}
*/
void deviceListManager(Response * response)
{
infoOutput(response);
// **************************************************************
// <device list data each entry is 13 bytes>
// <ID: uint8_t>
// <Short address: uint16_t>
// <IEEE address: uint64_t>
// <Power source: bool_t> 0 battery 1- AC power
// <LinkQuality : uint8_t> 1-255
// **************************************************************
}
/*
void bindResponseManager()
{
infoOutput(bindResponse);
}
void unbindResponseManager()
{
infoOutput(unbindResponse);
}
*/
void networkAddressManager(Response * response)
{
infoOutput(response);
}
void iEEEAddressManager(Response * response)
{
infoOutput(response);
}
void nodeDescriptorManager(Response * response)
{
infoOutput(response);
}
void simpleDescriptorManager(Response * response)
{
infoOutput(response);
}
/*
void powerDescriptorManager()
{
infoOutput(powerDescriptor);
}
void activeEndpointManager()
{
infoOutput(activeEndpoint);
}
void matchDescriptorManager()
{
infoOutput(matchDescriptor);
}
void userDescriptorNotifyManager()
{
infoOutput(userDescriptorNotify);
}
void userDescriptorManager()
{
infoOutput(userDescriptor);
}
void complexDescriptorManager()
{
infoOutput(complexDescriptor);
}
void managementLeaveManager()
{
infoOutput(managementLeave);
}
void leaveIndicationManager()
{
infoOutput(leaveIndication);
}
void managementNetworkUpdateManager()
{
infoOutput(managementNetworkUpdate);
}
void systemServerDiscoveryManager()
{
infoOutput(systemServerDiscovery);
}
// ********************************* //
// Bitmask according to spec". //
// ********************************* //
void managementLQIManager()
{
infoOutput(managementLQI);
}
void attributeDiscoveryManager()
{
infoOutput(attributeDiscovery);
}
*/

View File

@ -70,6 +70,7 @@
#include <QHash>
#include <QSerialPort>
#include "responseClasses.h"
#include <QtConcurrent/QtConcurrent>
//void deviceAnnounceManager(Response *);
//void commandReturnStatusManager(Response *);
@ -126,6 +127,9 @@ class ZigateBackend : public ZigbeeMgr
bool resetCoordinator();
void interpretResult();
// commands
void getVersion();
QMap <int, QString> resultCodes;
QMap <QString, QList <QByteArray>> cmdList =
{

View File

@ -693,6 +693,7 @@ bool ZigateBackend::initBackend()
temp->manager = &defaultManager;
resetCoordinator();
getVersion();
return returnCode;
}
@ -702,235 +703,3 @@ void infoOutput(Response *object)
}
void defaultManager(Response *responseObject)
{
int nbyte;
int isValue;
int offset = 0;
QByteArray datas = responseObject->datas;
QByteArray result;
QByteArray code = responseObject->code.toHex();
cout << responseObject->code.toStdString() << endl;
QMap <uint, QList<QVariant>>::iterator i = zigateBkd.responseListIndex[code]->properties.begin();
QList <QVariant> propertyList;
QMap <uint, QString> propertyDetail;
QMap<uint,QString> var;
infoOutput(responseObject);
while (i != zigateBkd.responseListIndex[code]->properties.end())
{
propertyList = i.value();
propertyDetail = zigateBkd.responseListIndex[code]->propertyDetail.value(i.key());
cout << propertyList.at(0).toString().toStdString() << ": ";
nbyte = propertyList.at(1).toInt();
isValue = propertyList.at(2).toInt();
result = datas.mid(offset, nbyte);
offset += nbyte;
switch (isValue)
{
case 0:
cout << result.toHex().toStdString() << endl;
break;
case 1:
cout << result.toHex().toStdString() << endl;
//foreach (var, propertyDetail)
//{
//}
break;
case 2:
if (propertyDetail.contains(result.toUInt()))
{
cout << propertyDetail.value(result.toUInt()).toStdString() << endl;
}else if (propertyDetail.contains(-1))
{
cout << propertyDetail.value(-1).toStdString() << endl;
}
break;
case 3:
zigateBkd.responseListIndex[responseObject->code]->propertyManagerList[i.key()](result);
break;
case 4:
cout << "Liste" << endl;
break;
case 5:
cout << result.toStdString() << endl;
break;
}
i++;
}
}
void macCapabilityManager(QByteArray mac)
{
cout << "macCapabilityManger" << mac.toStdString() << endl;
}
/* void deviceAnnounceManager()
{
infoOutput(responseListIndex(""));
}
*/
void dataIndicationManager(Response * response)
{
infoOutput(response);
}
void clustersListManager(Response * response)
{
infoOutput(response);
}
/*
void attributesListManager()
{
infoOutput(attributesList);
}
void commandsListManager()
{
infoOutput(commandsList);
}
void statusManager()
{
infoOutput(status);
}
void status2Manager()
{
}
void versionListManager()
{
infoOutput(versionList);
}
// ****************************************************************************
// 0 - Off
// 1 - On
// *******************************************************************************
void permitJoinManager()
{
infoOutput(permitJoin);
}
void networkJoinedFormedManager()
{
infoOutput(networkJoinedFormed);
}
*/
void deviceListManager(Response * response)
{
infoOutput(response);
// **************************************************************
// <device list data each entry is 13 bytes>
// <ID: uint8_t>
// <Short address: uint16_t>
// <IEEE address: uint64_t>
// <Power source: bool_t> 0 battery 1- AC power
// <LinkQuality : uint8_t> 1-255
// **************************************************************
}
/*
void bindResponseManager()
{
infoOutput(bindResponse);
}
void unbindResponseManager()
{
infoOutput(unbindResponse);
}
*/
void networkAddressManager(Response * response)
{
infoOutput(response);
}
void iEEEAddressManager(Response * response)
{
infoOutput(response);
}
void nodeDescriptorManager(Response * response)
{
infoOutput(response);
}
void simpleDescriptorManager(Response * response)
{
infoOutput(response);
}
/*
void powerDescriptorManager()
{
infoOutput(powerDescriptor);
}
void activeEndpointManager()
{
infoOutput(activeEndpoint);
}
void matchDescriptorManager()
{
infoOutput(matchDescriptor);
}
void userDescriptorNotifyManager()
{
infoOutput(userDescriptorNotify);
}
void userDescriptorManager()
{
infoOutput(userDescriptor);
}
void complexDescriptorManager()
{
infoOutput(complexDescriptor);
}
void managementLeaveManager()
{
infoOutput(managementLeave);
}
void leaveIndicationManager()
{
infoOutput(leaveIndication);
}
void managementNetworkUpdateManager()
{
infoOutput(managementNetworkUpdate);
}
void systemServerDiscoveryManager()
{
infoOutput(systemServerDiscovery);
}
// ********************************* //
// Bitmask according to spec". //
// ********************************* //
void managementLQIManager()
{
infoOutput(managementLQI);
}
void attributeDiscoveryManager()
{
infoOutput(attributeDiscovery);
}
*/

View File

@ -8,12 +8,458 @@ bool ZigateBackend::resetCoordinator()
cout << "Sending reset to coordinator" << endl;
sendCmd("0011", "");
getResponse();
getResponse();
getResponse();
getResponse();
getResponse();
cout << "***************************************************" << endl;
sleep(10);
sleep(5);
return returnCode;
}
void ZigateBackend::getVersion()
{
sendCmd("0010", "");
}
/*
bool ZigateBackend::setHeartBeat()
{
}
bool ZigateBackend::getNetworkState()
{
}
bool ZigateBackend::erasePersistentData()
{
}
bool ZigateBackend::factoryNewReset()
{
}
bool ZigateBackend::permitJoin()
{
}
bool ZigateBackend::setExpendedPANID()
{
}
bool ZigateBackend::setChannelMask()
{
}
bool ZigateBackend::setSecurityStateKey()
{
}
bool ZigateBackend::setDeviceType()
{
}
bool ZigateBackend::startNetwork()
{
}
bool ZigateBackend::startNetworkScan()
{
}
bool ZigateBackend::removeDevice()
{
}
bool ZigateBackend::enablePermissionsControlledJoins()
{
}
bool ZigateBackend::authenticateDevice()
{
}
bool ZigateBackend::outOfBandCommissioningDataRequest()
{
}
bool ZigateBackend::userDescriptorSet()
{
}
bool ZigateBackend::userDescriptorRequest()
{
}
bool ZigateBackend::bind()
{
}
bool ZigateBackend::unbind()
{
}
bool ZigateBackend::complexDescriptorRequest()
{
}
bool ZigateBackend::networkAddressRequest()
{
}
bool ZigateBackend::iEEEAddressRequest()
{
}
bool ZigateBackend::nodeDescriptorRequest()
{
}
bool ZigateBackend::simpleDescriptorRequest()
{
}
bool ZigateBackend::powerDescriptorRequest()
{
}
bool ZigateBackend::activeEndpointRequest()
{
}
bool ZigateBackend::matchDescriptorRequest()
{
}
bool ZigateBackend::managementLeaveRequest()
{
}
bool ZigateBackend::permitJoiningRequest()
{
}
bool ZigateBackend::managementNetworkUpdateRequest()
{
}
bool ZigateBackend::systemServerDiscoveryRequest()
{
}
bool ZigateBackend::managementLQIRequest()
{
}
bool ZigateBackend::addGroup()
{
}
bool ZigateBackend::viewGroup()
{
}
bool ZigateBackend::getGroupMembership()
{
}
bool ZigateBackend::removeGroup()
{
}
bool ZigateBackend::removeAllGroups()
{
}
bool ZigateBackend::addGroupIfIdentify()
{
}
bool ZigateBackend::identifySend()
{
}
bool ZigateBackend::identifyQuery()
{
}
bool ZigateBackend::moveToLevel()
{
}
bool ZigateBackend::moveToLevelWithWithoutOnOoff()
{
}
bool ZigateBackend::moveStep()
{
}
bool ZigateBackend::moveStopMove()
{
}
bool ZigateBackend::moveStopWithOnOff()
{
}
bool ZigateBackend::onOffWithNEffects()
{
}
bool ZigateBackend::onOffWithEffects()
{
}
bool ZigateBackend::onOffTimedSend()
{
}
bool ZigateBackend::onOffTimed()
{
}
bool ZigateBackend::onOffWithEffectsSend()
{
}
bool ZigateBackend::viewScene()
{
}
bool ZigateBackend::addScene()
{
}
bool ZigateBackend::removeScene()
{
}
bool ZigateBackend::removeAllScenes()
{
}
bool ZigateBackend::storeScene()
{
}
bool ZigateBackend::recallScene()
{
}
bool ZigateBackend::sceneMembershipRequest()
{
}
bool ZigateBackend::addEnhancedScene()
{
}
bool ZigateBackend::viewEnhancedHostToNodeScene()
{
}
bool ZigateBackend::copyScene()
{
}
bool ZigateBackend::moveToHue()
{
}
bool ZigateBackend::moveHue()
{
}
bool ZigateBackend::stepHue()
{
}
bool ZigateBackend::moveToSaturation()
{
}
bool ZigateBackend::moveSaturation()
{
}
bool ZigateBackend::stepSaturation()
{
}
bool ZigateBackend::moveToHueAndSaturation()
{
}
bool ZigateBackend::moveToColour()
{
}
bool ZigateBackend::moveColour()
{
}
bool ZigateBackend::stepColour()
{
}
bool ZigateBackend::enhancedMoveToHue()
{
}
bool ZigateBackend::enhancedMoveHue()
{
}
bool ZigateBackend::enhancedStepHue()
{
}
bool ZigateBackend::enhancedMoveToHueAndSaturation()
{
}
bool ZigateBackend::colourLoopSet()
{
}
bool ZigateBackend::stopMoveStep()
{
}
bool ZigateBackend::moveToColourTemperature()
{
}
bool ZigateBackend::moveColourTemperature()
{
}
bool ZigateBackend::stepColourTemperature()
{
}
bool ZigateBackend::initiateTouchlink()
{
}
bool ZigateBackend::touchLinkFactoryResetTarget()
{
}
bool ZigateBackend::identifyTriggerEffect()
{
}
bool ZigateBackend::lockUnlockDoor()
{
}
bool ZigateBackend::readAttributerequest()
{
}
bool ZigateBackend::writeAttributeRequest()
{
}
bool ZigateBackend::configureReportingRequest()
{
}
bool ZigateBackend::attributeDiscoveryRequest()
{
}
bool ZigateBackend::iASZoneEnrollResponse()
{
}
bool ZigateBackend::rawAPSDataRequest()
{
}
*/

View File

@ -1,8 +1,10 @@
QT += core gui
QT += core
QT += serialport
QT += widgets
QT += KConfigCore KConfigGui
QT += KCoreAddons
QT += concurrent
CONFIG += c++17 console
CONFIG -= app_bundle

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 9.0.1, 2023-04-24T00:30:23. -->
<!-- Written by QtCreator 9.0.1, 2023-04-26T22:50:40. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>