TestSineSensor

An Insense program which repeatedly requests temperature readings from the temperature sensor.

/**
* An  Insense program which repeatedly requests temperature readings from
* the temperature sensor.
*/

type sineI is interface(out bool tempReq ; in integer tempVal)

component sine presents sineI {

	state = true
	constructor() {

        }

        behaviour {
            send true on tempReq
            receive temp from tempVal

            printInt(temp);
            setRedLedPower(state)
            state := !state
        }
}

s = new sine()

connect s.tempReq to sensors.tempRequest
connect s.tempVal to sensors.tempOut

The corresponding nesC program for TinyOS is shown below.


module TestSineSensorC {
  uses {
    interface Boot;
    interface Thread as MainThread;
    interface BlockingRead;
    interface BlockingStdControl as AMControl;
    interface BlockingAMSend;
    interface Packet;
    interface Leds;
  }
}

implementation {
  event void Boot.booted() {
    call MainThread.start(NULL);
  }

  event void MainThread.run(void* arg) {
    uint16_t* var;
    message_t msg;
    var = call Packet.getPayload(&msg, sizeof(uint16_t));

    while( call AMControl.start() != SUCCESS );    
    for(;;){
      while( call BlockingRead.read(var) != SUCCESS );
      while( call BlockingAMSend.send(AM_BROADCAST_ADDR, &msg, sizeof(uint16_t)) != SUCCESS );
      call Leds.led0Toggle();
    }
  }
}

/*************************************************/
configuration TestSineSensorAppC {
}
implementation {
  components MainC, TestSineSensorC;
  components new ThreadC(150) as MainThread;
  
  components new BlockingSineSensorC();
  components BlockingSerialActiveMessageC;
  components new BlockingSerialAMSenderC(228);

  MainC.Boot  BlockingSineSensorC;
  TestSineSensorC.MainThread -> MainThread;
  TestSineSensorC.BlockingRead -> BlockingSineSensorC;
  TestSineSensorC.AMControl -> BlockingSerialActiveMessageC;
  TestSineSensorC.BlockingAMSend -> BlockingSerialAMSenderC;
  TestSineSensorC.Packet -> BlockingSerialAMSenderC;
  
  components LedsC;
  TestSineSensorC.Leds -> LedsC;
}
/*********************************/