Implement up to start network for nxp
parent
974911db06
commit
f900420470
|
|
@ -45,6 +45,13 @@ public:
|
|||
LogLevelDebug = 0x07
|
||||
};
|
||||
Q_ENUM(LogLevel)
|
||||
|
||||
|
||||
enum KeyType {
|
||||
KeyTypeGlobalLinkKey = 0x00,
|
||||
KeyTypeUniqueLinkKey = 0x01
|
||||
};
|
||||
Q_ENUM(KeyType)
|
||||
};
|
||||
|
||||
#endif // NXP_H
|
||||
|
|
|
|||
|
|
@ -102,6 +102,37 @@ ZigbeeInterfaceNxpReply *ZigbeeBridgeControllerNxp::requestSetChannelMask(quint3
|
|||
return createReply(Nxp::CommandSetChannelMask, m_sequenceNumber, "Request set channel mask", message, this);
|
||||
}
|
||||
|
||||
ZigbeeInterfaceNxpReply *ZigbeeBridgeControllerNxp::requestSetSecurityKey(Nxp::KeyType keyType, const ZigbeeNetworkKey &key)
|
||||
{
|
||||
QByteArray message;
|
||||
bumpSequenceNumber();
|
||||
QDataStream stream(&message, QIODevice::WriteOnly);
|
||||
stream.setByteOrder(QDataStream::LittleEndian);
|
||||
stream << static_cast<quint8>(Nxp::CommandSetSecurityKey);
|
||||
stream << static_cast<quint8>(m_sequenceNumber);
|
||||
stream << static_cast<quint16>(17); // Frame length
|
||||
stream << static_cast<quint8>(keyType);
|
||||
QByteArray keyData = key.toByteArray();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
stream << static_cast<quint8>(keyData.at(i));
|
||||
}
|
||||
|
||||
return createReply(Nxp::CommandSetSecurityKey, m_sequenceNumber, "Request set security key", message, this);
|
||||
}
|
||||
|
||||
ZigbeeInterfaceNxpReply *ZigbeeBridgeControllerNxp::requestStartNetwork()
|
||||
{
|
||||
QByteArray message;
|
||||
bumpSequenceNumber();
|
||||
QDataStream stream(&message, QIODevice::WriteOnly);
|
||||
stream.setByteOrder(QDataStream::LittleEndian);
|
||||
stream << static_cast<quint8>(Nxp::CommandStartNetwork);
|
||||
stream << static_cast<quint8>(m_sequenceNumber);
|
||||
stream << static_cast<quint16>(0); // Frame length
|
||||
|
||||
return createReply(Nxp::CommandStartNetwork, m_sequenceNumber, "Request start network", message, this);
|
||||
}
|
||||
|
||||
ZigbeeInterfaceNxpReply *ZigbeeBridgeControllerNxp::createReply(Nxp::Command command, quint8 sequenceNumber, const QString &requestName, const QByteArray &requestData, QObject *parent)
|
||||
{
|
||||
// Create the reply
|
||||
|
|
|
|||
|
|
@ -40,8 +40,14 @@ public:
|
|||
ZigbeeInterfaceNxpReply *requestControllerState();
|
||||
ZigbeeInterfaceNxpReply *requestSoftResetController();
|
||||
ZigbeeInterfaceNxpReply *requestFactoryResetController();
|
||||
|
||||
// Configure network
|
||||
ZigbeeInterfaceNxpReply *requestSetPanId(quint64 panId);
|
||||
ZigbeeInterfaceNxpReply *requestSetChannelMask(quint32 channelMask);
|
||||
ZigbeeInterfaceNxpReply *requestSetSecurityKey(Nxp::KeyType keyType, const ZigbeeNetworkKey &key);
|
||||
|
||||
ZigbeeInterfaceNxpReply *requestStartNetwork();
|
||||
|
||||
|
||||
signals:
|
||||
void controllerStateChanged(ControllerState controllerState);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ void ZigbeeNetworkNxp::onControllerAvailableChanged(bool available)
|
|||
qCDebug(dcZigbeeNetwork()) << "Controller is" << (available ? "now available" : "not available any more");
|
||||
|
||||
if (available) {
|
||||
reset();
|
||||
//reset();
|
||||
factoryResetNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +78,8 @@ void ZigbeeNetworkNxp::onControllerStateChanged(ZigbeeBridgeControllerNxp::Contr
|
|||
ZigbeeInterfaceNxpReply *reply = m_controller->requestVersion();
|
||||
connect(reply, &ZigbeeInterfaceNxpReply::finished, this, [this, reply](){
|
||||
qCDebug(dcZigbeeNetwork()) << "Version reply finished" << reply->status();
|
||||
//FIXME: error handling
|
||||
|
||||
QByteArray payload = reply->responseData();
|
||||
QDataStream stream(&payload, QIODevice::ReadOnly);
|
||||
stream.setByteOrder(QDataStream::LittleEndian);
|
||||
|
|
@ -91,12 +94,37 @@ void ZigbeeNetworkNxp::onControllerStateChanged(ZigbeeBridgeControllerNxp::Contr
|
|||
ZigbeeInterfaceNxpReply *reply = m_controller->requestSetPanId(extendedPanId());
|
||||
connect(reply, &ZigbeeInterfaceNxpReply::finished, this, [this, reply](){
|
||||
qCDebug(dcZigbeeNetwork()) << "Set PAN ID reply finished" << reply->status();
|
||||
//FIXME: error handling
|
||||
|
||||
qCDebug(dcZigbeeNetwork()) << "Set channel mask" << channelMask() << ZigbeeUtils::convertUint32ToHexString(channelMask().toUInt32()) << channelMask().toUInt32();
|
||||
ZigbeeInterfaceNxpReply *reply = m_controller->requestSetChannelMask(channelMask().toUInt32());
|
||||
connect(reply, &ZigbeeInterfaceNxpReply::finished, this, [reply](){
|
||||
connect(reply, &ZigbeeInterfaceNxpReply::finished, this, [this, reply](){
|
||||
qCDebug(dcZigbeeNetwork()) << "Set channel mask reply finished" << reply->status();
|
||||
//FIXME: error handling
|
||||
|
||||
qCDebug(dcZigbeeNetwork()) << "Set global link key" << securityConfiguration().globalTrustCenterLinkKey().toString();
|
||||
ZigbeeInterfaceNxpReply *reply = m_controller->requestSetSecurityKey(Nxp::KeyTypeGlobalLinkKey, securityConfiguration().globalTrustCenterLinkKey());
|
||||
connect(reply, &ZigbeeInterfaceNxpReply::finished, this, [this, reply](){
|
||||
qCDebug(dcZigbeeNetwork()) << "Set global link key" << reply->status();
|
||||
//FIXME: error handling
|
||||
|
||||
qCDebug(dcZigbeeNetwork()) << "Set network link key" << securityConfiguration().networkKey().toString();
|
||||
ZigbeeInterfaceNxpReply *reply = m_controller->requestSetSecurityKey(Nxp::KeyTypeUniqueLinkKey, securityConfiguration().networkKey());
|
||||
connect(reply, &ZigbeeInterfaceNxpReply::finished, this, [this, reply](){
|
||||
qCDebug(dcZigbeeNetwork()) << "Set network link key" << reply->status();
|
||||
//FIXME: error handling
|
||||
|
||||
qCDebug(dcZigbeeNetwork()) << "Start the network";
|
||||
ZigbeeInterfaceNxpReply *reply = m_controller->requestStartNetwork();
|
||||
connect(reply, &ZigbeeInterfaceNxpReply::finished, this, [this, reply](){
|
||||
qCDebug(dcZigbeeNetwork()) << "Start network" << reply->status();
|
||||
//FIXME: error handling
|
||||
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
#include "zigbeenetworkkey.h"
|
||||
#include "zigbeenetworkmanager.h"
|
||||
|
||||
//static QHash<QString, bool> s_loggingFilters;
|
||||
|
|
@ -138,14 +139,21 @@ int main(int argc, char *argv[])
|
|||
debugLevel = 1;
|
||||
}
|
||||
|
||||
// s_loggingFilters.insert("Application", true);
|
||||
// s_loggingFilters.insert("Zigbee", true);
|
||||
// s_loggingFilters.insert("ZigbeeController", (debugLevel > 1));
|
||||
// s_loggingFilters.insert("ZigbeeInterface", (debugLevel > 2));
|
||||
// s_loggingFilters.insert("ZigbeeInterfaceTraffic", (debugLevel > 3));
|
||||
// s_loggingFilters.insert("Application", true);
|
||||
// s_loggingFilters.insert("Zigbee", true);
|
||||
// s_loggingFilters.insert("ZigbeeController", (debugLevel > 1));
|
||||
// s_loggingFilters.insert("ZigbeeInterface", (debugLevel > 2));
|
||||
// s_loggingFilters.insert("ZigbeeInterfaceTraffic", (debugLevel > 3));
|
||||
|
||||
//QLoggingCategory::installFilter(loggingCategoryFilter);
|
||||
|
||||
QLoggingCategory::setFilterRules("*.debug=false\n"
|
||||
"Zigbee.debug=true\n"
|
||||
"ZigbeeController.debug=true\n"
|
||||
"ZigbeeInterface.debug=false\n"
|
||||
"ZigbeeInterfaceTraffic.debug=false\n"
|
||||
);
|
||||
|
||||
// Check channel
|
||||
bool channelValueOk = false;
|
||||
int channel = parser.value(channelOption).toInt(&channelValueOk);
|
||||
|
|
@ -172,9 +180,12 @@ int main(int argc, char *argv[])
|
|||
ZigbeeChannelMask mask;
|
||||
mask.setChannel(Zigbee::ZigbeeChannel13);
|
||||
network->setChannelMask(mask);
|
||||
network->startNetwork();
|
||||
|
||||
//Core core(parser.value(serialOption), baudrate, channel);
|
||||
ZigbeeSecurityConfiguration securityConfiguration;
|
||||
securityConfiguration.setNetworkKey(ZigbeeNetworkKey(QString("2a:59:f4:11:75:bb:64:48:55:c5:23:62:b0:33:ea:33")));
|
||||
network->setSecurityConfiguration(securityConfiguration);
|
||||
|
||||
network->startNetwork();
|
||||
|
||||
return application.exec();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue