Init fork from Stuart Robinson's repo

This commit is contained in:
2024-10-03 14:30:13 +03:00
commit 9395706524
201 changed files with 45709 additions and 0 deletions

View File

@ -0,0 +1,189 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 12/03/22
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is a program that transfers a file using data transfer (DT) packet functions
from the SX128X library to send a file from the SD card on one Arduino to the SD card on another Arduino.
Arduino DUEs were used for the test and this example transfers an JPG image.
DT packets can be used for transfering large amounts of data in a sequence of packets or segments,
in a reliable and resiliant way. The file open requests to the remote receiver, each segement sent and
the remote file close will all keep transmitting until a valid acknowledge comes from the receiver.
Use this transmitter with the matching receiver program, 234_SDfile_Transfer_Receiver.ino.
On transmission the NetworkID and CRC of the payload are appended to the end of the packet by the library
routines. The use of a NetworkID and CRC ensures that the receiver can validate the packet to a high degree
of certainty.
The transmitter sends the sequence of segments in order. If the sequence fails for some reason, the receiver
will return a NACK packet to the transmitter requesting the segment sequence it was expecting.
Details of the packet identifiers, header and data lengths and formats used are in the file;
'Data transfer packet definitions.md' in the \SX128X_examples\DataTransfer\ folder.
The transfer can be carried out using LoRa or FLRC packets, max segment size (defined by DTSegmentSize) is
245 bytes for LoRa and 117 bytes for FLRC.
Serial monitor baud rate is set at 115200.
*******************************************************************************************************/
#define USELORA //enable this define to use LoRa packets
//#define USEFLRC //enable this define to use FLRC packets
#include <SPI.h>
#include <SX128XLT.h>
#include <ProgramLT_Definitions.h>
#include "DTSettings.h" //LoRa settings etc.
SX128XLT LoRa; //create an SX128XLT library instance called LoRa, required by SDtransfer.h
#define ENABLEMONITOR //enable monitor prints
#define PRINTSEGMENTNUM //enable this define to print segment numbers
#define ENABLEFILECRC //enable this define to uses and show file CRCs
//#define DISABLEPAYLOADCRC //enable this define if you want to disable payload CRC checking
//#define DEBUG //see additional debug info
//#define SDLIB //define SDLIB for SD.h or SDFATLIB for SDfat.h
#define SDFATLIB
#include <DTSDlibrary.h> //library of SD functions
#include <SDtransfer.h> //library of data transfer functions
//choice of files to send
//char FileName[] = "/$50SATL.JPG"; //file length 63091 bytes, file CRC 0x59CE
char FileName[] = "/$50SATS.JPG"; //file length 6880 bytes, file CRC 0x0281
//char FileName[] = "/$50SATT.JPG"; //file length 1068 bytes, file CRC 0x6A02
void loop()
{
uint32_t filelength;
#ifdef ENABLEMONITOR
Monitorport.println(F("Transfer started"));
#endif
filelength = SDsendFile(FileName, sizeof(FileName));
if (filelength)
{
#ifdef ENABLEMONITOR
Monitorport.println(F("Transfer finished"));
#endif
}
else
{
#ifdef ENABLEMONITOR
Monitorport.println(F("Transfer failed"));
Monitorport.println();
#endif
}
delay(15000);
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
SDsetLED(LED1); //setup LED pin for data transfer indicator
#ifdef ENABLEMONITOR
Monitorport.begin(115200);
Monitorport.println();
Monitorport.println(F(__FILE__));
Monitorport.flush();
#endif
SPI.begin();
if (LoRa.begin(NSS, NRESET, RFBUSY, DIO1, LORA_DEVICE))
{
led_Flash(2, 125);
}
else
{
#ifdef ENABLEMONITOR
Monitorport.println(F("LoRa device error"));
#endif
while (1)
{
led_Flash(50, 50); //long fast speed flash indicates device error
}
}
#ifdef USELORA
LoRa.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate);
Serial.println(F("Using LoRa packets"));
#endif
#ifdef USEFLRC
LoRa.setupFLRC(Frequency, Offset, BandwidthBitRate, CodingRate, BT, Syncword);
Serial.println(F("Using FLRC packets"));
#endif
#ifdef ENABLEMONITOR
Monitorport.println();
Monitorport.print(F("Initializing SD card..."));
#endif
if (DTSD_initSD(SDCS))
{
#ifdef ENABLEMONITOR
Monitorport.println(F("SD Card initialized."));
#endif
}
else
{
Monitorport.println(F("SD Card failed, or not present."));
while (1) led_Flash(100, 25);
}
#ifdef ENABLEMONITOR
Monitorport.println();
#endif
#ifdef DISABLEPAYLOADCRC
LoRa.setReliableConfig(NoReliableCRC);
#endif
if (LoRa.getReliableConfig(NoReliableCRC))
{
#ifdef ENABLEMONITOR
Monitorport.println(F("Payload CRC disabled"));
#endif
}
else
{
#ifdef ENABLEMONITOR
Monitorport.println(F("Payload CRC enabled"));
#endif
}
SDDTFileTransferComplete = false;
#ifdef ENABLEMONITOR
Monitorport.println(F("SDfile transfer ready"));
Monitorport.println();
#endif
}

View File

@ -0,0 +1,64 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 12/03/22
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define RFBUSY 7 //RFBUSY pin on LoRa device
#define DIO1 3 //DIO1 pin on LoRa device, used for sensing RX and TX done
#define LED1 8 //LED used to indicate transmission
#define SDCS 30
#define Monitorport Serial //Port where serial prints go
#define LORA_DEVICE DEVICE_SX1280 //this is the device we are using
//******* Setup LoRa Test Parameters Here ! ***************
const uint32_t Frequency = 2445000000; //frequency of transmissions
const uint32_t Offset = 0; //offset frequency for calibration purposes
const int8_t TXpower = 10; //LoRa transmit power
//******* Setup LoRa modem parameters here ! ***************
const uint8_t Bandwidth = LORA_BW_1600; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF5; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
//******* Setup FLRC modem parameters here ! ***************
const uint8_t BandwidthBitRate = FLRC_BR_1_300_BW_1_2; //FLRC bandwidth and bit rate, 1.3Mbs
//const uint8_t BandwidthBitRate = FLRC_BR_0_260_BW_0_3; //FLRC 260kbps
const uint8_t CodingRate = FLRC_CR_1_0; //FLRC coding rate
const uint8_t BT = RADIO_MOD_SHAPING_BT_1_0; //FLRC BT
const uint32_t Syncword = 0x01234567; //FLRC uses syncword
const uint32_t TXtimeoutmS = 5000; //mS to wait for TX to complete
const uint32_t RXtimeoutmS = 60000; //mS to wait for receiving a packet
const uint32_t ACKdelaymS = 0; //ms delay after packet actioned and ack sent
const uint32_t ACKsegtimeoutmS = 75; //mS to wait for receiving an ACK before re-trying transmit segment
const uint32_t ACKopentimeoutmS = 250; //mS to wait for receiving an ACK before re-trying transmit file open
const uint32_t ACKclosetimeoutmS = 250; //mS to wait for receiving an ACK before re-trying transmit file close
const uint32_t DuplicatedelaymS = 10; //ms delay if there has been an duplicate segment or command receipt
const uint32_t FunctionDelaymS = 0; //delay between functions such as open file, send segments etc
const uint32_t PacketDelaymS = 1000; //mS delay between transmitted packets such as DTInfo etc
const uint8_t StartAttempts = 2; //number of attempts to start transfer before a fail
const uint8_t SendAttempts = 5; //number of attempts carrying out a process before a restart
const uint32_t NoAckCountLimit = 250; //if no NoAckCount exceeds this value - restart transfer
const uint8_t HeaderSizeMax = 12; //max size of header in bytes, minimum size is 7 bytes
const uint8_t DataSizeMax = 245; //max size of data array in bytes
const uint8_t Maxfilenamesize = 32; //size of DTfilename buffer
const uint16_t NetworkID = 0x3210; //a unique identifier to go out with packet
#ifdef USELORA
const uint8_t SegmentSize = 245; //number of bytes in each segment, 245 is maximum value for LoRa
#endif
#ifdef USEFLRC
const uint8_t SegmentSize = 117; //number of bytes in each segment, 117 is maximum value for FLRC
#endif