[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/handhelds/tos/lib/RovingNetworks RovingNetworksM.nc, 1.3, 1.4

steve ayer ayer1 at users.sourceforge.net
Fri Aug 10 10:13:04 PDT 2007


Update of /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/RovingNetworks
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23433

Modified Files:
	RovingNetworksM.nc 
Log Message:

changed sendNextChar to task
made write-accesses to charsSent and expectedCommandResponse atomic

both of these changes were necessary to prevent bogus (spurious) writeDone
events from being signalled.  this bug was just uncovered in a very large
application, the kind that can make any subtle inadequacy rear its
ugly head!




Index: RovingNetworksM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/tos/lib/RovingNetworks/RovingNetworksM.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** RovingNetworksM.nc	27 Mar 2007 17:37:34 -0000	1.3
--- RovingNetworksM.nc	10 Aug 2007 17:13:02 -0000	1.4
***************
*** 60,74 ****
    uint8_t radioMode, charsSent, setupStep;
    bool discoverable, authenticate, encrypt, setNameRequest, setPINRequest, runDiscoveryRequest, resetDefaultsRequest,
!     setSvcClassRequest, setDevClassRequest;
    norace bool transmissionOverflow, messageInProgress;
!   char expectedCommandResponse[8], newName[17], newPIN[17], newSvcClass[5], newDevClass[5];
    
    norace struct Message * outgoingMsg;
    norace struct Message * incomingMsg;
  
!   void sendNextChar() {
      if(charsSent < msg_get_length(outgoingMsg)) {
        call UARTControl.tx(msg_get_uint8(outgoingMsg, charsSent));
!       charsSent++;
      } 
      else{
--- 60,74 ----
    uint8_t radioMode, charsSent, setupStep;
    bool discoverable, authenticate, encrypt, setNameRequest, setPINRequest, runDiscoveryRequest, resetDefaultsRequest,
!     setSvcClassRequest, setDevClassRequest, setSvcNameRequest, newMode;
    norace bool transmissionOverflow, messageInProgress;
!   char expectedCommandResponse[8], newName[17], newPIN[17], newSvcClass[5], newDevClass[5], newSvcName[17];
    
    norace struct Message * outgoingMsg;
    norace struct Message * incomingMsg;
  
!   task void sendNextChar() {
      if(charsSent < msg_get_length(outgoingMsg)) {
        call UARTControl.tx(msg_get_uint8(outgoingMsg, charsSent));
!       atomic charsSent++;
      } 
      else{
***************
*** 84,93 ****
  
      messageInProgress = TRUE;
!     charsSent = 0;
      msg_clear(outgoingMsg);
      msg_append_buf(outgoingMsg, buf, len);
  
      if(!transmissionOverflow){
!       sendNextChar();
      }
  	
--- 84,93 ----
  
      messageInProgress = TRUE;
!     atomic charsSent = 0;
      msg_clear(outgoingMsg);
      msg_append_buf(outgoingMsg, buf, len);
  
      if(!transmissionOverflow){
!       post sendNextChar();
      }
  	
***************
*** 156,160 ****
  
    result_t writeCommand(char * cmd, char * response) {
!     strcpy(expectedCommandResponse, response);
      if(call Bluetooth.write(cmd, strlen(cmd)) == FAIL)
        return FAIL;
--- 156,160 ----
  
    result_t writeCommand(char * cmd, char * response) {
!     atomic strcpy(expectedCommandResponse, response);
      if(call Bluetooth.write(cmd, strlen(cmd)) == FAIL)
        return FAIL;
***************
*** 164,167 ****
--- 164,168 ----
  
    command void Bluetooth.setRadioMode(uint8_t mode){
+     newMode = TRUE;
      radioMode = mode;
    }    
***************
*** 198,201 ****
--- 199,207 ----
    }    
  
+   command void Bluetooth.setServiceName(char * name){
+     setSvcNameRequest = TRUE;
+     snprintf(newSvcName, 5, "%s", name);
+   }    
+ 
    command void Bluetooth.setPIN(char * PIN){
      setPINRequest = TRUE;
***************
*** 213,217 ****
      char commandbuf[32];
  
!     // if we're in default mode, don't even go to cmd mode
      if(!radioMode &&     
         discoverable &&
--- 219,223 ----
      char commandbuf[32];
  
!     /* if we're in default mode, don't even go to cmd mode
      if(!radioMode &&     
         discoverable &&
***************
*** 226,230 ****
        return;
      }
! 
      switch(setupStep) {
      case 0:
--- 232,236 ----
        return;
      }
!     */
      switch(setupStep) {
      case 0:
***************
*** 242,246 ****
        setupStep++;
        // default is slave (== 0), otherwise set mode
!       if(radioMode){
  	sprintf(commandbuf, "SM,%d\r", radioMode);
  	writeCommand(commandbuf, "AOK");
--- 248,252 ----
        setupStep++;
        // default is slave (== 0), otherwise set mode
!       if(newMode){
  	sprintf(commandbuf, "SM,%d\r", radioMode);
  	writeCommand(commandbuf, "AOK");
***************
*** 303,306 ****
--- 309,319 ----
      case 10:
        setupStep++;
+       if(setSvcNameRequest){
+ 	sprintf(commandbuf, "SS,%s\r", newSvcName);
+ 	writeCommand(commandbuf, "AOK");
+ 	break;
+       }
+     case 11:
+       setupStep++;
        // exit command mode
        writeCommand("---\r", "END");
***************
*** 312,315 ****
--- 325,336 ----
  
    command result_t StdControl.init(){
+     TOSH_MAKE_BT_RTS_INPUT();      
+ 
+     TOSH_MAKE_BT_RXD_INPUT();
+     TOSH_SEL_BT_RXD_MODFUNC();
+ 
+     TOSH_CLR_SW_BT_PWR_N_PIN();   // this powers it up on models so equipped, otherwise harmless
+ 
+     newMode = FALSE;
      radioMode = SLAVE_MODE;   
      discoverable = TRUE;
***************
*** 320,327 ****
      setPINRequest = FALSE;
      setSvcClassRequest = FALSE;
      setDevClassRequest = FALSE;
  
      setupStep = 0;
!     *expectedCommandResponse = NULL;
      transmissionOverflow = FALSE, messageInProgress = FALSE;
  
--- 341,349 ----
      setPINRequest = FALSE;
      setSvcClassRequest = FALSE;
+     setSvcNameRequest = FALSE;
      setDevClassRequest = FALSE;
  
      setupStep = 0;
!     atomic *expectedCommandResponse = NULL;
      transmissionOverflow = FALSE, messageInProgress = FALSE;
  
***************
*** 354,357 ****
--- 376,381 ----
      disableRN();
  
+     TOSH_SET_SW_BT_PWR_N_PIN();   // power off, see .init()
+ 
      call MessagePool.free(incomingMsg);
      call MessagePool.free(outgoingMsg);
***************
*** 406,413 ****
  	  msg_clear(incomingMsg);	
  	  if(!strcmp(expectedCommandResponse, "END"))
! 	    signal Bluetooth.commandModeEnded();//call Leds.greenOn();
  	  else
  	    post runSetCommands();
! 	  *expectedCommandResponse = '\0';
  	}
        }
--- 430,437 ----
  	  msg_clear(incomingMsg);	
  	  if(!strcmp(expectedCommandResponse, "END"))
! 	    signal Bluetooth.commandModeEnded();  //call Leds.greenOn();
  	  else
  	    post runSetCommands();
! 	  atomic *expectedCommandResponse = '\0';
  	}
        }
***************
*** 420,424 ****
    async event result_t UARTData.txDone() {
      if (!transmissionOverflow) {
!       sendNextChar();
      }
      return SUCCESS;
--- 444,448 ----
    async event result_t UARTData.txDone() {
      if (!transmissionOverflow) {
!       post sendNextChar();
      }
      return SUCCESS;
***************
*** 428,432 ****
      if (call RTSInterrupt.getValue() == FALSE) {
        transmissionOverflow = 0;
!       sendNextChar();
        //      call Leds.redOff();
      } 
--- 452,456 ----
      if (call RTSInterrupt.getValue() == FALSE) {
        transmissionOverflow = 0;
!       post sendNextChar();
        //      call Leds.redOff();
      } 



More information about the Tinyos-contrib-commits mailing list