
example for the ssWi library
Revision 0:8145d0de8bdc, committed 2012-09-06
- Comitter:
- mariob
- Date:
- Thu Sep 06 12:18:30 2012 +0000
- Child:
- 1:0c9911bd5715
- Commit message:
- usage example of the ssWi library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 06 12:18:30 2012 +0000 @@ -0,0 +1,78 @@ +#include "mbed.h" + +#include "xbee.hpp" +#include "ssWi.hpp" +#include "ssWiSocket.hpp" + +#define READING_PORTID 10 +#define WRITING_PORTID 10 + +#define WRITING_PERIOD 1.0 +#define READING_PERIOD 0.9 + +ssWiSocket* readingSocket; +ssWiSocket* writingSocket; + + +void checkSocket(ssWiSocket* sok, char* name); + +void readingFunction(const void* arg); + +void writingFunction(const void* arg); + +int main() +{ + + printf("\n\r************* CONFIG *************\n\r"); + + //radio module + XBeeModule xbee(p9, p10, 102, 14); + XBeeAddress addr = xbee.getLocalAddress(); + printf("XBEE: src addr: %s,%s\n\r", addr.getHighAddr().c_str(), addr.getLowAddr().c_str()); + xbee.setDstAddress(XBeeBroadcastAddress()); + XBeeAddress addr2 = xbee.getDstAddress(); + printf("XBEE: dts addr: %s,%s\n\r", addr2.getHighAddr().c_str(), addr2.getLowAddr().c_str()); + printf("XBEE: channel: %d\n\r", xbee.getChannel()); + printf("XBEE: pan id: %d\n\r", xbee.getPanID()); + + //wireless protocol + ssWi channel(&xbee, 10, 20); + readingSocket = channel.createSocket(READING_PORTID); + checkSocket(readingSocket, "reading"); + writingSocket = channel.createSocket(WRITING_PORTID); + checkSocket(writingSocket, "writing"); + + //thread + Thread readingThread(readingFunction); + Thread writingThread(writingFunction); + + printf("\n\r************* START *************\n\r"); + + while(1); +} + + +void checkSocket(ssWiSocket* socket, char* name) +{ + if (socket==NULL) + printf("CHANNEL: error on %s socket\n\r", name); + else + printf("CHANNEL: %s socket ok\n\r", name); +} + +void readingFunction(const void* arg) +{ + while(1) { + printf("Read value: %d\n\r", readingSocket->read()); + wait(READING_PERIOD); + } +} + +void writingFunction(const void* arg) +{ + static int value = 0; + while(1) { + writingSocket->write(value++); + wait(WRITING_PERIOD); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Sep 06 12:18:30 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Sep 06 12:18:30 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ssWi.lib Thu Sep 06 12:18:30 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mariob/code/ssWi/#1adc077d4906