Esempio n. 1
0
void bbk_init(){
   // prepare the resource descriptor for the /bbk path
   bbk_vars.desc.path0len             = sizeof(bbk_path0)-1;
   bbk_vars.desc.path0val             = (uint8_t*)(&bbk_path0);
   bbk_vars.desc.path1len             = 0;
   bbk_vars.desc.path1val             = NULL;
   bbk_vars.desc.componentID          = 0xcc; //just a number
   bbk_vars.desc.callbackRx           = &bbk_receive;
   bbk_vars.desc.callbackSendDone     = &bbk_sendDone;
   
   opencoap_register(&bbk_vars.desc);
   bbk_vars.timerId    = opentimers_start(BBKPERIOD,
                                                TIMER_PERIODIC,TIME_MS,
                                                bbk_timer_cb);
   bbk_vars.sequence  = 0;
}
Esempio n. 2
0
void cexample_init() {
   
   // prepare the resource descriptor for the /ex path
   cexample_vars.desc.path0len             = sizeof(cexample_path0)-1;
   cexample_vars.desc.path0val             = (uint8_t*)(&cexample_path0);
   cexample_vars.desc.path1len             = 0;
   cexample_vars.desc.path1val             = NULL;
   cexample_vars.desc.componentID          = COMPONENT_CEXAMPLE;
   cexample_vars.desc.callbackRx           = &cexample_receive;
   cexample_vars.desc.callbackSendDone     = &cexample_sendDone;
   
   
   opencoap_register(&cexample_vars.desc);
   cexample_vars.timerId    = opentimers_start(CEXAMPLEPERIOD,
                                                TIMER_PERIODIC,TIME_MS,
                                                cexample_timer_cb);
}
Esempio n. 3
0
void rex_init() {
   
   // prepare the resource descriptor for the /rex path
   rex_vars.desc.path0len             = sizeof(rex_path0)-1;
   rex_vars.desc.path0val             = (uint8_t*)(&rex_path0);
   rex_vars.desc.path1len             = 0;
   rex_vars.desc.path1val             = NULL;
   rex_vars.desc.componentID          = COMPONENT_REX;
   rex_vars.desc.callbackRx           = &rex_receive;
   rex_vars.desc.callbackSendDone     = &rex_sendDone;
   
   
   opencoap_register(&rex_vars.desc);
   rex_vars.timerId    = opentimers_start(REXPERIOD,
                                                TIMER_PERIODIC,TIME_MS,
                                                rex_timer_cb);
}
Esempio n. 4
0
void rheli_init() {
   // initialize the heli drivers
   heli_init();
   
   // prepare the resource descriptor
   rheli_vars.desc.path0len            = sizeof(rheli_path0)-1;
   rheli_vars.desc.path0val            = (uint8_t*)(&rheli_path0);
   rheli_vars.desc.path1len            = 0;
   rheli_vars.desc.path1val            = NULL;
   rheli_vars.desc.componentID         = COMPONENT_RHELI;
   rheli_vars.desc.callbackRx          = &rheli_receive;
   rheli_vars.desc.callbackSendDone    = &rheli_sendDone;
   
   opencoap_register(&rheli_vars.desc);
   rheli_vars.timerId    = opentimers_start(1000,
                                            TIMER_PERIODIC,TIME_MS,
                                            rheli_timer);
}
Esempio n. 5
0
void rreg_init() {
   // prepare the resource descriptor for the /.well-known/core path
   rreg_vars.desc.path0len             = sizeof(rreg_path0)-1;
   rreg_vars.desc.path0val             = (uint8_t*)(&rreg_path0);
   rreg_vars.desc.path1len             = 0;
   rreg_vars.desc.path1val             = NULL;
   rreg_vars.desc.componentID          = COMPONENT_RREG;
   rreg_vars.desc.callbackRx           = &rreg_receive;
   rreg_vars.desc.callbackSendDone     = &rreg_sendDone;
   

   
   opencoap_register(&rreg_vars.desc);
   // register to the RD server every 30s
   rreg_vars.timerId    = opentimers_start(RREGPERIOD,
                                          TIMER_PERIODIC,TIME_MS,
                                          rreg_timer);
}
Esempio n. 6
0
owerror_t openserial_printCritical(uint8_t calling_component, uint8_t error_code,
                              errorparameter_t arg1,
                              errorparameter_t arg2) {
   // blink error LED, this is serious
   leds_error_blink();
   
   // schedule for the mote to reboot in 10s
   opentimers_start(10000,
                    TIMER_ONESHOT,TIME_MS,
                    board_reset);
   
   return openserial_printInfoErrorCritical(
      SERFRAME_MOTE2PC_CRITICAL,
      calling_component,
      error_code,
      arg1,
      arg2
   );
}
Esempio n. 7
0
void update(debugNeighborEntry_t* entry, uint8_t ind, char act)
{
table_update_vars.desc.path0len             = sizeof(table_update_path0)-1;
   table_update_vars.desc.path0val             = (uint8_t*)(&table_update_path0);
   table_update_vars.desc.path1len             = 0;
   table_update_vars.desc.path1val             = NULL;
   table_update_vars.desc.componentID          = COMPONENT_TABLE_UPDATE;
   table_update_vars.desc.callbackRx           = &table_update_receive;
   table_update_vars.desc.callbackSendDone     = &table_update_sendDone;

   opencoap_register(&table_update_vars.desc);
   i = ind;
   action = act; 
tableEntry = entry;
//scheduler_push_task(table_update_task_cb,TASKPRIO_COAP);
  table_update_vars.timerId    = opentimers_start(WAITPERIOD,
                                                TIMER_ONESHOT,TIME_MS,
                                                table_update_timer_cb);
}
Esempio n. 8
0
void rt_init() {
   // startup the sensor
   sensitive_accel_temperature_init();
   
   // prepare the resource descriptor for the /temp path
   rt_vars.desc.path0len             = sizeof(rt_path0)-1;
   rt_vars.desc.path0val             = (uint8_t*)(&rt_path0);
   rt_vars.desc.path1len             = 0;
   rt_vars.desc.path1val             = NULL;
   rt_vars.desc.componentID          = COMPONENT_RT;
   rt_vars.desc.callbackRx           = &rt_receive;
   rt_vars.desc.callbackSendDone     = &rt_sendDone;
   

   rt_vars.timerId    = opentimers_start(openrandom_get16b()%RTPERIOD,
                                          TIMER_PERIODIC,TIME_MS,
                                          rt_timer);
   opencoap_register(&rt_vars.desc);
}
Esempio n. 9
0
/**
\brief Initialize this module.
*/
void icmpv6rpl_init() {
   
   //===== reset local variables
   memset(&icmpv6rpl_vars,0,sizeof(icmpv6rpl_vars_t));
   
   //=== admin
   
   icmpv6rpl_vars.busySending               = FALSE;
   icmpv6rpl_vars.DODAGIDFlagSet            = 0;
   
   //=== DIO-related
   
   icmpv6rpl_vars.dio.rplinstanceId         = 0x00;        ///< TODO: put correct value
   icmpv6rpl_vars.dio.verNumb               = 0x00;        ///< TODO: put correct value
   // rank: to be populated upon TX
   icmpv6rpl_vars.dio.rplOptions            = MOP_DIO_A | \
                                              MOP_DIO_B | \
                                              MOP_DIO_C | \
                                              PRF_DIO_A | \
                                              PRF_DIO_B | \
                                              PRF_DIO_C | \
                                              G_DIO ;
   icmpv6rpl_vars.dio.DTSN                  = 0x33;        ///< TODO: put correct value
   icmpv6rpl_vars.dio.flags                 = 0x00;
   icmpv6rpl_vars.dio.reserved              = 0x00;
   // DODAGID: to be populated upon receiving DIO
   
   icmpv6rpl_vars.dioDestination.type = ADDR_128B;
   memcpy(&icmpv6rpl_vars.dioDestination.addr_128b[0],all_routers_multicast,sizeof(all_routers_multicast));
   
   icmpv6rpl_vars.periodDIO                 = TIMER_DIO_TIMEOUT+(openrandom_get16b()&0xff);
   icmpv6rpl_vars.timerIdDIO                = opentimers_start(
                                                icmpv6rpl_vars.periodDIO,
                                                TIMER_PERIODIC,
                                                TIME_MS,
                                                icmpv6rpl_timer_DIO_cb
                                             );
   
   //=== DAO-related
   
   icmpv6rpl_vars.dao.rplinstanceId         = 0x00;        ///< TODO: put correct value
   icmpv6rpl_vars.dao.K_D_flags             = FLAG_DAO_A   | \
                                              FLAG_DAO_B   | \
                                              FLAG_DAO_C   | \
                                              FLAG_DAO_D   | \
                                              FLAG_DAO_E   | \
                                              PRF_DIO_C    | \
                                              FLAG_DAO_F   | \
                                              D_DAO        |
                                              K_DAO;
   icmpv6rpl_vars.dao.reserved              = 0x00;
   icmpv6rpl_vars.dao.DAOSequence           = 0x00;
   // DODAGID: to be populated upon receiving DIO
   
   icmpv6rpl_vars.dao_transit.type          = OPTION_TRANSIT_INFORMATION_TYPE;
   // optionLength: to be populated upon TX
   icmpv6rpl_vars.dao_transit.E_flags       = E_DAO_Transit_Info;
   icmpv6rpl_vars.dao_transit.PathControl   = PC1_A_DAO_Transit_Info | \
                                              PC1_B_DAO_Transit_Info | \
                                              PC2_A_DAO_Transit_Info | \
                                              PC2_B_DAO_Transit_Info | \
                                              PC3_A_DAO_Transit_Info | \
                                              PC3_B_DAO_Transit_Info | \
                                              PC4_A_DAO_Transit_Info | \
                                              PC4_B_DAO_Transit_Info;  
   icmpv6rpl_vars.dao_transit.PathSequence  = 0x00; // to be incremented at each TX
   icmpv6rpl_vars.dao_transit.PathLifetime  = 0xAA;
   //target information
   icmpv6rpl_vars.dao_target.type  = OPTION_TARGET_INFORMATION_TYPE;
   icmpv6rpl_vars.dao_target.optionLength  = 0;
   icmpv6rpl_vars.dao_target.flags  = 0;
   icmpv6rpl_vars.dao_target.prefixLength = 0;
   
   icmpv6rpl_vars.periodDAO                 = TIMER_DAO_TIMEOUT+(openrandom_get16b()&0xff);
   icmpv6rpl_vars.timerIdDAO                = opentimers_start(
                                                icmpv6rpl_vars.periodDAO,
                                                TIMER_PERIODIC,
                                                TIME_MS,
                                                icmpv6rpl_timer_DAO_cb
                                             );
   
}
Esempio n. 10
0
void udprand_init() {
   udprand_vars.timerId    = opentimers_start(openrandom_get16b()%UDPRANDPERIOD,
                                          TIMER_PERIODIC,TIME_MS,
                                          udprand_timer);
}
Esempio n. 11
0
owerror_t osens_val_receive(
    OpenQueueEntry_t* msg,
    coap_header_iht*  coap_header,
    coap_option_iht*  coap_options
) {
    owerror_t outcome = E_FAIL;
    uint8_t n;
    static uint8_t buf[128];
    uint8_t *pbuf = &buf[0];
    uint8_t index;

    switch (coap_header->Code) {
    case COAP_CODE_REQ_GET:
        // reset packet payload
        msg->payload = &(msg->packet[127]);
        msg->length = 0;
        // /s
        if (((coap_options[1].length == 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) ||
                (coap_options[1].type != COAP_OPTION_NUM_URIPATH))
        {
        } // /s/1 or /s/12
        else if(((coap_options[1].length == 1 || coap_options[1].length == 2)) &&
                (coap_options[1].type == COAP_OPTION_NUM_URIPATH))
        {

            osens_point_t pt;
#if (MYLINKXS_LIGHT_CONTROL == 0)
            if(coap_options[1].length == 2)
                index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30);
            else
                index = coap_options[1].pValue[0] - 0x30;


            if(osens_get_point(index,&pt))
            {
                pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0);
                pbuf = insert_point_val(pbuf,&pt);
                pbuf = insert_str(pbuf,(uint8_t*)"}",1,0);


#if (ENABLE_DEBUG_RFF == 1) && (DBG_APP_1 == 1)
                uint8_t pos=0;
                uint8_t *paux;

                rffbuf[pos++]= 0x85;
                rffbuf[pos++]= index;
                paux  = (uint8_t*) &pt.value.fp32;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                paux = (uint8_t*) &pbuf[0];
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;
                rffbuf[pos++]= *paux++;

                openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos);
#endif
            }
            else
                pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0);
#else
            //QUANDO TRABALHANDO COM A LAMPADA ESTAVA ESTE OUTRO CODIGO
            //TODO!!! DEIXAR O CODIGO UNICO
            pt.type = OSENS_DT_U8;
            pt.value.u8 = light_get_value();

            pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0);
            pbuf = insert_point_val(pbuf,&pt);
            pbuf = insert_str(pbuf,(uint8_t*)"}",1,0);


#endif
            outcome = E_SUCCESS;

        }

        if(outcome == E_SUCCESS)
        {
            n = ((uint32_t)pbuf - (uint32_t)buf);
            packetfunctions_reserveHeaderSize(msg, 1 + n);
            msg->payload[0] = COAP_PAYLOAD_MARKER;
            memcpy(&msg->payload[1], buf, n);
            coap_header->Code = COAP_CODE_RESP_CONTENT;
        }

        break;

    case COAP_CODE_REQ_PUT:
        // reset packet payload
        msg->payload = &(msg->packet[127]);
        msg->length = 0;

#if (DEBUG_LOG_RIT  == 1)
        {
            uint8_t   pos=0;

            rffbuf[pos++]= RFF_COMPONENT_STORMCOAP_TX;
            rffbuf[pos++]= 0x01;
            rffbuf[pos++]= coap_options[1].length;
            rffbuf[pos++]= coap_options[2].length;
            rffbuf[pos++]= coap_options[1].type;
            rffbuf[pos++]= coap_options[2].type;
            //rffbuf[pos++]= sensor_points.points[0].value.value.u8;

            openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos);
        }
#endif

        // /s/2/-12.45 or /s/12/12.45
        if((coap_options[1].length == 1 || coap_options[1].length == 2) &&
                (coap_options[2].length > 0) &&
                (coap_options[1].type == COAP_OPTION_NUM_URIPATH) &&
                (coap_options[2].type == COAP_OPTION_NUM_URIPATH))
        {
#if 0
            uint8_t index;
            double number;
            osens_point_t pt;

            if(coap_options[1].length == 2)
                index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30);
            else
                index = coap_options[1].pValue[0] - 0x30;

            number = decode_number(coap_options[2].pValue,coap_options[2].length);
            pt.type = osens_get_ptype(index);

            if(pt.type >= 0)
            {
                set_point_val(&pt,number);
                if(osens_set_pvalue(index,&pt))
                {
                    // set the CoAP header
                    coap_header->Code = COAP_CODE_RESP_CHANGED;
                    outcome = E_SUCCESS;
                }
            }
#else
            // switch on the light pulse (50 ms)
            light_on();

            opentimers_start(1000,TIMER_ONESHOT,TIME_MS,light_timer);
#endif

        }
        break;

    default:
        outcome = E_FAIL;
        break;
    }

    return outcome;
}
Esempio n. 12
0
/**
\brief Initialize this module.
*/
void icmpv6rpl_init() {
   uint8_t         dodagid[16];
   uint32_t        dioPeriod;
   uint32_t        daoPeriod;
   
   // retrieve my prefix and EUI64
   memcpy(&dodagid[0],idmanager_getMyID(ADDR_PREFIX)->prefix,8); // prefix
   memcpy(&dodagid[8],idmanager_getMyID(ADDR_64B)->addr_64b,8);  // eui64
   
   //===== reset local variables
   memset(&icmpv6rpl_vars,0,sizeof(icmpv6rpl_vars_t));
   
   //=== admin
   
   icmpv6rpl_vars.busySending               = FALSE;
   icmpv6rpl_vars.fDodagidWritten           = 0;
   
   //=== DIO
   
   icmpv6rpl_vars.dio.rplinstanceId         = 0x00;        ///< TODO: put correct value
   icmpv6rpl_vars.dio.verNumb               = 0x00;        ///< TODO: put correct value
   // rank: to be populated upon TX
   icmpv6rpl_vars.dio.rplOptions            = MOP_DIO_A | \
                                              MOP_DIO_B | \
                                              MOP_DIO_C | \
                                              PRF_DIO_A | \
                                              PRF_DIO_B | \
                                              PRF_DIO_C | \
                                              G_DIO ;
   icmpv6rpl_vars.dio.DTSN                  = 0x33;        ///< TODO: put correct value
   icmpv6rpl_vars.dio.flags                 = 0x00;
   icmpv6rpl_vars.dio.reserved              = 0x00;
   memcpy(
      &(icmpv6rpl_vars.dio.DODAGID[0]),
      dodagid,
      sizeof(icmpv6rpl_vars.dio.DODAGID)
   ); // can be replaced later
   
   icmpv6rpl_vars.dioDestination.type = ADDR_128B;
   memcpy(&icmpv6rpl_vars.dioDestination.addr_128b[0],all_routers_multicast,sizeof(all_routers_multicast));
   
   icmpv6rpl_vars.dioPeriod                 = TIMER_DIO_TIMEOUT;
   dioPeriod                                = icmpv6rpl_vars.dioPeriod - 0x80 + (openrandom_get16b()&0xff);
   icmpv6rpl_vars.timerIdDIO                = opentimers_start(
                                                dioPeriod,
                                                TIMER_PERIODIC,
                                                TIME_MS,
                                                icmpv6rpl_timer_DIO_cb
                                             );
   
   //=== DAO
   
   icmpv6rpl_vars.dao.rplinstanceId         = 0x00;        ///< TODO: put correct value
   icmpv6rpl_vars.dao.K_D_flags             = FLAG_DAO_A   | \
                                              FLAG_DAO_B   | \
                                              FLAG_DAO_C   | \
                                              FLAG_DAO_D   | \
                                              FLAG_DAO_E   | \
                                              PRF_DIO_C    | \
                                              FLAG_DAO_F   | \
                                              D_DAO        |
                                              K_DAO;
   icmpv6rpl_vars.dao.reserved              = 0x00;
   icmpv6rpl_vars.dao.DAOSequence           = 0x00;
   memcpy(
      &(icmpv6rpl_vars.dao.DODAGID[0]),
      dodagid,
      sizeof(icmpv6rpl_vars.dao.DODAGID)
   );  // can be replaced later
   
   icmpv6rpl_vars.dao_transit.type          = OPTION_TRANSIT_INFORMATION_TYPE;
   // optionLength: to be populated upon TX
   icmpv6rpl_vars.dao_transit.E_flags       = E_DAO_Transit_Info;
   icmpv6rpl_vars.dao_transit.PathControl   = PC1_A_DAO_Transit_Info | \
                                              PC1_B_DAO_Transit_Info | \
                                              PC2_A_DAO_Transit_Info | \
                                              PC2_B_DAO_Transit_Info | \
                                              PC3_A_DAO_Transit_Info | \
                                              PC3_B_DAO_Transit_Info | \
                                              PC4_A_DAO_Transit_Info | \
                                              PC4_B_DAO_Transit_Info;  
   icmpv6rpl_vars.dao_transit.PathSequence  = 0x00; // to be incremented at each TX
   icmpv6rpl_vars.dao_transit.PathLifetime  = 0xAA;
   //target information
   icmpv6rpl_vars.dao_target.type  = OPTION_TARGET_INFORMATION_TYPE;
   icmpv6rpl_vars.dao_target.optionLength  = 0;
   icmpv6rpl_vars.dao_target.flags  = 0;
   icmpv6rpl_vars.dao_target.prefixLength = 0;
   
   icmpv6rpl_vars.daoPeriod                 = TIMER_DAO_TIMEOUT;
   daoPeriod                                = icmpv6rpl_vars.daoPeriod - 0x80 + (openrandom_get16b()&0xff);
   icmpv6rpl_vars.timerIdDAO                = opentimers_start(
                                                daoPeriod,
                                                TIMER_PERIODIC,
                                                TIME_MS,
                                                icmpv6rpl_timer_DAO_cb
                                             );
   
}
Esempio n. 13
0
void    mpls_init(){
   mpls_vars.refreshperiod = 60000; // fires every 10 s on average
   mpls_vars.busySending       = FALSE;
   mpls_vars.timerId = opentimers_start(mpls_vars.refreshperiod,TIMER_PERIODIC,TIME_MS, mpls_timer_cb);
}