
example for the ssWi library
main.cpp
- Committer:
- mariob
- Date:
- 2012-09-06
- Revision:
- 0:8145d0de8bdc
- Child:
- 1:0c9911bd5715
File content as of revision 0:8145d0de8bdc:
#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); } }