Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THREAD::DELETE:Deletion of the class Receive #10

Merged
merged 5 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Lora/src/API.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* File: API.c
* Author: Fabien AMELINCK
*
* Created on 28 February 2023
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <stdint.h>
#include <time.h>
#include "gpio_util.h"
#include "SX1272.h"
#include "RF_LoRa_868_SO.h"
#include "sendRecept.h"
#include "filecsv.h"

#define debug 1
#define useInit
56 changes: 32 additions & 24 deletions Lora/src/Init.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,40 @@ int main(int argc, char *argv[]) {

if (init_spi()) return -1;

// Configure the pin used for RESET of LoRa transceiver
// here: physical pin n°38 (GPIO20)
create_port(20);
set_port_direction(20, 1);
uint8_t error = 0;
do {
error = 0;
// Configure the pin used for RESET of LoRa transceiver
// here: physical pin n°38 (GPIO20)
create_port(20);
usleep(10000);
set_port_direction(20, 1); // switch direction to input (high impedance)

// Configure the pin used for RX_SWITCH of LoRa transceiver
// here: physical pin n°29 (GPIO5)
create_port(5);
usleep(10000);
set_port_direction(5, 0);
set_port_value(5, 0);

// Configure the pin used for RX_SWITCH of LoRa transceiver
// here: physical pin n°29 (GPIO5)
create_port(5);
set_port_direction(5, 0);
set_port_value(5, 0);
// Configure the pin used for TX_SWITCH of LoRa transceiver
// here: physical pin n°31 (GPIO6)
create_port(6);
usleep(10000);
set_port_direction(6, 0);
if (set_port_value(6, 0)) {
fprintf(stdout, "Bug in port openning, please retry\n");
error = 1;
} else error = 0;

// Configure the pin used for TX_SWITCH of LoRa transceiver
// here: physical pin n°31 (GPIO6)
create_port(6);
set_port_direction(6, 0);
if (set_port_value(6, 0)) {
fprintf(stdout, "Bug in port openning, please retry\n");
return -1;
}

// Configure the pin used for LED
// here: physical pin n°40 (GPIO21)
/*create_port(21);
set_port_direction(21, 0);
set_port_value(21, 0);*/
// Configure the pin used for LED
// here: physical pin n°40 (GPIO21)
/*create_port(21);
usleep(1000);
set_port_direction(21, 0);
set_port_value(21, 0);*/
} while (error);

ResetModule();

Expand All @@ -73,9 +81,9 @@ int main(int argc, char *argv[]) {
// memset(inbuf, 0, sizeof inbuf);
// memset(outbuf, 0, sizeof outbuf);

//InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc);
//InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc);
InitModule(CH_17_868, BW_500, SF_7, CR_5, 0x12, 0x08, 2, G1, LONGT, HEADER_ON, CRC_ON);
// InitModule(CH_17_868, BW_500, SF_12, CR_5, 0x12, 0x08, 2, G1, SHORTT, HEADER_ON, CRC_ON);
InitModule(CH_17_868, BW_500, SF_7, CR_5, 0x12, 0x08, 2, G1, SHORTT, HEADER_ON, CRC_ON);

return 0;
} // end main
89 changes: 58 additions & 31 deletions Lora/src/Receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <signal.h>
#include <stdint.h>
#include <time.h>
#include <poll.h>
#include "gpio_util.h"
#include "SX1272.h"
#include "RF_LoRa_868_SO.h"
Expand All @@ -21,8 +22,6 @@
#define debug 1
#define useInit

//#define MY_ID ISEN_ID

int main(int argc, char *argv[]) {

uint8_t NodeData[255]; // data sent by a node
Expand All @@ -45,31 +44,38 @@ int main(int argc, char *argv[]) {

if (init_spi()) return -1;

// Configure the pin used for RESET of LoRa transceiver
// here: physical pin n°38 (GPIO20)
create_port(20);
set_port_direction(20, 1);

// Configure the pin used for RX_SWITCH of LoRa transceiver
// here: physical pin n°29 (GPIO5)
create_port(5);
set_port_direction(5, 0);
set_port_value(5, 0);

// Configure the pin used for TX_SWITCH of LoRa transceiver
// here: physical pin n°31 (GPIO6)
create_port(6);
set_port_direction(6, 0);
if (set_port_value(6, 0)) {
fprintf(stdout, "Bug in port openning, please retry");
return -1;
}

// Configure the pin used for LED
// here: physical pin n°40 (GPIO21)
/*create_port(21);
set_port_direction(21, 0);
set_port_value(21, 0);*/
uint8_t error = 0;
do {
// Configure the pin used for RESET of LoRa transceiver
// here: physical pin n°38 (GPIO20)
create_port(20);
usleep(10000);
set_port_direction(20, 1); // switch direction to input (high impedance)

// Configure the pin used for RX_SWITCH of LoRa transceiver
// here: physical pin n°29 (GPIO5)
create_port(5);
usleep(10000);
set_port_direction(5, 0);
set_port_value(5, 0);

// Configure the pin used for TX_SWITCH of LoRa transceiver
// here: physical pin n°31 (GPIO6)
create_port(6);
usleep(10000);
set_port_direction(6, 0);
if (set_port_value(6, 0)) {
fprintf(stdout, "Bug in port openning, please retry\n");
error = 1;
} else error = 0;

// Configure the pin used for LED
// here: physical pin n°40 (GPIO21)
/*create_port(21);
usleep(1000);
set_port_direction(21, 0);
set_port_value(21, 0);*/
} while (error);

#ifndef useInit
ResetModule();
Expand All @@ -89,10 +95,12 @@ int main(int argc, char *argv[]) {
// memset(inbuf, 0, sizeof inbuf);
// memset(outbuf, 0, sizeof outbuf);

//InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc);
InitModule(CH_17_868, BW_500, SF_12, CR_5, 0x12, 0x08, 2, G1, 0x00, HEADER_ON, CRC_ON);
//InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc);
InitModule(CH_17_868, BW_500, SF_7, CR_5, 0x12, 0x08, 2, G1, LONGT, HEADER_ON, CRC_ON);
#endif

setbuf(stdout, NULL);

if (argc > 1) {
#if debug
fprintf(stdout, "args %d", argc); // Printing all args passed during call
Expand All @@ -107,9 +115,28 @@ int main(int argc, char *argv[]) {
#endif

uint8_t received = 0, loop = 0, maxLoop = 10;
if (argc == 3) maxLoop = atoi(argv[2]);
uint8_t noending = 0, halt = 0;
if (argc == 3) !atoi(argv[2]) ? (noending = 1) : (maxLoop = atoi(argv[2]));

struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI, POLLIN|POLLPRI };

while (loop < maxLoop || noending) {
if( poll(&mypoll, 1, 10) ) {
char stopCmd[10];
scanf("%9s", stopCmd);
fprintf(stdout, "You have typed: %s\n", stopCmd);
if (!strcmp(stopCmd, "stop")) halt = 1;
else if (!strcmp(stopCmd, "exit")) return 0;
while (halt) {
if( poll(&mypoll, 1, 5000) ) {
char restartCmd[10];
scanf("%9s", restartCmd);
fprintf(stdout, "You have typed: %s\n", restartCmd);
if (!strcmp(restartCmd, "restart")) halt = 0;
} else fprintf(stdout, "Waiting for restart command\n");
};
}

while (!received && loop < maxLoop) {
if (argc == 3) CRCError = WaitIncomingMessageRXSingle(&TimeoutOccured);
else CRCError = WaitIncomingMessageRXContinuous();

Expand Down
12 changes: 6 additions & 6 deletions Lora/src/Transmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ int main(int argc, char *argv[]) {
// memset(inbuf, 0, sizeof inbuf);
// memset(outbuf, 0, sizeof outbuf);

//InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc);
InitModule(CH_17_868, BW_500, SF_12, CR_5, 0x12, 0x08, 2, G1, 0x00, HEADER_ON, CRC_ON);
//InitModule(freq, bw, sf, cr, sync, preamble, pout, gain, rxtimeout, hder, crc);
InitModule(CH_17_868, BW_500, SF_7, CR_5, 0x12, 0x08, 2, G1, LONGT, HEADER_ON, CRC_ON);
#endif

//DeleteDataFile();
Expand Down Expand Up @@ -146,21 +146,21 @@ int main(int argc, char *argv[]) {
}
TxBuffer[DEST_ID_POS] = (uint8_t) atoi(argv[2]);
TxBuffer[COMMAND_POS] = LED_OFF;
} else if (!strcmp(argv[1], "D")) {
} else if (!strcmp(argv[1], "D")) { // Discover
if (argc != 4) {
fprintf(stdout, "Error nb args, usage : D <destination_id> <source_id>");
return -1;
}
TxBuffer[DEST_ID_POS] = (uint8_t) atoi(argv[2]);
TxBuffer[COMMAND_POS] = DISCOVER;
} else if (!strcmp(argv[1], "P")) {
} else if (!strcmp(argv[1], "P")) { // Ping
if (argc != 4) {
fprintf(stdout, "Error nb args, usage : P <destination_id> <source_id>");
return -1;
}
TxBuffer[DEST_ID_POS] = (uint8_t) atoi(argv[2]);
TxBuffer[COMMAND_POS] = PING;
} else if (!strcmp(argv[1], "T")) {
} else if (!strcmp(argv[1], "T")) { // Transmit
if (argc != 7) {
fprintf(stdout, "Error nb args, usage : T <destination_id> <source_id> <sensor_id> <T> <O>");
return -1;
Expand All @@ -171,7 +171,7 @@ int main(int argc, char *argv[]) {
TxBuffer[T_POS] = (uint8_t) atoi(argv[5]);
TxBuffer[O_POS] = (uint8_t) atoi(argv[6]);
PayloadLength = TRANSMIT_LONG;
} else if (!strcmp(argv[1], "A")) {
} else if (!strcmp(argv[1], "A")) { // Acknowledge
if (argc != 7) {
fprintf(stdout, "Error nb args, usage : A <destination_id> <source_id> <sensor_id> <ACK> <R>");
return -1;
Expand Down
2 changes: 1 addition & 1 deletion Lora/src/filecsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void WriteResetInFile(void)

fprintf(df, "%02d/%02d/%d; ", day, month, year);
fprintf(df, "%02d:%02d:%02d; ", hour, min, sec);
fprintf(df, "LORa module reset\n");
fprintf(df, "LoRa module reset\n");

fclose(df);
}
Loading