void send_set(uint8_t dst, uint8_t device, int16_t value) { uart_putstr_P(PSTR("send_set()\r\n")); struct packet_t *packet=get_tx_packet(); set_devices(packet,0xff,device); set_data_int16(packet,value); send(dst,SET,packet); }
void bugone_loop() { uint8_t *bufcontents; uint8_t i; // RFM12 managment rfm12_tick(); if (rfm12_rx_status() == STATUS_COMPLETE) { bufcontents=rfm12_rx_buffer(); recv(bufcontents); } // Every minutes if (seconds > 20) { struct packet_t *packet = get_tx_packet(); application_t *application; int8_t len; uart_putstr_P(PSTR("\r\n")); i=0; while ( (application = get_app(i)) != NULL) { i++; uart_putstr_P(PSTR("#")); if (application->get == NULL) { continue; } set_devices(packet,i,0x29); len=application->get(packet); if (len > 0) { //data.remaining_len-=len; //data.buf+=len; } } send(0xFF,6,packet); seconds=0; } // Asynchronous events if (wake_me_up > 0) { struct packet_t *packet = get_tx_packet(); int8_t len; uart_putstr_P(PSTR("\r\n")); set_devices(packet,wake_me_up,42); len=applications[wake_me_up].get(packet); send(0xFF,VALUE,packet); wake_me_up = 0; } }
void recv_get(struct packet_t *packet) { uint8_t device_src,device_dst; uint8_t len; application_t* app; struct packet_t *send_packet = get_tx_packet(); while (get_devices(packet,&device_src,&device_dst)) { app=app_get(device_dst); set_devices(send_packet,device_dst,device_src); len=app->get(send_packet); // if (len > 0) { // data.remaining_len-=len; // } } send(packet->network->src,VALUE,send_packet); }
int setup_timer_handler(void) { int ret = 0; priv = netdev_priv(get_vlc_dev()); //Get the first packets in the packet ring rx_packet = get_rx_packet(); tx_packet = get_tx_packet(); //Init semas rtdm_sem_init(&tx_sem, 1); rtdm_sem_init(&rx_sem, 1); //Store the current time rx_sleep_slot = rtdm_clock_read_monotonic(); tx_sleep_slot = rx_sleep_slot + sleep_increment / 2; early_late_slot = do_div(sleep_increment, 5); //Return an error if either is NULL if(!rx_packet || !tx_packet) goto error; //Start the rx and tx handler tasks rtdm_task_init(&rx_handler_task, "VLC rx handler", rx_handler, NULL, RTDM_TASK_HIGHEST_PRIORITY, 0); if(ret) goto error; rtdm_task_init(&tx_handler_task, "VLC tx handler", tx_handler, NULL, RTDM_TASK_HIGHEST_PRIORITY, 0); if(ret) goto error; return 0; error: rtdm_task_destroy(&rx_handler_task); rtdm_task_destroy(&tx_handler_task); return -1; }