diff --git a/Development/Software/Client API/Client API.vcxproj b/Development/Software/Client API/Client API.vcxproj index 62853c1d179708c20a91dce0db314d17f56c11bd..b65fdf6cf024e3d79c86d5dc7c3f898637851c4b 100644 --- a/Development/Software/Client API/Client API.vcxproj +++ b/Development/Software/Client API/Client API.vcxproj @@ -11,6 +11,7 @@ </ProjectConfiguration> </ItemGroup> <ItemGroup> + <ClCompile Include="..\Communications\Bluetooth.cpp" /> <ClCompile Include="Communications.cpp" /> </ItemGroup> <ItemGroup> diff --git a/Development/Software/Client API/Client API.vcxproj.filters b/Development/Software/Client API/Client API.vcxproj.filters index 2b71db93ad48186336956683edc94be662a9fe2e..3c5672722d706358ef402b2a4ef98de0fa4742b5 100644 --- a/Development/Software/Client API/Client API.vcxproj.filters +++ b/Development/Software/Client API/Client API.vcxproj.filters @@ -18,6 +18,9 @@ <ClCompile Include="Communications.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\Communications\Bluetooth.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <Text Include="README.txt"> diff --git a/Development/Software/Communications/Communications.vcxproj b/Development/Software/Communications/Communications.vcxproj index 2516a0cfbe5221cd78b590cc511e026ced0bea7f..1331ec8e2a56890943d137d142e2bd507bf74c99 100644 --- a/Development/Software/Communications/Communications.vcxproj +++ b/Development/Software/Communications/Communications.vcxproj @@ -64,7 +64,6 @@ </Link> </ItemDefinitionGroup> <ItemGroup> - <ClCompile Include="Bluetooth.cpp" /> <ClCompile Include="Communications.cpp" /> </ItemGroup> <ItemGroup> diff --git a/Development/Software/Communications/Communications.vcxproj.filters b/Development/Software/Communications/Communications.vcxproj.filters index abb71d536fc3ca44b9c03cb5e3c889c885424077..f55fb2cb6bb0aa36142d0710ccf5cf99929dca95 100644 --- a/Development/Software/Communications/Communications.vcxproj.filters +++ b/Development/Software/Communications/Communications.vcxproj.filters @@ -15,9 +15,6 @@ </Filter> </ItemGroup> <ItemGroup> - <ClCompile Include="Bluetooth.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="Communications.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/Development/Software/Controller API/Bluetooth.cpp b/Development/Software/Controller API/Bluetooth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..404c86585c56e474ec24e4879fd113fc103ff6d1 --- /dev/null +++ b/Development/Software/Controller API/Bluetooth.cpp @@ -0,0 +1,11 @@ +#include "Bluetooth.h" + + +Bluetooth::Bluetooth() +{ +} + + +Bluetooth::~Bluetooth() +{ +} diff --git a/Development/Software/Controller API/Bluetooth.h b/Development/Software/Controller API/Bluetooth.h new file mode 100644 index 0000000000000000000000000000000000000000..90e9e7918440a167b61333abf173300f46e80380 --- /dev/null +++ b/Development/Software/Controller API/Bluetooth.h @@ -0,0 +1,10 @@ +#pragma once +class Bluetooth +{ +public: + Bluetooth(); + ~Bluetooth(); + + +}; + diff --git a/Development/Software/Controller API/Client.cpp b/Development/Software/Controller API/Client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12f043f6556fbf5a198a547a214eef3ca282b374 --- /dev/null +++ b/Development/Software/Controller API/Client.cpp @@ -0,0 +1,41 @@ +#include "Client.h" + +bool Client::cInit(string destination) +{ + if (destination.length == 18) + { + // set the connection parameters (who to connect to) + addr.rc_family = AF_BLUETOOTH; + addr.rc_channel = (uint8_t)1; + str2ba(dest, &addr.rc_bdaddr); + + return true; + } + + return false; +} + +void Client::cConnect() +{ + // allocate a socket + s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + + // connect to server + status = connect(s, (sockaddr *)&addr, sizeof(addr)); +} + +bool Client::cCheckStatus() +{ + if (status < 0) return false; + return true; +} + +void Client::cSendMessage(string message) +{ + status = write(s, message.c_str(), message.length); +} + +void Client::cDisconnect() +{ + close(s); +} \ No newline at end of file diff --git a/Development/Software/Controller API/Client.h b/Development/Software/Controller API/Client.h new file mode 100644 index 0000000000000000000000000000000000000000..2563b45985a34413f4065eea97e7b06fcdf6f1eb --- /dev/null +++ b/Development/Software/Controller API/Client.h @@ -0,0 +1,28 @@ +#pragma once + +#include <iostream> +#include <stdio.h> +#include <unistd.h> +#include <sys/socket.h> +#include <bluetooth/bluetooth.h> +#include <bluetooth/rfcomm.h> + +using namespace std; + +namespace Client +{ + sockaddr_rc addr; + int s, status; + string dest; + + bool cInit(string destination); + + void cConnect(); + + bool cCheckStatus(); + + void cSendMessage(string message); + + void cDisconnect(); +}; + diff --git a/Development/Software/Controller API/Controller API.vcxproj b/Development/Software/Controller API/Controller API.vcxproj index ffb48f61dc915f8fa3ba5d87aee4cfa0505e77fa..07f1ac6bc5514a689f8d039976fb31be2ab96299 100644 --- a/Development/Software/Controller API/Controller API.vcxproj +++ b/Development/Software/Controller API/Controller API.vcxproj @@ -11,12 +11,19 @@ </ProjectConfiguration> </ItemGroup> <ItemGroup> + <ClCompile Include="Bluetooth.cpp" /> + <ClCompile Include="Client.cpp" /> <ClCompile Include="Communications.cpp" /> <ClCompile Include="Sensors.cpp" /> + <ClCompile Include="Server.cpp" /> + <ClCompile Include="Source.cpp" /> </ItemGroup> <ItemGroup> + <ClInclude Include="Bluetooth.h" /> + <ClInclude Include="Client.h" /> <ClInclude Include="Communications.h" /> <ClInclude Include="Sensors.h" /> + <ClInclude Include="Server.h" /> </ItemGroup> <ItemGroup> <Text Include="Makefile.txt" /> diff --git a/Development/Software/Controller API/Controller API.vcxproj.filters b/Development/Software/Controller API/Controller API.vcxproj.filters index d05d8f2879efb75f31a33af5955f0044b341f4d8..31605d5cc1dc7fa73051cbc421a2baedf99da25d 100644 --- a/Development/Software/Controller API/Controller API.vcxproj.filters +++ b/Development/Software/Controller API/Controller API.vcxproj.filters @@ -21,6 +21,18 @@ <ClCompile Include="Sensors.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="Bluetooth.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Server.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Client.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Source.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="Communications.h"> @@ -29,6 +41,15 @@ <ClInclude Include="Sensors.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="Bluetooth.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Server.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Client.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Text Include="Makefile.txt"> diff --git a/Development/Software/Controller API/Server.cpp b/Development/Software/Controller API/Server.cpp new file mode 100644 index 0000000000000000000000000000000000000000..84e3847216b0205bc1586595b9f71425c1c29142 --- /dev/null +++ b/Development/Software/Controller API/Server.cpp @@ -0,0 +1,46 @@ +#include "Server.h" + +#include <stdio.h> +#include <unistd.h> +#include <sys/socket.h> +#include <bluetooth/bluetooth.h> +#include <bluetooth/rfcomm.h> + +void Server::launch() +{ + struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 }; + char buf[1024] = { 0 }; + int s, client, bytes_read; + socklen_t opt = sizeof(rem_addr); + + // allocate socket + s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + + // bind socket to port 1 of the first available + // local bluetooth adapter + loc_addr.rc_family = AF_BLUETOOTH; + loc_addr.rc_bdaddr = *BDADDR_ANY; + loc_addr.rc_channel = (uint8_t)1; + bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr)); + + // put socket into listening mode + listen(s, 1); + + // accept one connection + client = accept(s, (struct sockaddr *)&rem_addr, &opt); + + ba2str(&rem_addr.rc_bdaddr, buf); + fprintf(stderr, "accepted connection from %s\n", buf); + memset(buf, 0, sizeof(buf)); + + // read data from the client + bytes_read = read(client, buf, sizeof(buf)); + if (bytes_read > 0) { + printf("received [%s]\n", buf); + } + + // close connection + close(client); + close(s); + return 0; +} diff --git a/Development/Software/Controller API/Server.h b/Development/Software/Controller API/Server.h new file mode 100644 index 0000000000000000000000000000000000000000..6c0f46489e973197f3ce65de35da585133e5ec18 --- /dev/null +++ b/Development/Software/Controller API/Server.h @@ -0,0 +1,12 @@ +#pragma once +namespace Server +{ + bool init(); + + void listen(); + + void disconnect(); + + void launch(); +} + diff --git a/Development/Software/Controller API/Source.cpp b/Development/Software/Controller API/Source.cpp new file mode 100644 index 0000000000000000000000000000000000000000..20661c4d0253a38bb5c50e04d4f42704aa0b688f --- /dev/null +++ b/Development/Software/Controller API/Source.cpp @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <iostream> +#include <string> + +#include "Client.h" +#include "Server.h" + +using namespace std; +using namespace Client; +using namespace Server; + +int main(int argc, char **argv) +{ + string choice; + + cout << "Would you like to be Client or Server? "; + cin >> choice; + + if (choice.compare("Client") == 0) clientSide(); + else if (choice.compare("Server") == 0) serverSide(); + else cout << "Wrong choice" << endl; + + exit(0); +} + +void clientSide() +{ + string address; + bool stop = false; + string message = ""; + + cout << "MAC Address I need to connect to: "; + cin >> address; + + if (!cInit(address)) + { + cout << "That address is not properly formatted." << endl; + return; + } + + cConnect(); + + cout << "Please input your message, if you would like to stop type \"STOP\"" << endl; + + while (cCheckStatus() && !stop) + { + cin >> message; + + if (message.compare("STOP")) stop = true; + + + } + + if (!cCheckStatus()) + { + perror("Oh no!"); + } + + cDisconnect(); + return; +} + +void serverSide() +{ + +} \ No newline at end of file diff --git a/Development/Software/Software.sln b/Development/Software/Software.sln index b10d22014aada1303f3c267f10c79a2226b9760b..0751d9d51385ac6e98a12bf3457143070e9051fe 100644 --- a/Development/Software/Software.sln +++ b/Development/Software/Software.sln @@ -1,14 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 +VisualStudioVersion = 12.0.30324.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client API", "Client API\Client API.vcxproj", "{F76D86D2-FD04-4813-AC90-7F8CD03FE37C}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Controller API", "Controller API\Controller API.vcxproj", "{C081C010-BF33-4DE3-AEDE-54975FC27D8D}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Communications", "Communications\Communications.vcxproj", "{EC81185B-84DB-4836-915B-68EB12CBEDC2}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Default Controller", "Default Controller\Default Controller.vcxproj", "{AC5B185E-4C05-4379-9A89-FF1D1CDA7775}" EndProject Global @@ -25,10 +23,6 @@ Global {C081C010-BF33-4DE3-AEDE-54975FC27D8D}.Debug|Win32.Build.0 = Debug|Win32 {C081C010-BF33-4DE3-AEDE-54975FC27D8D}.Release|Win32.ActiveCfg = Release|Win32 {C081C010-BF33-4DE3-AEDE-54975FC27D8D}.Release|Win32.Build.0 = Release|Win32 - {EC81185B-84DB-4836-915B-68EB12CBEDC2}.Debug|Win32.ActiveCfg = Debug|Win32 - {EC81185B-84DB-4836-915B-68EB12CBEDC2}.Debug|Win32.Build.0 = Debug|Win32 - {EC81185B-84DB-4836-915B-68EB12CBEDC2}.Release|Win32.ActiveCfg = Release|Win32 - {EC81185B-84DB-4836-915B-68EB12CBEDC2}.Release|Win32.Build.0 = Release|Win32 {AC5B185E-4C05-4379-9A89-FF1D1CDA7775}.Debug|Win32.ActiveCfg = Debug|Win32 {AC5B185E-4C05-4379-9A89-FF1D1CDA7775}.Debug|Win32.Build.0 = Debug|Win32 {AC5B185E-4C05-4379-9A89-FF1D1CDA7775}.Release|Win32.ActiveCfg = Release|Win32