Exemplo n.º 1
0
int
cmd_handler_cc2420(const uint8_t *data, int len)
{
  if(data[0] == '!') {
    if(data[1] == 'C' && len == 3) {
      printf("cc2420_cmd: setting channel: %d\n", data[2]);
      cc2420_set_channel(data[2]);
      return 1;
    } else if(data[1] == 'M' && len == 10) {
        printf("cc2420_cmd: Got MAC\n");
        memcpy(uip_lladdr.addr, data+2, sizeof(uip_lladdr.addr));
        linkaddr_set_node_addr((linkaddr_t *) uip_lladdr.addr);
        uint16_t shortaddr = (linkaddr_node_addr.u8[0] << 8) +
          linkaddr_node_addr.u8[1];
        cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, linkaddr_node_addr.u8);
        return 1;
      }
  } else if(data[0] == '?') {
    if(data[1] == 'C' && len == 2) {
      uint8_t buf[4];
      printf("cc2420_cmd: getting channel: %d\n", data[2]);
      buf[0] = '!';
      buf[1] = 'C';
      buf[2] = cc2420_get_channel();
      cmd_send(buf, 3);
      return 1;
    }
  }
  return 0;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_rfchannel_process, ev, data)
{
  struct {
    uint16_t len;
    uint16_t channel;
  } msg;
  const char *newptr;
  PROCESS_BEGIN();

  msg.channel = shell_strtolong(data, &newptr);
  
  /* If no channel was given on the command line, we print out the
     current channel. */
  if(newptr == data) {
    msg.channel = cc2420_get_channel();
  } else {
    cc2420_set_channel(msg.channel);
  }

  msg.len = 1;

  shell_output(&rfchannel_command, &msg, sizeof(msg), "", 0);

  PROCESS_END();
}
Exemplo n.º 3
0
/*
 * @brief Get the radio channel of any transceiver device
 *
 * @param t     The transceiver device
 *
 * @return The current radio channel of the transceiver, -1 on error
 */
static int32_t get_channel(transceiver_type_t t)
{
    switch (t) {
        case TRANSCEIVER_CC1100:
#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY))
            return cc110x_get_channel();
#elif MODULE_CC110X_LEGACY_CSMA
            return cc1100_get_channel();
#else
            return -1;
#endif
#ifdef MODULE_CC2420

        case TRANSCEIVER_CC2420:
            return cc2420_get_channel();
#endif
#ifdef MODULE_MC1322X

        case TRANSCEIVER_MC1322X:
            ///< TODO:implement return maca_get_channel();
            return -1;
#endif
#ifdef MODULE_NATIVENET

        case TRANSCEIVER_NATIVE:
            return nativenet_get_channel();
#endif
#ifdef MODULE_AT86RF231

        case TRANSCEIVER_AT86RF231:
            return at86rf231_get_channel();
#endif

        default:
            return -1;
    }
}
Exemplo n.º 4
0
// receives packet -- called in radio.c,radio.h
static void input(void)
{
  if(NETSTACK_FRAMER.parse() < 0)
    printf("Incorrect decode frame\n");


#ifdef SF_MOTE_TYPE_SENSOR
  /*-------------SN CODE----------------------*/

  ctimer_stop(&SN_sleep_timer);
  ctimer_stop(&SN_listen_timer);

  //check if the packet is from BS
  if (!rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER),&rimeaddr_null))
  {
    printf("Packet is not from base station, rejected!\n");
    incorrect_rx_counter++;

    if (incorrect_rx_counter < TOTAL_TS*2)
    {
      TDMA_SN_listen();
    }
    else
    {
      TDMA_SN_sleep();
    }
    return;
  }

  uint8_t *rx_pkt = (uint8_t *)packetbuf_dataptr();
  uint16_t rx_pkt_len = packetbuf_datalen();

  //turn off radio -- save power
  if(NETSTACK_RADIO.off() != 1)
  {
    printf("TDMA RDC: SN fails to turn off radio");
  }


  SN_RX_start_time = packetbuf_attr(PACKETBUF_ATTR_TIMESTAMP);

  /*--------from BS------------*/
  if (packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == PACKETBUF_ATTR_PACKET_TYPE_CMD)
  {
    //skip this period for TX
    rtimer_clock_t next_bkn_time = SN_RX_start_time + SEGMENT_PERIOD - GRD_PERIOD;
    rtimer_set(&SNTimer,next_bkn_time,0,NETSTACK_RADIO.on,NULL);

#ifdef SF_FEATURE_SHELL_OPT
    char command_string[128];
    strncpy(command_string,rx_pkt,rx_pkt_len);
    command_string[rx_pkt_len] = (uint8_t)'\0';
    PRINTF("RX Command: %s %d\n",command_string,strlen(command_string));

    //process_post(&remote_shell_process,remote_command_event_message,command_string);
    remote_shell_input();

    return;
#endif /* SF_FEATURE_SHELL_OPT */
  }
  else if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == PACKETBUF_ATTR_PACKET_TYPE_DATA)
  {
    //schedule for TX

    if (sf_tdma_slot_num != -1)
    {
      //PRINTF("Schedule for TX at Slot %d\n",my_slot);
      rtimer_clock_t SN_TX_time = SN_RX_start_time + (BS_period+TS_period * (sf_tdma_slot_num-1))-GRD_PERIOD+33;//20 might need to be changed later, do better calibration, increase to 33 if timing problems
      rtimer_set(&SNTimer,SN_TX_time,0,TDMA_SN_send,NULL);
    }
  }

  app_conn_input(); //For debugging timing
#endif /* SF_MOTE_TYPE_SENSOR */

#ifdef SF_MOTE_TYPE_AP
  /*-----------------BS CODE---------------*/

  rimeaddr_t *sent_sn_addr = packetbuf_addr(PACKETBUF_ADDR_SENDER);
  uint8_t sent_sn_id = sent_sn_addr->u8[0];

  rtimer_clock_t relFrameTime =(rtimer_clock_t)((packetbuf_attr(PACKETBUF_ATTR_TIMESTAMP)-radio_TX_time)%segment_period);
  uint16_t current_TS = (uint16_t)((relFrameTime-BS_period)/TS_period )+1;

  uint8_t packet_id = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);



  //set flag in pkt for TS occupancy
/*
  if(node_list[current_TS-1] == FREE_SLOT_CONST) //collision -- ask the node to find a new available slot
  {
    //node_list[current_TS] = rx_pkt[NODE_INDEX];
    node_list[current_TS-1] = sent_sn_id;
  }
*/

  PRINTF("[Sensor: %u] [Slot: %u] [Seq: %u]\n",
         sent_sn_id,current_TS,packetbuf_attr(PACKETBUF_ATTR_PACKET_ID));

  PRINTF("Channel: %d;", cc2420_get_channel());
  PRINTF("RSSI: %d\n", cc2420_last_rssi-45);

  if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == PACKETBUF_ATTR_PACKET_TYPE_DATA)
  {
    // callback to application layer
    app_conn_input();
  }

#endif /*SF_MOTE_TYPE_AP */


}
Exemplo n.º 5
0
/**
 * @brief start_discovery_process
 */
static void start_discovery_process(){
    uint16_t Tup_bound = 0, random_slot = 1;

    random_slot = 1 +  random_rand()%period_length;

    Tup_bound = (period_length*period_length)/4;

    //random_slot = random_slot + random_rand()%Tup_bound ;

    /*if (rimeaddr_node_addr.u8[0] < 130){
        random_slot = random_slot + random_rand()%period_length;
    }else{
        random_slot = random_slot + Tup_bound + random_rand()%period_length;
    }*/


    /*if(rimeaddr_node_addr.u8[0] == 10 || rimeaddr_node_addr.u8[0] == 11){
      //uint8_t channel_group = 1+rimeaddr_node_addr.u8[0]%GROUP_MERGE_SIZE;
      uint8_t channel_group = 1;
      
      
      random_slot = 0;

      cc2420_set_channel(i3e154_channels[channel_group]);
    }*/

    //enable random offset wait flag..
    rand_offset_wait_flag = 1;
    node_slots_offset     = random_slot;
    slot_upperBound       = 10000 - node_slots_offset;

    //-------- HERE WE DIVIDE NODES INTO CHANNELS.........
    if(1 /*rimeaddr_node_addr.u8[0] == 10*/){
        //uint8_t channel_group = 1+rimeaddr_node_addr.u8[0]%GROUP_MERGE_SIZE;
        uint8_t channel_group = 0;

        cc2420_set_channel(i3e154_channels[channel_group]);
    }

    COOJA_DEBUG_PRINTF("======>>>>> ID:%2u, channel:%2u\n", rimeaddr_node_addr.u8[0], cc2420_get_channel());
    //--------END GROUP CHANNEL SETTING...

    rtimer_clock_t startTime = RTIMER_NOW() + 2;

    int ret = rtimer_set(&generic_timer, startTime, 1,
                         (void (*)(struct rtimer *, void *))power_cycle, NULL);
    if(ret){
        PRINTF("synchronization failed\n");
    }
}