Hi all, I am trying to read from port UARTO on a tmote sky. I was able to
read until i tried to define two different MSP430ResourceUART0C to use two
difference resource arbitration. I was hoping to get a better accuracy in
reading values, but as it seems, I am not reading anything anymore, and
moreover, the program stops running while in event void
ResourceTxCmd.granted(uint8_t rh).
Can anyone help me?
ReaderController.nc (config file)
includes ReaderCmdMsg;
configuration ReaderController
{
}
implementation
{
components
GenericComm,
SPC,
Main,
ReaderControllerM,
HPLUSART0M as HPLUSART0MTx,
HPLUSART0M as HPLUSART0MRx,
LedsC, // Using the onboard Leds
new MSP430ResourceUART0C() as ResourceCmdCRx,
new MSP430ResourceUART0C() as ResourceCmdCTx;
// Wiring
Main.StdControl -> ReaderControllerM;
ReaderControllerM.UartTxControl -> HPLUSART0MTx;
ReaderControllerM.UartRxControl -> HPLUSART0MRx;
ReaderControllerM.Leds -> LedsC;
ReaderControllerM.SPReceive -> SPC.SPReceive[AM_READERCMDMSG];
ReaderControllerM.SPSend -> SPC.SPSend[1];
ReaderControllerM.ResourceRxCmd -> ResourceCmdCRx;
ReaderControllerM.ResourceTxCmd -> ResourceCmdCTx;
}
__________________________________
ReaderControllerM.nc (Module)
includes ReaderCmdMsg;
module ReaderControllerM
{
provides interface StdControl;
uses interface Leds;
uses interface StdControl as CommControl;
//C:\cygwin\opt\moteiv\tinyos-1.x\tos\interfaces
uses interface ResourceCmd as ResourceRxCmd;
uses interface ResourceCmd as ResourceTxCmd;
//C:\cygwin\opt\moteiv\tos\lib\resource
uses interface HPLUSARTControl as UartRxControl;
uses interface HPLUSARTControl as UartTxControl;
uses interface SPSend;
//C:\cygwin\opt\moteiv\tos\lib\sp
uses interface SPReceive;
//C:\cygwin\opt\moteiv\tos\lib\sp
}
/*
* Module Implementation
*/
implementation //********************************************
{
sp_message_t m_spmsg;
TOS_Msg m_tosmsg;
uint8_t *msgSize_Ptr; // Used to set the message lenght for SPSend
void sendMessage() {
uint8_t msgSize = *msgSize_Ptr;
m_tosmsg.data[0]=TOS_LOCAL_ADDRESS & 0xFF; // Not really
necessary
m_tosmsg.data[1]=TOS_LOCAL_ADDRESS>>8; // Not really
necessary
//m_tosmsg.data[0]=0xFF;
//m_tosmsg.data[1]=0xFF;
m_tosmsg.group=0x07; // Warning: Not allowed to write another
variable here after...
call Leds.yellowOn() ;
if (call SPSend.send(&m_spmsg, &m_tosmsg, TOS_BCAST_ADDR, msgSize)
== SUCCESS) {
call Leds.redOn();
}
}
event void SPSend.sendDone(sp_message_t* spmsg, sp_message_flags_t
flags, sp_error_t error) {
call Leds.greenOff();
}
void getResult() {
uint8_t j=0;
uint8_t uartIn = 0;
uint8_t resultBuffer[20];
resultBuffer[2]=2; // To ensure that it reads up to byte 3,
which defines the lenght of the response
// Note that the first byte is senseless
// Receive data from UART0RX
do {
uartIn = call UartRxControl.rx();
resultBuffer[j++] = uartIn;
while (!(call UartRxControl.isRxIntrPending()));
m_tosmsg.data[16]=resultBuffer[2];
} while (j<=resultBuffer[2]); // Reads the lenght of the
response of m1 mini and reads up to that length+1
memcpy(m_tosmsg.data+2, resultBuffer+1,j); // Copies buffer into
TOS_Msg
m_tosmsg.data[15]=j;
call Leds.greenOn();
// This is done to set the length of the TOS_Msg sent back to PC
// The pointer *msgSize_Ptr will be called by SPSend.send
// j=j+3 permitts to send the adress (2 bytes) and j is actually one
shorter than
// the actual TOS_Msg lenght (starts at 0 above...)
j=j+3;
msgSize_Ptr = &j; // p44 A Book on C
m_tosmsg.data[14]=*msgSize_Ptr;
call Leds.greenOff();
}
/**
* Message received:
*
* Get command for Reader from message and set
* action.
*
**/
event void SPReceive.receive(sp_message_t *spmsg, TOS_MsgPtr tosmsg,
sp_error_t result){
ReaderCmdMsg_t* body;
body = (ReaderCmdMsg_t*)tosmsg->data; // Get pointer to mesage
data
call Leds.yellowOff() ;
call Leds.redOff();
call Leds.greenOff();
switch (body->cmd) {
case CMD_FORWARD:
//call Leds.redOn();
call ResourceTxCmd.request( RESOURCE_NONE );
break;
}
}
event void ResourceTxCmd.granted(uint8_t rh) {
uint8_t i;
Cmd4Tag testcmd;
call Leds.redOn();
// A read Serial Number Command
testcmd.cmd4tag[0] = 0x02; //init
testcmd.cmd4tag[1] = 0x06; //length
testcmd.cmd4tag[2] = 0x20; //flags
testcmd.cmd4tag[3] = 0x22; //command
testcmd.cmd4tag[4] = 0x00; //starting block
testcmd.cmd4tag[5] = 0x01; //number of blocks
testcmd.cmd4tag[6] = 0x13; //crc
testcmd.cmd4tag[7] = 0xC1; //crc
call UartTxControl.setClockSource(SSEL_2); // I now have the UART
and it is in UART mode.
call UartTxControl.setClockRate(UBR_SMCLK_9600, UMCTL_SMCLK_9600);
// Make any necessary UART changes
call Leds.greenOn();
// Send data to NFC reader
for (i = 0; i<SIZE_CMD4TAG; ++i){
call UartTxControl.tx( testcmd.cmd4tag[i]);
while (! call UartTxControl.isTxEmpty() ) ;
}
call Leds.redOff();
call ResourceTxCmd.release(); // Release the Rx
resource
sendMessage();
call ResourceRxCmd.request( RESOURCE_NONE ); // Call the Rx
resource to read the answer
}
event void ResourceRxCmd.granted(uint8_t rh) {
call UartTxControl.setClockSource(SSEL_2); // I now have the UART
and it is in UART mode.
call UartTxControl.setClockRate(UBR_SMCLK_9600, UMCTL_SMCLK_9600);
// Make any necessary UART changes
//getResult();
call ResourceTxCmd.release(); // Release the Tx resource
sendMessage();
call Leds.yellowOff() ;
call Leds.redOff();
call Leds.greenOff();
}
//init -----------------------------------------------------------
command result_t StdControl.init(){
return SUCCESS;
}
//start -----------------------------------------------------------
command result_t StdControl.start(){
return SUCCESS;
}
//stop -----------------------------------------------------------
command result_t StdControl.stop(){
return SUCCESS;
}
} // end of implementation
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help