User manual
IDUINO for maker’s life
www.openplatform.cc
// Got a packet and is it a data packet?
{
// Print data
Serial.write(packet.data, packet.len);
// Reply with ACK
packet.type = PACKET_TYPE_ACK;
packet.len = 0;
sendPacket(&packet);
// Put into receive mode
nRF905_receive();
}
else if(Serial.available()) // We've got some serial data,
need to send it
break;
}
}
// Send a packet
static void sendPacket(void* _packet)
{
// Void pointer to packet_s pointer hack
// Arduino puts all the function defs at the top of the file
before packet_s being declared :/
packet_s* packet = (packet_s*)_packet;
// Convert packet data to plain byte array
byte totalLength = packet->len + 2;
byte tmpBuff[totalLength];
tmpBuff[0] = packet->type;
tmpBuff[1] = packet->len;
memcpy(&tmpBuff[2], packet->data, packet->len);
// Set address of device to send to
//nRF905_setTXAddress(packet->dstAddress);
// Set payload data
nRF905_setData(tmpBuff, totalLength);
// Send payload (send fails if other transmissions are going
on, keep trying until success)
while(!nRF905_send());
}