[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/handhelds/hwtest/shimmer/GyroTilt GyroAccelApp.nc, 1.1, 1.2 GyroAccelAppM.nc, 1.1, 1.2 GyroTiltApp.nc, 1.1, 1.2 GyroTiltAppM.nc, 1.1, 1.2

steve ayer ayer1 at users.sourceforge.net
Mon Dec 18 08:56:25 PST 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/hwtest/shimmer/GyroTilt
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25325

Modified Files:
	GyroAccelApp.nc GyroAccelAppM.nc GyroTiltApp.nc 
	GyroTiltAppM.nc 
Log Message:

updates taking advantage of dma block transfer handling; double
buffering added to radio transfer; both udp and tcp transfers in code
(one commented out!).


Index: GyroAccelApp.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/hwtest/shimmer/GyroTilt/GyroAccelApp.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GyroAccelApp.nc	7 Sep 2006 18:36:07 -0000	1.1
--- GyroAccelApp.nc	18 Dec 2006 16:56:23 -0000	1.2
***************
*** 45,48 ****
--- 45,49 ----
      IPCLIENT as IPClientC,
      TelnetM,
+     DS2411LiteM,
      ParamViewM;
  
***************
*** 68,75 ****
    GyroAccelAppM.Client        -> IPClientC;
    GyroAccelAppM.TCPClient     -> IPClientC.TCPClient[unique("TCPClient")];
!   GyroAccelAppM.UDPClient     -> IPClientC.UDPClient[unique("UDPClient")];
  
    GyroAccelAppM.TelnetRun         -> TelnetM.Telnet[unique("Telnet")];
  
    GyroAccelAppM.PVStdControl      -> ParamViewM;
    GyroAccelAppM.TelnetStdControl  -> TelnetM;
--- 69,78 ----
    GyroAccelAppM.Client        -> IPClientC;
    GyroAccelAppM.TCPClient     -> IPClientC.TCPClient[unique("TCPClient")];
!   //  GyroAccelAppM.UDPClient     -> IPClientC.UDPClient[unique("UDPClient")];
  
    GyroAccelAppM.TelnetRun         -> TelnetM.Telnet[unique("Telnet")];
  
+   GyroAccelAppM.ClientStdControl   -> IPClientC.StdControl;
+ 
    GyroAccelAppM.PVStdControl      -> ParamViewM;
    GyroAccelAppM.TelnetStdControl  -> TelnetM;

Index: GyroAccelAppM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/hwtest/shimmer/GyroTilt/GyroAccelAppM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GyroAccelAppM.nc	7 Sep 2006 18:36:07 -0000	1.1
--- GyroAccelAppM.nc	18 Dec 2006 16:56:23 -0000	1.2
***************
*** 54,57 ****
--- 54,59 ----
      interface StdControl as PVStdControl;
  
+     interface StdControl as ClientStdControl;
+ 
      interface StdControl as AccelStdControl;
  
***************
*** 63,67 ****
      interface Client; 
      interface TCPClient;
-     interface UDPClient;
  
      /* end telnet stuff */
--- 65,68 ----
***************
*** 80,90 ****
  #define MESSAGE_MAX_LENGTH 128
  
!   uint8_t dma_transfers, myreason = 0, enable_shipping = 0, enable_gyros = 0, adcregnum;
    uint16_t inbuf0[128], inbuf1[128], inbuf2[128], *curr0, *curr1, *curr2;
    uint16_t abuf[6], gbuf[3];
    uint8_t msgbuf[128];
  
-   struct udp_address udpaddr;
- 
    uint16_t adcifg_count = 0;
  
--- 81,90 ----
  #define MESSAGE_MAX_LENGTH 128
  
!   uint8_t myreason = 0, enable_shipping = 0, enable_gyros = 0, adcregnum;
    uint16_t inbuf0[128], inbuf1[128], inbuf2[128], *curr0, *curr1, *curr2;
    uint16_t abuf[6], gbuf[3];
+   norace uint16_t dma_transfers;
    uint8_t msgbuf[128];
  
    uint16_t adcifg_count = 0;
  
***************
*** 95,101 ****
  
      atomic {
!       call DMA0.setDestinationAddress((uint16_t)inbuf0);
!       call DMA1.setDestinationAddress((uint16_t)inbuf1);
!       call DMA2.setDestinationAddress((uint16_t)inbuf2);
  
        call DMA0.setBlockSize(1);
--- 95,105 ----
  
      atomic {
!       call DMA0.setDestinationAddress(&abuf[0]);
!       call DMA1.setDestinationAddress(&abuf[1]);
!       call DMA2.setDestinationAddress(&abuf[2]);
! 
!       SET_FLAG(DMA0CTL, DMADSTINCR_0);   // hold the destination address still
!       SET_FLAG(DMA1CTL, DMADSTINCR_0);
!       SET_FLAG(DMA2CTL, DMADSTINCR_0);
  
        call DMA0.setBlockSize(1);
***************
*** 114,118 ****
        SET_FLAG(ADC12CTL1, ADC12SSEL_1);         // clk from aclk
        
!       SET_FLAG(ADC12CTL1, ADC12DIV_7);         // divide clk by 8
        // sample and hold time four adc12clk cycles
        SET_FLAG(ADC12CTL0, SHT0_0);   
--- 118,122 ----
        SET_FLAG(ADC12CTL1, ADC12SSEL_1);         // clk from aclk
        
!       SET_FLAG(ADC12CTL1, ADC12DIV_0);         // divide clk by 8
        // sample and hold time four adc12clk cycles
        SET_FLAG(ADC12CTL0, SHT0_0);   
***************
*** 125,128 ****
--- 129,133 ----
      }
  
+ 
      SET_FLAG(ADC12MCTL0, INCH_5);  // x accel
      SET_FLAG(ADC12MCTL1, INCH_4);  // y accel
***************
*** 138,142 ****
      SET_FLAG(ADC12MCTL4, SREF_1);             // Vref = Vref+ and Vr-
      SET_FLAG(ADC12MCTL5, SREF_1);             // Vref = Vref+ and Vr-
- 
      
      /* set up for three adc channels -> three adcmem regs -> three dma channels in round-robin */
--- 143,146 ----
***************
*** 150,154 ****
      SET_FLAG(ADC12MCTL6, EOS);       // sez "this is the last reg" 
      */
-     //    SET_FLAG(ADC12IE, 0x0008);       // wait to enable until after the three dma-mapped channels
  
      setupDMA();
--- 154,157 ----
***************
*** 158,161 ****
--- 161,165 ----
      call DMA2.beginTransfer();
  
+ 
      call DMA0.ADCbeginConversion();
  	
***************
*** 176,194 ****
  
    task void ship_contents() {
!     if(enable_shipping){
!       call Leds.redToggle(); 
!       call UDPClient.send((uint8_t *)abuf, 12);
!     }
!     //      call TCPClient.write((uint8_t *)abuf, 12);
    }
  
    task void adc3Results() { 
      atomic gbuf[0] = ADC12MEM3;
!     //    SET_FLAG(ADC12IE, 0x0038);
    } 
  
    task void adc4Results() { 
      atomic gbuf[1] = ADC12MEM4;
!     //    SET_FLAG(ADC12IE, 0x0038);
    } 
  
--- 180,195 ----
  
    task void ship_contents() {
!     if(enable_shipping)
!       call TCPClient.write((uint8_t *)abuf, 12);
    }
  
    task void adc3Results() { 
      atomic gbuf[0] = ADC12MEM3;
!     SET_FLAG(ADC12IE, 0x0038);
    } 
  
    task void adc4Results() { 
      atomic gbuf[1] = ADC12MEM4;
!     SET_FLAG(ADC12IE, 0x0038);
    } 
  
***************
*** 203,215 ****
      
    task void dma2Results() { 
!     atomic{
        abuf[0] = inbuf0[dma_transfers];
        abuf[1] = inbuf1[dma_transfers];
        abuf[2] = inbuf2[dma_transfers];
      }
-     //    post ship_contents();
  
      dma_transfers++;
-     call Leds.orangeToggle();
  
      if(dma_transfers == 128){
--- 204,215 ----
      
    task void dma2Results() { 
!     /*
!       atomic{
        abuf[0] = inbuf0[dma_transfers];
        abuf[1] = inbuf1[dma_transfers];
        abuf[2] = inbuf2[dma_transfers];
      }
  
      dma_transfers++;
  
      if(dma_transfers == 128){
***************
*** 217,233 ****
  
        dma_transfers = 0;
!       atomic{
! 	DMA0DA = (uint16_t)inbuf0;
! 	DMA1DA = (uint16_t)inbuf1;
! 	DMA2DA = (uint16_t)inbuf2;
!       }
!       /*
!       call DMA0.setDestinationAddress(inbuf0);
!       call DMA1.setDestinationAddress(inbuf1);
!       call DMA2.setDestinationAddress(inbuf2);
!       */
        call DMA0.ADCbeginConversion();
      }
! 
      SET_FLAG(ADC12IE, 0x0008);
    }	
--- 217,228 ----
  
        dma_transfers = 0;
!       
!       DMA0DA = (uint16_t)inbuf0;
!       DMA1DA = (uint16_t)inbuf1;
!       DMA2DA = (uint16_t)inbuf2;
! 
        call DMA0.ADCbeginConversion();
      }
!     */
      SET_FLAG(ADC12IE, 0x0008);
    }	
***************
*** 240,249 ****
      call AccelStdControl.init();
  
-     udpaddr.ip[0] = 63;
-     udpaddr.ip[1] = 118;
-     udpaddr.ip[2] = 194;
-     udpaddr.ip[3] = 100;
-     udpaddr.port = 5666;
- 
      dma_transfers = 0;
      
--- 235,238 ----
***************
*** 288,291 ****
--- 277,282 ----
    }
  
+   char * do_id(char * in, char * out, char * outmax) { 
+   }
    char * do_gyros(char * in, char * out, char * outmax) { 
      if(!enable_gyros){
***************
*** 299,316 ****
      return out;
    }
        
    char * do_sends(char * in, char * out, char * outmax) { 
      if(!enable_shipping){
!       enable_shipping = 1;
!       //      call TCPClient.connect(63, 118, 194, 100, 5067);
!       call UDPClient.connect(&udpaddr);
      }
      else{
        enable_shipping = 0;
!       //      call TCPClient.close();
!       call UDPClient.connect(NULL);   // unbinds socket
        call Leds.greenOff();
      }
-     sprintf(msgbuf, "sending enable now %d", enable_shipping);
  
      return out;
--- 290,356 ----
      return out;
    }
+ 
+   result_t parse_address(char * address, 
+ 			 uint8_t * a1,
+ 			 uint8_t * a2,
+ 			 uint8_t * a3,
+ 			 uint8_t * a4) {
+     char * scout, * period;
+     char buffer[64];
+     uint8_t offset;
+ 
+     scout = address;
+     if((period = strchr(scout, '.'))){
+       offset = period - scout;
+       memcpy(buffer, scout, offset);
+       buffer[offset] = '\0';
+       *a1 = atoi(buffer);
+       scout += offset + 1;
+ 
+       if((period = strchr(scout, '.'))){
+ 	offset = period - scout;
+ 	memcpy(buffer, scout, offset);
+ 	buffer[offset] = '\0';
+ 	*a2 = atoi(buffer);
+ 	scout += offset + 1;
+       }
+       if((period = strchr(scout, '.'))){
+ 	offset = period - scout;
+ 	memcpy(buffer, scout, offset);
+ 	buffer[offset] = '\0';
+ 	*a3 = atoi(buffer);
+ 	scout += offset + 1;
+       }
+       strcpy(buffer, scout);
+       *a4 = atoi(buffer);
        
+       return SUCCESS;
+     }
+     else
+       return FAIL;
+   }
+ 
    char * do_sends(char * in, char * out, char * outmax) { 
+     uint8_t a1, a2, a3, a4;
+ 
      if(!enable_shipping){
!       if(parse_address(in, &a1, &a2, &a3, &a4) == FAIL){
! 	a1 = 63;
! 	a2 = 118;
! 	a3 = 194;
! 	a4 = 100;
!       }
!       sprintf(msgbuf, "requested connection to %d %d %d %d", a1, a2, a3, a4);
! 
!       call Leds.yellowOn();
!       call TCPClient.connect(a1, a2, a3, a4, 5067);
      }
      else{
        enable_shipping = 0;
!       call TCPClient.close();
!       call Leds.yellowOff();
        call Leds.greenOff();
+       sprintf(msgbuf, "requested connection closed");
      }
  
      return out;
***************
*** 319,322 ****
--- 359,363 ----
    event void TCPClient.connectionMade(uint8_t status) {
      call Leds.greenOn();
+     call Leds.yellowOff();
  
      enable_shipping = 1;
***************
*** 326,336 ****
    }
  
-   event void UDPClient.sendDone() {
-   }
- 
    event    void     TCPClient.dataAvailable(uint8_t *buf, uint16_t len) {}
  
-   event    void     UDPClient.receive(const struct udp_address *addr, uint8_t *buf, uint16_t len) {}
- 
    event    void     TCPClient.connectionFailed(uint8_t reason) { 
      myreason = reason;
--- 367,372 ----
***************
*** 342,408 ****
  
    async event void DMA0.transferComplete() {
!     atomic DMA0DA += 2;
    }
  
    async event void DMA1.transferComplete() {
!     atomic DMA1DA += 2;
    }
  
    async event void DMA2.transferComplete() {
!     atomic DMA2DA += 2;
!     post dma2Results();
    }
  
    async event void DMA0.ADCInterrupt(uint8_t regnum) {
!     //    adcregnum = regnum;
!     atomic{
!       abuf[3] = ADC12MEM3;
!       ADC12IE = 0x0010;
!     }
!     /*    atomic {
!       if(adcifg_count++ > 128){
! 	ADC12CTL0 = 0;
! 	ADC12IE = 0;
!       }
!     }	
!     */       
!     //    post adc3Results();
    } 
    async event void DMA1.ADCInterrupt(uint8_t regnum) {
!     atomic {
!       abuf[4] = ADC12MEM4;
!       ADC12IE = 0x0020;
!     }
!     /*
!     atomic {
!       if(adcifg_count++ > 128){
! 	ADC12CTL0 = 0;
! 	ADC12IE = 0;
!       }
!     }	
!     */       
!     //    post adc4Results();
    }
    async event void DMA2.ADCInterrupt(uint8_t regnum) {
!     atomic{
!       abuf[5] = ADC12MEM5;
!       ADC12IE = 0;
!     }
!     call Leds.yellowToggle();
      post ship_contents();
- 
-     /*
-     atomic {
-       if(adcifg_count++ > 128){
- 	ADC12CTL0 = 0;
- 	ADC12IE = 0;
-       }
-     }	
-     */       
-     //    post adc5Results();
    }
  
!   event void Client.connected( bool isConnected ) {
!   }
  
    const struct Param s_ADCRegs[] = {
--- 378,412 ----
  
    async event void DMA0.transferComplete() {
!     //    atomic DMA0DA += 2;
    }
  
    async event void DMA1.transferComplete() {
!     //    atomic DMA1DA += 2;
    }
  
    async event void DMA2.transferComplete() {
!     //    atomic DMA2DA += 2;
! 
!     SET_FLAG(ADC12IE, 0x0008);
!     //    call Leds.redToggle();
!     //    post dma2Results();
    }
  
    async event void DMA0.ADCInterrupt(uint8_t regnum) {
!     atomic  abuf[3] = ADC12MEM3;
!     ADC12IE = 0x0010;
    } 
    async event void DMA1.ADCInterrupt(uint8_t regnum) {
!     atomic abuf[4] = ADC12MEM4;
!     ADC12IE = 0x0020;
    }
    async event void DMA2.ADCInterrupt(uint8_t regnum) {
!     atomic abuf[5] = ADC12MEM5;
!     ADC12IE = 0;
!     //    call Leds.greenToggle();
      post ship_contents();
    }
  
!   event void Client.connected( bool isConnected ) {}
  
    const struct Param s_ADCRegs[] = {
***************
*** 476,480 ****
  	  //this is a hack to prevent hanging telnet.process if nothing is returned from service function
  	  if(extrastuff)
! 	    out += snprintf(out, outmax - out, "%s\r\n", extrastuff);
  	  else
  	    out += snprintf(out, outmax - out, "%s\r\n", "dummy");
--- 480,484 ----
  	  //this is a hack to prevent hanging telnet.process if nothing is returned from service function
  	  if(extrastuff)
! 	    out += snprintf(out, outmax - out, "%s\r\n", msgbuf);
  	  else
  	    out += snprintf(out, outmax - out, "%s\r\n", "dummy");

Index: GyroTiltApp.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/hwtest/shimmer/GyroTilt/GyroTiltApp.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GyroTiltApp.nc	7 Sep 2006 18:36:07 -0000	1.1
--- GyroTiltApp.nc	18 Dec 2006 16:56:23 -0000	1.2
***************
*** 66,72 ****
    //  GyroTiltAppM.Accel             -> MMA7260_AccelM;
  
!   //  TimeM.LocalTime              -> TimerC;
    //  TimeM.Timer                  -> TimerC.Timer[unique("Timer")];
!   //  GyroTiltAppM.LocalTime       -> TimerC;
  
    /* telnet stuff */
--- 66,72 ----
    //  GyroTiltAppM.Accel             -> MMA7260_AccelM;
  
!   //TimeM.LocalTime              -> TimerC;
    //  TimeM.Timer                  -> TimerC.Timer[unique("Timer")];
!   GyroTiltAppM.LocalTime       -> TimerC;
  
    /* telnet stuff */
***************
*** 75,83 ****
    GyroTiltAppM.Client        -> IPClientC;
    GyroTiltAppM.TCPClient     -> IPClientC.TCPClient[unique("TCPClient")];
  
!   //  GyroTiltAppM.TelnetRun         -> TelnetM.Telnet[unique("Telnet")];
  
    GyroTiltAppM.PVStdControl      -> ParamViewM;
!   //  GyroTiltAppM.TelnetStdControl  -> TelnetM;
  
    TelnetM.TCPServer            -> IPClientC.TCPServer[unique("TCPServer")];
--- 75,84 ----
    GyroTiltAppM.Client        -> IPClientC;
    GyroTiltAppM.TCPClient     -> IPClientC.TCPClient[unique("TCPClient")];
+   GyroTiltAppM.UDPClient     -> IPClientC.UDPClient[unique("UDPClient")];
  
!   GyroTiltAppM.TelnetRun         -> TelnetM.Telnet[unique("Telnet")];
  
    GyroTiltAppM.PVStdControl      -> ParamViewM;
!   GyroTiltAppM.TelnetStdControl  -> TelnetM;
  
    TelnetM.TCPServer            -> IPClientC.TCPServer[unique("TCPServer")];

Index: GyroTiltAppM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/handhelds/hwtest/shimmer/GyroTilt/GyroTiltAppM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GyroTiltAppM.nc	7 Sep 2006 18:36:07 -0000	1.1
--- GyroTiltAppM.nc	18 Dec 2006 16:56:23 -0000	1.2
***************
*** 51,55 ****
      /* telnet stuff */
      interface StdControl as IPStdControl;
!     //    interface StdControl as TelnetStdControl;
      interface StdControl as PVStdControl;
  
--- 51,55 ----
      /* telnet stuff */
      interface StdControl as IPStdControl;
!     interface StdControl as TelnetStdControl;
      interface StdControl as PVStdControl;
  
***************
*** 63,68 ****
      interface Client; 
      interface TCPClient;
  
!     //    interface LocalTime;
      
  
--- 63,69 ----
      interface Client; 
      interface TCPClient;
+     interface UDPClient;
  
!     interface LocalTime;
      
  
***************
*** 82,110 ****
  #define MESSAGE_MAX_LENGTH 128
  
!   uint8_t dma_transfers, myreason = 0, enable_shipping = 0, enable_gyros = 0, current_buffer = 0, write_step;
!   uint16_t inbuf0[256], inbuf1[256], inbuf2[256], *curr0, *curr1, *curr2;
!   //uint16_t sbuf0[36], sbuf1[36];
    uint8_t msgbuf[128], sectornum = 0, shipnum = 0;
!   uint16_t cardbuf[256];
!   norace uint32_t current_sector = 2222, shipping_sector;
    
-   void initIP() {
-     call Leds.redOn();
-     //    call PVStdControl.init();
-     //    call TelnetStdControl.init();
-     call IPStdControl.init();
-   }
- 
-   void startIP() {
-     call IPStdControl.start();
-     //    call TelnetStdControl.start();
-   }
- 
-   void stopIP(){
-     //    call TelnetStdControl.stop();
-     call IPStdControl.stop();
-     call Leds.redOff();
-   }
-     
    void setupDMA() {
      call DMA0.init();
--- 83,94 ----
  #define MESSAGE_MAX_LENGTH 128
  
!   uint8_t dma_transfers, myreason = 0, enable_shipping = 0, enable_gyros = 0, write_step;
!   norace uint8_t current_buffer = 0;
!   uint16_t sbuf0[36], sbuf1[36];
    uint8_t msgbuf[128], sectornum = 0, shipnum = 0;
!   //  uint16_t cardbuf[256];
!   //  norace uint32_t current_sector = 2222, shipping_sector;
!   struct udp_address udpaddr;
    
    void setupDMA() {
      call DMA0.init();
***************
*** 112,122 ****
      call DMA2.init();
  
!     call DMA0.setDestinationAddress((uint16_t)inbuf0);
!     call DMA1.setDestinationAddress((uint16_t)inbuf1);
!     call DMA2.setDestinationAddress((uint16_t)inbuf2);
  
!     call DMA0.setBlockSize(1);
!     call DMA1.setBlockSize(1);
!     call DMA2.setBlockSize(1);
      /*    
      CLR_FLAG(DMA0CTL, DMADSTINCR_3);    // clear increment (doesn't work?) for manual increment
--- 96,106 ----
      call DMA2.init();
  
!     call DMA0.setDestinationAddress((uint16_t)&sbuf0[0]);
!     call DMA1.setDestinationAddress((uint16_t)&sbuf0[12]);
!     call DMA2.setDestinationAddress((uint16_t)&sbuf0[24]);
  
!     call DMA0.setBlockSize(12);
!     call DMA1.setBlockSize(12);
!     call DMA2.setBlockSize(12);
      /*    
      CLR_FLAG(DMA0CTL, DMADSTINCR_3);    // clear increment (doesn't work?) for manual increment
***************
*** 138,142 ****
        SET_FLAG(ADC12CTL1, ADC12SSEL_1);         // clk from aclk
        
!       SET_FLAG(ADC12CTL1, ADC12DIV_1);         // divide clk by 8
        // sample and hold time four adc12clk cycles
        SET_FLAG(ADC12CTL0, SHT0_0);   
--- 122,126 ----
        SET_FLAG(ADC12CTL1, ADC12SSEL_1);         // clk from aclk
        
!       SET_FLAG(ADC12CTL1, ADC12DIV_0);         // with ekg, _3 is about 180hz, _2 ~= 210 hz, _1 ~= 320 hz, _0 ~= 640 hz
        // sample and hold time four adc12clk cycles
        SET_FLAG(ADC12CTL0, SHT0_0);   
***************
*** 154,157 ****
--- 138,145 ----
      SET_FLAG(ADC12MCTL2, EOS);       //sez "this is the last reg" 
  
+     SET_FLAG(ADC12MCTL0, SREF_1);             // Vref = Vref+ and Vr-
+     SET_FLAG(ADC12MCTL1, SREF_1);             // Vref = Vref+ and Vr-
+     SET_FLAG(ADC12MCTL2, SREF_1);             // Vref = Vref+ and Vr-
+     
      /* set up for three adc channels -> three adcmem regs -> three dma channels in round-robin */
      /* clear init defaults first */
***************
*** 167,202 ****
  
      call DMA0.ADCbeginConversion();
-     /*	
-     *curr0 = ADC12MEM0;
-     *curr0 = 0;
-     *curr1 = ADC12MEM1;
-     *curr1 = 0;
-     *curr2 = ADC12MEM2;
-     *curr2 = 0;
-     */
    }
!   /*
!   void ship_contents() {
      if(enable_shipping){
        if(current_buffer == 1)
!  	call TCPClient.write((uint8_t *)sbuf0, 72);
        else
! 	call TCPClient.write((uint8_t *)sbuf1, 72);
      }
    }
-   */
    
    task void adcResults() { 
    } 
  
-   task void ship_contents() {
-     uint8_t rval;
- 
-     if((rval = call SD.readSector(shipping_sector++, (uint8_t *)cardbuf)))
-       sprintf(msgbuf, "bad read, error=%d", rval);
- 
-     call TCPClient.write((uint8_t *)cardbuf, 72);
-   }
- 
    task void dma0Results() { 
    }	 
--- 155,176 ----
  
      call DMA0.ADCbeginConversion();
    }
! 
!   
!   task void ship_contents() {
      if(enable_shipping){
+       enable_shipping = 0;
        if(current_buffer == 1)
! 	call UDPClient.send((uint8_t *)sbuf0, 72);
!       //	call TCPClient.write((uint8_t *)sbuf0, 72);
        else
! 	call UDPClient.send((uint8_t *)sbuf1, 72);
!       //	call TCPClient.write((uint8_t *)sbuf1, 72);
      }
    }
    
    task void adcResults() { 
    } 
  
    task void dma0Results() { 
    }	 
***************
*** 206,265 ****
      
    task void dma2Results() { 
-     uint8_t rval;
-     //    tbuf[dma_transfers] = call LocalTime.read();
- 
-     dma_transfers++;
-     if(dma_transfers == 255){
-       call DMA0.ADCstopConversion();
-       dma_transfers = 0;
-       call Leds.orangeOn();
- 
- 	/*
- 	  atomic{
- 	  if(current_buffer == 0){
- 	  current_buffer = 1;
- 	  DMA0DA = &sbuf1[0];
- 	  DMA1DA = &sbuf1[12];
- 	  DMA2DA = &sbuf1[24];
- 	  }
- 	  else{
- 	  current_buffer = 0;
- 	  DMA0DA = &sbuf0[0];
- 	  DMA1DA = &sbuf0[12];
- 	  DMA2DA = &sbuf0[24];
- 	  }
- 	  }
- 	  ship_contents(); 
- 
-       */
-       call Leds.redOn();
-       if((rval = call SD.writeSector(current_sector++, (uint8_t *)inbuf0)))
- 	sprintf(msgbuf, "bad write, error=%d", rval);
-       if((rval = call SD.writeSector(current_sector++, (uint8_t *)inbuf1)))
- 	sprintf(msgbuf, "bad write, error=%d", rval);
-       if((rval = call SD.writeSector(current_sector++, (uint8_t *)inbuf2)))
- 	sprintf(msgbuf, "bad write, error=%d", rval);
-       call Leds.redOff();
- 
-       atomic{
- 	DMA0DA = (uint16_t)inbuf0;
- 	DMA1DA = (uint16_t)inbuf1;
- 	DMA2DA = (uint16_t)inbuf2;
-       }
- 
-       write_step = 0;
- 
-       call TCPClient.connect(63, 118, 194, 100, 5067);
-       //      initIP();
-       //      startIP();
- 
-     }
    }	
  
    command result_t StdControl.init() {
!     initIP();
!     call SDStdControl.init();
  
-     shipping_sector = current_sector;
      dma_transfers = 0;
      
--- 180,192 ----
      
    task void dma2Results() { 
    }	
  
    command result_t StdControl.init() {
!     call PVStdControl.init();
!     call TelnetStdControl.init();
!     call IPStdControl.init();
! 
!     //    call SDStdControl.init();
  
      dma_transfers = 0;
      
***************
*** 272,286 ****
      TOSH_SEL_ADC_2_MODFUNC();
      TOSH_SEL_ADC_6_MODFUNC();
! 
      TOSH_MAKE_PROG_OUT_OUTPUT();
      TOSH_SEL_PROG_OUT_IOFUNC();
  
!     /*
!     memset(inbuf0, 0, sizeof(inbuf0));
!     curr0 = inbuf0;
!     memset(inbuf1, 0, sizeof(inbuf1));
!     curr1 = inbuf1;
!     memset(inbuf2, 0, sizeof(inbuf2));
!     curr2 = inbuf2;
      */
      call Leds.init();
--- 199,216 ----
      TOSH_SEL_ADC_2_MODFUNC();
      TOSH_SEL_ADC_6_MODFUNC();
!     /*
      TOSH_MAKE_PROG_OUT_OUTPUT();
      TOSH_SEL_PROG_OUT_IOFUNC();
  
!     // pins for tilt switches 
!     TOSH_MAKE_SER0_CTS_INPUT();   // tiltzy_n:  when enabled, this means that this switch is upright
!     TOSH_MAKE_SOMI0_INPUT();      // tiltxy_n:  ditto
!     TOSH_MAKE_UTXD0_INPUT();      // tiltxy_ccw: when disabled (logical false), this switch is tilted "left"
!     TOSH_MAKE_URXD0_INPUT();      // tiltzy_ccw: when disabled (logical false), this switch is tilted "left"
! 
!     TOSH_SEL_SER0_CTS_IOFUNC();
!     TOSH_SEL_SOMI0_IOFUNC();
!     TOSH_SEL_UTXD0_IOFUNC();
!     TOSH_SEL_URXD0_IOFUNC();
      */
      call Leds.init();
***************
*** 290,295 ****
  
    command result_t StdControl.start() {
!     startIP();
!     call SDStdControl.start();
  
      //    TOSH_CLR_PROG_OUT_PIN();   // this pin is gyro pwren, logical false
--- 220,227 ----
  
    command result_t StdControl.start() {
!     call IPStdControl.start();
!     call TelnetStdControl.start();
! 
!     //    call SDStdControl.start();
  
      //    TOSH_CLR_PROG_OUT_PIN();   // this pin is gyro pwren, logical false
***************
*** 304,330 ****
    }
  
!   char * do_gyros(char * in, char * out, char * outmax) { 
!     if(!enable_gyros){
!       TOSH_CLR_PROG_OUT_PIN();   // turn on, logical false
!       enable_gyros = 1;
!     }
!     else{
!       TOSH_SET_PROG_OUT_PIN();
!       enable_gyros = 0;
      }
!     return out;
    }
!       
    char * do_sends(char * in, char * out, char * outmax) { 
      if(!enable_shipping){
!       call TCPClient.connect(63, 118, 194, 100, 5067);
      }
!   else{
        enable_shipping = 0;
!       call TCPClient.close();
        call Leds.greenOff();
      }
-     sprintf(msgbuf, "sending enable now %d", enable_shipping);
- 
      return out;
    }
--- 236,306 ----
    }
  
!   result_t parse_address(char * address, 
! 			 uint8_t * a1,
! 			 uint8_t * a2,
! 			 uint8_t * a3,
! 			 uint8_t * a4) {
!     char * scout, * period;
!     char buffer[64];
!     uint8_t offset;
! 
!     scout = address;
!     if((period = strchr(scout, '.'))){
!       offset = period - scout;
!       memcpy(buffer, scout, offset);
!       buffer[offset] = '\0';
!       *a1 = atoi(buffer);
!       scout += offset + 1;
! 
!       if((period = strchr(scout, '.'))){
! 	offset = period - scout;
! 	memcpy(buffer, scout, offset);
! 	buffer[offset] = '\0';
! 	*a2 = atoi(buffer);
! 	scout += offset + 1;
!       }
!       if((period = strchr(scout, '.'))){
! 	offset = period - scout;
! 	memcpy(buffer, scout, offset);
! 	buffer[offset] = '\0';
! 	*a3 = atoi(buffer);
! 	scout += offset + 1;
!       }
!       strcpy(buffer, scout);
!       *a4 = atoi(buffer);
!       
!       return SUCCESS;
      }
!     else
!       return FAIL;
    }
! 
    char * do_sends(char * in, char * out, char * outmax) { 
+     udpaddr.port = 5067;
+ 
      if(!enable_shipping){
!       if(parse_address(in, 
! 		       &udpaddr.ip[0], 
! 		       &udpaddr.ip[1], 
! 		       &udpaddr.ip[2], 
! 		       &udpaddr.ip[3]) == FAIL){
! 	udpaddr.ip[0] = 63;
! 	udpaddr.ip[1] = 118;
! 	udpaddr.ip[2] = 194;
! 	udpaddr.ip[3] = 100;
!       }
!       sprintf(msgbuf, "requested connection to %d.%d.%d.%d", udpaddr.ip[0], udpaddr.ip[1], udpaddr.ip[2], udpaddr.ip[3]);
! 
!       //      call TCPClient.connect(udpaddr.ip[0], udpaddr.ip[1], udpaddr.ip[2], udpaddr.ip[3], udpaddr.port);
!       enable_shipping = 1;
!       call UDPClient.connect(&udpaddr);
      }
!     else{
        enable_shipping = 0;
!       sprintf(msgbuf, "requested connection closed");
!       //      call TCPClient.close();
!       call UDPClient.connect(NULL);
        call Leds.greenOff();
      }
      return out;
    }
***************
*** 332,427 ****
    event void TCPClient.connectionMade(uint8_t status) {
      call Leds.greenOn();
! 
!     post ship_contents();
    }  
  
    event void TCPClient.writeDone() {
-     write_step++;
-     switch (write_step) {
-     case 1:
-       call TCPClient.write((uint8_t *)(cardbuf + 36), 72);
-       break;
-     case 2:
-       call TCPClient.write((uint8_t *)(cardbuf + 72), 72);
-       break;
-     case 3:
-       call TCPClient.write((uint8_t *)(cardbuf + 108), 72);
-       break;
-     case 4:
-       call TCPClient.write((uint8_t *)(cardbuf + 144), 72);
-       break;
-     case 5:
-       call TCPClient.write((uint8_t *)(cardbuf + 180), 72);
-       break;
-     case 6:
-       call TCPClient.write((uint8_t *)(cardbuf + 216), 72);
-       break;
-     case 7:
-       call TCPClient.write((uint8_t *)(cardbuf + 252), 8);
-       break;
-     case 8:
-       post ship_contents();
-       break;
-     case 9:
-       call TCPClient.write((uint8_t *)(cardbuf + 36), 72);
-       break;
-     case 10:
-       call TCPClient.write((uint8_t *)(cardbuf + 72), 72);
-       break;
-     case 11:
-       call TCPClient.write((uint8_t *)(cardbuf + 108), 72);
-       break;
-     case 12:
-       call TCPClient.write((uint8_t *)(cardbuf + 144), 72);
-       break;
-     case 13:
-       call TCPClient.write((uint8_t *)(cardbuf + 180), 72);
-       break;
-     case 14:
-       call TCPClient.write((uint8_t *)(cardbuf + 216), 72);
-       break;
-     case 15:
-       call TCPClient.write((uint8_t *)(cardbuf + 252), 8);
-       break;
-     case 16:
-       post ship_contents();
-       break;
-     case 17:
-       call TCPClient.write((uint8_t *)(cardbuf + 36), 72);
-       break;
-     case 18:
-       call TCPClient.write((uint8_t *)(cardbuf + 72), 72);
-       break;
-     case 19:
-       call TCPClient.write((uint8_t *)(cardbuf + 108), 72);
-       break;
-     case 20:
-       call TCPClient.write((uint8_t *)(cardbuf + 144), 72);
-       break;
-     case 21:
-       call TCPClient.write((uint8_t *)(cardbuf + 180), 72);
-       break;
-     case 22:
-       call TCPClient.write((uint8_t *)(cardbuf + 216), 72);
-       break;
-     case 23:
-       call TCPClient.write((uint8_t *)(cardbuf + 252), 8);
-       break;
-     default:
-       call TCPClient.close();
-       call Leds.greenOff();
-       //      stopIP();
-       write_step = 0;
- 
-       call Leds.orangeOff();
-       
-       call DMA0.ADCbeginConversion();
- 
-       break;
-     }
    }
  
    event    void     TCPClient.dataAvailable(uint8_t *buf, uint16_t len) {}
  
    event    void     TCPClient.connectionFailed(uint8_t reason) { 
      myreason = reason;
--- 308,326 ----
    event void TCPClient.connectionMade(uint8_t status) {
      call Leds.greenOn();
!     
!     enable_shipping = 1;
!     //    post ship_contents();
    }  
  
+   event void UDPClient.sendDone() {
+     enable_shipping = 1;
+   }
    event void TCPClient.writeDone() {
    }
  
    event    void     TCPClient.dataAvailable(uint8_t *buf, uint16_t len) {}
  
+   event    void     UDPClient.receive(const struct udp_address *addr, uint8_t *buf, uint16_t len) {}
+ 
    event    void     TCPClient.connectionFailed(uint8_t reason) { 
      myreason = reason;
***************
*** 433,446 ****
  
    async event void DMA0.transferComplete() {
-     atomic DMA0DA += 2;
    }
  
    async event void DMA1.transferComplete() {
-     atomic DMA1DA += 2;
    }
  
    async event void DMA2.transferComplete() {
!     atomic DMA2DA += 2;
!     post dma2Results();
    }
  
--- 332,358 ----
  
    async event void DMA0.transferComplete() {
    }
  
    async event void DMA1.transferComplete() {
    }
  
    async event void DMA2.transferComplete() {
!     if(current_buffer == 0){
!       atomic{
! 	DMA0DA = (uint16_t)&sbuf1[0];
! 	DMA1DA = (uint16_t)&sbuf1[12];
! 	DMA2DA = (uint16_t)&sbuf1[24];
!       }
!       current_buffer = 1;
!     }
!     else { 
!       atomic{
! 	DMA0DA = (uint16_t)&sbuf0[0];
! 	DMA1DA = (uint16_t)&sbuf0[12];
! 	DMA2DA = (uint16_t)&sbuf0[24];
!       }
!       current_buffer = 1;
!     }
!     post ship_contents();
    }
  
***************
*** 508,512 ****
    const struct TelnetCommand operations[] = {
      { "ship", &do_sends },
-     { "gyro", &do_gyros },
      { 0, NULL }
    };
--- 420,423 ----
***************
*** 527,531 ****
  	  //this is a hack to prevent hanging telnet.process if nothing is returned from service function
  	  if(extrastuff)
! 	    out += snprintf(out, outmax - out, "%s\r\n", extrastuff);
  	  else
  	    out += snprintf(out, outmax - out, "%s\r\n", "dummy");
--- 438,442 ----
  	  //this is a hack to prevent hanging telnet.process if nothing is returned from service function
  	  if(extrastuff)
! 	    out += snprintf(out, outmax - out, "%s\r\n", msgbuf);
  	  else
  	    out += snprintf(out, outmax - out, "%s\r\n", "dummy");



More information about the Tinyos-contrib-commits mailing list