int main() { init(); pinMode(14, OUTPUT); pinMode(15, OUTPUT); digitalWrite(15, LOW); pinMode(radioPowerPin, OUTPUT); // power cycle radio digitalWrite(radioPowerPin, LOW); delay(100); digitalWrite(radioPowerPin, HIGH); delay(100); pinMode(sonarPowerPin, OUTPUT); pinMode(sonarGroundPin, OUTPUT); digitalWrite(sonarGroundPin, LOW); digitalWrite(sonarPowerPin, HIGH); Sonar_Init(); Radio_Init(); Radio_Configure(RADIO_2MBPS, RADIO_HIGHEST_POWER); Radio_Configure_Rx(RADIO_PIPE_0, sensor_address, ENABLE); for (;;) { if (radio_flag) { radio_flag = 0; Radio_Receive(&packet); // assumption: radio FIFO contains just one packet if (packet.type == REQUEST_ECHO) { Sonar_PreTrigger(); Radio_Set_Tx_Addr(packet.payload.request.return_address); packet.type = CONFIRM_ECHO; packet.payload.confirm.station_id = STATION_ID; Radio_Transmit(&packet, RADIO_WAIT_FOR_TX); // sonar is triggered as soon as the explorer acknowledges it received the confirmation Sonar_Trigger(); delay(50); digitalWrite(14, LOW); } packet.type = EMPTY; } } for (;;); return 0; }
void radioSend() { /* * Remote Station should only send message of type SENSORDATA to the * Base Station. */ packet.type = SENSORDATA; packet.payload.hovercraftData.command = NONE; // memcpy(packet.payload.message.address, RemoteStationAddr, RADIO_ADDRESS_LENGTH); // snprintf((char*)packet.payload.message.messagecontent, 20, msg); // Send the packet to the address specified with Radio_Set_Tx_Addr above. Radio_Transmit(&packet, RADIO_WAIT_FOR_TX); }
void Net_Send(net_address to_addr, void* pkt, uint8_t len) { packet_header* h = (packet_header*)pkt; memcpy(h->from, _node_address, sizeof(_node_address)); Radio_Set_Tx_Addr(to_addr); Radio_Transmit(pkt, len); }