#include "stm32l4xx_hal.h"
#include "stm32l4xx_hal_spi.h"
#include "SX127x.h"
#include "string.h"
#include "usbd_cdc_if.h"
#include "ctype.h"

extern SPI_HandleTypeDef hspi1;
extern uint16_t begin_flag ;
extern uint8_t* CDC_RX_BUFFER ;
extern TIM_HandleTypeDef htim2;

uint16_t RX_LoRa_Flag = 0;

unsigned int    fre = 470;
unsigned char   SpreadingFactor=11;    //7-12
unsigned char   CodingRate=2;          //1-4
unsigned char   Bw_Frequency=7;        //6-9
unsigned char   powerValue= 20;        //(5~20)
unsigned char   power_data[16]={0X80,0X81,0X82,0X83,0X84,0X85,0X86,0X87,0X88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f};
unsigned char   RF_EX0_STATUS;
unsigned char   CRC_Value;
unsigned char   SX127x_RLEN;


int32_t string_to_dec(uint8_t *buf,uint32_t len)
{
  uint32_t i=0;
  uint32_t base=10;       //基数
  int32_t  neg=1;         //表示正负,1=正数
  int32_t  result=0;

   if((buf[0]=='0')&&(buf[1]=='x'))
   {
      base=16;
      neg=1;
      i=2;
   }
   else if(buf[0]=='-')
   {
      base=10;
      neg=-1;
      i=1;
   }
   for(;i<len;i++)
   {
      if(buf[i]==0x20 || buf[i]==0x0D)    //为空格
      {
          break;
      }
      result *= base;
      if(isdigit(buf[i]))                 //是否为0~9
      {
          result += buf[i]-'0';
      }
      else if(isxdigit(buf[i]))           //是否为a~f或者A~F
      {
           result+=tolower(buf[i])-87;
      }
      else
      {
          result += buf[i]-'0';
      }
   }
   result *= neg;

   return result ;
}

uint32_t count_num(void)
{
	uint8_t  REV[10];
	uint32_t Count_num = 0;
	while(1)
	{
		if(CDC_RX_BUFFER != NULL)
		{
			usb_printf("%c", *CDC_RX_BUFFER);
			if((*CDC_RX_BUFFER) == 0x0d || (*(CDC_RX_BUFFER+1)) == 0x0a)
			{
				return string_to_dec(REV,Count_num);//如果每次真的只传一个的话，那么这个地方的条件有一点欠妥，或许可以改成或 ||
			}
			REV[Count_num] = *CDC_RX_BUFFER;
			Count_num += 1;
			CDC_RX_BUFFER = NULL;
			if(Count_num == 10)
			{
				Count_num = 0;
				usb_printf("Value overflow, please re-enter\r\n");
			}
		}
		if(begin_flag)
		{
			return 0; //使用默认配置参数
		}
	}
}

void Parameter_Init(void)
{
	 HAL_TIM_Base_Start_IT(&htim2);
//	 HAL_Delay(3000);
	 usb_printf("LoRa default frequency:%d\r\n",fre);
	 HAL_Delay(500);
	 usb_printf("LoRa default Spreading Factor:%d\r\n",SpreadingFactor);
	 HAL_Delay(500);
	 usb_printf("LoRa default output power:%d\r\n",powerValue);
	 uint32_t Decnumber = 0;
	 HAL_Delay(500);
	 usb_printf("Please enter the frequency and end with Enter. (400 ~ 1000) MHz: ");
	 while(1){
		 //计算收到的数
		 Decnumber = count_num();
		 if(begin_flag)
		 {
			 return ; //使用默认配置参数
		 }
		 if( (Decnumber > 0) && (Decnumber <1000))
		 {
			 HAL_TIM_Base_Stop_IT(&htim2);
			 fre = Decnumber;
			 HAL_Delay(200);
			 usb_printf("\nLoRa frequency set to %d MHz\r\n",fre);
			 HAL_Delay(50);
			 Decnumber = 0;
			 break;
		 }
		 else
		 {
			 usb_printf("\nIncorrect input, please re-enter\r\n");
			 CDC_RX_BUFFER = NULL;
		 }
	 }
	 usb_printf("Please enter Spreading Factor, end with Enter (7 ~ 12): ");
	 CDC_RX_BUFFER = NULL;
	 while(1)
	 {
		 Decnumber = count_num();
		 if( (Decnumber >6) &&(Decnumber <13) )
		 {
			 SpreadingFactor = Decnumber;
			 HAL_Delay(200);
			 usb_printf("\nSpreading Factor: %d\r\n",SpreadingFactor);
			 HAL_Delay(50);
			 Decnumber = 0;
			 break;
		 }
		 else
		 {
			 usb_printf("\nIncorrect input, please re-enter\r\n");
			 CDC_RX_BUFFER =NULL;
		 }
	 }
	 usb_printf("Please enter CodingRate and end with Enter (1 ~ 4): ");
	 CDC_RX_BUFFER = NULL;
	 while(1)
	 {
		 Decnumber = count_num();
		 if( (Decnumber >0) &&(Decnumber <5) )
		 {
			 CodingRate = Decnumber;
			 HAL_Delay(200);
			 usb_printf("\nCoding Rate: %d\r\n",CodingRate);
			 HAL_Delay(50);
			 Decnumber = 0;
			 break;
		 }
		 else
		 {
			 usb_printf("\nIncorrect input, please re-enter\r\n");
			 CDC_RX_BUFFER =NULL;
		 }
	 }
	 usb_printf("Please enter LoRa output power, end with Enter (11 ~ 20) dBm: ");
	 CDC_RX_BUFFER = NULL;

	 while(1)
	 {
		 Decnumber = count_num();
		 if( (Decnumber >10) &&(Decnumber <21))
		 {
			 powerValue = Decnumber;
			 HAL_Delay(200);
			 usb_printf("\nLoRa output power set to %d dBm\r\n",powerValue);
			 HAL_Delay(500);
			 Decnumber = 0;
			 break;
		 }
		 else
		 {
			 usb_printf("\nIncorrect input, please re-enter\r\n");
			 CDC_RX_BUFFER =NULL;
		 }
	 }
}


void gByteWritefunc(unsigned char buffer)
{
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);//set NSS(PA_4) to low
    HAL_SPI_Transmit(&hspi1, &buffer, 1, 10);
}

unsigned char gByteReadfunc(void)
{
    unsigned char temp=0;
    
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);//set NSS(PA_4) to low
    HAL_SPI_Receive(&hspi1, &temp, 1,10);
	
	return temp;
}

void SX127xWriteBuffer( unsigned char addr, unsigned char buffer)
{
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);//set NSS(PA_4) to low
	gByteWritefunc(addr|0x80);
	gByteWritefunc(buffer);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);//set NSS(PA_4) to high
}

unsigned char SX127xReadBuffer(unsigned char addr)
{
	unsigned char Value;
	
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);//set NSS(PA_4) to low
	gByteWritefunc(addr & 0x7f);
	Value = gByteReadfunc();
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);//set NSS(PA_4) to high
	
	return Value; 
}

void SX127xReset(void)
{
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);//set LoRa RESET(PA_1) to low
	HAL_Delay(200);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
	HAL_Delay(500);
}

void SX127xLoRaSetOpMode( RFMode_SET opMode )
{
	unsigned char opModePrev;
	opModePrev=SX127xReadBuffer(REG_LR_OPMODE);
	opModePrev &=0xf8;
	opModePrev |= (unsigned char)opMode;
	SX127xWriteBuffer( REG_LR_OPMODE, opModePrev);
}

void SX127xLoRaFsk( Debugging_fsk_ook opMode )
{
	unsigned char opModePrev;
	opModePrev=SX127xReadBuffer(REG_LR_OPMODE);
	opModePrev &=0x7F;
	opModePrev |= (unsigned char)opMode;
	SX127xWriteBuffer( REG_LR_OPMODE, opModePrev);
}

void SX127xLoRaSetRFFrequency(unsigned int fre)
{
	int n=fre/61.035;
	unsigned char Frequency[3];
	Frequency[0]=n>>16;
	Frequency[1]=n>>8;
	Frequency[2]=n>>0;
	SX127xWriteBuffer( REG_LR_FRFMSB, Frequency[0]);
	SX127xWriteBuffer( REG_LR_FRFMID, Frequency[1]);
	SX127xWriteBuffer( REG_LR_FRFLSB, Frequency[2]);
}

void SX127xLoRaSetRFPower(unsigned char power )
{
	//Set Pmax to +20dBm for PA_HP, Must turn off PA_LF or PA_HF, and set RegOcp
	//SX1276WriteBuffer( REG_LR_PACONFIG,  power_data[power] );
	SX127xWriteBuffer( REG_LR_OCP, 0x3f);
	SX127xWriteBuffer( REG_LR_PADAC, 0x87);  //high power
	SX127xWriteBuffer( REG_LR_PACONFIG, power_data[power - 5] );
}

void SX127xLoRaSetSpreadingFactor(unsigned char factor )
{
	unsigned char RECVER_DAT;
	SX127xLoRaSetNbTrigPeaks( 3 ); //0x03-->SF7 to SF12
	RECVER_DAT=SX127xReadBuffer( REG_LR_MODEMCONFIG2);
	RECVER_DAT = ( RECVER_DAT & RFLR_MODEMCONFIG2_SF_MASK ) | ( factor << 4 );
	SX127xWriteBuffer( REG_LR_MODEMCONFIG2, RECVER_DAT );	 
}

void SX127xLoRaSetNbTrigPeaks(unsigned char value )
{
	unsigned char RECVER_DAT;
	RECVER_DAT = SX127xReadBuffer( 0x31);  //Read RegDetectOptimize,
	RECVER_DAT = ( RECVER_DAT & 0xF8 ) | value; //process;
	SX127xWriteBuffer( 0x31, RECVER_DAT );  //write back;
}

void SX127xLoRaSetErrorCoding(unsigned char value )
{	
	unsigned char RECVER_DAT;
	RECVER_DAT=SX127xReadBuffer( REG_LR_MODEMCONFIG1);
	RECVER_DAT = ( RECVER_DAT & RFLR_MODEMCONFIG1_CODINGRATE_MASK ) | ( value << 1 );
	SX127xWriteBuffer( REG_LR_MODEMCONFIG1, RECVER_DAT);
}

void SX127xLoRaSetPacketCrcOn(BOOL_t enable )
{	
	unsigned char RECVER_DAT;
	RECVER_DAT= SX127xReadBuffer( REG_LR_MODEMCONFIG2);
	RECVER_DAT = ( RECVER_DAT & RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK ) | ( enable << 2 );
	SX127xWriteBuffer( REG_LR_MODEMCONFIG2, RECVER_DAT );
}

void SX127xLoRaSetSignalBandwidth(unsigned char bw )
{
	unsigned char RECVER_DAT;
	RECVER_DAT=SX127xReadBuffer( REG_LR_MODEMCONFIG1);
	RECVER_DAT = ( RECVER_DAT & RFLR_MODEMCONFIG1_BW_MASK ) | ( bw << 4 );
	SX127xWriteBuffer( REG_LR_MODEMCONFIG1, RECVER_DAT );
}

void SX127xLoRaSetImplicitHeaderOn(BOOL_t enable )
{
	unsigned char RECVER_DAT;
	RECVER_DAT=SX127xReadBuffer( REG_LR_MODEMCONFIG1 );
	RECVER_DAT = ( RECVER_DAT & RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) | ( enable );
	SX127xWriteBuffer( REG_LR_MODEMCONFIG1, RECVER_DAT );
}

void SX127xLoRaSetSymbTimeout(unsigned int value )
{
	unsigned char RECVER_DAT[2];
	RECVER_DAT[0]=SX127xReadBuffer( REG_LR_MODEMCONFIG2 );
	RECVER_DAT[1]=SX127xReadBuffer( REG_LR_SYMBTIMEOUTLSB );
	RECVER_DAT[0] = ( RECVER_DAT[0] & RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) | ( ( value >> 8 ) & ~RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK );
	RECVER_DAT[1] = value & 0xFF;
	SX127xWriteBuffer( REG_LR_MODEMCONFIG2, RECVER_DAT[0]);
	SX127xWriteBuffer( REG_LR_SYMBTIMEOUTLSB, RECVER_DAT[1]);
}

void SX127xLoRaSetPayloadLength(unsigned char value )
{
	SX127xWriteBuffer( REG_LR_PAYLOADLENGTH, value );
} 

void SX127xLoRaSetMobileNode(BOOL_t enable )
{	 
	unsigned char RECVER_DAT;
	RECVER_DAT=SX127xReadBuffer( REG_LR_MODEMCONFIG3 );
	RECVER_DAT = ( RECVER_DAT & RFLR_MODEMCONFIG3_MOBILE_NODE_MASK ) | ( enable << 3 );
	SX127xWriteBuffer( REG_LR_MODEMCONFIG3, RECVER_DAT );
}

void SX127xLORA_INT(void)
{
	SX127xLoRaSetOpMode(Sleep_mode);
	SX127xLoRaFsk(LORA_mode);
	SX127xLoRaSetOpMode(Stdby_mode);

	usb_printf("SPI write 0xAB to LoRa buffer\r\n");
	SX127xWriteBuffer(0x40, 0xAB);
	HAL_Delay(10);
	usb_printf("LoRa buffer read result: 0x%X\r\n", SX127xReadBuffer(0x40));
	
//	usb_printf("0x%X\r\n", SX127xReadBuffer(REG_LR_DIOMAPPING1));
	SX127xWriteBuffer( REG_LR_DIOMAPPING1,GPIO_VARE_1);
//	usb_printf("0x%X\r\n", SX127xReadBuffer(REG_LR_DIOMAPPING1));
	SX127xWriteBuffer( REG_LR_DIOMAPPING2,GPIO_VARE_2);
	SX127xLoRaSetRFFrequency(fre*1000000);
	SX127xLoRaSetRFPower(powerValue);
	SX127xLoRaSetSpreadingFactor(SpreadingFactor);
	SX127xLoRaSetErrorCoding(CodingRate);
	SX127xLoRaSetPacketCrcOn(true);
	SX127xLoRaSetSignalBandwidth( Bw_Frequency );
	SX127xLoRaSetImplicitHeaderOn(false);
	SX127xLoRaSetPayloadLength( 0xff);
	SX127xLoRaSetSymbTimeout( 0x3FF );
	SX127xLoRaSetMobileNode(true);
	
	unsigned char RECVER_DAT;
	RECVER_DAT=SX127xReadBuffer( REG_LR_MODEMCONFIG2);
	//DebugPrintf("%x\r\n",RECVER_DAT);
	RECVER_DAT = ( RECVER_DAT & 0xF7 ) ;
	//DebugPrintf("%x\r\n",RECVER_DAT);
	SX127xWriteBuffer( REG_LR_MODEMCONFIG2, RECVER_DAT );	
	
	//DebugPrintf("LoRa Chip SX127x Initial done!\r\n");
	RF_RECEIVE();
}

void FUN_RF_SENDPACKET(unsigned char *RF_TRAN_P,unsigned char LEN)
{	
	unsigned char ASM_i;
	
	SX127xLoRaSetOpMode( Stdby_mode );
	SX127xWriteBuffer( REG_LR_HOPPERIOD, 0 );
	SX127xWriteBuffer(REG_LR_IRQFLAGSMASK,IRQN_TXD_Value);
	SX127xWriteBuffer( REG_LR_PAYLOADLENGTH, LEN);
	SX127xWriteBuffer( REG_LR_FIFOTXBASEADDR, 0);
	SX127xWriteBuffer( REG_LR_FIFOADDRPTR, 0 ); //SPI interface address pointer in FIFO data buffer
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
	gByteWritefunc( 0x80 );
	for( ASM_i = 0; ASM_i < LEN; ASM_i++ )
	{
		gByteWritefunc( *RF_TRAN_P );RF_TRAN_P++;
	}
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
	SX127xWriteBuffer(REG_LR_DIOMAPPING1,0x40);
	SX127xWriteBuffer(REG_LR_DIOMAPPING2,0x00);
	SX127xLoRaSetOpMode( Transmitter_mode );
}

void RF_RECEIVE(void)
{
	SX127xLoRaSetOpMode(Stdby_mode );
	SX127xWriteBuffer(REG_LR_IRQFLAGSMASK,IRQN_RXD_Value);
	SX127xWriteBuffer(REG_LR_HOPPERIOD,	PACKET_MIAX_Value );
	SX127xWriteBuffer( REG_LR_DIOMAPPING1, 0X00 );
	SX127xWriteBuffer( REG_LR_DIOMAPPING2, 0X00 );	
	SX127xLoRaSetOpMode( Receiver_mode );
}

unsigned char recv[50];
unsigned char RF_REC_RLEN_i;
unsigned char temp0[50]={0};
void SX127x_Interupt(void)
{
	RF_EX0_STATUS=SX127xReadBuffer( REG_LR_IRQFLAGS ); 
	if((RF_EX0_STATUS&0x40)==0x40)
	{
		CRC_Value=SX127xReadBuffer( REG_LR_MODEMCONFIG2 );
		if((CRC_Value&0x04) == 0x04)
		{
			SX127xWriteBuffer (REG_LR_FIFOADDRPTR,0x00);
			SX127x_RLEN = SX127xReadBuffer(REG_LR_NBRXBYTES);
			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
			gByteWritefunc( 0x00 );
			if(SX127x_RLEN > 50)
				SX127x_RLEN = 50;
			for(RF_REC_RLEN_i=0;RF_REC_RLEN_i<SX127x_RLEN;RF_REC_RLEN_i++)
			{
				recv[RF_REC_RLEN_i]=gByteReadfunc();
			}
			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
		}
			CDC_Transmit_FS((unsigned char *)"Receive OK\r\n",sizeof("Receive OK\r\n"));
			LED_GREEN();
			CDC_Transmit_FS(recv,SX127x_RLEN);
			RX_LoRa_Flag = 1;
			HAL_Delay(50);
			usb_printf("\r\n");

			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
			gByteWritefunc( 0x00 );
			for(RF_REC_RLEN_i=0;RF_REC_RLEN_i<SX127x_RLEN;RF_REC_RLEN_i++)
			{
				gByteWritefunc(temp0[RF_REC_RLEN_i]);
			}
			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
			
		FUN_RF_SENDPACKET((unsigned char *)recv,SX127x_RLEN);

		while((SX127xReadBuffer( REG_LR_IRQFLAGS ) & 0x08) != 0x08)
		{
			HAL_Delay(10);
		}
//					CDC_Transmit_FS((unsigned char *)"Send OK\r\n",sizeof("Send OK\r\n"));
//					CDC_Transmit_FS(recv,SX127x_RLEN);
		memset(recv, 0, sizeof(recv));
				
			
		SX127xLoRaSetOpMode( Stdby_mode );
		SX127xWriteBuffer(REG_LR_IRQFLAGSMASK, IRQN_RXD_Value);
		SX127xWriteBuffer(REG_LR_HOPPERIOD,    PACKET_MIAX_Value);
		SX127xWriteBuffer( REG_LR_DIOMAPPING1, 0X00 );
		SX127xWriteBuffer( REG_LR_DIOMAPPING2, 0x00 );	
		HAL_Delay(10);
		SX127xLoRaSetOpMode( Receiver_mode );

	}
	else if((RF_EX0_STATUS&0x08)==0x08)
	{
		SX127xLoRaSetOpMode( Stdby_mode );
		SX127xWriteBuffer(REG_LR_IRQFLAGSMASK,IRQN_RXD_Value);
		SX127xWriteBuffer(REG_LR_HOPPERIOD,   PACKET_MIAX_Value );
		SX127xWriteBuffer( REG_LR_DIOMAPPING1, 0X00 );
		SX127xWriteBuffer( REG_LR_DIOMAPPING2, 0x00 );	
		SX127xLoRaSetOpMode( Receiver_mode );
	}
	else if((RF_EX0_STATUS&0x04)==0x04)
	{  
		if((RF_EX0_STATUS&0x01)==0x01)
		{
			SX127xLoRaSetOpMode( Stdby_mode );
			SX127xWriteBuffer(REG_LR_IRQFLAGSMASK,IRQN_RXD_Value);
			SX127xWriteBuffer(REG_LR_HOPPERIOD,   PACKET_MIAX_Value );
			SX127xWriteBuffer( REG_LR_DIOMAPPING1, 0X02 );
			SX127xWriteBuffer( REG_LR_DIOMAPPING2, 0x00 );	
			SX127xLoRaSetOpMode( Receiver_mode );
		}
		else
		{
			SX127xLoRaSetOpMode( Stdby_mode );
			SX127xWriteBuffer(REG_LR_IRQFLAGSMASK,	IRQN_SEELP_Value);
			SX127xWriteBuffer( REG_LR_DIOMAPPING1, 0X00 );
			SX127xWriteBuffer( REG_LR_DIOMAPPING2, 0X00 );	
			SX127xLoRaSetOpMode( Sleep_mode );
		}
	}
	else
	{
		SX127xLoRaSetOpMode( Stdby_mode );
		SX127xWriteBuffer(REG_LR_IRQFLAGSMASK,IRQN_RXD_Value);
		SX127xWriteBuffer(REG_LR_HOPPERIOD,   PACKET_MIAX_Value );
		SX127xWriteBuffer( REG_LR_DIOMAPPING1, 0X02 );
		SX127xWriteBuffer( REG_LR_DIOMAPPING2, 0x00 );	
		SX127xLoRaSetOpMode( Receiver_mode );
	}
	SX127xLoRaSetOpMode( Stdby_mode );
	SX127xWriteBuffer(REG_LR_IRQFLAGSMASK,IRQN_RXD_Value);
	SX127xWriteBuffer(REG_LR_HOPPERIOD,   PACKET_MIAX_Value );
	SX127xWriteBuffer( REG_LR_DIOMAPPING1, 0X02 );
	SX127xWriteBuffer( REG_LR_DIOMAPPING2, 0x00 );
	SX127xLoRaSetOpMode( Receiver_mode );
	SX127xWriteBuffer( REG_LR_IRQFLAGS, 0xff  );

}

void LED_RED(void)
{
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
	HAL_Delay(250);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
	HAL_Delay(250);
}

void LED_GREEN(void)
{
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
	HAL_Delay(250);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
	HAL_Delay(250);
}
//void fqcRecvData(unsigned char *lpbuf)
//{
////	unsigned char i;
////	unsigned char Irq_flag=0;
//	switch(lpbuf[1]&0x0f)
//	{
//		case 0x01: HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);break;
//		case 0x02: HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);break;
//	}
//}



