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.
main.cpp
- Committer:
- mariob
- Date:
- 2012-09-09
- Revision:
- 3:a0d27c04263e
- Parent:
- 1:0c9911bd5715
- Child:
- 4:989ea19b8fd2
File content as of revision 3:a0d27c04263e:
#include "mbed.h"
#include "rtos.h"
#include "xbee.hpp"
#include "ssWiSocket.hpp"
#define WRITING_PERIOD_MS 1000
#define READING_PERIOD_MS 1000
struct Task {
PortID _id;
int _ratio;
ssWiSocket* _s;
int _val;
Task (PortID id, int ratio, int value) {
_id = id;
_ratio = ratio;
_s = ssWiSocket::createSocket(id);
_val = value;
}
};
Task *t1;
Task *t2;
Task *t3;
Task *t4;
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 network
xbee.init(1.0, 1.0);
t1 = new Task(10, 3, 20);
t2 = new Task(15, 5, 30);
t3 = new Task(100, 7, 25);
t4 = new Task(120, 4, 65);
//thread
Thread readingThread(readingFunction);
Thread writingThread(writingFunction);
printf("\n\r************* START *************\n\r");
Thread::wait(osWaitForever);
}
void readingFunction(const void* arg)
{
while(1) {
printf("Read value: (%d, %d), (%d, %d), (%d, %d), (%d, %d)\n\r",
t1->_id, t1->_s->read(), t2->_id, t2->_s->read(),
t3->_id, t3->_s->read(), t4->_id, t4->_s->read());
Thread::wait(READING_PERIOD_MS);
}
}
void writingFunction(const void* arg)
{
int x = 1;
while(1) {
if ((x%(t1->_ratio))==0)
t1->_s->write(t1->_val++);
if ((x%(t2->_ratio))==0)
t2->_s->write(t2->_val++);
if ((x%(t3->_ratio))==0)
t3->_s->write(t3->_val++);
if ((x%(t4->_ratio))==0)
t4->_s->write(t4->_val++);
x++;
Thread::wait(WRITING_PERIOD_MS);
}
}