/* 
 * File:  
 * Author: JF
 *
 * Created on November 30, 2018, 7:33 PM
 */

#ifndef E220_MODULE_H
#define	E220_MODULE_H
#include "define.h"

#define E220_CONFIG_SIZE 6  //Nb of bytes composing the configuration of the module

#define E220_UART_RATE_MASK 0x07
enum eE220UartRates
{
    E220_UART_1200 = 0,
    E220_UART_2400,
    E220_UART_4800,
    E220_UART_9600,
    E220_UART_19200,
    E220_UART_38400,
    E220_UART_57600,
    E220_UART_115200
    
};

#define E220_UART_PARITY_MASK 0x03
enum eE220ParityBit
{
    E220_UART_8N1=0,
    E220_UART_8O1,
    E220_UART_8E1,
    E220_UART_8N1_bis
};

#define E220_AIR_RATE_MASK 0x07
enum e220AirDataRates
{
    E220_AIR_RATE_24K = 0,
    E220_AIR_RATE_24K_1,
    E220_AIR_RATE_24K_2,
    E220_AIR_RATE_48K,
    E220_AIR_RATE_96K,
    E220_AIR_RATE_192K,
    E220_AIR_RATE_384K,
    E220_AIR_RATE_625K
};

#define E220_PACKET_SIZE_MASK 0x03
enum e220PacketSizes
{
    E220_PACKET_200,
    E220_PACKET_128,
    E220_PACKET_64,
    E220_PACKET_32
};

#define E220_TX_POWER_MASK 0x03
enum e220TransmitPower
{
    E220_TX_PWR_30,
    E220_TX_PWR_27,
    E220_TX_PWR_24,
    E220_TX_PWR_21
};

#define E220_WOR_CYCLE_MASK 0x07
enum e220WORCycles
{
    E220_WOR_500MS,
    E220_WOR_1000MS,
    E220_WOR_1500MS,
    E220_WOR_2000MS,
    E220_WOR_2500MS,
    E220_WOR_3000MS,
    E220_WOR_3500MS,
    E220_WOR_4000MS
};

int InitLoraModule();

int SetLoraModuleTxMode();
int SetLoraModuleConfigMode();
int ReadLoraModuleConfig();
int AnalyzeLoraModuleConfigData(char *Data, int size);
int ReadLoraModuleRSSI();
int AnalyzeLoraModuleRSSI(char *Data, int size);



unsigned short mModuleInternalAddress;
unsigned char mModuleUARTParity;
unsigned char mModuleUARTRate;
unsigned char mModuleAirRate;
unsigned char mModuleSubPacket;
unsigned char mModuleRSSIEnabled;
unsigned char mModuleTxPower;
unsigned char mModuleInternalChannel;
unsigned char mModuleRSSIByteEnabled;
unsigned char mModuleTxMethod;
unsigned char mModuleLBTEnabled;
unsigned char mModuleWORCycle;

unsigned char mModuleAmbientRSSI;
unsigned char mModuleLastRxRSSI;

#endif	/* E220_MODULE_H */

