Stats convered to RapidJSON

This commit is contained in:
Justin Hammond 2019-11-11 23:10:28 +08:00
parent d634d95c45
commit 0101ae4547
2 changed files with 61 additions and 64 deletions

View file

@ -495,8 +495,8 @@ NodeStatistics QTOZWManager_Internal::GetNodeStatistics(quint8 const _node) {
ns.lastFailedLinkTo = nd.m_lastFailedLinkTo;
ns.averageRequestRTT = nd.m_averageRequestRTT;
/* 2019-11-06 21:11:02:549 */
ns.lastSentTimeStamp = QDateTime::fromString(nd.m_sentTS.c_str(), "YYYY-MM-DD HH:mm:ss:zzz");
ns.lastReceivedTimeStamp = QDateTime::fromString(nd.m_receivedTS.c_str(), "YYYY-MM-DD HH:mm:ss:zzz");
ns.lastSentTimeStamp = QDateTime::fromString(QString::fromStdString(nd.m_sentTS).trimmed(), "yyyy-MM-dd HH:mm:ss:zzz");
ns.lastReceivedTimeStamp = QDateTime::fromString(QString::fromStdString(nd.m_receivedTS).trimmed(), "yyyy-MM-dd HH:mm:ss:zzz");
ns.averageResponseRTT = nd.m_averageResponseRTT;
ns.lastFailedLinkFrom = nd.m_lastFailedLinkFrom;
ns.receivedDupPackets = nd.m_receivedDups;

View file

@ -327,77 +327,75 @@ void mqttpublisher::brokerError(QMqttClient::ClientError error) {
void mqttpublisher::doStats() {
QJsonObject stats;
if (!this->m_qtozwdeamon) {
return;
}
QTOZWManager *manager = this->m_qtozwdeamon->getManager();
DriverStatistics ds = manager->GetDriverStatistics();
QJsonObject dsjson;
dsjson["SOFCnt"] = static_cast<qint64>(ds.m_SOFCnt);
dsjson["ACKWaiting"] = static_cast<qint64>(ds.m_ACKWaiting);
dsjson["readAborts"] = static_cast<qint64>(ds.m_readAborts);
dsjson["badChecksum"] = static_cast<qint64>(ds.m_badChecksum);
dsjson["readCnt"] = static_cast<qint64>(ds.m_readCnt);
dsjson["writeCnt"] = static_cast<qint64>(ds.m_writeCnt);
dsjson["CANCnt"] = static_cast<qint64>(ds.m_CANCnt);
dsjson["NAKCnt"] = static_cast<qint64>(ds.m_NAKCnt);
dsjson["ACKCnt"] = static_cast<qint64>(ds.m_ACKCnt);
dsjson["OOFCnt"] = static_cast<qint64>(ds.m_OOFCnt);
dsjson["dropped"] = static_cast<qint64>(ds.m_dropped);
dsjson["retries"] = static_cast<qint64>(ds.m_retries);
dsjson["callbacks"] = static_cast<qint64>(ds.m_callbacks);
dsjson["badroutes"] = static_cast<qint64>(ds.m_badroutes);
dsjson["noack"] = static_cast<qint64>(ds.m_noack);
dsjson["netbusy"] = static_cast<qint64>(ds.m_netbusy);
dsjson["notidle"] = static_cast<qint64>(ds.m_notidle);
dsjson["txverified"] = static_cast<qint64>(ds.m_txverified);
dsjson["nondelivery"] = static_cast<qint64>(ds.m_nondelivery);
dsjson["routedbusy"] = static_cast<qint64>(ds.m_routedbusy);
dsjson["broadcastReadCnt"] = static_cast<qint64>(ds.m_broadcastReadCnt);
dsjson["broadcastWriteCnt"] = static_cast<qint64>(ds.m_broadcastWriteCnt);
rapidjson::Document dsjson;
QT2JS::SetInt64(dsjson, "SOFCnt", ds.m_SOFCnt);
QT2JS::SetInt64(dsjson, "ACKWaiting", ds.m_ACKWaiting);
QT2JS::SetInt64(dsjson, "readAborts", ds.m_readAborts);
QT2JS::SetInt64(dsjson, "badChecksum", ds.m_badChecksum);
QT2JS::SetInt64(dsjson, "readCnt", ds.m_readCnt);
QT2JS::SetInt64(dsjson, "writeCnt", ds.m_writeCnt);
QT2JS::SetInt64(dsjson, "CANCnt", ds.m_CANCnt);
QT2JS::SetInt64(dsjson, "NAKCnt", ds.m_NAKCnt);
QT2JS::SetInt64(dsjson, "ACKCnt", ds.m_ACKCnt);
QT2JS::SetInt64(dsjson, "OOFCnt", ds.m_OOFCnt);
QT2JS::SetInt64(dsjson, "dropped", ds.m_dropped);
QT2JS::SetInt64(dsjson, "retries", ds.m_retries);
QT2JS::SetInt64(dsjson, "callbacks", ds.m_callbacks);
QT2JS::SetInt64(dsjson, "badroutes", ds.m_badroutes);
QT2JS::SetInt64(dsjson, "noack", ds.m_noack);
QT2JS::SetInt64(dsjson, "netbusy", ds.m_netbusy);
QT2JS::SetInt64(dsjson, "notidle", ds.m_notidle);
QT2JS::SetInt64(dsjson, "txverified", ds.m_txverified);
QT2JS::SetInt64(dsjson, "nondelivery", ds.m_nondelivery);
QT2JS::SetInt64(dsjson, "routedbusy", ds.m_routedbusy);
QT2JS::SetInt64(dsjson, "broadcastReadCnt", ds.m_broadcastReadCnt);
QT2JS::SetInt64(dsjson, "broadcastWriteCnt", ds.m_broadcastWriteCnt);
stats["Network"] = dsjson;
this->m_client->publish(QMqttTopicName(getTopic(MQTT_OZW_STATS_TOPIC)), QJsonDocument(stats).toJson(), 0, false);
this->m_client->publish(QMqttTopicName(getTopic(MQTT_OZW_STATS_TOPIC)), QT2JS::getJSON(dsjson), 0, false);
for (int i = 0; i < this->m_nodeModel->rowCount(QModelIndex()); i++) {
QJsonObject nsjson;
rapidjson::Document nsjson;
int NodeID = this->m_nodeModel->data(this->m_nodeModel->index(i, mqttNodeModel::NodeColumns::NodeID), Qt::DisplayRole).toInt();
NodeStatistics ns = manager->GetNodeStatistics(NodeID);
nsjson["sendCount"] = static_cast<qint64>(ns.sentCount); /**< Number of Packets Sent to the Node */
nsjson["sentFailed"] = static_cast<qint64>(ns.sentFailed); /**< Number of Packets that Failed to be acknowledged by the Node or Controller */
nsjson["retries"] = static_cast<qint64>(ns.retries); /**< Number of times we have had to Retry sending packets to the Node */
nsjson["receivedPackets"] = static_cast<qint64>(ns.receivedPackets); /**< Number of received Packets from the Node */
nsjson["receivedDupPackets"] = static_cast<qint64>(ns.receivedDupPackets); /**< Number of Duplicate Packets received from the Node */
nsjson["receivedUnsolicited"] = static_cast<qint64>(ns.receivedUnsolicited); /**< Number of Unsolicited Packets received from the Node */
nsjson["lastSentTimeStamp"] = ns.lastSentTimeStamp.toSecsSinceEpoch(); /**< TimeStamp of the Last time we sent a packet to the Node */
nsjson["lastRecievedTimeStamp"] = ns.lastReceivedTimeStamp.toSecsSinceEpoch(); /**< Timestamp of the last time we received a packet from the Node */
nsjson["lastRequestRTT"] = static_cast<qint64>(ns.lastRequestRTT); /**< Last Round-Trip Time when we made a request to the Node */
nsjson["averageRequestRTT"] = static_cast<qint64>(ns.averageRequestRTT); /**< Average Round-Trip Time when we make requests to a Node */
nsjson["lastResponseRTT"] = static_cast<qint64>(ns.lastResponseRTT); /**< Last Round-Trip Time when we got a Response from a Node */
nsjson["averageResponseRTT"] = static_cast<qint64>(ns.averageResponseRTT); /**< Average Round-Trip Time when got a Response from a Node */
nsjson["quality"] = ns.quality; /**< The Quality of the Signal from the Node, as Reported by the Controller */
nsjson["extendedTXSupported"] = ns.extendedTXSupported; /**< If these statistics support Extended TX Reporting (Controller Dependent) */
nsjson["txTime"] = ns.txTime; /**< The Time it took to Transmit the last packet to the Node */
nsjson["hops"] = ns.hops; /**< The Number of hops the packet traversed to reach the node */
nsjson["rssi_1"] = ns.rssi_1; /**< The RSSI Strength of the first hop */
nsjson["rssi_2"] = ns.rssi_2; /**< The RSSI Strength of the second hop */
nsjson["rssi_3"] = ns.rssi_3; /**< The RSSI Strength of the third hop */
nsjson["rssi_4"] = ns.rssi_4; /**< The RSSI Strength of the fourth hop */
nsjson["rssi_5"] = ns.rssi_5; /**< The RSSI Strength of the final hop */
nsjson["route_1"] = ns.route_1; /**< The NodeId of the First Hop */
nsjson["route_2"] = ns.route_2; /**< The NodeId of the Second Hop */
nsjson["route_3"] = ns.route_3; /**< The NodeId of the third Hop */
nsjson["route_4"] = ns.route_4; /**< The NodeId of the Fourth Hop */
nsjson["ackChannel"] = ns.ackChannel; /**< The Channel that recieved the ACK From the Node */
nsjson["lastTXChannel"] = ns.lastTXChannel; /**< The last Channel we used to communicate with the Node */
nsjson["routeScheme"] = ns.routeScheme; /**< How the Route was calculated when we last communicated with the Node */
nsjson["routeUsed"] = ns.routeUsed; /**< The Route last used to communicate with the Node */
nsjson["routeSpeed"] = ns.routeSpeed; /**< The Speed that was used when we last communicated with the node */
nsjson["routeTries"] = ns.routeTries; /**< The Number of attempts the Controller made to route the packet to the Node */
nsjson["lastFailedLinkFrom"] = ns.lastFailedLinkFrom; /**< The Last Failed Link From */
nsjson["lastFailedLinkTo"] = ns.lastFailedLinkTo; /**< The Last Failed Link To */
this->m_client->publish(QMqttTopicName(getNodeTopic(MQTT_OZW_STATS_NODE_TOPIC, NodeID)), QJsonDocument(nsjson).toJson(), 0, false);
QT2JS::SetInt64(nsjson, "sendCount", ns.sentCount); /**< Number of Packets Sent to the Node */
QT2JS::SetInt64(nsjson, "sentFailed", ns.sentFailed); /**< Number of Packets that Failed to be acknowledged by the Node or Controller */
QT2JS::SetInt64(nsjson, "retries", ns.retries); /**< Number of times we have had to Retry sending packets to the Node */
QT2JS::SetInt64(nsjson, "receivedPackets", ns.receivedPackets); /**< Number of received Packets from the Node */
QT2JS::SetInt64(nsjson, "receivedDupPackets", ns.receivedDupPackets); /**< Number of Duplicate Packets received from the Node */
QT2JS::SetInt64(nsjson, "receivedUnsolicited", ns.receivedUnsolicited); /**< Number of Unsolicited Packets received from the Node */
QT2JS::SetInt64(nsjson, "lastSentTimeStamp", ns.lastSentTimeStamp.toSecsSinceEpoch()); /**< TimeStamp of the Last time we sent a packet to the Node */
QT2JS::SetInt64(nsjson, "lastReceivedTimeStamp", ns.lastReceivedTimeStamp.toSecsSinceEpoch()); /**< Timestamp of the last time we received a packet from the Node */
QT2JS::SetInt64(nsjson, "lastRequestRTT", ns.lastRequestRTT); /**< Last Round-Trip Time when we made a request to the Node */
QT2JS::SetInt64(nsjson, "averageRequestRTT", ns.averageRequestRTT); /**< Average Round-Trip Time when we make requests to a Node */
QT2JS::SetInt64(nsjson, "lastResponseRTT", ns.lastResponseRTT); /**< Last Round-Trip Time when we got a Response from a Node */
QT2JS::SetInt64(nsjson, "averageResponseRTT", ns.averageResponseRTT); /**< Average Round-Trip Time when got a Response from a Node */
QT2JS::SetInt(nsjson, "quality", ns.quality); /**< The Quality of the Signal from the Node, as Reported by the Controller */
QT2JS::SetBool(nsjson, "extendedTXSupported", ns.extendedTXSupported); /**< If these statistics support Extended TX Reporting (Controller Dependent) */
QT2JS::SetInt(nsjson, "txTime", ns.txTime); /**< The Time it took to Transmit the last packet to the Node */
QT2JS::SetInt(nsjson, "hops", ns.hops); /**< The Number of hops the packet traversed to reach the node */
QT2JS::SetString(nsjson, "rssi_1", ns.rssi_1); /**< The RSSI Strength of the first hop */
QT2JS::SetString(nsjson, "rssi_2", ns.rssi_2); /**< The RSSI Strength of the second hop */
QT2JS::SetString(nsjson, "rssi_3", ns.rssi_3); /**< The RSSI Strength of the third hop */
QT2JS::SetString(nsjson, "rssi_4", ns.rssi_4); /**< The RSSI Strength of the fourth hop */
QT2JS::SetString(nsjson, "rssi_5", ns.rssi_5); /**< The RSSI Strength of the final hop */
QT2JS::SetInt(nsjson, "route_1", ns.route_1); /**< The NodeId of the First Hop */
QT2JS::SetInt(nsjson, "route_2", ns.route_2); /**< The NodeId of the Second Hop */
QT2JS::SetInt(nsjson, "route_3", ns.route_3); /**< The NodeId of the third Hop */
QT2JS::SetInt(nsjson, "route_4", ns.route_4); /**< The NodeId of the Fourth Hop */
QT2JS::SetInt(nsjson, "ackChannel", ns.ackChannel); /**< The Channel that recieved the ACK From the Node */
QT2JS::SetInt(nsjson, "lastTXChannel", ns.lastTXChannel); /**< The last Channel we used to communicate with the Node */
QT2JS::SetString(nsjson, "routeScheme", ns.routeScheme); /**< How the Route was calculated when we last communicated with the Node */
QT2JS::SetString(nsjson, "routeUsed", ns.routeUsed); /**< The Route last used to communicate with the Node */
QT2JS::SetString(nsjson, "routeSpeed", ns.routeSpeed); /**< The Speed that was used when we last communicated with the node */
QT2JS::SetInt(nsjson, "routeTries", ns.routeTries); /**< The Number of attempts the Controller made to route the packet to the Node */
QT2JS::SetInt(nsjson, "lastFailedLinkFrom", ns.lastFailedLinkFrom); /**< The Last Failed Link From */
QT2JS::SetInt(nsjson, "lastFailedLinkTo", ns.lastFailedLinkTo); /**< The Last Failed Link To */
this->m_client->publish(QMqttTopicName(getNodeTopic(MQTT_OZW_STATS_NODE_TOPIC, NodeID)), QT2JS::getJSON(nsjson), 0, false);
}
}
@ -528,7 +526,6 @@ bool mqttpublisher::sendStatusUpdate() {
bool mqttpublisher::sendNodeUpdate(quint8 node) {
QT2JS::SetUInt64(*this->m_nodes[node], "TimeStamp", QDateTime::currentSecsSinceEpoch());
this->m_client->publish(QMqttTopicName(getNodeTopic(MQTT_OZW_NODE_TOPIC, node)), QT2JS::getJSON(*this->m_nodes[node]), 0, true);
qDebug() << QT2JS::getJSON(*this->m_nodes[node]);
return true;
}