Quellcode durchsuchen

1、更新ModuleType定义
2、订阅相关约定更改:订阅更改到表级,后面各个具体使用模块,再进一步过滤;TDengine::msgProcess(TAOS_RES* msg)对字段进行组合
3、增加RedisAgent::hset(QString k, QString f, QString v)

舍得 vor 1 Jahr
Ursprung
Commit
a4b3d28467
4 geänderte Dateien mit 64 neuen und 13 gelöschten Zeilen
  1. 5 0
      RedisAgent/RedisAgent.cpp
  2. 1 0
      RedisAgent/RedisAgent.h
  3. 50 6
      TDAgent/TDengine.cpp
  4. 8 7
      include/Define.h

+ 5 - 0
RedisAgent/RedisAgent.cpp

@@ -74,3 +74,8 @@ QHash<QString, QString> RedisAgent::hgetall(QString k)
 {
     return objRedis.hgetall(k);
 }
+
+bool RedisAgent::hset(QString k, QString f, QString v)
+{
+    return objRedis.hset(k,f,v);
+}

+ 1 - 0
RedisAgent/RedisAgent.h

@@ -35,6 +35,7 @@ public:
     void Publish(std::string,QVariant v);
     QStringList hvals(QString k);
     QHash<QString, QString> hgetall(QString k);
+    bool hset(QString k, QString f, QString v);
 };
 
 //extern "C" {//一定要添加上

+ 50 - 6
TDAgent/TDengine.cpp

@@ -3,12 +3,15 @@
 #include <QtCore/QDebug>
 #include <QtConcurrent/QtConcurrent>
 
+#include <QJsonArray>
+#include <QJsonObject>
+#include <QJsonDocument>
+
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include "taos.h"
 
 
 TAOS* pConn = NULL;
@@ -40,6 +43,47 @@ int32_t TDengine::msgProcess(TAOS_RES* msg)
         //        int32_t     precision = taos_result_precision(msg);
         rows++;
         taos_print_row(buf, row, fields, numOfFields);
+
+        QJsonObject jsonObject;
+        for(int k = 0;k < numOfFields;k++)
+        {
+            QString fieldName = fields[k].name;
+            if(fields[k].type == TSDB_DATA_TYPE_TIMESTAMP)
+            {
+                uint64_t value = *((int64_t *)row[k]);
+                int intvalue = (int)value;
+                jsonObject.insert(fieldName,intvalue);
+            }
+            else if(fields[k].type == TSDB_DATA_TYPE_VARCHAR)
+            {
+                QString value((char *)row[k]);
+                jsonObject.insert(fieldName,value);
+            }
+            else if(fields[k].type == TSDB_DATA_TYPE_DOUBLE)
+            {
+                double value = *(double *)(row[k]);
+                jsonObject.insert(fieldName,value);
+            }
+            else if(fields[k].type == TSDB_DATA_TYPE_FLOAT)
+            {
+                float value = *(float *)(row[k]);
+                jsonObject.insert(fieldName,value);
+            }
+            else if(fields[k].type == TSDB_DATA_TYPE_INT)
+            {
+                int value = *(int *)(row[k]);
+                jsonObject.insert(fieldName,value);
+            }
+            else if(fields[k].type == TSDB_DATA_TYPE_BIGINT)
+            {
+                int64_t value = *(int64_t *)(row[k]);
+                int intvalue = (int)value;
+                jsonObject.insert(fieldName,intvalue);
+            }
+        }
+
+        std::string content = QJsonDocument(jsonObject).toJson(QJsonDocument::Compact).toStdString();
+
         if( g_pSubCB != nullptr )
         {
             std::string topic = topicName;
@@ -102,11 +146,11 @@ tmq_t* TDengine::buildConsumer()
     }
 
     //v3.2以后默认为最新的latest
-//    code = tmq_conf_set(conf, "auto.offset.reset", "latest");
-//    if (TMQ_CONF_OK != code) {
-//        tmq_conf_destroy(conf);
-//        return NULL;
-//    }
+    //    code = tmq_conf_set(conf, "auto.offset.reset", "latest");
+    //    if (TMQ_CONF_OK != code) {
+    //        tmq_conf_destroy(conf);
+    //        return NULL;
+    //    }
 
     //tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); //禁用提交回调
 

+ 8 - 7
include/Define.h

@@ -6,12 +6,12 @@
 
 enum ModuleType
 {
-    Sensor=1,
-    Actor=2,
-    Purifier=3,
-    Calculator=4,
-    Storage=5,
-    Transfer=6,
+    comm=1,
+    purify=2,
+    calculate=3,
+    transfer=4,
+    store=5,
+    control=6,
 };
 
 struct DataItem
@@ -36,7 +36,7 @@ struct Setting
 
 struct ModuleInfo
 {
-    int Id;
+    int Id;                         // 实例编号,不是moduleinfo里的编号,而是intelligentcontrol里的编号
     ModuleType Type;                // 类型
     std::string Name;               // 名称
     std::string Code;               // 标识码
@@ -45,6 +45,7 @@ struct ModuleInfo
     std::string ClassName;          // 组件的 类名
     std::string Description;        // 描述
     std::string Version;            // 版本
+    int serverId;                   // 所属服务器编号
 
     std::list<std::string> lstInputs;// 输入
     std::vector<Setting> vSettings; // 自定义配置