/*
 * NessLab.c
 *
 *  Created on: Aug 3, 2020
 *      Author: parkyj
 */


#include "main.h"
#include "NessLab.h"
#include "adc.h"
#include "crc.h"
//extern uint8_t NessLab_Checksum(uint8_t* data,uint8_t size);

Nesslab_Prot Currstatus;
uint8_t data_Tx[50] = {0,};
extern volatile uint16_t ADC1value[ADC1_CNT];

void NessLab_Operate(uint8_t* data){
	uint8_t datatype = data[NessLab_MsgID0];

	switch(datatype){
		case NessLab_STATUS_REQ:
			ADC_Check();
			break;


	}
    NessLab_Frame_Set(data,12);
    Uart1_Data_Send(&data, 30);


}



void NessLab_Frame_Set(uint8_t* data,uint8_t size){
    data[NessLab_Header0] = 0x7E;
    data[NessLab_Header1] = 0x7E;

    data[NessLab_MsgID0] = NessLab_STATUS_RES;// ID
    data[NessLab_MsgSN0] = 0; // SEQ NUMBER
    data[NessLab_MsgSN1] = 0; // SEQ NUMBER   
    data[NessLab_Reserve0] = 0; // NessLab_Reserve0
    data[NessLab_DataLength] = size; // Nesslab Size
    data[NessLab_Data_ADC0_H] = 12; // (uint8_t)((ADC1value & 0xFF00) >> 8);
    data[NessLab_Data_ADC0_L] = 34; // (uint8_t)(ADC1value & 0x00FF);
    data[NessLab_Data_ADC1_H] = 00;
    data[NessLab_Data_ADC1_L] = 00;
    data[DC_FAIL_ALARM] = 11;
    data[NessLab_DownLink_Status] = 22;
    data[NessLab_Over_Power_Alarm] = 33;
    data[NessLab_VSWR_ALARM] = 44;
    data[NessLab_Over_Input_Alarm] = 55;
    data[NessLab_Over_Temp_Alarm] = 66;
    data[NessLab_Temp_Monitor] = 77;
    data[NessLab_ALC_ALARM] = 88;
    data[NessLab_ChecksumVal] = NessLab_Checksum(0, 17);
    /* Exception Header Tail Checksum */
    data[NessLab_Tail0] = 0x7E;
    data[NessLab_Tail0] = 0x7E; 
}


void NessLab_Status_Check(){
	//HAL_GPIO_ReadPin(, GPIO_Pin)
}
void NessLab_PAU_Enable(){
	HAL_GPIO_WritePin(AMP_EN_GPIO_Port,AMP_EN_Pin, HAL_GPIO_ReadPin(PAU_EN_GPIO_Port, PAU_EN_Pin));
	//HAL_GPIO_WritePin(AMP_EN_GPIO_Port,AMP_EN_Pin, HAL_GPIO_ReadPin(PAU_RESET_GPIO_Port, PAU_RESET_Pin));
}
void NessLab_GPIO_Operate(){
	NessLab_PAU_Enable();
}

