Permalink
Browse files

Beginnings of synchoronization. not Fully working.

  • Loading branch information...
1 parent 6b60877 commit bda8628bc9d2ea30a674267bd6cbadf4b5a8c867 @mckk committed Mar 9, 2012
Showing with 65 additions and 11 deletions.
  1. +10 −1 Receiver/ReceiverAppC.nc
  2. +27 −6 Receiver/ReceiverC.nc
  3. +4 −0 Sender/SenderAppC.nc
  4. +14 −4 Sender/SenderC.nc
  5. +10 −0 TimerRestartMsg.h
View
@@ -7,16 +7,22 @@ implementation
{
components MainC, ReceiverC, LedsC;
+ components new TimerMilliC() as SyncTimer;
+
components ActiveMessageC;
components new AMReceiverC(AM_DATAMSG) as DataReceiver;
components SerialActiveMessageC;
components new SerialAMSenderC(AM_SERIALMSG) as SerialSender;
- components new AMReceiverC(AM_FIREMSG) as FireMsgReceiver;
+ components new AMReceiverC(AM_FIREMSG) as FireMsgReceiver;
+
+ components new AMSenderC(AM_TIMERRESTARTMSG) as TimerMsgSender;
ReceiverC -> MainC.Boot;
+ ReceiverC.SyncTimer -> SyncTimer;
+
ReceiverC.Leds -> LedsC;
ReceiverC.AMControl -> ActiveMessageC;
@@ -27,5 +33,8 @@ implementation
ReceiverC.SerialSend -> SerialSender;
ReceiverC.FireMsgReceive -> FireMsgReceiver;
+
+ ReceiverC.TimerPacket -> TimerMsgSender;
+ ReceiverC.TimerSend -> TimerMsgSender;
}
View
@@ -2,20 +2,26 @@
#include "../DataMsg.h"
#include "SerialMsg.h"
#include "../FireMsg.h"
+#include "../TimerRestartMsg.h"
module ReceiverC
{
uses interface Leds;
uses interface Boot;
+ uses interface Timer<TMilli> as SyncTimer;
+
uses interface SplitControl as AMControl;
uses interface Receive as DataReceive;
uses interface SplitControl as SerialAMControl;
uses interface Packet as SerialPacket;
uses interface AMSend as SerialSend;
- uses interface Receive as FireMsgReceive;
+ uses interface Receive as FireMsgReceive;
+
+ uses interface Packet as TimerPacket;
+ uses interface AMSend as TimerSend;
}
implementation
{
@@ -36,20 +42,35 @@ implementation
call AMControl.start();
+ call SyncTimer.startPeriodic(10000);
+
call SerialAMControl.start();
}
- event void AMControl.stopDone(error_t err) {
- if(err == SUCCESS){
- AMBusy = TRUE;
+ event void SyncTimer.fired() {
+ TimerRestartMsg *pkt = NULL;
+ pkt = (TimerRestartMsg *)(call TimerPacket.getPayload(&datapkt, sizeof(TimerRestartMsg)));
+ pkt -> srcid = TOS_NODE_ID;
+ if (!AMBusy && call TimerSend.send(AM_BROADCAST_ADDR, &datapkt, sizeof(DataMsg)) == SUCCESS){
+ AMBusy = TRUE;
+ }
+ }
+
+ event void TimerSend.sendDone(message_t *msg, error_t error) {
+ AMBusy = FALSE;
+ }
+
+ event void AMControl.stopDone(error_t err) {
+ if(err == SUCCESS){
+ AMBusy = TRUE;
}
}
event void AMControl.startDone(error_t err) {
if (err == SUCCESS) {
AMBusy = FALSE;
}
- }
+ }
event message_t * DataReceive.receive(message_t * msg, void * payload, uint8_t len) {
@@ -58,7 +79,7 @@ implementation
if(len == sizeof(DataMsg)) {
d_pkt = (DataMsg *) payload;
- }
+ }
s_pkt = (SerialMsg *)(call SerialPacket.getPayload(&serialpkt, sizeof(SerialMsg)));
View
@@ -18,6 +18,8 @@ implementation
components new AMSenderC(AM_FIREMSG) as FireMsgSender;
components new AMReceiverC(AM_DATAMSG) as DataReceiver;
+ components new AMReceiverC(AM_TIMERRESTARTMSG) as TimerMsgReceiver;
+
SenderC -> MainC.Boot;
SenderC.SensorTimer -> SensorTimer;
@@ -32,5 +34,7 @@ implementation
SenderC.DataSend -> DataSender;
SenderC.FireMsgSend -> FireMsgSender;
SenderC.DataReceive -> DataReceiver;
+
+ SenderC.TimerMsgReceive -> TimerMsgReceiver;
}
View
@@ -1,6 +1,7 @@
#include "Timer.h"
#include "../DataMsg.h"
#include "../FireMsg.h"
+#include "../TimerRestartMsg.h"
module SenderC
{
@@ -18,15 +19,17 @@ module SenderC
uses interface AMSend as FireMsgSend;
uses interface Receive as DataReceive;
+ uses interface Receive as TimerMsgReceive;
+
}
implementation
{
enum {
SAMPLE_PERIOD = 1000,
- NEIGHBOURS_NUMBER = 2, // the number of neighbour nodes
- LOG_SIZE = 30, // log size should be even
- BASE_ADDR = 0x22, // the address of base station
+ NEIGHBOURS_NUMBER = 2, // the number of neighbour nodes
+ LOG_SIZE = 30, // log size should be even
+ BASE_ADDR = 0x22, // the address of base station
};
// used to store sensor's readings
@@ -76,7 +79,6 @@ implementation
neighboursLux[i] = FALSE;
}
- call SensorTimer.startPeriodic(SAMPLE_PERIOD);
call AMControl.start();
}
@@ -141,6 +143,14 @@ implementation
return msg;
}
+ // for receiving syncMessages
+ event message_t * TimerMsgReceive.receive(message_t * msg, void * payload, uint8_t len) {
+ if(len == sizeof(TimerRestartMsg)) {
+ call SensorTimer.startPeriodic(SAMPLE_PERIOD);
+ }
+ return msg;
+ }
+
// If both temperature and light readings occured, send the data
task void sendData(){
View
@@ -0,0 +1,10 @@
+#define TIMERRESTARTMSG_H
+
+enum {
+ AM_TIMERRESTARTMSG = 189,
+ TIMERRESTARTMSG_HEADER = 0x99,
+};
+
+typedef nx_struct TimerRestartMsg {
+ nx_uint8_t srcid;
+} TimerRestartMsg;

0 comments on commit bda8628

Please sign in to comment.