#include <stdlib.h>
#define DEFAULT_PERIOD_S 10
#define DEFAULT_PERIOD_US (DEFAULT_PERIOD_S*1000*1000)
#define EXECUTION_TIME_US 500
#define SET_PERIOD_EP 10
#define DATA_EP 1
static uint32_t period_us;
static uint32_t get_value_from_string(const uint8_t * bytes,
size_t num_bytes)
{
uint32_t value = 0;
while ((num_bytes--) > 0)
{
char c = (char)(*bytes++);
if ((c < '0') || (c > '9'))
{
break;
}
value *= 10;
value += c - '0';
}
return value;
}
static uint32_t send_data(void)
{
static uint32_t id = 0;
data_to_send.
bytes = (
const uint8_t *) &
id;
lib_data->sendData(&data_to_send);
id++;
return period_us;
}
{
{
}
uint32_t new_period = get_value_from_string(data->
bytes, data->
num_bytes);
period_us = (new_period > 0) ? new_period * 1000 * 1000 :
lib_system->setPeriodicCb(send_data,
period_us,
EXECUTION_TIME_US);
}
{
{
return;
}
period_us = DEFAULT_PERIOD_US;
lib_system->setPeriodicCb(send_data,
period_us,
EXECUTION_TIME_US);
lib_data->setDataReceivedCb(dataReceivedCb);
lib_data->setBcastDataReceivedCb(dataReceivedCb);
lib_state->startStack();
}