Created
December 28, 2015 09:18
-
-
Save flk92/98897db2a6bf9d42dec1 to your computer and use it in GitHub Desktop.
Bluetooth SPP + Edison library patches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -uprN a/bt_test_nonblock_read/bt_test_nonblock_read.ino b/bt_test_nonblock_read/bt_test_nonblock_read.ino | |
--- a/bt_test_nonblock_read/bt_test_nonblock_read.ino 1969-12-31 21:00:00.000000000 -0300 | |
+++ b/bt_test_nonblock_read/bt_test_nonblock_read.ino 2015-12-14 11:32:58.394690200 -0200 | |
@@ -0,0 +1,22 @@ | |
+#include <Wire.h> | |
+#include <Intel_Edison_BT_SPP.h> | |
+ | |
+static Intel_Edison_BT_SPP spp = Intel_Edison_BT_SPP(); | |
+ | |
+void setup() { | |
+ Serial.begin(115200); | |
+ Serial.println("Intel Edison BT SPP test!"); | |
+ | |
+ spp.open(); | |
+} | |
+ | |
+void loop() { | |
+ ssize_t size = -1; | |
+ if (spp.wait() > 0 && spp.ready()) { | |
+ size = spp.read(); | |
+ } | |
+ if (size != -1) { | |
+ Serial.println(spp.getBuf()); | |
+ } | |
+} | |
+ | |
diff -uprN a/Intel_Edison_BT_SPP.cpp b/Intel_Edison_BT_SPP.cpp | |
--- a/Intel_Edison_BT_SPP.cpp 2015-05-04 11:40:35.342959600 -0300 | |
+++ b/Intel_Edison_BT_SPP.cpp 2015-12-14 11:32:27.232621000 -0200 | |
@@ -4,6 +4,10 @@ | |
#include <unistd.h> | |
#include <errno.h> | |
#include <string.h> | |
+#include <sys/types.h> | |
+#include <sys/time.h> | |
+#include <sys/select.h> | |
+#include <errno.h> | |
#include <Intel_Edison_BT_SPP.h> | |
using namespace std; | |
@@ -25,6 +40,19 @@ int Intel_Edison_BT_SPP::open() { | |
return -1; | |
} | |
+int Intel_Edison_BT_SPP::wait() { | |
+ struct timeval tv; | |
+ tv.tv_sec = 0; | |
+ tv.tv_usec = 500000; | |
+ FD_ZERO(&_readfd); | |
+ FD_SET(_fd, &_readfd); | |
+ return select(_fd + 1, &_readfd, NULL, NULL, &tv); | |
+} | |
+ | |
+int Intel_Edison_BT_SPP::ready() { | |
+ return FD_ISSET(_fd, &_readfd); | |
+} | |
+ | |
ssize_t Intel_Edison_BT_SPP::read() { | |
if (_fd == -1) | |
diff -uprN a/Intel_Edison_BT_SPP.h b/Intel_Edison_BT_SPP.h | |
--- a/Intel_Edison_BT_SPP.h 2015-05-04 11:21:22.269419400 -0300 | |
+++ b/Intel_Edison_BT_SPP.h 2015-12-14 10:29:37.340650900 -0200 | |
@@ -13,11 +13,14 @@ class Intel_Edison_BT_SPP { | |
public: | |
int open(); | |
int read(); | |
+ int wait(); | |
+ int ready(); | |
const char * getBuf(); | |
~Intel_Edison_BT_SPP(); | |
private: | |
int _fd = -1; | |
+ fd_set _readfd; | |
const char * _pipeName = "/tmp/arduino_pipe_out"; | |
char _buf[MAX_BUF]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -uprN a/Intel_Edison_BT_SPP.cpp b/Intel_Edison_BT_SPP.cpp | |
--- a/Intel_Edison_BT_SPP.cpp 2015-12-14 12:01:35.970646200 -0200 | |
+++ b/Intel_Edison_BT_SPP.cpp 2015-12-14 11:32:27.232621000 -0200 | |
@@ -17,6 +17,17 @@ int Intel_Edison_BT_SPP::open() { | |
if (_fd != -1) | |
close(_fd); | |
+ struct stat st; | |
+ while(stat(_pipeName, &st) == -1) { | |
+ if(errno != ENOENT) { | |
+ perror("Cannot open file\n"); | |
+ printf("errno %s\n", strerror(errno)); | |
+ Serial.print("open error "); Serial.println(strerror(errno)); | |
+ return 0; | |
+ } | |
+ usleep(200000); | |
+ } | |
+ | |
_fd = ::open(_pipeName, O_RDONLY); | |
if (_fd == -1) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment