From 16cf1d7c4cca275023cebe3b68c8fce715c4b12b Mon Sep 17 00:00:00 2001 From: Flavien Haas Date: Tue, 12 Jun 2018 10:28:26 +0200 Subject: [PATCH] FRAME TREATMENT ALGORYTHM WORKS --- LoRaReceiver-struct/LoRaReceiver-struct.ino | 6 -- fakeStation/fakeStation.ino | 2 +- frameTreatment/frameTreatment.ino | 107 ++++++-------------- gateway/gateway.ino | 2 +- 4 files changed, 34 insertions(+), 83 deletions(-) diff --git a/LoRaReceiver-struct/LoRaReceiver-struct.ino b/LoRaReceiver-struct/LoRaReceiver-struct.ino index 29c9058..a490f1a 100644 --- a/LoRaReceiver-struct/LoRaReceiver-struct.ino +++ b/LoRaReceiver-struct/LoRaReceiver-struct.ino @@ -35,10 +35,4 @@ void loop() { } } - - - - - - // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes diff --git a/fakeStation/fakeStation.ino b/fakeStation/fakeStation.ino index 1e1fdc5..96d9d66 100644 --- a/fakeStation/fakeStation.ino +++ b/fakeStation/fakeStation.ino @@ -12,7 +12,7 @@ void setup() { SerialUSB.begin(9600); SerialUSB.println("LoRa Sender"); thisLoRa.begin(); - protocol.codeFrame(0x05,0x07,0x0000,0x0001,0x0300,0x0005,0x0000); + protocol.codeFrame(0x02,0x00,0x0000,0x0001,0x0000,0x0000,0x0000); } void loop() diff --git a/frameTreatment/frameTreatment.ino b/frameTreatment/frameTreatment.ino index 50bf227..8b99e26 100644 --- a/frameTreatment/frameTreatment.ino +++ b/frameTreatment/frameTreatment.ino @@ -7,88 +7,45 @@ #include // to use personalised LoRa class #include // to use our protocol -CModemLoRa receiveLoRa; // create object for personnalizeed LoRa class -CProtocol12Bytes goodOne; // create object that will be used to send data using our protocol +CModemLoRa thisLoRa; // create object for personnalizeed LoRa class +CProtocol12Bytes received; // create object that will be used to send data using our protocol + +uint16_t saveIDandTS[255]; // used to send the correct frame +int numCase; void setup(){ - Serial.begin(9600); - while (!Serial); // wait for serial to initialize - Serial.println("LoRa frame treatment"); // display on serial the name of the device + SerialUSB.begin(9600); + SerialUSB.println("LoRa frame treatment"); // display on serial the name of the device thisLoRa.begin(); // initialise LoRa -} // end of setup +}// end of setup void loop() { - // frame treatment - while(readFrameAndCheckID() == true){ - // post to server - } - -}// end void loop - -bool readFrameAndCheckID(){ - int packetSize = thisLoRa.parsePacket(); - if (packetSize > 0) - { - thisLoRa.read(&checkID); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes - SerialUSB.println("Frame received"); - delay(100); - } - id1 = checkID.getStationId(); - packetSize = thisLoRa.parsePacket(); - if (packetSize > 0) - { - thisLoRa.read(&checkID); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes - SerialUSB.println("Frame received"); - delay(100); - } - id2 = checkID.getStationId(); - if(id1==id2){ - readFrameAndCheckID(); - } - else{ - readFrameAndCheckTS(); - return true; - } -} //end readframeandcheckid - -bool readFrameAndCheckTS(){ int packetSize = thisLoRa.parsePacket(); if (packetSize > 0) { - thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes - SerialUSB.println("Frame received"); - delay(100); - } - ts1 = protocol.getTimestampMessage(); - packetSize = thisLoRa.parsePacket(); - if (packetSize > 0) - { - thisLoRa.read(&protocol); // objet thislora qui appele classe Lora.h et rempli la stucture de l'objet protocol, ser a allèger -5lignes - SerialUSB.println("Frame received"); - delay(100); - } - ts2 = protocol.getTimestampMessage(); - if(ts1==ts2){ - return false; + thisLoRa.read(&received); + numCase = received.getStationId(); + if(received.getTimestampMessage() == saveIDandTS[numCase]) + {} + else{ + saveIDandTS[numCase] = received.getTimestampMessage(); + //post to server + delay(100); + SerialUSB.print("ID = "); + SerialUSB.print(received.getStationId(),HEX); + SerialUSB.println(received.getGatewayId(),HEX); + SerialUSB.print("TS = "); + SerialUSB.println(received.getTimestampMessage(),HEX); + SerialUSB.print("DT = "); + SerialUSB.println(received.getDataType(),HEX); + SerialUSB.print("D1 = "); + SerialUSB.println(received.getDataOne(),HEX); + SerialUSB.print("D2 = "); + SerialUSB.println(received.getDataTwo(),HEX); + SerialUSB.print("D3 = "); + SerialUSB.println(received.getDataThree(),HEX); + SerialUSB.println("NOUVELLE TRAME"); } - else{ - SerialUSB.println("New Frame :"); - SerialUSB.print("ID = "); - SerialUSB.print(protocol.getStationId(),HEX); - SerialUSB.println(protocol.getGatewayId(),HEX); - SerialUSB.print("TS = "); - SerialUSB.println(protocol.getTimestampMessage(),HEX); - SerialUSB.print("DT = "); - SerialUSB.println(protocol.getDataType(),HEX); - SerialUSB.print("D1 = "); - SerialUSB.println(protocol.getDataOne(),HEX); - SerialUSB.print("D2 = "); - SerialUSB.println(protocol.getDataTwo(),HEX); - SerialUSB.print("D3 = "); - SerialUSB.println(protocol.getDataThree(),HEX); - return true; - } -} //end readframeandcheckts - - + }//if (packetSize > 0) +}// end void loop diff --git a/gateway/gateway.ino b/gateway/gateway.ino index 8bc9ade..9deed7e 100644 --- a/gateway/gateway.ino +++ b/gateway/gateway.ino @@ -19,7 +19,7 @@ CProtocol12Bytes protocol; // create object to File webFile; // variable for the file containing the webpage byte mac[] = {0xFA, 0xE3, 0x40, 0xEF, 0xFF, 0xFD}; // set the mac address -IPAddress ip(192, 1, 1, 150); // set the IP address for the ethernet shield, overwise the librairy use DHCP +//IPAddress ip(192, 1, 1, 150); // set the IP address for the ethernet shield, overwise the librairy use DHCP EthernetServer server(80); // initialize the EthernetServer library, using port 80 (default fot HTTP)