/*==================================================================================================

FILE INFORMATION HEADER

USED IN PROJECT:			S1003065-01 PPS-TX/S1003067-01 PPS-RX software application
ITEM TYPE:					Source Code
ITEM NAME:					xlru_pps.cpp
ITEM DESCRIPTION:			This file contains the implementation of the class e and the interfaces for the PPS / REP connection
TARGET:						ATSAM4LC8B / ATSAM4LS8B
DOC REFERENCES:				SWDS1003065-01/SWDS1003065-01
PROGRAMMER NAME(S):			A.Chessa, L.Vallongo
COPYRIGHT:					LEONARDO-FINMECCANICA S.p.A
REVISION HISTORY:
- 01.00: first release

====================================================================================================
© Copyright LEONARDO S.p.A.. All rights reserved
Any right of industrial and intellectual property on this document,
and of technical Know-how herein contained, belongs to
LEONARDO S.p.A. and/or third parties.
According to the law, it is forbidden to disclose, reproduce or however
use this document and any data herein contained for any use without
previous written authorization by LEONARDO S.p.A.
==================================================================================================*/
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "xlru_pps.h"
#include "xlru_message_def.h"
#include "xlru_common_func.h"
#include "xlru_bytes_def.h"

using namespace xlru;

//GENERAL DECLARATION

char pps_rx_buffer[BUFFER_DIM];		//bytes buffer to store input

char pps_tx_buffer[BUFFER_DIM];		//bytes buffer to store output

/*header received */

uint8_t PPS_Mode_Status = PPSPowerUp;
uint8_t PPS_Current_limitation_status = PPSNoCurrentLimitation;
uint8_t PPS_wow_tellback_status = PPSWowNotActive;
uint8_t PPS_Health_Status = PPSHealthGo;
uint8_t PPS_Hazard_Status = PPSNoHazard;

uint32_t pps_error_link = 0;

//*** STATIC
xlru_pps::xlru_pps_command_t xlru_pps::xlru_pps_command;
xlru_pps::xlru_pps_status_t xlru_pps::xlru_pps_status;
xlru_counter_t xlru_pps::xlru_counter;

char xlru_pps::xlru_pps_fcs_prev = 'p';


void xlru_pps::pps_header_master(void)
{
	//SOM
	pps_tx_buffer[0] = SOM;

	//DSTID
	pps_tx_buffer[1] = DSTID_PPS;

	// FCS
	char fcs_temp = ((xlru_pps::xlru_pps_fcs_prev%16)+'a');
	pps_tx_buffer[FCS_INDEX] = fcs_temp;
	xlru_pps::xlru_pps_fcs_prev = fcs_temp;

	pps_tx_buffer[ACK_INDEX] = XGET;
}

//****************************************************
// MASTER - from EIF TO PPS - SET MESSAGE - PPS Operative Control Msg

void xlru_pps::pps_set_message_payload_master(void)
{
	pps_tx_buffer[4] = PPS_CONTROL_MSG;				//"O", operative command

	switch (xlru_pps::xlru_pps_command.operativeCmd)
	{
	//// 0 -> 'I', 1 -> 'G'. 2 -> 'T'
		case 0:
			pps_tx_buffer[5] = PPS_OPERATIVE_CMD_IDLE; 	//'I'
			break;
		case 1:
			pps_tx_buffer[5] = PPS_OPERATIVE_CMD_GO;	//'G'
			break;
		case 2:
			pps_tx_buffer[5] = PPS_OPERATIVE_CMD_T;		//'T'
			break;
		default:
			pps_tx_buffer[5] = PPS_OPERATIVE_CMD_IDLE;
			break;
	}

	if (xlru_pps::xlru_pps_command.hazardOverride==1)
		pps_tx_buffer[6] = PPS_HAZARD_OVERRIDE;			//"O", OVERRIDE on
	else
		pps_tx_buffer[6] = PPS_HAZARD_OVERRIDE_NO;		//"N", no OVERRIDE

	if (xlru_pps::xlru_pps_command.radomeBounce_Test==1)
		pps_tx_buffer[7] = PPS_RADOME_BOUNCE_TEST;		//"R", RADOME_BOUNCE test
	else
		pps_tx_buffer[7] = PPS_RADOME_BOUNCE_TEST_NO;	//"N", no RADOME_BOUNCE test

    pps_tx_buffer[8] = STATUS_SPARE;
    pps_tx_buffer[9] = STATUS_SPARE;
	pps_tx_buffer[10] = 0;

	char checksum[2] = {0};
	xlru::calc_checksum(checksum, pps_tx_buffer);
	pps_tx_buffer[10] = checksum[0];
	pps_tx_buffer[11] = checksum[1];

	pps_tx_buffer[12]= CR_EOM;
	pps_tx_buffer[13]= 0;
}


char* xlru_pps::pps_set_message_master(void)
{
	memset(pps_tx_buffer, 0, sizeof(pps_tx_buffer));
	pps_header_master();
	pps_set_message_payload_master();
	return pps_tx_buffer;
}

//****************************************************
// MASTER - from EIF TO PPS - GET MESSAGE

void xlru_pps::pps_get_message_payload_master(void)
{
	pps_tx_buffer[4] = PPS_GET_MESSAGE;			//"S", LCU General Status Message
	pps_tx_buffer[5] = 0;

	char checksum[2] = {0};
	xlru::calc_checksum(checksum, pps_tx_buffer);
	pps_tx_buffer[5] = checksum[0];
	pps_tx_buffer[6] = checksum[1];

	pps_tx_buffer[7]= CR_EOM;
	pps_tx_buffer[8]= 0;
}

char* xlru_pps::pps_get_message_master(void)
{
	pps_header_master();
	pps_get_message_payload_master();
	return pps_tx_buffer;
}


void xlru_pps::init(void)
{
	xlru_pps::xlru_pps_status.status.overtempHazard = false;
	xlru_pps::xlru_pps_status.status.overtempWarning = false;
	xlru_pps::xlru_pps_status.status.unitOk = false;

	xlru_pps::set_pps_hazard_override(DEF_HAZARD);
	xlru_pps::set_pps_operative_cmd(DEF_OPERATIVE);
	xlru_pps::set_pps_radome_bounce(DEF_RADOME);
}

//***********************************************************************************
void xlru_pps::pps_reset_buffer_TX_RX(void)
{
	memset(pps_tx_buffer, 0, sizeof(pps_tx_buffer));
	memset(pps_rx_buffer, 0, sizeof(pps_rx_buffer));
}

char * xlru_pps::pps_getStringTx(void)
{
	return pps_tx_buffer;
}

char * xlru_pps::pps_getStringRx(void)
{
	return pps_rx_buffer;
}

void xlru_pps::pps_setStringTx(char *txt)
{
	strcpy(pps_tx_buffer, txt);
}

void xlru_pps::pps_setStringRx(char *txt)
{
	strcpy(pps_rx_buffer, txt);
}

int xlru_pps::xlru_pps_command_message_decoder(char* buffer)
{
	char tmp = { 0 };
	int value = 0;

	int error = DECODE_NO_ERROR;

	//check message's len, if it is too short, return error
	int len = strlen(buffer);

	if (len<PPS_CHECKSUM_MIN_INDEX)
		return DECODE_TOO_SHORT;	//message is too short
	memset( &xlru_pps::xlru_pps_status, 0, sizeof( xlru_pps::xlru_pps_status ) );

	//MODE STATUS
	tmp = buffer[PPS_MODE_STATUS_INDEX];
	switch(tmp)
	{
		case PPS_MODE_IDLE:
			xlru_pps::xlru_pps_status.mode_status = PPSIdle;
			break;
		case PPS_MODE_POWERUP:
			xlru_pps::xlru_pps_status.mode_status = PPSPowerUp;
			break;
		case PPS_MODE_STANDBY:
			xlru_pps::xlru_pps_status.mode_status = PPSStandBy;
			break;
		case PPS_MODE_IBIT:
			xlru_pps::xlru_pps_status.mode_status = PPSIBIT;
			break;
		case PPS_MODE_GO:
			xlru_pps::xlru_pps_status.mode_status = PPSOnGo;
			break;
		default:
			break;
	}

	//HEALTH STATUS
	tmp = buffer[PPS_HEALTH_STATUS_INDEX];
	switch(tmp)
	{
		case PPS_HEALTH_GO:
			xlru_pps::xlru_pps_status.health_status = PPSHealthGo;
			break;
		case PPS_HEALTH_WARNING:
			xlru_pps::xlru_pps_status.health_status = PPSHealthWarning;
			break;
		case PPS_HEALTH_FAIL:
			xlru_pps::xlru_pps_status.health_status = PPSHealthFail;
			break;
		default:
			break;
	}

	//WOW tellback STATUS
	tmp = buffer[PPS_WOW_STATUS_INDEX];
	switch(tmp)
	{
		case PPS_WOW_NOT_ACTIVE:
			xlru_pps::xlru_pps_status.wow_tellback_status = PPSWowNotActive;
		    break;
		case PPS_WOW_ACTIVE:
			xlru_pps::xlru_pps_status.wow_tellback_status = PPSWowActive;
			break;
		case PPS_WOW_FAIL:
			xlru_pps::xlru_pps_status.wow_tellback_status = PPSWowFail;
			break;
		default:
			break;
	}

	//Hazard STATUS
	tmp = buffer[PPS_HAZARD_STATUS_INDEX];
	switch(tmp)
	{
		case PPS_HAZARD_NO:
			xlru_pps::xlru_pps_status.hazard_status = PPSNoHazard;
		    break;
		case PPS_HAZARD_1:
			xlru_pps::xlru_pps_status.hazard_status = PPSHazard1;
			break;
		case PPS_HAZARD_2:
			xlru_pps::xlru_pps_status.hazard_status = PPSHazard2;
			break;
		default:
			break;
	}

	//Current limitation STATUS
	tmp = buffer[PPS_CURR_LIMIT_STATUS_INDEX];
	switch(tmp)
	{
		case PPS_LIMIT_NO:
			xlru_pps::xlru_pps_status.current_limitation_status = PPSNoCurrentLimitation;
		    break;
		case PPS_LIMIT_CURRENT:
			xlru_pps::xlru_pps_status.current_limitation_status = PPSCurrentLimitation;
			break;
		default:
			break;
	}

	//PPS_BIT_STATUS

	bool ok = false;

	//BYTES#1 - RX Board
	ok=xlru::hex2u8(&value , &buffer[PPS_BYTES1_INDEX]);
	if (!ok)
		error++;	//problem in decode value;
    xlru_pps::xlru_pps_status.byte1_holdUp_boards.b1_LP_under_voltage_fail = ((value & PPS1_Bit1_HoldUp_LP_Under_Voltage_Fail) == PPS1_Bit1_HoldUp_LP_Under_Voltage_Fail);
    xlru_pps::xlru_pps_status.byte1_holdUp_boards.b2_HP_under_voltage_fail = ((value & PPS1_Bit2_HoldUp_HP_Under_Voltage_Fail) == PPS1_Bit2_HoldUp_HP_Under_Voltage_Fail);
    //xlru_pps::xlru_pps_status.byte1_holdUp_boards.b3_LP_under_voltage_fail = ((value & PPS1_Bit3_HoldUp_LP_Under_Voltage_Fail) == PPS1_Bit3_HoldUp_LP_Under_Voltage_Fail);
    //xlru_pps::xlru_pps_status.byte1_holdUp_boards.b4_LP_charging_time_fail = ((value & PPS1_Bit4_HoldUp_LP_Charging_Time_Fail) == PPS1_Bit4_HoldUp_LP_Charging_Time_Fail);
	//spare
	xlru_pps::xlru_pps_status.byte1_holdUp_boards.b6_AC_power_umbalance_fail_ph1 = ((value & PPS1_Bit6_AC_Power_Unbalance_Fail_Ph1) == PPS1_Bit6_AC_Power_Unbalance_Fail_Ph1);
	xlru_pps::xlru_pps_status.byte1_holdUp_boards.b7_AC_power_umbalance_fail_ph2 = ((value & PPS1_Bit7_AC_Power_Unbalance_Fail_Ph2) == PPS1_Bit7_AC_Power_Unbalance_Fail_Ph2);
	xlru_pps::xlru_pps_status.byte1_holdUp_boards.b8_AC_power_umbalance_fail_ph3 = ((value & PPS1_Bit7_AC_Power_Unbalance_Fail_Ph3) == PPS1_Bit7_AC_Power_Unbalance_Fail_Ph3);

	//BYTES#2 - rx board
	ok=xlru::hex2u8(&value , &buffer[PPS_BYTES2_INDEX]);
	if (!ok)
		error++;	//problem in decode value;
	xlru_pps::xlru_pps_status.byte2_rx_board.b1_rx_link_fail =((value & PPS2_Bit1_RX_Link_Fail) == PPS2_Bit1_RX_Link_Fail);
	xlru_pps::xlru_pps_status.byte2_rx_board.b2_rx_input_dc_overcurrent_fail = ((value & PPS2_Bit2_RX_Input_DC_Overcurrent_Fail) == PPS2_Bit2_RX_Input_DC_Overcurrent_Fail);
    xlru_pps::xlru_pps_status.byte2_rx_board.b3_rx_rectified_dc_under_voltage_fail_ac_power_loss = ((value & PPS2_Bit3_RX_Rectified_DC_Under_Voltage_Fail_Ac_Power_Loss) == PPS2_Bit3_RX_Rectified_DC_Under_Voltage_Fail_Ac_Power_Loss);
	//spare
	xlru_pps::xlru_pps_status.byte2_rx_board.b5_output_rx_over_voltage_fail = ((value & PPS2_Bit5_Output_RX_Over_Voltage_Fail) == PPS2_Bit5_Output_RX_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte2_rx_board.b6_output_rx_under_voltage_fail = ((value & PPS2_Bit6_Output_RX_Under_Voltage_Fail) == PPS2_Bit6_Output_RX_Under_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte2_rx_board.b7_rx_hazard = ((value & PPS2_Bit7_RX_Hazard1) == PPS2_Bit7_RX_Hazard1);
	xlru_pps::xlru_pps_status.byte2_rx_board.b8_rx_hazard = ((value & PPS2_Bit8_RX_Hazard2) == PPS2_Bit8_RX_Hazard2);

	//BYTES#3 - tx1 board
	ok=xlru::hex2u8(&value , &buffer[PPS_BYTES3_INDEX]);
	if (!ok)
		error++;	//problem in decode value;
	xlru_pps::xlru_pps_status.byte3_tx1_board.b1_tx1_link_with_rx = ((value & PPS3_Bit1_TX1_link_with_RX) == PPS3_Bit1_TX1_link_with_RX);
	xlru_pps::xlru_pps_status.byte3_tx1_board.b2_tx1_input_dc_over_current_fail = ((value & PPS3_Bit2_TX1_Input_DC_Over_Current_Fail) == PPS3_Bit2_TX1_Input_DC_Over_Current_Fail);
    xlru_pps::xlru_pps_status.byte3_tx1_board.b3_tx1_rectified_dc_under_voltage_fail_270_uv = ((value & PPS3_Bit3_TX1_Rectified_DC_Under_Voltage_Fail_270_uv) == PPS3_Bit3_TX1_Rectified_DC_Under_Voltage_Fail_270_uv);
    //xlru_pps::xlru_pps_status.byte3_tx1_board.b4_tx1_rectified_dc_over_voltage_fail = ((value & PPS3_Bit4_TX1_Rectified_DC_Over_Voltage_Fail) == PPS3_Bit4_TX1_Rectified_DC_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte3_tx1_board.b5_output_tx1_over_voltage_fail = ((value & PPS3_Bit5_Output_TX1_Over_Voltage_Fail) == PPS3_Bit5_Output_TX1_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte3_tx1_board.b6_output_tx1_under_voltage_fail = ((value & PPS3_Bit6_Output_TX1_Over_Voltage_Fail) == PPS3_Bit6_Output_TX1_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte3_tx1_board.b7_tx1_hazard = ((value & PPS3_Bit7_TX1_Hazard1) == PPS3_Bit7_TX1_Hazard1);
	xlru_pps::xlru_pps_status.byte3_tx1_board.b8_tx1_hazard = ((value & PPS3_Bit8_TX1_Hazard2) == PPS3_Bit8_TX1_Hazard2);

	//BYTES#4 - tx2 board
	ok=xlru::hex2u8(&value , &buffer[PPS_BYTES4_INDEX]);
	if (!ok)
		error++;	//problem in decode value;
	xlru_pps::xlru_pps_status.byte4_tx2_board.b1_tx2_link_with_rx = ((value & PPS4_Bit1_TX2_link_with_RX) == PPS4_Bit1_TX2_link_with_RX);
	xlru_pps::xlru_pps_status.byte4_tx2_board.b2_tx2_input_dc_over_current_fail = ((value & PPS4_Bit2_TX2_Input_DC_Over_Current_Fail) == PPS4_Bit2_TX2_Input_DC_Over_Current_Fail);
    xlru_pps::xlru_pps_status.byte4_tx2_board.b3_tx2_rectified_dc_under_voltage_fail_270_uv = ((value & PPS4_Bit3_TX2_Rectified_DC_Under_Voltage_Fail_270_uv) == PPS4_Bit3_TX2_Rectified_DC_Under_Voltage_Fail_270_uv);
    //xlru_pps::xlru_pps_status.byte4_tx2_board.b4_tx2_rectified_dc_over_voltage_fail = ((value & PPS4_Bit4_TX2_Rectified_DC_Over_Voltage_Fail) == PPS4_Bit4_TX2_Rectified_DC_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte4_tx2_board.b5_output_tx2_over_voltage_fail = ((value & PPS4_Bit5_Output_TX2_Over_Voltage_Fail) == PPS4_Bit5_Output_TX2_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte4_tx2_board.b6_output_tx2_under_voltage_fail = ((value & PPS4_Bit6_Output_TX2_Over_Voltage_Fail) == PPS4_Bit6_Output_TX2_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte4_tx2_board.b7_tx2_hazard = ((value & PPS4_Bit7_TX2_Hazard1) == PPS4_Bit7_TX2_Hazard1);
	xlru_pps::xlru_pps_status.byte4_tx2_board.b8_tx2_hazard = ((value & PPS4_Bit8_TX2_Hazard2) == PPS4_Bit8_TX2_Hazard2);

	//BYTES#5 - tx3 board
	ok=xlru::hex2u8(&value , &buffer[PPS_BYTES5_INDEX]);
	if (!ok)
		error++;	//problem in decode value;
	xlru_pps::xlru_pps_status.byte5_tx3_board.b1_tx3_link_with_rx = ((value & PPS5_Bit1_TX3_link_with_RX) == PPS5_Bit1_TX3_link_with_RX);
	xlru_pps::xlru_pps_status.byte5_tx3_board.b2_tx3_input_dc_over_current_fail = ((value & PPS5_Bit2_TX3_Input_DC_Over_Current_Fail) == PPS5_Bit2_TX3_Input_DC_Over_Current_Fail);
    xlru_pps::xlru_pps_status.byte5_tx3_board.b3_tx3_rectified_dc_under_voltage_fail_270_uv = ((value & PPS5_Bit3_TX3_Rectified_DC_Under_Voltage_Fail_270_uv) == PPS5_Bit3_TX3_Rectified_DC_Under_Voltage_Fail_270_uv);
    //xlru_pps::xlru_pps_status.byte5_tx3_board.b4_tx3_rectified_dc_over_voltage_fail = ((value & PPS5_Bit4_TX3_Rectified_DC_Over_Voltage_Fail) == PPS5_Bit4_TX3_Rectified_DC_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte5_tx3_board.b5_output_tx3_over_voltage_fail = ((value & PPS5_Bit5_Output_TX3_Over_Voltage_Fail) == PPS5_Bit5_Output_TX3_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte5_tx3_board.b6_output_tx3_under_voltage_fail =((value & PPS5_Bit6_Output_TX3_Over_Voltage_Fail) == PPS5_Bit6_Output_TX3_Over_Voltage_Fail);
	xlru_pps::xlru_pps_status.byte5_tx3_board.b7_tx3_hazard = ((value & PPS5_Bit7_TX3_Hazard1) == PPS5_Bit7_TX3_Hazard1);
	xlru_pps::xlru_pps_status.byte5_tx3_board.b8_tx3_hazard = ((value & PPS5_Bit8_TX3_Hazard2) == PPS5_Bit8_TX3_Hazard2);

	//BYTES#6 - general
	ok=xlru::hex2u8(&value , &buffer[PPS_BYTES6_INDEX]);
	if (!ok)
		error++;	//problem in decode value;
	xlru_pps::xlru_pps_status.byte6_general.b1_wow_tellback_1 = ((value & PPS6_Bit1_WOW_Tellback_1) == PPS6_Bit1_WOW_Tellback_1);
	xlru_pps::xlru_pps_status.byte6_general.b2_wow_tellback_2 = ((value & PPS6_Bit2_WOW_Tellback_2) == PPS6_Bit2_WOW_Tellback_2);
	xlru_pps::xlru_pps_status.byte6_general.b3_wow_tellback_3 = ((value & PPS6_Bit3_WOW_Tellback_3) == PPS6_Bit3_WOW_Tellback_3);

	//PPS_RX_VERSION_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.rx_board_version, &buffer[PPS_RX_VERSION_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_RX_RELEASE_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.rx_board_release, &buffer[PPS_RX_RELEASE_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_TX1_VERSION_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.tx1_board_version, &buffer[PPS_TX1_VERSION_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_TX1_RELEASE_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.tx1_board_release, &buffer[PPS_TX1_RELEASE_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_TX2_VERSION_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.tx2_board_version, &buffer[PPS_TX2_VERSION_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_TX2_RELEASE_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.tx2_board_release, &buffer[PPS_TX2_RELEASE_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_TX3_VERSION_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.tx3_board_version, &buffer[PPS_TX3_VERSION_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_TX3_RELEASE_INDEX
	ok=xlru::hex2u8(&xlru_pps::xlru_pps_status.tx3_board_release, &buffer[PPS_TX3_RELEASE_INDEX]);
	if (!ok)
			error++;	//problem in decode value;

	//PPS_RX_TEMP_INDEX

    ok=xlru::hex2s8(&xlru_pps::xlru_pps_status.rx_board_temp, &buffer[PPS_RX_TEMP_INDEX]);
	if (!ok)
            error++;	//problem in decode value;

	//PPS_TX1_TEMP_INDEX
    ok=xlru::hex2s8(&xlru_pps::xlru_pps_status.tx1_board_temp, &buffer[PPS_TX1_TEMP_INDEX]);
	if (!ok)
            error++;	//problem in decode value;

	//PPS_TX2_TEMP_INDEX
    ok=xlru::hex2s8(&xlru_pps::xlru_pps_status.tx2_board_temp, &buffer[PPS_TX2_TEMP_INDEX]);
	if (!ok)
            error++;	//problem in decode value;

	//PPS_TX3_TEMP_INDEX
    ok=xlru::hex2s8(&xlru_pps::xlru_pps_status.tx3_board_temp, &buffer[PPS_TX3_TEMP_INDEX]);
	if (!ok)
            error++;	//problem in decode value;

	//PPS_LIQUID_INLET_TEMP_IDX
    ok=xlru::hex2s8(&xlru_pps::xlru_pps_status.liquid_inlet_temp, &buffer[PPS_LIQUID_INLET_TEMP_IDX]);
	if (!ok)
            error++;	//problem in decode value;

	//PPS_LIQUID_OUTLET_TEMP_IDX
    ok=xlru::hex2s8(&xlru_pps::xlru_pps_status.liquid_outlet_temp, &buffer[PPS_LIQUID_OUTLET_TEMP_IDX]);
	if (!ok)
        error++;	//problem in decode value;

	//PPS_CURR_IDX
	{
        ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.curr_42v , &buffer[PPS_CURR_IDX], PPS_CURR_LSB);
        if (!ok)
            error++;	//problem in decode value;
    }

    //PPS_TX1_CURR_IDX
    {
        ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.tx_curr[0] , &buffer[PPS_TX1_CURR_IDX], PPS_CURR_LSB);
        if (!ok)
            error++;	//problem in decode value;
    }

    //PPS_TX2_CURR_IDX
    {
        ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.tx_curr[1] , &buffer[PPS_TX2_CURR_IDX], PPS_CURR_LSB);
        if (!ok)
            error++;	//problem in decode value;
    }

    //PPS_TX3_CURR_IDX
    {
        ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.tx_curr[2] , &buffer[PPS_TX3_CURR_IDX], PPS_CURR_LSB);
        if (!ok)
            error++;	//problem in decode value;
    }

    xlru_pps::xlru_pps_status.tx_curr_max_valid=false;
    xlru_pps::xlru_pps_status.tx_curr_avg_valid=false;
    for(int i=0; i<3; ++i)
    {
    	xlru_pps::xlru_pps_status.tx_curr_max[i]=xlru_pps::xlru_pps_status.tx_curr[i];
    	xlru_pps::xlru_pps_status.tx_curr_avg[i]=xlru_pps::xlru_pps_status.tx_curr[i];
    }

    if (len>PPS_TX3_CURR_MAX_IDX+5)
    {
        xlru_pps::xlru_pps_status.tx_curr_max_valid=true;
    	for(int i=0; i<3; ++i)
    	{
            ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.tx_curr_max[i] , &buffer[PPS_TX1_CURR_MAX_IDX+2*i], PPS_CURR_LSB);
            if (!ok)
            {
                error++;	//problem in decode value;
                xlru_pps::xlru_pps_status.tx_curr_max_valid=false;
                break;
            }
    	}
    }

    if (len>PPS_TX3_CURR_AVG_IDX+5)
    {
        xlru_pps::xlru_pps_status.tx_curr_avg_valid=true;
    	for(int i=0; i<3; ++i)
    	{
            ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.tx_curr_avg[i] , &buffer[PPS_TX1_CURR_AVG_IDX+2*i], PPS_CURR_LSB);
            if (!ok)
            {
                error++;	//problem in decode value;
                xlru_pps::xlru_pps_status.tx_curr_avg_valid=false;
                break;
            }
    	}
    }
#if 1
    if (len>PPS_PHASET_MIN_IDX+5)
    {
        xlru_pps::xlru_pps_status.rx_phase_valid=true;
        for(int i=0; i<3; ++i)
        {
            ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.rx_phase_min[i] , &buffer[PPS_PHASER_MIN_IDX+2*i], PPS_CURR_LSB);
            if (!ok)
            {
                error++;	//problem in decode value;
                xlru_pps::xlru_pps_status.rx_phase_valid=false;
                break;
            }
        }
    }
    if (len>PPS_PHASET_MAX_IDX+5)
    {
        for(int i=0; i<3; ++i)
        {
            ok=xlru::hex3u8f(&xlru_pps::xlru_pps_status.rx_phase_max[i] , &buffer[PPS_PHASER_MAX_IDX+2*i], PPS_CURR_LSB);
            if (!ok)
            {
                error++;	//problem in decode value;
            }
        }
    }
#endif

	xlru_pps::xlru_pps_status.status.unitOk=(xlru_pps::xlru_pps_status.health_status==PPSHealthGo) || (xlru_pps::xlru_pps_status.health_status==PPSHealthWarning);
	xlru_pps::xlru_pps_status.warning=(!xlru_pps::xlru_pps_status.status.unitOk) || (xlru_pps::xlru_pps_status.health_status==PPSHealthWarning);

	if (!xlru_pps::xlru_pps_status.status.unitOk)
	{
		//TODO: WARNING - remove, just a workaround for HOLD Up Fail
		//bool ac_fail=xlru_pps::xlru_pps_status.byte1_holdUp_boards.b6_AC_power_umbalance_fail_ph1 || xlru_pps::xlru_pps_status.byte1_holdUp_boards.b7_AC_power_umbalance_fail_ph2 || xlru_pps::xlru_pps_status.byte1_holdUp_boards.b8_AC_power_umbalance_fail_ph3);
		//if (!ac_fail)
		{
			bool hold_up_fail=
                       xlru_pps::xlru_pps_status.byte1_holdUp_boards.b1_LP_under_voltage_fail
                    || xlru_pps::xlru_pps_status.byte1_holdUp_boards.b2_HP_under_voltage_fail;
                    /*|| xlru_pps::xlru_pps_status.byte1_holdUp_boards.b3_LP_under_voltage_fail
                    || xlru_pps::xlru_pps_status.byte1_holdUp_boards.b4_LP_charging_time_fail;*/
			if (hold_up_fail)
				xlru_pps::xlru_pps_status.status.unitOk=true;
		}
	}

	switch(xlru_pps::xlru_pps_status.hazard_status)
	{
		case PPSNoHazard:
			xlru_pps::xlru_pps_status.status.overtempWarning=false;
			xlru_pps::xlru_pps_status.status.overtempHazard=false;
			break;
		case PPSHazard1:
			xlru_pps::xlru_pps_status.status.overtempHazard=false;
			xlru_pps::xlru_pps_status.status.overtempWarning=true;
			break;
		case PPSHazard2:
		default:
			xlru_pps::xlru_pps_status.status.overtempHazard=true;
			xlru_pps::xlru_pps_status.status.overtempWarning=true;
		}

	return error;
}


void xlru_pps::set_pps_operative_cmd(int value)
{
	xlru_pps::xlru_pps_command.operativeCmd = value;
}

void xlru_pps::set_pps_hazard_override(int value)
{
	xlru_pps::xlru_pps_command.hazardOverride = value;
}

void xlru_pps::set_pps_radome_bounce(int value)
{
	xlru_pps::xlru_pps_command.radomeBounce_Test = value;
}

unsigned int xlru_pps::get_pps_operativeCmd()
{
	return xlru_pps::xlru_pps_command.operativeCmd;
}

unsigned int xlru_pps::get_pps_hazardOverride()
{
	return xlru_pps::xlru_pps_command.hazardOverride;
}

unsigned int xlru_pps::get_pps_radomeBounce()
{
	return xlru_pps::xlru_pps_command.radomeBounce_Test;
}

void xlru_pps::xlru_display(int (*print_func)(const char*, ...))
{
	print_func("\n   -> Info from PPS <-\n");

    print_func("     %-35s: %d.%d\n","rx board version.release",
               xlru_pps::xlru_pps_status.rx_board_version,
               xlru_pps::xlru_pps_status.rx_board_release);

    print_func("     %-35s: %d.%d\n","tx1 board version.release",
               xlru_pps::xlru_pps_status.tx1_board_version,
               xlru_pps::xlru_pps_status.tx1_board_release);

    print_func("     %-35s: %d.%d\n","tx2 board version.release",
               xlru_pps::xlru_pps_status.tx2_board_version,
               xlru_pps::xlru_pps_status.tx2_board_release);

    print_func("     %-35s: %d.%d\n","tx3 board version.release",
               xlru_pps::xlru_pps_status.tx3_board_version,
               xlru_pps::xlru_pps_status.tx3_board_release);

    print_func("     %-35s: %c\n","status mode",
               xlru_pps::xlru_pps_status.mode_status);

    print_func("     %-35s: %c\n","health status",
               xlru_pps::xlru_pps_status.health_status);

    print_func("     %-35s: %c\n","wow tellback status",
               xlru_pps::xlru_pps_status.wow_tellback_status);

    print_func("     %-35s: %c\n","hazard status",
               xlru_pps::xlru_pps_status.hazard_status);

    print_func("     %-35s: %c\n","current limitation",
               xlru_pps::xlru_pps_status.current_limitation_status);

    print_func("     %-35s: %-4d    %-35s: %-4d\n",
               "rx board temp.",
               xlru_pps::xlru_pps_status.rx_board_temp,
               "tx2 board temp.",
               xlru_pps::xlru_pps_status.tx2_board_temp);

    print_func("     %-35s: %-4d    %-35s: %-4d\n",
               "tx1 board temp.",
               xlru_pps::xlru_pps_status.tx1_board_temp,
               "tx3 board temp.",
               xlru_pps::xlru_pps_status.tx3_board_temp);

    print_func("     %-35s: %-4d    %-35s: %-4d\n",
               "liquid inlet temp.",
               xlru_pps::xlru_pps_status.liquid_inlet_temp,
               "liquid outlet temp.",
               xlru_pps::xlru_pps_status.liquid_outlet_temp);

    print_func("     %-35s: %-4.1f\n\n",
               "RX current.",
               xlru_pps::xlru_pps_status.curr_42v
              );

    print_func("     %-35s: %-4.1f  %-4.1f  %-4.1f\n\n ",
                "TX1 cur/max/avg",
                xlru_pps::xlru_pps_status.tx_curr[0],
                xlru_pps::xlru_pps_status.tx_curr_max[0],
                xlru_pps::xlru_pps_status.tx_curr_avg[0]
                );

    print_func("     %-35s: %-4.1f  %-4.1f  %-4.1f\n\n ",
                "TX2 cur/max/avg",
                xlru_pps::xlru_pps_status.tx_curr[1],
                xlru_pps::xlru_pps_status.tx_curr_max[1],
                xlru_pps::xlru_pps_status.tx_curr_avg[1]
                );

    print_func("     %-35s: %-4.1f  %-4.1f  %-4.1f\n\n ",
                "TX3 cur/max/avg",
                xlru_pps::xlru_pps_status.tx_curr[2],
                xlru_pps::xlru_pps_status.tx_curr_max[2],
                xlru_pps::xlru_pps_status.tx_curr_avg[2]
                );

	print_func("\n     -> Hold up status (byte1 status) <-        -> General status (byte6 status) <-\n");

    print_func("bit1 %-35s: %-4d    %-35s: %-4d\n",
               "hp under voltage failure",
               xlru_pps::xlru_pps_status.byte1_holdUp_boards.b1_LP_under_voltage_fail,
               "temperature hazard",
               xlru_pps::xlru_pps_status.byte6_general.b1_wow_tellback_1);

    print_func("bit2 %-35s: %-4d    %-35s: %-4d\n",
               "hp under voltage failure",
               xlru_pps::xlru_pps_status.byte1_holdUp_boards.b2_HP_under_voltage_fail,
               "temperature warning",
               xlru_pps::xlru_pps_status.byte6_general.b2_wow_tellback_2);

    print_func("bit3 %-35s: %-4d    %-35s: %-4d\n",
               "",
               0,
               "nvm access warning",
               xlru_pps::xlru_pps_status.byte6_general.b3_wow_tellback_3);

    print_func("bit4 %-35s: %-4d    %-35s: %-4d\n",
               "",
               0,
               "",
               0);

    print_func("bit5 %-35s: %-4d    %-35s: %-4d\n",
               "",
               0,
               "",
               0);

    print_func("bit6 %-35s: %-4d    %-35s: %-4d\n",
               "ac power unbalance PH1",
               xlru_pps::xlru_pps_status.byte1_holdUp_boards.b6_AC_power_umbalance_fail_ph1,
               " ",
               0);

    print_func("bit7 %-35s: %-4d    %-35s: %-4d\n",
               "ac power unbalance PH2",
               xlru_pps::xlru_pps_status.byte1_holdUp_boards.b7_AC_power_umbalance_fail_ph2,
               " ",
               0);

    print_func("bit8 %-35s: %-4d    %-35s: %-4d\n",
               "ac power unbalance PH3",
               xlru_pps::xlru_pps_status.byte1_holdUp_boards.b8_AC_power_umbalance_fail_ph3,
               " ",
               0);

	print_func("\n     -> RX board (byte2 status) <-        	  -> TX1 board (byte3 status) <-\n");

    print_func("bit1 %-35s: %-4d    %-35s: %-4d\n",
               "link failure",
               xlru_pps::xlru_pps_status.byte2_rx_board.b1_rx_link_fail,
               "link with rx",
               xlru_pps::xlru_pps_status.byte3_tx1_board.b1_tx1_link_with_rx);

    print_func("bit2 %-35s: %-4d    %-35s: %-4d\n",
               "input dc overcurrent fail",
               xlru_pps::xlru_pps_status.byte2_rx_board.b2_rx_input_dc_overcurrent_fail,
               "input dc over current fail",
               xlru_pps::xlru_pps_status.byte3_tx1_board.b2_tx1_input_dc_over_current_fail);

    print_func("bit3 %-35s: %-4d    %-35s: %-4d\n",
               "rectified dc under voltage fail ac power loss",
               xlru_pps::xlru_pps_status.byte2_rx_board.b3_rx_rectified_dc_under_voltage_fail_ac_power_loss,
               "rectified dc under voltage fail 270 uv",
               xlru_pps::xlru_pps_status.byte3_tx1_board.b3_tx1_rectified_dc_under_voltage_fail_270_uv);

    print_func("bit4 %-35s: %-4d    %-35s: %-4d\n",
               "",
               0,
               "",
               0);

    print_func("bit5 %-35s: %-4d    %-35s: %-4d\n",
               "output over voltage fail",
               xlru_pps::xlru_pps_status.byte2_rx_board.b5_output_rx_over_voltage_fail,
               "output tx1 over voltage fail",
               xlru_pps::xlru_pps_status.byte3_tx1_board.b5_output_tx1_over_voltage_fail);

    print_func("bit6 %-35s: %-4d    %-35s: %-4d\n",
               "output under voltage fail",
               xlru_pps::xlru_pps_status.byte2_rx_board.b6_output_rx_under_voltage_fail,
               "output tx1 under voltage fail",
               xlru_pps::xlru_pps_status.byte3_tx1_board.b6_output_tx1_under_voltage_fail);

	//print_func("b7-8 %-35s: %-4d    %-35s: %-4d\n","phase sequence failure",xlru_pps::xlru_pps_status.byte2_rx_board.b7b8_rx_hazard, "hazard", xlru_pps::xlru_pps_status.byte3_tx1_board.b7b8_tx1_hazard);

	print_func("\n     -> TX2 board (byte4 status) <-        	  -> TX3 board (byte5 status) <-\n");

    print_func("bit1 %-35s: %-4d    %-35s: %-4d\n",
               "phase A failure",
               xlru_pps::xlru_pps_status.byte4_tx2_board.b1_tx2_link_with_rx,
               "temperature hazard",
               xlru_pps::xlru_pps_status.byte5_tx3_board.b1_tx3_link_with_rx);

    print_func("bit2 %-35s: %-4d    %-35s: %-4d\n",
               "phase B failure",
               xlru_pps::xlru_pps_status.byte4_tx2_board.b2_tx2_input_dc_over_current_fail,
               "temperature warning",
               xlru_pps::xlru_pps_status.byte5_tx3_board.b2_tx3_input_dc_over_current_fail);

    print_func("bit3 %-35s: %-4d    %-35s: %-4d\n",
               "phase C failure",
               xlru_pps::xlru_pps_status.byte4_tx2_board.b3_tx2_rectified_dc_under_voltage_fail_270_uv,
               "nvm access warning",
               xlru_pps::xlru_pps_status.byte5_tx3_board.b3_tx3_rectified_dc_under_voltage_fail_270_uv);

    print_func("bit4 %-35s: %-4d    %-35s: %-4d\n",
               "phase sequence failure",
               0,
               "board error failure",
               0);

    print_func("bit5 %-35s: %-4d    %-35s: %-4d\n",
               "phase sequence failure",
               xlru_pps::xlru_pps_status.byte4_tx2_board.b5_output_tx2_over_voltage_fail,
               "board error failure",
               xlru_pps::xlru_pps_status.byte5_tx3_board.b5_output_tx3_over_voltage_fail);

    print_func("bit6 %-35s: %-4d    %-35s: %-4d\n",
               "phase sequence failure",
               xlru_pps::xlru_pps_status.byte4_tx2_board.b6_output_tx2_under_voltage_fail,
               "board error failure",
               xlru_pps::xlru_pps_status.byte5_tx3_board.b6_output_tx3_under_voltage_fail);

    //print_func("b7-8 %-35s: %-4d    %-35s: %-4d\n","phase sequence failure",xlru_pps::xlru_pps_status.byte4_tx2_board.b7b8_tx2_hazard, "board error failure", xlru_pps::xlru_pps_status.byte5_tx3_board.b7b8_tx3_hazard);

	print_func("\n");
}


void xlru_pps::xlru_add_error(int n_error)	//error into last decode response message
{
	xlru_pps::xlru_counter.last_decode_error += n_error;
}

void xlru_pps::xlru_add_rx(int n_rx)				//response messages
{
	xlru_pps::xlru_counter.rx_mess+= n_rx;
}

void xlru_pps::xlru_add_rx_error(int n_error)		//response messages with error
{
	xlru_pps::xlru_counter.rx_mess_error += n_error;
}

void xlru_pps::xlru_add_no_rx(int n_error)	//count messages without response
{
	xlru_pps::xlru_counter.no_response += n_error;
}

void xlru_pps::xlru_set_last_error(char *last_error)	//report last error
{
	strcpy(xlru_pps::xlru_counter.last_error, last_error);
}

void xlru_pps::xlru_set_last_rx(char *last_rx)		//report last received message
{
	strcpy(xlru_pps::xlru_counter.last_rx, last_rx);
}
void xlru_pps::xlru_set_last_tx(char *last_tx)		//report last trasmitted message
{
	strcpy(xlru_pps::xlru_counter.last_tx, last_tx);
}
char* xlru_pps::xlru_get_last_rx()
{
	return xlru_pps::xlru_counter.last_rx;
}
char* xlru_pps::xlru_get_last_tx()
{
	return xlru_pps::xlru_counter.last_tx;
}
char* xlru_pps::xlru_get_last_error()
{
	return xlru_pps::xlru_counter.last_error;
}

void xlru_pps::xlru_display_compact(int (*print_func)(const char*, ...))
{
	print_func("\n   -> Info from PPS <-\n");

	print_func("     %-11s: %d.%d	%-11s: %d.%d\n",
			"rx ver.rel",
			xlru_pps::xlru_pps_status.rx_board_version,
			xlru_pps::xlru_pps_status.rx_board_release,
			"tx1 ver.rel",
			xlru_pps::xlru_pps_status.tx1_board_version,
			xlru_pps::xlru_pps_status.tx1_board_release);

	print_func("     %-11s: %d.%d	%-11s: %d.%d\n",
			"tx2 ver.rel",
			xlru_pps::xlru_pps_status.tx2_board_version,
			xlru_pps::xlru_pps_status.tx2_board_release,
			"tx3 ver.rel",
			xlru_pps::xlru_pps_status.tx3_board_version,
			xlru_pps::xlru_pps_status.tx3_board_release);


	print_func("     %-11s: %c     %-11s: %c\n",
			"mode",
			xlru_pps::xlru_pps_status.mode_status,
			"wow",
			xlru_pps::xlru_pps_status.wow_tellback_status);

	print_func("     %-11s: %c     %-11s: %c\n",
			"health",
			xlru_pps::xlru_pps_status.health_status,
			"hazard",
			xlru_pps::xlru_pps_status.hazard_status);

    print_func("     %-11s: %c\n","cur. limit.",
               xlru_pps::xlru_pps_status.current_limitation_status);

    print_func("     %-11s: %-4d    %-11s: %-4d\n",
               "rx temp",
               xlru_pps::xlru_pps_status.rx_board_temp,
               "tx2temp",
               xlru_pps::xlru_pps_status.tx2_board_temp);

    print_func("     %-11s: %-4d    %-11s: %-4d\n",
               "tx1 temp",
               xlru_pps::xlru_pps_status.tx1_board_temp,
               "tx3temp",
               xlru_pps::xlru_pps_status.tx3_board_temp);

    print_func("     %-11s: %-4d    %-11s: %-4d\n",
               "inlet temp",
               xlru_pps::xlru_pps_status.liquid_inlet_temp,
               "outlet temp",
               xlru_pps::xlru_pps_status.liquid_outlet_temp);

    print_func("     %-11s: %-4.1f\n",
               "RX curr",
               xlru_pps::xlru_pps_status.curr_42v);


    print_func("     %-35s: %-4.1f  %-4.1f  %-4.1f\n\n ",
                "TX1 cur/max/avg",
                xlru_pps::xlru_pps_status.tx_curr[0],
                xlru_pps::xlru_pps_status.tx_curr_max[0],
                xlru_pps::xlru_pps_status.tx_curr_avg[0]
                );

    print_func("     %-35s: %-4.1f  %-4.1f  %-4.1f\n\n ",
                "TX2 cur/max/avg",
                xlru_pps::xlru_pps_status.tx_curr[1],
                xlru_pps::xlru_pps_status.tx_curr_max[1],
                xlru_pps::xlru_pps_status.tx_curr_avg[1]
                );

    print_func("     %-35s: %-4.1f  %-4.1f  %-4.1f\n\n ",
                "TX3 cur/max/avg",
                xlru_pps::xlru_pps_status.tx_curr[2],
                xlru_pps::xlru_pps_status.tx_curr_max[2],
                xlru_pps::xlru_pps_status.tx_curr_avg[2]
                );


	print_func("\nbit     ->  7 6 5 4 3 2 1 0\n");
	print_func("byte%d   ->  %01d %01d %01d %01d %01d %01d %01d %01d\n",
				1,
				xlru_pps::xlru_pps_status.byte1_holdUp_boards.b8_AC_power_umbalance_fail_ph3,
				xlru_pps::xlru_pps_status.byte1_holdUp_boards.b7_AC_power_umbalance_fail_ph2,
				xlru_pps::xlru_pps_status.byte1_holdUp_boards.b6_AC_power_umbalance_fail_ph1,
				0,
                0,
                0,
                xlru_pps::xlru_pps_status.byte1_holdUp_boards.b2_HP_under_voltage_fail,
                xlru_pps::xlru_pps_status.byte1_holdUp_boards.b1_LP_under_voltage_fail
				);

	print_func("byte%d   ->  %01d %01d %01d %01d %01d %01d %01d %01d\n",
					2,
					xlru_pps::xlru_pps_status.byte2_rx_board.b8_rx_hazard,
					xlru_pps::xlru_pps_status.byte2_rx_board.b7_rx_hazard,
					xlru_pps::xlru_pps_status.byte2_rx_board.b6_output_rx_under_voltage_fail,
					xlru_pps::xlru_pps_status.byte2_rx_board.b5_output_rx_over_voltage_fail,
					0,
                    xlru_pps::xlru_pps_status.byte2_rx_board.b3_rx_rectified_dc_under_voltage_fail_ac_power_loss,
					xlru_pps::xlru_pps_status.byte2_rx_board.b2_rx_input_dc_overcurrent_fail,
					xlru_pps::xlru_pps_status.byte2_rx_board.b1_rx_link_fail
					);

	print_func("byte%d   ->  %01d %01d %01d %01d %01d %01d %01d %01d\n",
					3,
					xlru_pps::xlru_pps_status.byte3_tx1_board.b8_tx1_hazard,
					xlru_pps::xlru_pps_status.byte3_tx1_board.b7_tx1_hazard,
					xlru_pps::xlru_pps_status.byte3_tx1_board.b6_output_tx1_under_voltage_fail,
					xlru_pps::xlru_pps_status.byte3_tx1_board.b5_output_tx1_over_voltage_fail,
                    0,
                    xlru_pps::xlru_pps_status.byte3_tx1_board.b3_tx1_rectified_dc_under_voltage_fail_270_uv,
					xlru_pps::xlru_pps_status.byte3_tx1_board.b2_tx1_input_dc_over_current_fail,
					xlru_pps::xlru_pps_status.byte3_tx1_board.b1_tx1_link_with_rx
					);

	print_func("byte%d   ->  %01d %01d %01d %01d %01d %01d %01d %01d\n",
					4,
					xlru_pps::xlru_pps_status.byte4_tx2_board.b8_tx2_hazard,
					xlru_pps::xlru_pps_status.byte4_tx2_board.b7_tx2_hazard,
					xlru_pps::xlru_pps_status.byte4_tx2_board.b6_output_tx2_under_voltage_fail,
					xlru_pps::xlru_pps_status.byte4_tx2_board.b5_output_tx2_over_voltage_fail,
                    0,
                    xlru_pps::xlru_pps_status.byte4_tx2_board.b3_tx2_rectified_dc_under_voltage_fail_270_uv,
					xlru_pps::xlru_pps_status.byte4_tx2_board.b2_tx2_input_dc_over_current_fail,
					xlru_pps::xlru_pps_status.byte4_tx2_board.b1_tx2_link_with_rx
					);

	print_func("byte%d   ->  %01d %01d %01d %01d %01d %01d %01d %01d\n",
					5,
					xlru_pps::xlru_pps_status.byte5_tx3_board.b8_tx3_hazard,
					xlru_pps::xlru_pps_status.byte5_tx3_board.b7_tx3_hazard,
					xlru_pps::xlru_pps_status.byte5_tx3_board.b6_output_tx3_under_voltage_fail,
					xlru_pps::xlru_pps_status.byte5_tx3_board.b5_output_tx3_over_voltage_fail,
                    0,
                    xlru_pps::xlru_pps_status.byte5_tx3_board.b3_tx3_rectified_dc_under_voltage_fail_270_uv,
					xlru_pps::xlru_pps_status.byte5_tx3_board.b2_tx3_input_dc_over_current_fail,
					xlru_pps::xlru_pps_status.byte5_tx3_board.b1_tx3_link_with_rx
					);

	print_func("byte%d   ->  %01d %01d %01d %01d %01d %01d %01d %01d\n",
					6,
					0,
					0,
					0,
					0,
					0,
					xlru_pps::xlru_pps_status.byte6_general.b3_wow_tellback_3,
					xlru_pps::xlru_pps_status.byte6_general.b2_wow_tellback_2,
					xlru_pps::xlru_pps_status.byte6_general.b1_wow_tellback_1
					);


	print_func("\n");
}

void xlru_pps::pps_test_status_payload_master(void)
{
	pps_tx_buffer[4] = PPS_GET_MESSAGE;			//"T", pps test status message
	pps_tx_buffer[5] = 0;

	char checksum[2] = {0};
	calc_checksum(checksum, pps_tx_buffer);
	pps_tx_buffer[5] = checksum[0];
	pps_tx_buffer[6] = checksum[1];

	//snprintf(&tx_buffer[5], 3, "%02x", get_checksum(tx_buffer));
	pps_tx_buffer[7]= CR_EOM;
	pps_tx_buffer[8]= 0;
}

char* xlru_pps::pps_set_test_status_master(void)
{
	memset(pps_tx_buffer, 0, sizeof(pps_tx_buffer));
	pps_header_master();
	pps_test_status_payload_master();
	return pps_tx_buffer;
}

