Commit initial du projet
This commit is contained in:
commit
a8ed96cb5f
23 files changed
+3037
No files matched your search
@@ -0,0 +1,114 @@
|
||||
#include <SPI.h>
|
||||
#include <RH_RF95.h>
|
||||
#include <M5Stack.h>
|
||||
|
||||
//Déclaration des constantes
|
||||
#define RFM95_CS 5 //M5 LoRa
|
||||
#define RFM95_DIO0 36 //M5 LoRa
|
||||
RH_RF95 rf95(RFM95_CS, RFM95_DIO0);
|
||||
|
||||
uint8_t state;
|
||||
uint8_t txbuf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
uint8_t rxbuf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
uint8_t rxlen=RH_RF95_MAX_MESSAGE_LEN;
|
||||
uint8_t RxSeq;
|
||||
|
||||
#define E0 0
|
||||
#define E1 1
|
||||
#define E2 2
|
||||
#define E3 3
|
||||
|
||||
#define TYPE_DATA 1
|
||||
#define TYPE_ACK 2
|
||||
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
M5.Power.begin();
|
||||
Serial.println("====Recepteur CAP2====");
|
||||
M5.Lcd.println("====Recepteur CAP2====");
|
||||
|
||||
delay(3000);
|
||||
|
||||
if(!rf95.init()){
|
||||
Serial.println("Echec de la mise en place");
|
||||
M5.Lcd.println("Echec de la mise en place");
|
||||
}
|
||||
else{
|
||||
Serial.println("Mise en place reussie !!!");
|
||||
M5.Lcd.println("Mise en place reussie !!!");
|
||||
rf95.setModemConfig(RH_RF95::Bw125Cr45Sf128);
|
||||
rf95.setFrequency(867.8);
|
||||
|
||||
state=E0;
|
||||
Serial.println("Boucle principale");
|
||||
M5.Lcd.println("Boucle principale");
|
||||
RxSeq=255;
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
switch(state){
|
||||
case E0:
|
||||
Serial.println("Mode Reception");
|
||||
M5.Lcd.println("Mode Reception");
|
||||
rf95.setModeRx();
|
||||
state=E1;
|
||||
break;
|
||||
|
||||
case E1:
|
||||
if(rf95.recv(rxbuf, &rxlen)){
|
||||
if(rxbuf[0]==TYPE_DATA){
|
||||
state=E2;
|
||||
}
|
||||
else{
|
||||
state=E0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case E2:
|
||||
|
||||
if(RxSeq!=rxbuf[1]){
|
||||
RxSeq=rxbuf[1];
|
||||
Serial.printf("[%d] ", RxSeq);
|
||||
M5.Lcd.printf("[%d] ", RxSeq);
|
||||
Serial.printf("DATA de %d octets :", rxlen);
|
||||
M5.Lcd.printf("DATA de %d octets :", rxlen);
|
||||
Serial.println();
|
||||
M5.Lcd.println();
|
||||
for(int i=0;i<rxlen;i++){
|
||||
Serial.printf("%02x|", rxbuf[i]);
|
||||
M5.Lcd.printf("%02x|", rxbuf[i]);
|
||||
}
|
||||
Serial.println();
|
||||
M5.Lcd.println();
|
||||
}
|
||||
else{
|
||||
Serial.printf("Duplication\n");
|
||||
M5.Lcd.printf("Duplication\n");
|
||||
}
|
||||
state=E3;
|
||||
break;
|
||||
|
||||
case E3:
|
||||
|
||||
Serial.println("Envoi ACK");
|
||||
M5.Lcd.println("Envoi ACK");
|
||||
|
||||
txbuf[0]=TYPE_ACK;
|
||||
txbuf[1]=rxbuf[1];
|
||||
|
||||
rf95.send(txbuf,2);
|
||||
rf95.waitPacketSent();
|
||||
|
||||
state=E0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user