: bharatvaj/forwarder-initiators

commit 5f8b8b727a20febd8572288abe3a6ea0abde1df9
parent eacddda36cc901ea36548b52c6e608b6c80e833c
Author: Bharatvaj H <bharatvajph@gmail.com>
Date: Thu, 28 Mar 2019 18:33:47 +0000

Added traditional style C++ formatting
2 files changed, 47 insertions(+), 38 deletions(-)
M
.gitignore
|
1
+
M
right_initiator.cpp
|
84
+++++++++++++++++++++++++++++++++++++++++++------------------------------------
diff --git a/.gitignore b/.gitignore
@@ -1 +1,2 @@
 build/
+.vscode/
diff --git a/right_initiator.cpp b/right_initiator.cpp
@@ -9,54 +9,62 @@
 
 using namespace std;
 
-bdaddr_t inc = ((bdaddr_t) {{0, 0, 0, 0, 0, 0}});
+bdaddr_t inc = ((bdaddr_t){{0, 0, 0, 0, 0, 0}});
 
-int main(int argc, char *argv[]){
+int main(int argc, char *argv[])
+{
 
-	    struct sockaddr_rc addr = { 0 };
-	    int s, status=0;
-	    char *msg = (char *)calloc(sizeof(char), BUF_SIZE);
-	    char dest[18] = "18:5E:0F:75:DB:8F";
-	    // allocate a socket
-	    s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
-	    cout << s << endl;
+	struct sockaddr_rc addr = {0};
+	int s, status = 0;
+	char *msg = (char *)calloc(sizeof(char), BUF_SIZE);
+	char dest[18] = "18:5E:0F:75:DB:8F";
+	// allocate a socket
+	s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
+	cout << s << endl;
 
-	    // set the connection parameters (who to connect to)
-	    addr.rc_family = AF_BLUETOOTH;
-	    addr.rc_bdaddr = inc;
-	    addr.rc_channel = (uint8_t) 1;
-	    str2ba( dest, &addr.rc_bdaddr );
+	// set the connection parameters (who to connect to)
+	addr.rc_family = AF_BLUETOOTH;
+	addr.rc_bdaddr = inc;
+	addr.rc_channel = (uint8_t)1;
+	str2ba(dest, &addr.rc_bdaddr);
 
-	    // connect to server
-	    status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
+	// connect to server
+	status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
 
-	    // send a message
-	    if( status == 0 ) {
+	// send a message
+	if (status == 0)
+	{
 		int bytesRead = 0;
-		new std::thread([&](){
+		new std::thread([&]() {
 			string str;
 			std::getline(std::cin, str);
 			write(s, str.c_str(), str.size());
 		});
-		while((bytesRead = read(s, msg, BUF_SIZE-1)) > 0){
+		while ((bytesRead = read(s, msg, BUF_SIZE - 1)) > 0)
+		{
 			msg[bytesRead] = '\0';
-			if(strncmp("hello", msg, 5) == 0){
-		system("echo \"475\" > /sys/class/gpio/export");
-		system("echo \"out\" > /sys/class/gpio/gpio475/direction");
-		system(" echo \"1\" > /sys/class/gpio/gpio475/value");
-		printf("light on\n");
-			} else { 
-		system(" echo \"0\" > /sys/class/gpio/gpio475/value");
-		printf("light off\n");
-		}
+			if (strncmp("hello", msg, 5) == 0)
+			{
+				system("echo \"475\" > /sys/class/gpio/export");
+				system("echo \"out\" > /sys/class/gpio/gpio475/direction");
+				system(" echo \"1\" > /sys/class/gpio/gpio475/value");
+				printf("light on\n");
+			}
+			else
+			{
+				system(" echo \"0\" > /sys/class/gpio/gpio475/value");
+				printf("light off\n");
+			}
 			printf("%s", msg);
-		} 
-	    } else {
-		    int se=errno;
-		cout << "Connection failed" <<status<<se<< endl;
-
-	    }
-	    close(s);
-	    while(1);
-	    return 0;
+		}
+	}
+	else
+	{
+		int se = errno;
+		cout << "Connection failed" << status << se << endl;
+	}
+	close(s);
+	while (1)
+		;
+	return 0;
 }