#include <bcm2835.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
void sig_handler(int sig);
void printbuffer(uint8_t buff[], int len);
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
RH_NRF24 nrf24(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24);
volatile sig_atomic_t flag = 0;
int main (int argc, const char* argv[] )
{
signal(SIGINT, sig_handler);
if (!bcm2835_init())
{
printf( "\n\nRasPiRH Tester Startup Failed\n\n" );
return 1;
}
printf( "\nRasPiRH Tester Startup\n\n" );
if (!manager.init())
{
printf( "Init failed\n" );
}
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
while (true)
{
uint8_t len = sizeof(buf);
uint8_t from, to, id, flags;
if (manager.available())
{
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAck(buf, &len, &from))
{
Serial.print("got request from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
}
if (flag)
{
printf("\n---CTRL-C Caught - Exiting---\n");
break;
}
delay(25);
}
printf( "\nRasPiRH Tester Ending\n" );
bcm2835_close();
return 0;
}
void sig_handler(int sig)
{
flag=1;
}
void printbuffer(uint8_t buff[], int len)
{
for (int i = 0; i< len; i++)
{
printf(" %2X", buff[i]);
}
}
RHDatagram subclass for sending addressed, acknowledged, retransmitted datagrams.
Definition RHReliableDatagram.h:96
Send and receive unaddressed, unreliable datagrams by nRF24L01 and compatible transceivers.
Definition RH_NRF24.h:424