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);
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
}
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)) {
}
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;
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);
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);