-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
53 lines (46 loc) · 1.08 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
This code primarily comes from
http://www.prasannatech.net/2008/07/socket-programming-tutorial.html
and
http://www.binarii.com/files/papers/c_sockets.txt
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "listen-to-pebble.h"
#include "listen-to-arduino.h"
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
float average = 0;
float min, max, latest;
int arduino;
int sock;
int received;
int connection;
int alarm_status = 'd';
int error() {
return -1;
}
int main(int argc, char *argv[])
{
// check the number of arguments
if (argc < 2) {
printf("\nUsage: %s [port_number] \n", argv[0]);
exit(-1);
}
int port_number = atoi(argv[1]);
if (port_number <= 1024) {
printf("\nPlease specify a port number greater than 1024\n");
exit(-1);
}
puts("Enter 'q' at any time to quit.");
pthread_t t1, t2;
if (pthread_create(&t1, NULL, listen_to_arduino, argv) != 0) {
return error();
}
if (pthread_create(&t2, NULL, listen_to_pebble, argv) != 0) {
return error();
}
if (pthread_join(t2, NULL) != 0) {
return error();
}
}