2 Commits a297d3b8ce ... 24902ce136

Author SHA1 Message Date
  Per Mårtensson 24902ce136 Airband fix 2 weeks ago
  Per Mårtensson 72fcd00a58 Airband fix 2 weeks ago
2 changed files with 19 additions and 6 deletions
  1. 18 6
      src/rtl_airband.cpp
  2. 1 0
      src/rtl_airband.h

+ 18 - 6
src/rtl_airband.cpp

@@ -30,7 +30,7 @@
 #include "hello_fft/gpu_fft.h"
 #include "hello_fft/mailbox.h"
 #endif /* WITH_BCM_VC */
-//#define GPIOX
+#define GPIOX
 #include <fcntl.h>
 #include <lame/lame.h>
 #include <ogg/ogg.h>
@@ -245,7 +245,7 @@ public:
     void delivery_complete(mqtt::delivery_token_ptr token) override
     {
         token=token;
-        std::cout << "Message delivered" << std::endl;
+        //std::cout << "Message delivered" << std::endl;
     }
     void message_arrived (mqtt::const_message_ptr msg) override
     {
@@ -258,8 +258,8 @@ void* mqtt_control_thread(void*){
 			clientID = bel_mqtt_client_id,
 			username  = bel_mqtt_user_id,
 			password  = bel_mqtt_password;
-    const std::string TOPIC1("device/SE0001/sq");
-    const std::string TOPIC2("device/SE0001/light");
+    const std::string TOPIC1("device/"+username+"/sq");
+    const std::string TOPIC2("device/"+username+"/light");
     const int QOS = 1;
     //const int TIMEOUT = 10000;
     mqtt::async_client client(address, clientID,mqtt::create_options(MQTTVERSION_5));
@@ -290,15 +290,21 @@ void* mqtt_control_thread(void*){
                 //printf("Size %i\n",mqtt_queue.size());
             temp_mess=mqtt_queue.pop();
             Json::Value event;
-            if (temp_mess.bel_status==-1){
+            event["type"]=temp_mess.type;
+            if (temp_mess.type==1){
                 event["sq"]=temp_mess.sq;
                 event["freq"]=temp_mess.freq;
                 event["name"]=temp_mess.name;
+                
                 event["mountpoint"]=temp_mess.mountpoint;
             }
-            if (temp_mess.bel_status!=-1){
+            if (temp_mess.type==2){
                 event["bel_status"]=temp_mess.bel_status;
             }
+            if (temp_mess.type==2){
+                event["type"]=temp_mess.type;
+                event["status"]="connect";
+            }
             Json::StreamWriterBuilder builder;
             if (client.is_connected()){
                 mqtt::message_ptr pubMessage = mqtt::make_message(TOPIC1,Json::writeString(builder, event), QOS, false);
@@ -335,6 +341,7 @@ void* belysning_control_thread(void*){
     mqtt_msg.audio = 0;
     mqtt_msg.mountpoint = str;
     mqtt_msg.bel_status = -1;
+    mqtt_msg.type=2;
     int status_data_temp=0;
     gettimeofday(&tv, 0);
     start_time=tv.tv_sec;
@@ -995,6 +1002,7 @@ void* demodulate(void* params) {
                                 mqtt_msg.name = fparms->label;
                                 mqtt_msg.mountpoint = fparms->mountpoint;
                                 mqtt_msg.bel_status = -1;
+                                mqtt_msg.type=1;
                                 mqtt_queue.push(mqtt_msg);
                             }
                             channel->freqlist[channel->freq_idx].oldstatus = temp_status;
@@ -1479,6 +1487,10 @@ int main(int argc, char* argv[]) {
     THREAD mqtt_control_check;
     pthread_create(&belysning_control_check, NULL, &belysning_control_thread, NULL);
     pthread_create(&mqtt_control_check, NULL, &mqtt_control_thread, NULL);
+
+    mqtt_msg_t mqtt_msg;
+    mqtt_msg.type=3;
+    mqtt_queue.push(mqtt_msg);
     THREAD output_check;
     pthread_create(&output_check, NULL, &output_check_thread, NULL);
 

+ 1 - 0
src/rtl_airband.h

@@ -292,6 +292,7 @@ struct mqtt_msg_t {
     int sq;
     int audio;
     int freq;
+    int type;
     char* name;
     char* mountpoint;
     int bel_status;