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

#ifndef LORA_INTERFACE_H
#define	LORA_INTERFACE_H
#include "define.h"
#include "E220Module.h"

#define MAX_LORA_BUFFER_SIZE 2048
#define LORA_RX_INTERBYTE_TIMEOUT 200  //ms


int mLoraRxSMState;
char mLoraModuleBuffer[MAX_LORA_BUFFER_SIZE];
int mBufferIndex;
int mLastConfigCommand;

enum eLoraModuleModel
{
    LORA_MODULE_E32_MODEL = 32,
    LORA_MODULE_E220_MODEL = 220,
    
    LORA_MODULE_MAX_MODEL
          
};

enum eLoraNetworkRxSMStates
{
    LORA_RX_SM_STANBY_STATE,
    LORA_RX_SM_RECEIVING_STATE,
    LORA_RX_SM_CONFIG_STATE,
    
    LORA_RX_SM_MAX_STATE
};

enum eLoraRxSMEvents
{
    LORA_RX_SM_NEW_DATA_EVENT,
    LORA_RX_SM_TICK_EVENT,
    
    LORA_RX_SM_MAX_EVENT 
};

enum eLoraInterfaceStatusCodes
{
    LORA_IF_RET_OK,
    LORA_IF_RET_GENERAL_ERROR,
    LORA_IF_RET_BUSY_CHANNEL,
    
    LORA_IF_MAX_STATUS_CODE
    
};

enum eLoraConfigCmds
{
    LORA_CONFIG_READ_CONFIG_CMD,
    LORA_CONFIG_READ_RSSI_CMD,
    
    LORA_CONFIG_MAX_CMD
};

#define LORA_MODULE_MODEL LORA_MODULE_E220_MODEL

int InitLoraInterface();
int LoraInterfaceRxData(char Data);
int LoraRxStateMachine(char Data, int Event);
void LoraResetRxStateMachine();
int LoraInterfaceTransmitLoRaData(char *Payload, unsigned int PayloadSize);
void LoraInterfaceTick();
void LoraInterfaceRequestModuleConfig();
void LoraInterfaceRequestModuleRSSI();
int LoraInterfaceIsBusy();
   

#endif	/* LORA_MODULE_H */

