Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q Multi_WS2811 NVIC_set_all_priorities TSI cc3000_hostdriver_mbedsocket mbed
Fork of CubicHand by
Revision 15:b48ac00af0b8, committed 2014-12-07
- Comitter:
- kalbers
- Date:
- Sun Dec 07 21:49:33 2014 +0000
- Parent:
- 14:0c4a26dc6873
- Child:
- 17:c2e59ada97ee
- Commit message:
- Added a reconnect to GloveWifi.
Changed in this revision
--- a/DataGlove.cpp Sun Dec 07 19:50:47 2014 +0000
+++ b/DataGlove.cpp Sun Dec 07 21:49:33 2014 +0000
@@ -21,6 +21,11 @@
{
GloveSocket.Init();
GloveSocket.Connect();
+ StreamData();
+}
+
+void DataGlove::StreamData()
+{
SendBuf[0] = '$';
SendBuf[1] = 0x0A;
SendBuf[2] = 0x03;
@@ -33,20 +38,8 @@
void DataGlove::Receive()
{
- uint8_t *Buf, *buffer;
- int8_t numReceived;
- bool raw = false;
- unsigned char bcc;
- int pkglen, u;
- int timeOfArrival, id, pkgtype;
- int j, k, y;
- double roll, yaw, pitch;
- double norm, test;
- int q0, q1, q2, q3;
- double q00, q11, q22, q33;
- printf("beginning of receive\r\n");
+ raw = false;
numReceived = GloveSocket.GetDataFromBuffer(Buf, 1);
- printf("received %d bytes\r\n", numReceived);
if (Buf[0] == '$') {
bcc = '$';
numReceived = GloveSocket.GetDataFromBuffer(Buf, 2);
@@ -222,19 +215,16 @@
}
}
else {
- printf("couldn't get data %d\r\n", notConnectedCount);
+ //printf("couldn't get data %d\r\n", notConnectedCount);
notConnectedCount++;
}
- printf("just before re-establishing connection\r\n");
// Re-establishing communication in case no data is received for 1s (20 frames per second*1 = 20)
if (notConnectedCount > 20) {
printf("Connection broke! Trying to re-establish...\r\n");
- GloveSocket.Disconnect();
- printf("Disconnected wifi\r\n");
+ GloveSocket.Reconnect();
+ StreamData();
notConnectedCount = 0;
- GloveSocket.Connect();
}
- wait(0.1);
}
void DataGlove::Parse()
--- a/DataGlove.h Sun Dec 07 19:50:47 2014 +0000
+++ b/DataGlove.h Sun Dec 07 21:49:33 2014 +0000
@@ -19,6 +19,7 @@
DataGlove();
~DataGlove();
void Init();
+ void StreamData();
void Receive();
int16_t finger1, finger2, finger3, finger4, finger5;
int16_t accelx, accely, accelz;
@@ -26,10 +27,19 @@
private:
void Parse();
- uint8_t Buf[100];
uint8_t SendBuf[20];
int16_t notConnectedCount;
- int numReceived;
+ int8_t numReceived;
+ uint8_t Buf[256], buffer[256];
+ bool raw;
+ unsigned char bcc;
+ int pkglen, u;
+ int timeOfArrival, id, pkgtype;
+ int j, k, y;
+ double roll, yaw, pitch;
+ double norm, test;
+ int q0, q1, q2, q3;
+ double q00, q11, q22, q33;
Glove *gl;
GloveWifi GloveSocket;
--- a/GloveWifi.cpp Sun Dec 07 19:50:47 2014 +0000
+++ b/GloveWifi.cpp Sun Dec 07 21:49:33 2014 +0000
@@ -47,7 +47,6 @@
//wifi = new cc3000(PTD4, PTC9, PTD0, SPI(PTD2, PTD3, PTD1), SSID, PASSWORD, WPA2, false);
wifi = new cc3000(PTD4, PTC9, PTC4, SPI(PTC6, PTC7, PTC5), SSID, PASSWORD, WPA2, false);
wifi->init();
- socket = new TCPSocketConnection;
if (wifi->connect() == -1)
{
printf("Failed to connect. Please verify connection details and try again. \r\n");
@@ -55,6 +54,7 @@
{
printf("IP address: %s \r\n", wifi->getIPAddress());
}
+ socket = new TCPSocketConnection;
while (socket->connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
{
printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
@@ -62,6 +62,7 @@
}
socket->set_blocking(true);
printf("Connected!\r\n");
+
}
void GloveWifi::Disconnect()
@@ -72,8 +73,22 @@
delete wifi;
}
+void GloveWifi::Reconnect()
+{
+ delete socket;
+ socket = new TCPSocketConnection;
+ while (socket->connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
+ {
+ printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+ wait(1);
+ }
+ socket->set_blocking(true);
+ printf("Reconnected!\r\n");
+}
+
uint8_t GloveWifi::GetDataFromBuffer(uint8_t * buf, uint16_t size)
{
+ //printf("Buffer Size: %d\r\n", wifi->_simple_link.get_transmit_error());
return socket->receive((char *)buf, size);
}
--- a/GloveWifi.h Sun Dec 07 19:50:47 2014 +0000 +++ b/GloveWifi.h Sun Dec 07 21:49:33 2014 +0000 @@ -14,6 +14,7 @@ void Init(); void Connect(); void Disconnect(); + void Reconnect(); uint8_t GetDataFromBuffer(uint8_t * buf, uint16_t size); uint8_t SendDataToGlove(uint8_t * buf, uint16_t size);
--- a/main.cpp Sun Dec 07 19:50:47 2014 +0000
+++ b/main.cpp Sun Dec 07 21:49:33 2014 +0000
@@ -17,7 +17,7 @@
while(true)
{
MasterGlove.Receive();
- pc.printf("Looping \r\n");
- wait(0.5);
+ //pc.printf("Looping \r\n");
+ //wait(0.1);
}
}
