int8_t control_generate (SAMPL_UPSTREAM_PKT_T * pkt, SAMPL_DOWNSTREAM_PKT_T * ds_pkt) { ACK_PKT_T p; CONTROL_PKT_T r; uint8_t g,num_pkts, i, selected, checksum; nrk_time_t t; g = control_pkt_get (&r, ds_pkt->payload, 0, &checksum); if(g==0) return NRK_ERROR; if (checksum == r.checksum && r.mobile_reserve_seconds != 0) { bmac_set_cca_thresh (r.cca_threshold); if ((r.ctrl_flags_1 & GLOBAL_DEBUG_MASK) != 0) admin_debug_flag = 1; else admin_debug_flag = 0; t.secs = r.mobile_reserve_seconds; t.nano_secs = 0; i = nrk_reserve_set (mobile_reserve, &t, r.mobile_reserve_cnt, NULL); // add route persistence here... nrk_kprintf (PSTR ("Control Pkt:\r\n")); nrk_kprintf (PSTR (" CCA:")); printf ("%d", (int8_t) r.cca_threshold); nrk_kprintf (PSTR ("\r\n Debug:")); printf ("%d", (r.ctrl_flags_1 & GLOBAL_DEBUG_MASK)); nrk_kprintf (PSTR ("\r\n Mobile Reserve time:")); printf ("%lu", r.mobile_reserve_seconds); nrk_kprintf (PSTR (" sec\r\n Mobile Reserve count:")); printf ("%lu", r.mobile_reserve_cnt); nrk_kprintf (PSTR ("\r\n")); // build ACK reply packet p.mac_addr = my_mac; pkt->payload_len = ack_pkt_add (&p, pkt->payload, 0); pkt->num_msgs = 1; pkt->pkt_type = ACK_PKT; pkt->error_code = 0; // set error type for NCK } else { nrk_kprintf (PSTR ("Control packet failed checksum\r\n")); nrk_kprintf (PSTR (" pkt: ")); printf ("%d", r.checksum); nrk_kprintf (PSTR (" calc: ")); printf ("%d\r\n", checksum); // build NCK reply packet p.mac_addr = my_mac; pkt->payload_len = ack_pkt_add (&p, pkt->payload, 0); pkt->num_msgs = 1; pkt->pkt_type = ACK_PKT; pkt->error_code = 1; // set error type for NCK } return NRK_OK; }
int8_t bmac_tx_reserve_set( nrk_time_t *period, uint16_t pkts ) { #ifdef NRK_MAX_RESERVES // Create a reserve if it doesn't exist if(tx_reserve==-1) tx_reserve=nrk_reserve_create(); if(tx_reserve>=0) return nrk_reserve_set(tx_reserve, period,pkts,NULL); else return NRK_ERROR; #else return NRK_ERROR; #endif }