Exemplo n.º 1
0
void task_application_imu_radio(uint16_t input) {
   counter++;
   P1OUT ^= 0x02;                                // toggle P1.1 for debug
   P4OUT ^= 0x20;                                // toggle P4.5 for debug
   P1OUT |= 0x04;P1OUT &= ~0x04;                 // pulse P1.2 for debug
   if (counter==0) {
      leds_circular_shift();                     // circular shift LEDs for debug
   }
   //get RAM space for packet
   testImuRadiopacketToSend = openqueue_getFreePacketBuffer();
   //l1
   testImuRadiopacketToSend->l1_channel  = DEFAULTCHANNEL;
   //payload
   packetfunctions_reserveHeaderSize(testImuRadiopacketToSend,8);
   gyro_get_measurement(&(testImuRadiopacketToSend->payload[0]));
   P1OUT |= 0x04;P1OUT &= ~0x04;                 // pulse P1.2 for debug
   packetfunctions_reserveHeaderSize(testImuRadiopacketToSend,6);
   large_range_accel_get_measurement(&(testImuRadiopacketToSend->payload[0]));
   P1OUT |= 0x04;P1OUT &= ~0x04;                 // pulse P1.2 for debug
   packetfunctions_reserveHeaderSize(testImuRadiopacketToSend,6);
   magnetometer_get_measurement(&(testImuRadiopacketToSend->payload[0]));
   P1OUT |= 0x04;P1OUT &= ~0x04;                 // pulse P1.2 for debug
   packetfunctions_reserveHeaderSize(testImuRadiopacketToSend,10);
   sensitive_accel_temperature_get_measurement(&(testImuRadiopacketToSend->payload[0]));
   P1OUT |= 0x04;P1OUT &= ~0x04;                 // pulse P1.2 for debug
   packetfunctions_reserveFooterSize(testImuRadiopacketToSend,2);//space for radio to fill in CRC
   //send packet
   radio_send(testImuRadiopacketToSend);
}
Exemplo n.º 2
0
/**
\brief Transfer packet to MAC.

This function adds a IEEE802.15.4 header to the packet and leaves it the 
OpenQueue buffer. The very last thing it does is assigning this packet to the 
virtual component COMPONENT_RES_TO_IEEE802154E. Whenever it gets a change,
IEEE802154E will handle the packet.

\param [in] msg The packet to the transmitted

\returns E_SUCCESS iff successful.
*/
error_t res_send_internal(OpenQueueEntry_t* msg) {
   // assign a number of retries
   if (packetfunctions_isBroadcastMulticast(&(msg->l2_nextORpreviousHop))==TRUE) {
      msg->l2_retriesLeft = 1;
   } else {
      msg->l2_retriesLeft = TXRETRIES;
   }
   // record this packet's dsn (for matching the ACK)
   msg->l2_dsn = res_vars.dsn++;
   // this is a new packet which I never attempted to send
   msg->l2_numTxAttempts = 0;
   // transmit with the default TX power
   msg->l1_txPower = TX_POWER;
   // record the location, in the packet, where the l2 payload starts
   msg->l2_payload = msg->payload;
   // add a IEEE802.15.4 header
   ieee802154_prependHeader(msg,
                            msg->l2_frameType,
                            IEEE154_SEC_NO_SECURITY,
                            msg->l2_dsn,
                            &(msg->l2_nextORpreviousHop)
                            );
   // reserve space for 2-byte CRC
   packetfunctions_reserveFooterSize(msg,2);
   // change owner to IEEE802154E fetches it from queue
   msg->owner  = COMPONENT_RES_TO_IEEE802154E;
   return E_SUCCESS;
}
Exemplo n.º 3
0
void isr_button() {
   //prepare packet
   testRadioPacketToSend = openqueue_getFreePacketBuffer();
   //l1
   testRadioPacketToSend->l1_channel  = DEFAULTCHANNEL;
   //payload
   packetfunctions_reserveHeaderSize(testRadioPacketToSend,5);
   testRadioPacketToSend->payload[0]  =  0x01;
   testRadioPacketToSend->payload[1]  =  0x02;
   testRadioPacketToSend->payload[2]  =  0x03;
   testRadioPacketToSend->payload[3]  =  0x04;
   testRadioPacketToSend->payload[4]  =  0x05;
   packetfunctions_reserveFooterSize(testRadioPacketToSend,2); //space for radio to fill in CRC
   //send packet
   radio_send(testRadioPacketToSend);
   //debug
   P1OUT ^= 0x02;                                // toggle P1.1 (for debug)
   leds_circular_shift();                        // circular-shift LEDs (for debug)
}
Exemplo n.º 4
0
void task_application_intersection(uint16_t input) {
   counter++;
   P1OUT ^= 0x02;                                // toggle P1.1 for debug
   P4OUT ^= 0x20;                                // toggle P4.5 for debug
   P1OUT |= 0x04;P1OUT &= ~0x04;                 // pulse P1.2 for debug
   if (counter==0) {
      leds_circular_shift();                     // circular shift LEDs for debug
   }
   
   //get RAM space for packet
   testIntersection = openqueue_getFreePacketBuffer();
   //l1
   testIntersection->l1_channel  = DEFAULTCHANNEL;
   
   P1OUT ^= 0x02;                                // toggle P1.1 for debug
   
   magnetometer_get_measurement(mag_reading);
   mag_X = 0;
   mag_Y = 0;
   mag_Z = 0;
   
   mag_X |= mag_reading[0]<<8;
   mag_X |= mag_reading[1];

   mag_Y |= mag_reading[2]<<8;
   mag_Y |= mag_reading[3];
   
   mag_Z |= mag_reading[4]<<8;
   mag_Z |= mag_reading[5];
   
   //note: in the following I use functions for simple multiplications
   //and divisions for easy replacements in case the number of
   //instruction cycles is too large to be acceptable in this application
   mag_X = div_int(mag_X, 970);
   mag_Y = div_int(mag_Y, 970);
   mag_Z = div_int(mag_Z, 970);//970: look in HMC5843 datasheet

   XX = mul_int(mag_X,mag_X);
   YY = mul_int(mag_Y,mag_Y);
   ZZ = mul_int(mag_Z,mag_Z);
   
   mag_norm = XX + YY + ZZ; //no sqrt for faster execution
   filt_norm = LPF(mag_norm);
   
   //here we enter the state machine
   
   switch (state) {
   case NOCAR:
     if (filt_norm>=threshold){
       FSMcounter = 1;
       state = PERHAPS;
     }
     break; //else you break
     
   case PERHAPS:
     if (filt_norm >= threshold && FSMcounter < maxCount){
       FSMcounter++;
     }
     
     else if (filt_norm < threshold && FSMcounter >minCount)
       FSMcounter--;
     
     else if (filt_norm < threshold && FSMcounter <=minCount){
       state = NOCAR;
       FSMcounter=0;
       if(seenCar){
         seenCar=0;
         packetfunctions_reserveHeaderSize(testIntersection,1);
         testIntersection->payload[0] = seenCar;
         packetfunctions_reserveFooterSize(testIntersection,2);//space for radio to fill in CRC
         //send packet(noCar)
         radio_send(testIntersection);
       }
     }
     
     else if (filt_norm>=threshold && FSMcounter >=maxCount){
       state=CAR;
       if(!seenCar){
         seenCar=1;
         packetfunctions_reserveHeaderSize(testIntersection,1);
         testIntersection->payload[0] = seenCar;
         packetfunctions_reserveFooterSize(testIntersection,2);//space for radio to fill in CRC
         //send packet(Car)
         radio_send(testIntersection);
       }
     }
     break;
     
   case CAR:
     if (filt_norm < threshold){
       FSMcounter--;
       state = PERHAPS;
     }
     break;
   default:
     break;   
   }
   
}