本文整理汇总了C++中PROCESS_BEGIN函数的典型用法代码示例。如果您正苦于以下问题:C++ PROCESS_BEGIN函数的具体用法?C++ PROCESS_BEGIN怎么用?C++ PROCESS_BEGIN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PROCESS_BEGIN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PROCESS_THREAD
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(program_handler_process, ev, data)
{
#ifdef WITH_LOADER_ARCH
unsigned char err;
struct dsc *dsc;
#endif /* WITH_LOADER_ARCH */
unsigned char i;
struct dsc **dscp;
PROCESS_BEGIN();
/* Create the menus */
ctk_menu_add(&contikimenu);
#if WITH_LOADER_ARCH
runmenuitem = ctk_menuitem_add(&contikimenu, "Run program...");
make_windows();
#endif /* WITH_LOADER_ARCH */
#if QUIT_MENU
quitmenuitem = ctk_menuitem_add(&contikimenu, "Quit");
#endif /* QUIT_MENU */
displayname = NULL;
#if CTK_CONF_SCREENSAVER
program_handler_screensaver[0] = 0;
#endif /* CTK_CONF_SCREENSAVER */
while(1) {
PROCESS_WAIT_EVENT();
if(ev == ctk_signal_button_activate) {
#ifdef WITH_LOADER_ARCH
if(data == (process_data_t)&loadbutton) {
ctk_window_close(&runwindow);
program_handler_load(name, NULL);
} else if(data == (process_data_t)&errorokbutton) {
ctk_dialog_close();
}
#endif /* WITH_LOADER_ARCH */
#if QUIT_MENU
if(data == (process_data_t)&quityesbutton) {
ctk_draw_init();
exit(EXIT_SUCCESS);
} else if(data == (process_data_t)&quitnobutton) {
ctk_dialog_close();
}
#endif /* QUIT_MENU */
dscp = &contikidsc[0];
for(i = 0; i < CTK_MAXMENUITEMS; ++i) {
if(*dscp != NULL
#if CTK_CONF_ICONS
&& data == (process_data_t)(*dscp)->icon
#endif /* CTK_CONF_ICONS */
) {
RUN((*dscp)->prgname, (*dscp)->process, NULL);
break;
}
++dscp;
}
} else if(ev == ctk_signal_menu_activate) {
if((struct ctk_menu *)data == &contikimenu) {
#if WITH_LOADER_ARCH
dsc = contikidsc[contikimenu.active];
if(dsc != NULL) {
RUN(dsc->prgname, dsc->process, NULL);
} else if(contikimenu.active == runmenuitem) {
make_windows();
ctk_window_close(&runwindow);
ctk_window_open(&runwindow);
CTK_WIDGET_FOCUS(&runwindow, &nameentry);
}
#else /* WITH_LOADER_ARCH */
if(contikidsc[contikimenu.active] != NULL) {
RUN(contikidsc[contikimenu.active]->prgname,
contikidsc[contikimenu.active]->process,
NULL);
}
#endif /* WITH_LOADER_ARCH */
#if QUIT_MENU
if(contikimenu.active == quitmenuitem) {
ctk_dialog_new(&quitdialog, 24, 5);
CTK_WIDGET_ADD(&quitdialog, &quitdialoglabel);
CTK_WIDGET_ADD(&quitdialog, &quityesbutton);
CTK_WIDGET_ADD(&quitdialog, &quitnobutton);
CTK_WIDGET_FOCUS(&quitdialog, &quitnobutton);
ctk_dialog_open(&quitdialog);
}
#endif /* QUIT_MENU */
}
#if CTK_CONF_SCREENSAVER
} else if(ev == ctk_signal_screensaver_start) {
#if WITH_LOADER_ARCH
if(program_handler_screensaver[0] != 0) {
program_handler_load(program_handler_screensaver, NULL);
}
#endif /* WITH_LOADER_ARCH */
#endif /* CTK_CONF_SCREENSAVER */
} else if(ev == LOADER_EVENT_DISPLAY_NAME) {
#if WITH_LOADER_ARCH
//.........这里部分代码省略.........
示例2: PROCESS_THREAD
/* A periodic process to send TSCH Enhanced Beacons (EB) */
PROCESS_THREAD(tsch_send_eb_process, ev, data)
{
static struct etimer eb_timer;
PROCESS_BEGIN();
/* Wait until association */
etimer_set(&eb_timer, CLOCK_SECOND / 10);
while(!tsch_is_associated) {
PROCESS_WAIT_UNTIL(etimer_expired(&eb_timer));
etimer_reset(&eb_timer);
}
/* Set an initial delay except for coordinator, which should send an EB asap */
if(!tsch_is_coordinator) {
etimer_set(&eb_timer, random_rand() % TSCH_EB_PERIOD);
PROCESS_WAIT_UNTIL(etimer_expired(&eb_timer));
}
while(1) {
unsigned long delay;
if(tsch_is_associated && tsch_current_eb_period > 0) {
/* Enqueue EB only if there isn't already one in queue */
if(tsch_queue_packet_count(&tsch_eb_address) == 0) {
int eb_len;
uint8_t hdr_len = 0;
uint8_t tsch_sync_ie_offset;
/* Prepare the EB packet and schedule it to be sent */
packetbuf_clear();
/* We don't use seqno 0 */
if(++tsch_packet_seqno == 0) {
tsch_packet_seqno++;
}
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_BEACONFRAME);
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, tsch_packet_seqno);
#if LLSEC802154_ENABLED
if(tsch_is_pan_secured) {
/* Set security level, key id and index */
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, TSCH_SECURITY_KEY_SEC_LEVEL_EB);
packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, FRAME802154_1_BYTE_KEY_ID_MODE); /* Use 1-byte key index */
packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, TSCH_SECURITY_KEY_INDEX_EB);
}
#endif /* LLSEC802154_ENABLED */
eb_len = tsch_packet_create_eb(packetbuf_dataptr(), PACKETBUF_SIZE,
tsch_packet_seqno, &hdr_len, &tsch_sync_ie_offset);
if(eb_len != 0) {
struct tsch_packet *p;
packetbuf_set_datalen(eb_len);
/* Enqueue EB packet */
if(!(p = tsch_queue_add_packet(&tsch_eb_address, NULL, NULL))) {
PRINTF("TSCH:! could not enqueue EB packet\n");
} else {
PRINTF("TSCH: enqueue EB packet %u %u\n", eb_len, hdr_len);
p->tsch_sync_ie_offset = tsch_sync_ie_offset;
p->header_len = hdr_len;
}
}
}
}
if(tsch_current_eb_period > 0) {
/* Next EB transmission with a random delay
* within [tsch_current_eb_period*0.75, tsch_current_eb_period[ */
delay = (tsch_current_eb_period - tsch_current_eb_period / 4)
+ random_rand() % (tsch_current_eb_period / 4);
} else {
delay = TSCH_EB_PERIOD;
}
etimer_set(&eb_timer, delay);
PROCESS_WAIT_UNTIL(etimer_expired(&eb_timer));
}
PROCESS_END();
}
示例3: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2538_demo_process, ev, data)
{
PROCESS_EXITHANDLER(broadcast_close(&bc))
PROCESS_BEGIN();
counter = 0;
broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10);
while(1) {
etimer_set(&et, CLOCK_SECOND*10);
//ivanm
// Configure ADC, Internal reference, 512 decimation rate (12bit)
//
SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL);
//
// Trigger single conversion on AIN6 (connected to LV_ALS_OUT).
//
SOCADCSingleStart(SOCADC_VDD);
//
// Wait until conversion is completed
//
while(!SOCADCEndOfCOnversionGet())
{
}
//
// Get data and shift down based on decimation rate
//
ui1Dummy = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT;
printf("konverzija(ADC) = 0x%08x\n",ui1Dummy);
PROCESS_YIELD();
if(ev == PROCESS_EVENT_TIMER) {
leds_on(LEDS_PERIODIC);
printf("Counter = 0x%08x\n", counter);
err = s_measure(&temperature, checksum, TEMP);
if (err == 0)
{
//printf("Temperature (ADC value) = 0x%4x\n", temperature);
err = s_measure(&humidity, checksum, HUMI);
if (err == 0)
{
//printf("Humidity (ADC value) = 0x%4x\n", humidity);
//tc=sht11_TemperatureC(temperature);
//hc=sht11_Humidity(temperature,humidity);
tc=0;
hc=0;
printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10);
}
else
printf("SHT11 error - could not read humidity!\n");
}
else
printf("SHT11 error - could not read temperature!\n");
etimer_set(&et, CLOCK_SECOND);
rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
rt_callback, NULL);
} else if(ev == sensors_event) {
if(data == &button_select_sensor) {
if (swt==0)
{
packetbuf_copyfrom(&temperature, sizeof(temperature));
broadcast_send(&bc);
swt=1;
}
else
{
packetbuf_copyfrom(&humidity, sizeof(humidity));
broadcast_send(&bc);
swt=0;
}
} else if(data == &button_left_sensor || data == &button_right_sensor) {
leds_toggle(LEDS_BUTTON);
} else if(data == &button_down_sensor) {
cpu_cpsid();
leds_on(LEDS_REBOOT);
watchdog_reboot();
} else if(data == &button_up_sensor) {
sys_ctrl_reset();
}
} else if(ev == serial_line_event_message) {
leds_toggle(LEDS_SERIAL_IN);
}
counter++;
/* put measaruement sht11 here*/
}
PROCESS_END();
}
示例4: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
static struct etimer periodic, set_tx_timer;
static struct ctimer backoff_timer;
#if WITH_COMPOWER
static int print = 0;
#endif
PROCESS_BEGIN();
PROCESS_PAUSE();
set_global_address();
PRINTF("UDP client process started\n");
print_local_addresses();
/* new connection with remote host */
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
if(client_conn == NULL) {
PRINTF("No UDP connection available, exiting the process!\n");
PROCESS_EXIT();
}
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));
PRINTF("Created a connection with the server ");
PRINT6ADDR(&client_conn->ripaddr);
PRINTF(" local/remote port %u/%u\n",
UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
//---------------------- Set Tx ----------
etimer_set(&set_tx_timer, 30 * CLOCK_SECOND);
set_tx_flag();
set_tx();
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&set_tx_timer));
clear_tx_flag();
//--------------------------------------
#if WITH_COMPOWER
powertrace_sniff(POWERTRACE_ON);
#endif
etimer_set(&periodic, SEND_INTERVAL);
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
tcpip_handler();
}
if(etimer_expired(&periodic)) {
etimer_reset(&periodic);
ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);
#if WITH_COMPOWER
if (print == 0) {
powertrace_print("#P");
}
if (++print == 3) {
print = 0;
}
#endif
}
}
PROCESS_END();
}
示例5: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(etimer_process, ev, data)
{
struct etimer *t, *u;
PROCESS_BEGIN();
timerlist = NULL;
while(1) {
PROCESS_YIELD();
if(ev == PROCESS_EVENT_EXITED) {
struct process *p = data;
while(timerlist != NULL && timerlist->p == p) {
timerlist = timerlist->next;
}
if(timerlist != NULL) {
t = timerlist;
while(t->next != NULL) {
if(t->next->p == p) {
t->next = t->next->next;
} else
t = t->next;
}
}
continue;
} else if(ev != PROCESS_EVENT_POLL) {
continue;
}
again:
u = NULL;
for(t = timerlist; t != NULL; t = t->next) {
if(timer_expired(&t->timer)) {
if(process_post(t->p, PROCESS_EVENT_TIMER, t) == PROCESS_ERR_OK) {
/* Reset the process ID of the event timer, to signal that the
etimer has expired. This is later checked in the
etimer_expired() function. */
t->p = PROCESS_NONE;
if(u != NULL) {
u->next = t->next;
} else {
timerlist = t->next;
}
t->next = NULL;
update_time();
goto again;
} else {
etimer_request_poll();
}
}
u = t;
}
}
PROCESS_END();
}
示例6: PROCESS_THREAD
PROCESS_THREAD(sbk_in_process, ev, data)
{
PROCESS_BEGIN();
while (1)
{
PROCESS_WAIT_UNTIL(sbk_in_track!=0);
DBG("Einfahrt auf Gleis ");
DBG('0' + sbk_in_track);
DBG("\r\n");
switch (sbk_in_track)
{
case 1:
shiftreg |= (1<<RELAIS_G1_IN);
break;
case 2:
shiftreg |= (1<<RELAIS_G2_IN);
break;
case 3:
shiftreg |= (1<<RELAIS_G3_IN);
break;
case 4:
shiftreg |= (1<<RELAIS_G4_IN);
break;
case 5:
shiftreg |= (1<<RELAIS_G5_IN);
break;
case 6:
shiftreg |= (1<<RELAIS_G6_IN);
break;
default:
break;
}
shiftreg_out16(shiftreg,1);
#if 0
// First: wait until track is free (allows proper functioning of the cleaning mode)
PROCESS_WAIT_UNTIL((gbm_register_filt_filt&(1<<sbk_in_track))==0);
// Second: wait until track is occupied again
PROCESS_WAIT_UNTIL((gbm_register_filt_filt&(1<<sbk_in_track))!=0);
#else
while ((gbm_register_filt_filt&(1<<sbk_in_track))!=0)
{
PROCESS_PAUSE();
}
while ((gbm_register_filt_filt&(1<<sbk_in_track))==0)
{
PROCESS_PAUSE();
}
#endif
if ((sbk_in_track!=sbk_out_track) && (sbk_mode==SBK_MODE_FSS))
{
// --> FSS aktivieren via LN --> 120612: nicht nötig, da ständig aktiv
shiftreg |= (1<<RELAIS_FSS);
shiftreg_out16(shiftreg,1);
etimer_set(&sbk_in_timer, 3*CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&sbk_in_timer));
}
//PT_WAIT_UNTIL(pt, (TickGet()-sbk_in_timer) >= 3*TICKS_PER_SECOND);
shiftreg &= ~((1<<RELAIS_G1_IN)
|(1<<RELAIS_G2_IN)
|(1<<RELAIS_G3_IN)
|(1<<RELAIS_G4_IN)
|(1<<RELAIS_G5_IN)
|(1<<RELAIS_G6_IN)
|(1<<RELAIS_FSS));
// FSS deaktivieren (oder automatisch nach Ablauf von Timeout)
shiftreg_out16(shiftreg,1);
sbk_in_track = 0;
process_poll(&sbk_out_process);
}
PROCESS_END();
}
示例7: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
static struct etimer periodic;
static struct ctimer backoff_timer;
static struct etimer wait;
//static int tx[] = { 31, 27, 23, 19, 15, 11, 7, 3};
static int i ;
#if WITH_COMPOWER
static int print = 0;
#endif
PROCESS_BEGIN();
//powertrace_start(CLOCK_SECOND * 2); //elnaz
cc2420_set_txpower(19);
printf(" Tx=%d\n", cc2420_get_txpower());
PROCESS_PAUSE();
set_global_address();
PRINTF("UDP client process started\n");
print_local_addresses();
/* new connection with remote host */
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
if(client_conn == NULL) {
PRINTF("No UDP connection available, exiting the process!\n");
PROCESS_EXIT();
}
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));
PRINTF("Created a connection with the server ");
PRINT6ADDR(&client_conn->ripaddr);
PRINTF(" local/remote port %u/%u\n",
UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
#if WITH_COMPOWER
powertrace_sniff(POWERTRACE_ON);
#endif
etimer_set(&periodic, SEND_INTERVAL);
//for(i = 0 ; i<8 ; i++)
//{
while(seq<100)
{
PROCESS_YIELD();
if(ev == tcpip_event)
{
tcpip_handler();
}
if(etimer_expired(&periodic))
{
etimer_reset(&periodic);
ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);
} //end etimer_expired
}
seq = 0;
etimer_stop(&periodic);
etimer_set(&wait, WAIT_INTERVAL);
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
etimer_set(&periodic, SEND_INTERVAL);
// } // end loop on Tx
PROCESS_END();
}
示例8: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data) {
PROCESS_BEGIN()
;
PROCESS_PAUSE()
;
set_global_address();
// senderStartTime = get_time_ms();
PRINTF("UDP client process started\n");
// print_local_addresses();
/* new connection with remote host */
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));
// PRINTF("Created a connection with the server ");
// PRINT6ADDR(&client_conn->ripaddr);
// PRINTF(" local/remote port %u/%u\n",
// UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
// Initial value of nodeInf
// Initial values
nodeInf.sinkMinTX = 65535;
stopCond = 0;
static struct etimer et;
//etimer_set(&et, CLOCK_SECOND * 1 + random_rand() % (CLOCK_SECOND * 1));
static struct etimer periodic;
//etimer_set(&et, 2 * CLOCK_SECOND);
int i;
while (1) {
// PROCESS_YIELD();
PROCESS_WAIT_EVENT()
;
/* Send a packet every 30 seconds. */
if (etimer_expired(&periodic)) {
i = 0;
etimer_set(&periodic, CLOCK_SECOND * 2);
etimer_set(&et, random_rand() % (CLOCK_SECOND * 2));
}
if (stopCond == 1) {
break;
}
//
if (ev == tcpip_event) {
tcpip_handler();
} else if (etimer_expired(&et)) {
client_send();
}
}
PROCESS_END();
}
示例9: PROCESS_THREAD
PROCESS_THREAD(er_example_server, ev, data)
{
PROCESS_BEGIN();
PROCESS_PAUSE();
PRINTF("Starting Erbium Example Server\n");
#ifdef RF_CHANNEL
PRINTF("RF channel: %u\n", RF_CHANNEL);
#endif
#ifdef IEEE802154_PANID
PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID);
#endif
PRINTF("uIP buffer: %u\n", UIP_BUFSIZE);
PRINTF("LL header: %u\n", UIP_LLH_LEN);
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
/* Initialize the REST engine. */
rest_init_engine();
/*
* Bind the resources to their Uri-Path.
* WARNING: Activating twice only means alternate path, not two instances!
* All static variables are the same for each URI path.
*/
rest_activate_resource(&res_hello, "test/hello");
/* rest_activate_resource(&res_mirror, "debug/mirror"); */
/* rest_activate_resource(&res_chunks, "test/chunks"); */
/* rest_activate_resource(&res_separate, "test/separate"); */
rest_activate_resource(&res_push, "test/push");
/* rest_activate_resource(&res_event, "test/serial"); */
/* rest_activate_resource(&res_sub, "test/sub"); */
/* rest_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); */
#if PLATFORM_HAS_LEDS
/* rest_activate_resource(&res_leds, "actuators/leds"); */
rest_activate_resource(&res_toggle, "actuators/toggle");
#endif
#if PLATFORM_HAS_LIGHT
rest_activate_resource(&res_light, "sensors/light");
SENSORS_ACTIVATE(light_sensor);
#endif
#if PLATFORM_HAS_BATTERY
rest_activate_resource(&res_battery, "sensors/battery");
SENSORS_ACTIVATE(battery_sensor);
#endif
#if PLATFORM_HAS_TEMPERATURE
rest_activate_resource(&res_temperature, "sensors/temperature");
SENSORS_ACTIVATE(temperature_sensor);
#endif
/*
#if PLATFORM_HAS_RADIO
rest_activate_resource(&res_radio, "sensors/radio");
SENSORS_ACTIVATE(radio_sensor);
#endif
#if PLATFORM_HAS_SHT11
rest_activate_resource(&res_sht11, "sensors/sht11");
SENSORS_ACTIVATE(sht11_sensor);
#endif
*/
#if PLATFORM_HAS_PRESSURE
rest_activate_resource(&res_pressure, "sensors/pressure");
SENSORS_ACTIVATE(pressure_sensor);
#endif
#if PLATFORM_HAS_GYROSCOPE
rest_activate_resource(&res_gyros, "sensors/gyros");
SENSORS_ACTIVATE(gyr_sensor);
#endif
#if PLATFORM_HAS_ACCELEROMETER
rest_activate_resource(&res_accel, "sensors/accel");
SENSORS_ACTIVATE(acc_sensor);
#endif
#if PLATFORM_HAS_MAGNETOMETER
rest_activate_resource(&res_magne, "sensors/magne");
SENSORS_ACTIVATE(mag_sensor);
#endif
/* Define application-specific events here. */
while(1) {
PROCESS_WAIT_EVENT();
if(ev == serial_line_event_message) {
res_serial_data = (char*)data;
/* Call the event_handler for this application-specific event. */
res_event.trigger();
/* Also call the separate response example handler. */
// res_separate.resume();
}
} /* while (1) */
PROCESS_END();
}
示例10: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
uint32_t err_code;
// Initialize the SoftDevice handler module.
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
APP_ERROR_CHECK(err_code);
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);
ble_gap_conn_sec_mode_t sec_mode;
char name_buffer[9];
sprintf(name_buffer, "%08X",(unsigned int) NRF_FICR->DEVICEID[0]);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)name_buffer,
strlen(name_buffer));
APP_ERROR_CHECK(err_code);
ble_advdata_t advdata;
uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
ble_advdata_service_data_t service_data[2];
uint8_t battery_data = 98;//battery_level_get();
uint32_t temperature_data = 0xFE001213;
service_data[0].service_uuid = BLE_UUID_BATTERY_SERVICE;
service_data[0].data.size = sizeof(battery_data);
service_data[0].data.p_data = &battery_data;
service_data[1].service_uuid = BLE_UUID_HEALTH_THERMOMETER_SERVICE;
service_data[1].data.size = sizeof(temperature_data);
service_data[1].data.p_data = (uint8_t *) &temperature_data;
// Build and set advertising data
memset(&advdata, 0, sizeof(advdata));
advdata.name_type = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance = false;
advdata.flags.size = sizeof(flags);
advdata.flags.p_data = &flags;
advdata.service_data_count = 2;
advdata.p_service_data_array = service_data;
err_code = ble_advdata_set(&advdata, NULL);
APP_ERROR_CHECK(err_code);
ble_gap_adv_params_t adv_params;
// Start advertising
memset(&adv_params, 0, sizeof(adv_params));
adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
adv_params.p_peer_addr = NULL;
adv_params.fp = BLE_GAP_ADV_FP_ANY;
adv_params.interval = ADV_INTERVAL;
adv_params.timeout = ADV_TIMEOUT_IN_SECONDS;
err_code = sd_ble_gap_adv_start(&adv_params);
APP_ERROR_CHECK(err_code);
leds_off(LEDS_ALL);
leds_on(LEDS_RED);
PROCESS_PAUSE();
etimer_set(&et_hello, CLOCK_SECOND/2);
rand_val = 0;
blinks = 0;
while(1) {
PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_TIMER) {
sd_rand_application_vector_get(&blinks,1);
printf("Sensor says #%X\n", (unsigned int) blinks);
etimer_reset(&et_hello);
}
}
PROCESS_END();
}
示例11: PROCESS_THREAD
/*---------------------------------------------------------------*/
PROCESS_THREAD(null_app_process, ev, data)
{
PROCESS_BEGIN();
printf("Sine Wave Started\n");
serial_shell_init();
remote_shell_init();
shell_reboot_init();
shell_blink_init();
shell_sky_init();
app_conn_open(&nullApp_callback);
/*
if (node_id != 0)
etimer_set(&et,16);
else
etimer_set(&et,200);
*/
if (node_id != 0)
{
ctimer_set(&ct,10,sample_fun,(void*)NULL);
/*
while(1)
{
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
uint8_t i;
for(i = 0; i < 6; i++)
{
data_buf[i] = sinI(counter);
counter++;
}
app_conn_send((uint8_t *)data_buf,6*sizeof(int8_t));
}
*/
}
/*
else
{
while(1)
{
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}
}
*/
/*
int8_t data_buf[6] = {0};
static struct etimer et;
//static uint16_t counter = 0;
uint8_t i;
etimer_set(&et,(unsigned long)102);
if (node_id != 0)
{
while(1)
{
//etimer_set(&et,(unsigned long)102);
//printf("here 1\n");
printf("1timer start %lu interval %lu process %s\n",et.timer.start,et.timer.interval,et.p->name);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
printf("if expired %u\n",etimer_expired(&et));
etimer_reset(&et);
printf("2timer start %lu interval %lu process %s\n",et.timer.start,et.timer.interval,et.p->name);
printf("next timer start %lu interval %lu process %s\n",et.next->timer.start,et.next->timer.interval,et.next->p->name);
for(i = 0; i < 6; i++)
{
data_buf[i] = sinI(counter);
counter++;
}
printf("here 3\n");
app_conn_send((uint8_t *)data_buf,6*sizeof(int8_t));
printf("here 4\n");
}
}
*/
PROCESS_END();
}
示例12: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(clock_test_process, ev, data)
{
PROCESS_BEGIN();
etimer_set(&et, 2 * CLOCK_SECOND);
PROCESS_YIELD();
#if TEST_CLOCK_DELAY_USEC
printf("clock_delay_usec test, (10,000 x i) usec:\n");
i = 1;
while(i < 7) {
start_count = RTIMER_NOW();
clock_delay_usec(10000 * i);
end_count = RTIMER_NOW();
diff = end_count - start_count;
printf("Requested: %u usec, Real: %u rtimer ticks = ~%u us\n",
10000 * i, diff, diff * 64);
i++;
}
#endif
#if TEST_RTIMER
printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND);
i = 0;
while(i < 5) {
etimer_set(&et, 2 * CLOCK_SECOND);
printf("=======================\n");
ct = clock_time();
rt_now = RTIMER_NOW();
rt_for = rt_now + RTIMER_SECOND;
printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for);
if(rtimer_set(&rt, rt_for, 1, (rtimer_callback_t) rt_callback, NULL) !=
RTIMER_OK) {
printf("Error setting\n");
}
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
i++;
}
#endif
#if TEST_ETIMER
printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n",
CLOCK_SECOND);
i = 0;
while(i < 10) {
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
count = clock_time();
printf("%u ticks\n", count);
leds_toggle(LEDS_RED);
i++;
}
#endif
#if TEST_CLOCK_SECONDS
printf("Clock seconds test (5s):\n");
i = 0;
while(i < 10) {
etimer_set(&et, 5 * CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
etimer_reset(&et);
sec = clock_seconds();
printf("%lu seconds\n", sec);
leds_toggle(LEDS_GREEN);
i++;
}
#endif
printf("Done!\n");
PROCESS_END();
}
示例13: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(remote_grove_gyro_process, ev, data)
{
PROCESS_BEGIN();
uint8_t aux;
/* Use Contiki's sensor macro to enable the sensor */
SENSORS_ACTIVATE(grove_gyro);
/* The sensor itself is in low-power mode, to power on just the sensor and not
* the 3 gyroscope axis use GROVE_GYRO_SENSOR. Alternatively the value
* GROVE_GYRO_ALL could also be used to power everything at once
*/
grove_gyro.configure(GROVE_GYRO_POWER_ON, GROVE_GYRO_SENSOR);
/* Read back the configured sensor I2C address to check if the sensor is
* working OK, this is the only case in which the value() returns a value
*/
aux = grove_gyro.value(GROVE_GYRO_ADDR);
if(aux == GROVE_GYRO_EXPECTED_ADDR) {
printf("Gyro sensor started with addr 0x%02X\n", GROVE_GYRO_EXPECTED_ADDR);
} else {
printf("Gyro sensor with unrecognized address 0x%02X\n", aux);
PROCESS_EXIT();
}
/* Register the interrupt handler */
GROVE_GYRO_REGISTER_INT(gyro_interrupt_callback);
/* The gyroscope sensor should be on now but the three gyroscope axis should
* be off, to enable a single axis or any combination of the 3 you can use as
* argument either GROVE_GYRO_X, GROVE_GYRO_Y, GROVE_GYRO_Z. To enable or
* disable the three axis alternatively use GROVE_GYRO_XYZ
*/
grove_gyro.configure(GROVE_GYRO_POWER_ON, GROVE_GYRO_XYZ);
/* Calibrate the sensor taking 200 samples every 5ms for the zero-point offset
* value, this has to be done manually and is up to the user
*/
grove_gyro.configure(GROVE_GYRO_CALIBRATE_ZERO, 1);
/* Enabling the data interrupt will feed data directly to the extern data
* structure and notify us about it, depending on the sampling rate and
* divisor this could generate many interrupts/second. A zero argument would
* disable the interrupts
*/
grove_gyro.configure(GROVE_GYRO_DATA_INTERRUPT, 1);
/* And periodically poll the sensor, values are in º/s */
while(1) {
etimer_set(&et, SENSOR_READ_INTERVAL);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
/* This sensor has a different operation from others using Contiki's sensor
* API, to make data acquisition we write the readings directly to the
* extern data structure, allowing to write more than 1 value at the same
* operation, and also allowing upon a data interrupt event to immediatly
* access the data. The return value of the value() call is then the status
* result of the read operation
*/
if(grove_gyro.value(GROVE_GYRO_XYZ) == GROVE_GYRO_SUCCESS) {
/* Converted values with a 2-digit precision */
printf("Gyro: X: %u.%u, Y: %u.%u, Z: %u.%u\n", gyro_values.x / 100,
gyro_values.x % 100,
gyro_values.y / 100,
gyro_values.y % 100,
gyro_values.z / 100,
gyro_values.z % 100);
} else {
printf("Error, enable the DEBUG flag in the grove-gyro driver for info,");
printf(" or check if the sensor is properly connected\n");
PROCESS_EXIT();
}
if(grove_gyro.value(GROVE_GYRO_TEMP) == GROVE_GYRO_SUCCESS) {
printf("Gyro: temperature %d.%02u C\n", gyro_values.temp / 100,
gyro_values.temp % 100);
} else {
printf("Error, enable the DEBUG flag in the grove-gyro driver for info,");
printf(" or check if the sensor is properly connected\n");
PROCESS_EXIT();
}
}
PROCESS_END();
}
示例14: PROCESS_THREAD
PROCESS_THREAD(test_RTC_process, ev, data)
{ PROCESS_BEGIN();
leds_off(LEDS_ALL);
// Set the RTC time to be 12:34:56 on 30/1/15
//
struct RTC_time t = {
0, // hundredths
0, // tenths
56, // seconds
34, // minutes
12, // hours
30, // day
01, // month
15 // year
};
struct RTC_alarm q = {
10, // seconds
35, // minutes
12, // hours
30, // day
01 // month
};
RTC_setTime(&t);
// Alarm can be set with a callback
// (or this can be NULL)
RTC_setAlarm(&q, alarmCallback, RPT_MINUTE);
int i = 0;
while(1) {
printf("GOING TO SLEEP\n");
clock_delay_msec(50);
/* ------------
* Go to sleep
* ------------
*/
*CRM_SLEEP_CNTL = 0x71; // hibernate, keep all RAM pages, retain state, don't power GPIO, approx. 2kHz = 16.1uA
while((*CRM_STATUS & 0x1) == 0) // wait for the sleep cycle to complete
{ continue; }
*CRM_STATUS = 1; // write 1 to sleep_sync --- this clears the bit (it's a r1wc bit) and powers down
/* ------------
* Wake up again
* ------------
*/
printf("AWAKE AGAIN\n");
for (i = 0; i < 2; i++)
FLASH_LED(LEDS_ALL);
PROCESS_YIELD();
RTC_getTime(&t);
printf("%02d/%02d/%02d %02d:%02d:%02d.%d%d\n", t.day, t.month, t.year, t.hours, t.minutes, t.seconds, t.tenths, t.hundredths);
}
PROCESS_END();
}
示例15: PROCESS_THREAD
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(simpletelnet_process, ev, data)
{
struct ctk_widget *w;
int sendlen;
PROCESS_BEGIN();
ctk_window_new(&telnetwindow, TELNET_WINDOW_WIDTH, TELNET_WINDOW_HEIGHT, "Simple telnet");
strcpy(telnetport, "23");
CTK_WIDGET_ADD(&telnetwindow, &telnethostlabel);
CTK_WIDGET_ADD(&telnetwindow, &telnetportlabel);
CTK_WIDGET_ADD(&telnetwindow, &telnethosttextentry);
CTK_WIDGET_ADD(&telnetwindow, &telnetporttextentry);
CTK_WIDGET_ADD(&telnetwindow, &telnetconnectbutton);
CTK_WIDGET_ADD(&telnetwindow, &telnetdisconnectbutton);
CTK_WIDGET_ADD(&telnetwindow, &telnetlinetextentry);
CTK_WIDGET_ADD(&telnetwindow, &telnetsendbutton);
CTK_WIDGET_ADD(&telnetwindow, &telnetsep1);
CTK_WIDGET_ADD(&telnetwindow, &telnettextarea);
CTK_WIDGET_ADD(&telnetwindow, &telnetsep2);
CTK_WIDGET_ADD(&telnetwindow, &telnetstatus);
CTK_WIDGET_FOCUS(&telnetwindow, &telnethosttextentry);
ctk_window_open(&telnetwindow);
while(1) {
PROCESS_WAIT_EVENT();
if(ev == ctk_signal_button_activate) {
w = (struct ctk_widget *)data;
if(w == (struct ctk_widget *)&telnetsendbutton) {
strcpy(sendline, telnetline);
sendlen = (int)strlen(sendline);
petsciiconv_toascii(sendline, sendlen);
sendline[sendlen++] = ISO_CR;
sendline[sendlen++] = ISO_NL;
if(telnet_send(&ts_appstate, sendline, sendlen)) {
/* Could not send. */
ctk_label_set_text(&telnetstatus, "Could not send");
ctk_window_redraw(&telnetwindow);
/* } else {*/
/* Could send */
}
} else if(w == (struct ctk_widget *)&telnetdisconnectbutton) {
telnet_close(&ts_appstate);
show("Closing...");
} else if(w == (struct ctk_widget *)&telnetconnectbutton) {
connect();
ctk_window_redraw(&telnetwindow);
}
#if UIP_UDP
} else if(ev == resolv_event_found) {
if(strcmp(data, telnethost) == 0) {
if(resolv_lookup(telnethost) != NULL) {
connect();
} else {
show("Host not found");
}
}
#endif /* UIP_UDP */
} else if(
#if CTK_CONF_WINDOWCLOSE
ev == ctk_signal_window_close ||
#endif /* CTK_CONF_WINDOWCLOSE */
ev == PROCESS_EVENT_EXIT) {
process_exit(&simpletelnet_process);
ctk_window_close(&telnetwindow);
LOADER_UNLOAD();
} else if(ev == tcpip_event) {
telnet_app(data);
}
}
PROCESS_END();
}