new command codes for power switches
authorChristian Pointner <equinox@realraum.at>
Sat, 6 Mar 2010 12:55:57 +0000 (12:55 +0000)
committerChristian Pointner <equinox@realraum.at>
Sat, 6 Mar 2010 12:55:57 +0000 (12:55 +0000)
added listener messages

powersensordaemon/command_queue.c
powersensordaemon/powersensordaemon.c
rf433ctl/rf433ctl.pde

index 09fea0b..e1dbba2 100644 (file)
@@ -86,7 +86,7 @@ int cmd_has_expired(cmd_t cmd)
   struct timeval now;
   timerclear(&now);
   gettimeofday(&now, NULL);
-  cmd.tv_start.tv_sec++;
+  cmd.tv_start.tv_sec+=2;
 
   return timercmp(&cmd.tv_start, &now, <);
 }
index 85e9433..99dbf74 100644 (file)
@@ -136,6 +136,17 @@ int send_response(int fd, const char* response)
   return ret;
 }
 
+#define SEND_TO_LISTENER(LISTENER_TYPE, TYPE_NAME, FD, STRING)                        \
+      client_t* client;                                                               \
+      int listener_cnt = 0;                                                           \
+      for(client = client_lst; client; client = client->next)                         \
+        if(client->LISTENER_TYPE && client->fd != FD) {                               \
+          send_response(client->fd, STRING);                                          \
+          listener_cnt++;                                                             \
+        }                                                                             \
+      log_printf(DEBUG, "sent %s to %d additional listeners", TYPE_NAME,listener_cnt);
+  
+
 int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst)
 {
   log_printf(DEBUG, "processing command from %d", fd);
@@ -167,15 +178,8 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst)
     if(resp) {
       char* linefeed = strchr(resp, '\n');
       if(linefeed) linefeed[0] = 0;
-      client_t* client;
-      int listener_cnt = 0;
-      for(client = client_lst; client; client = client->next)
-        if(client->request_listener && client->fd != fd) {
-          send_response(client->fd, resp);
-          listener_cnt++;
-        }
+      SEND_TO_LISTENER(request_listener, "request", fd, resp);
       free(resp);
-      log_printf(DEBUG, "sent request to %d additional listeners", listener_cnt);
     }
 // else silently ignore memory alloc error
   }
@@ -305,7 +309,7 @@ int process_tty(read_buffer_t* buffer, int tty_fd, cmd_t **cmd_q, client_t* clie
       if(buffer->offset > 0 && buffer->buf[buffer->offset-1] == '\r')
         buffer->buf[buffer->offset-1] = 0;
 
-      log_printf(NOTICE, "tty-firmware: %s", buffer->buf);      
+      log_printf(NOTICE, "firmware: %s", buffer->buf);      
 
       int cmd_fd = -1;
       if(cmd_q && (*cmd_q)) {
@@ -314,16 +318,21 @@ int process_tty(read_buffer_t* buffer, int tty_fd, cmd_t **cmd_q, client_t* clie
       }
       
       if(!strncmp(buffer->buf, "Error:", 6)) {
-        client_t* client;
-        int listener_cnt = 0;
-        for(client = client_lst; client; client = client->next)
-          if(client->error_listener && client->fd != cmd_fd) {
-            send_response(client->fd, buffer->buf);
-            listener_cnt++;
-          }
-        log_printf(DEBUG, "sent error to %d additional listeners", listener_cnt);
+        SEND_TO_LISTENER(error_listener, "error", cmd_fd, buffer->buf);
       }
       
+      if(!strncmp(buffer->buf, "movement", 8)) {
+        SEND_TO_LISTENER(movement_listener, "movement", cmd_fd, buffer->buf);
+      }
+
+      if(!strncmp(buffer->buf, "PanicButton", 11)) {
+        SEND_TO_LISTENER(button_listener, "panic buttont", cmd_fd, buffer->buf);
+      }
+
+      if(!strncmp(buffer->buf, "Temp ", 5)) {
+        SEND_TO_LISTENER(temp_listener, "", cmd_fd, buffer->buf);
+      }
+
       cmd_pop(cmd_q);
       buffer->offset = 0;
       return 0;
index 6b541e2..9837f3e 100644 (file)
@@ -222,7 +222,7 @@ void setup()
   dallas_sensors.begin();
   //in case we change temp sensor:
   if (!dallas_sensors.getAddress(onShieldTemp, 0)) 
-    Serial.println("Unable to find address for Device 0"); 
+    Serial.println("Error: Unable to find address for Device 0"); 
   dallas_sensors.setResolution(onShieldTemp, 9);
   
   Serial.begin(9600);
@@ -271,40 +271,40 @@ void loop()
   if(Serial.available()) {
     char command = Serial.read();
     
-    if(command == 'q')
+    if(command == 'A')
       send_frame(words[A1_ON]);
     else if(command == 'a')
       send_frame(words[A1_OFF]);
-    else if(command == 'w')
+    else if(command == 'B')
       send_frame(words[A2_ON]);
-    else if(command == 's')
+    else if(command == 'b')
       send_frame(words[A2_OFF]);
 
-    else if(command == 'e')
+    else if(command == 'C')
       send_frame(words[B1_ON]);
-    else if(command == 'd')
+    else if(command == 'c')
       send_frame(words[B1_OFF]);
-    else if(command == 'r')
+    else if(command == 'D')
       send_frame(words[B2_ON]);
-    else if(command == 'f')
+    else if(command == 'd')
       send_frame(words[B2_OFF]);
 
-    else if(command == 't')
+    else if(command == 'E')
       send_frame(words[C1_ON]);
-    else if(command == 'g')
+    else if(command == 'e')
       send_frame(words[C1_OFF]);
-    else if(command == 'z')
+    else if(command == 'F')
       send_frame(words[C2_ON]);
-    else if(command == 'h')
+    else if(command == 'f')
       send_frame(words[C2_OFF]);
 
-    else if(command == 'u')
+    else if(command == 'G')
       send_frame(words[D1_ON]);
-    else if(command == 'j')
+    else if(command == 'g')
       send_frame(words[D1_OFF]);
-    else if(command == 'i')
+    else if(command == 'H')
       send_frame(words[D2_ON]);
-    else if(command == 'k')
+    else if(command == 'h')
       send_frame(words[D2_OFF]);
     else if(command == 'T')
       printTemperature(onShieldTemp);