Demo réception RFM69 (module rf69) Ce programme attend la réception de messages, les affichent sur la liaison série et retourne un accusé réception si demandé.
Il est possible de modifier la puissance d'emission et l'activation du mode promiscuité.
Voilà un exemple d'affichage :
Demo Gateway RFM69 **
----------- Menu -----------
[space]: start/stop Rx
p: toggle promiscous
w: change power level
Frf: 868000 kHz - Power Level: 0 dBm - Promiscuous: 1
Own address: [10]
Receiving data on network 1...
R[10]<[1] < 'Hello 0' > Ack [RSSI = -28]
R[10]<[1] < 'Hello 1' > Ack [RSSI = -28]
....
wPower level [-18,13]? 3
Frf: 868000 kHz - Power Level: 3 dBm - Promiscuous: 1
Own address: [10]
Receiving data on network 1...
R[10]<[1] < 'Hello 10' > Ack [RSSI = -28]
#include <avrio/delay.h>
#include <avrio/led.h>
#include <avrio/rf69.h>
#include <avrio/tc.h>
#include <avrio/assert.h>
#include <avr/pgmspace.h>
#include <string.h>
#define BAUDRATE 115200
#define PORT "tty0"
#define DIO0_IRQ INT0 // Interruption utilisée pour DIO0 (IO2 sur Arduino)
#define MYNODE_ID 10 // Adresse de notre module
#define NET_ID 1 // Numéro de notre réseau
int
main (void) {
int ret, c;
int src, level, net;
bool bPrintStat = true;
bool bRxOn = true;
bool bPromiscuous = true;
stdout = serial_port;
stderr = serial_port;
stdin = serial_port;
printf_P (PSTR ("\n\n** Demo Gateway RFM69 **\n"
"----------- Menu -----------\n"
"[space]: start/stop Rx\n"
" p: toggle promiscous\n"
" w: change power level\n"));
ret =
iRf69Open (rf, eRf69Band868Mhz, MYNODE_ID, NET_ID);
for (;;) {
c = getchar();
switch (c) {
case ' ':
bRxOn = ! bRxOn;
printf_P (PSTR ("\nRx %s\n"), bRxOn ? "On" : "Off");
break;
case 'p':
bPromiscuous = ! bPromiscuous;
printf_P (PSTR ("\nPromiscuous %s\n"), bPromiscuous ? "On" : "Off");
break;
case 'w':
do {
scanf ("%d", &ret);
}
while ( (ret < -18) || (ret > 13));
level = ret + 18;
bPrintStat = true;
break;
default:
break;
}
}
if (bPrintStat) {
if (ret) {
level = level / 2 + 5;
}
else {
level -= 18;
}
printf_P (PSTR ("\nFrf: %lu kHz - Power Level: %d dBm - Promiscuous: %d\n"
"Own address: [%d]\n"
"Receiving data on network %d...\n"),
frf / 1000, level, bPromiscuous, src , net);
bPrintStat = false;
}
if (bRxOn) {
if (ret == true) {
}
if (ret == true) {
printf_P (PSTR (" > Ack"));
}
printf_P (PSTR (" [RSSI = %d]\n"), rssi);
}
}
}
return 0;
}