//#############################################################################################################################################################################################################
#include "IDIBUS_4DC.h"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IdiBusDevice *IdiBus_4DC::getDevice(uint8_t Num)
{
 switch (Num)
	{
	 case ( IDIBUS_PSU_CNTRL_DEV ) :  { return &this->PSUC_DEV; }
	 case ( IDIBUS_INPV_CNTRL_DEV ) : { return &this->INPV_DEV; }
	 default :                        { return NULL; }
	}
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
IdiBus_4DC_PSUChannel::IdiBus_4DC_PSUChannel(void) : IdiBusChannel()
{ 
 this->TargetVoltage = 0;
 this->CurrentLimit = 0;
 this->Voltage = 0;
 this->Current = 0;
 this->STATUS.Enable = 0;
 this->STATUS.PowerGood = 0;
 this->STATUS.ERRORS.Sum = 0;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IdiBusChannel *IdiBus_4DC_PSUCDevice::getChannel(uint8_t Num)
{
 if ( Num < IDIBUS_4DC_CH_COUNT ) { return &this->CH[Num]; }
 else                             { return NULL; }
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IdiBus_4DC_PSUChannel IdiBus_4DC_PSUCDevice::getChData(uint8_t ChNum)
{
 if ( ChNum < IDIBUS_4DC_CH_COUNT ) { return this->CH[ChNum]; }
 else                               { IdiBus_4DC_PSUChannel NewData; return NewData;  }
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
IdiBus_4DC_INPVChannel::IdiBus_4DC_INPVChannel(void) : IdiBusChannel()
{
 this->InpVoltage = 0;
 this->STATUS.Sum = 0;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IdiBusChannel *IdiBus_4DC_INPVCDevice::getChannel(uint8_t Num)
{
 if ( Num == 0 ) { return &this->INPV; }
 else            { return NULL; }
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
IdiBus_4DC_INPVChannel IdiBus_4DC_INPVCDevice::getChData(void)
{
 return this->INPV;
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_INPVCDevice::getInputVoltage(void)
{
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );
 MMES.DEV.NUM       = IDIBUS_INPV_CNTRL_DEV;
 MMES.CHNL.NUM      = 0;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_GET_INP_VOLTAGE;
 uint8_t ChDataSize = IDIBUS_CUSTDEF_PSUINPV_MES_LENGTH;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->INPV.MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength == 1 )                { this->INPV.MMES_Error = MMES.RxData[0]; }
 else if ( MMES.RxDataLength != (ChDataSize + 1) ) { this->INPV.MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; }
else {
	  this->INPV.MMES_Error = MMES.RxData[0];
	  if ( this->INPV.MMES_Error == IDIER_NOPE )
	      {
		   uint8_t *Data = &MMES.RxData[1];
		   if ( (Data[IDIBUS_CUSTDEF_PSUINPV_STATE_Pos] & (1U << IDIBUS_CUSTDEF_PSUINPV_STATE_UV_Pos)) != 0 ) { this->INPV.STATUS.BF.Undervoltage = 1; }
		   else                                                                                               { this->INPV.STATUS.BF.Undervoltage = 0; }
		   if ( (Data[IDIBUS_CUSTDEF_PSUINPV_STATE_Pos] & (1U << IDIBUS_CUSTDEF_PSUINPV_STATE_OV_Pos)) != 0 ) { this->INPV.STATUS.BF.Overvoltage = 1; }
		   else                                                                                               { this->INPV.STATUS.BF.Overvoltage = 0; }
		   this->INPV.InpVoltage = (uint16_t)( (uint16_t)Data[IDIBUS_CUSTDEF_PSUINPV_VOLTAGE_Pos] << 8 ) | MMES.RxData[IDIBUS_CUSTDEF_PSUINPV_VOLTAGE_Pos + 1];
		  }
	 }
 return this->INPV.MMES_Error;
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::getChOutputVoltage(uint8_t ChNum)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );		
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_VOLTAGE;
 uint8_t ChDataSize = 4;		//int32_t
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength == 1 )                { this->CH[ChNum].MMES_Error = MMES.RxData[0]; }
 else if ( MMES.RxDataLength != (ChDataSize + 1) ) { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; }
 else {
	  this->CH[ChNum].MMES_Error = MMES.RxData[0];
	  if ( this->CH[ChNum].MMES_Error == IDIER_NOPE )
	      {
		   this->CH[ChNum].Voltage = (int32_t) (
								     (uint32_t)((uint32_t)MMES.RxData[1] << 24) |
									 (uint32_t)((uint32_t)MMES.RxData[2] << 16) |
									 (uint32_t)((uint32_t)MMES.RxData[3] << 8)  |
									 (uint32_t)((uint32_t)MMES.RxData[4])       );
		  }
	 }
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void IdiBus_4DC_PSUCDevice::getAllChOutputVoltage(void)
{
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_VOLTAGE;
 uint8_t ChDataSize = 4;		//int32_t
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )            { this->setAllPsuChErr(RequestError); return; }
 else if (MMES.RxDataLength < IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; }
 else {
	   uint8_t ExpDataLength = IDIBUS_4DC_CH_COUNT; // Errors
	   for (uint8_t I=0; I<IDIBUS_4DC_CH_COUNT; I++) {  if ( MMES.RxData[I] == IDIER_NOPE ) { ExpDataLength = (uint16_t)(ExpDataLength + ChDataSize); }  }
	   if ( ExpDataLength != MMES.RxDataLength )     {  this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return;  }
	  }
 uint8_t ErrorPos = 0;
 uint8_t DataPos  = ErrorPos + IDIBUS_4DC_CH_COUNT;
 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
	{
	 this->CH[I].MMES_Error = MMES.RxData[ErrorPos];
	 ErrorPos = (uint8_t)(ErrorPos + 1);
	 if ( this->CH[I].MMES_Error == IDIER_NOPE )
		{
		 this->CH[I].Voltage = (int32_t) (
							   (uint32_t)((uint32_t)MMES.RxData[DataPos]   << 24) |
							   (uint32_t)((uint32_t)MMES.RxData[DataPos+1] << 16) |
							   (uint32_t)((uint32_t)MMES.RxData[DataPos+2] << 8)  |
							   (uint32_t)((uint32_t)MMES.RxData[DataPos+3])      );
		 DataPos  = (uint8_t)(DataPos  + ChDataSize);
		}
	}
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::getChOutputCurrent(uint8_t ChNum)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );		
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_CURRENT;
 uint8_t ChDataSize = 4;		//int32_t
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength == 1 )                { this->CH[ChNum].MMES_Error = MMES.RxData[0]; }
 else if ( MMES.RxDataLength != (ChDataSize + 1) ) { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; }
 else {
	  this->CH[ChNum].MMES_Error = MMES.RxData[0];
	  if ( this->CH[ChNum].MMES_Error == IDIER_NOPE )
	      {
		   this->CH[ChNum].Current = (int32_t) (
								     (uint32_t)((uint32_t)MMES.RxData[1] << 24) |
									 (uint32_t)((uint32_t)MMES.RxData[2] << 16) |
									 (uint32_t)((uint32_t)MMES.RxData[3] << 8)  |
									 (uint32_t)((uint32_t)MMES.RxData[4])       );
		  }
	 }
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------	
void IdiBus_4DC_PSUCDevice::getAllChOutputCurrent(void)
{
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_CURRENT;
 uint8_t ChDataSize = 4;		//int32_t
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )            { this->setAllPsuChErr(RequestError); return; }
 else if (MMES.RxDataLength < IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; }
 else {
	   uint8_t ExpDataLength = IDIBUS_4DC_CH_COUNT; // Errors
	   for (uint8_t I=0; I<IDIBUS_4DC_CH_COUNT; I++) {  if ( MMES.RxData[I] == IDIER_NOPE ) { ExpDataLength = (uint16_t)(ExpDataLength + ChDataSize); }  }
	   if ( ExpDataLength != MMES.RxDataLength )     {  this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return;  }
	  }
 uint8_t ErrorPos = 0;
 uint8_t DataPos  = ErrorPos + IDIBUS_4DC_CH_COUNT;
 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
	{
	 this->CH[I].MMES_Error = MMES.RxData[ErrorPos];
	 ErrorPos = (uint8_t)(ErrorPos + 1);
	 if ( this->CH[I].MMES_Error == IDIER_NOPE )
		{
		 this->CH[I].Current = (int32_t) (
							   (uint32_t)((uint32_t)MMES.RxData[DataPos]   << 24) |
							   (uint32_t)((uint32_t)MMES.RxData[DataPos+1] << 16) |
							   (uint32_t)((uint32_t)MMES.RxData[DataPos+2] << 8)  |
							   (uint32_t)((uint32_t)MMES.RxData[DataPos+3])      );
		 DataPos  = (uint8_t)(DataPos  + ChDataSize);
		}
	}
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::getChStatus(uint8_t ChNum)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );		
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_STATUS;
 uint8_t ChDataSize = IDIBUS_CUSTDEF_PSUCH_STBUF_SIZE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength == 1 )                { this->CH[ChNum].MMES_Error = MMES.RxData[0]; }
 else if ( MMES.RxDataLength != (ChDataSize + 1) ) { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; }
 else {
	  this->CH[ChNum].MMES_Error = MMES.RxData[0];
	  if ( this->CH[ChNum].MMES_Error == IDIER_NOPE ) { this->parsePsuChState(&MMES.RxData[1], ChNum); }
	 }	
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------	
void IdiBus_4DC_PSUCDevice::getAllChStatus(void)
{
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_STATUS;
 uint8_t ChDataSize = IDIBUS_CUSTDEF_PSUCH_STBUF_SIZE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )            { this->setAllPsuChErr(RequestError); return; }
 else if (MMES.RxDataLength < IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; }
 else {
	   uint8_t ExpDataLength = IDIBUS_4DC_CH_COUNT; // Errors
	   for (uint8_t I=0; I<IDIBUS_4DC_CH_COUNT; I++) {  if ( MMES.RxData[I] == IDIER_NOPE ) { ExpDataLength = (uint16_t)(ExpDataLength + ChDataSize); }  }
	   if ( ExpDataLength != MMES.RxDataLength )     {  this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return;  }
	  }
 uint8_t ErrorPos = 0;
 uint8_t DataPos  = ErrorPos + IDIBUS_4DC_CH_COUNT;
 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
	{
	 this->CH[I].MMES_Error = MMES.RxData[ErrorPos];
	 ErrorPos = (uint8_t)(ErrorPos + 1);
	 if ( this->CH[I].MMES_Error == IDIER_NOPE )
		{
		 this->parsePsuChState(&MMES.RxData[DataPos], I);
		 DataPos  = (uint8_t)(DataPos  + ChDataSize);
		}
	}
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::getChAllData(uint8_t ChNum)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );		
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_ALLDATA;
 uint8_t ChDataSize = IDIBUS_CUSTDEF_PSUCH_STALLBUF_SIZE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength == 1 )                { this->CH[ChNum].MMES_Error = MMES.RxData[0]; }
 else if ( MMES.RxDataLength != (ChDataSize + 1) ) { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; }
 else {
	   this->CH[ChNum].MMES_Error = MMES.RxData[0];
	   if ( this->CH[ChNum].MMES_Error == IDIER_NOPE ) { this->parsePsuChAllState(&MMES.RxData[1], ChNum); }
	  }	
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		
void IdiBus_4DC_PSUCDevice::getAllChAllData(void)
{
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() );
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_GET_ALLDATA;
 uint8_t ChDataSize = IDIBUS_CUSTDEF_PSUCH_STALLBUF_SIZE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )            { this->setAllPsuChErr(RequestError); return; }
 else if (MMES.RxDataLength < IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; }
 else {
	   uint8_t ExpDataLength = IDIBUS_4DC_CH_COUNT; // Errors
	   for (uint8_t I=0; I<IDIBUS_4DC_CH_COUNT; I++) {  if ( MMES.RxData[I] == IDIER_NOPE ) { ExpDataLength = (uint16_t)(ExpDataLength + ChDataSize); }  }
	   if ( ExpDataLength != MMES.RxDataLength )     {  this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return;  }
	  }
 uint8_t ErrorPos = 0;
 uint8_t DataPos  = ErrorPos + IDIBUS_4DC_CH_COUNT;
 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
	{
	 this->CH[I].MMES_Error = MMES.RxData[ErrorPos];
	 ErrorPos = (uint8_t)(ErrorPos + 1);
	 if ( this->CH[I].MMES_Error == IDIER_NOPE )
		{
		 this->parsePsuChAllState(&MMES.RxData[DataPos], I);
		 DataPos  = (uint8_t)(DataPos  + ChDataSize);
		}
	}
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::setChState(uint8_t ChNum, uint8_t State)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 if ( State != 0 ) { State = IDIBUS_CUSTDEF_PSU_CH_STATE_ENABLE; }
 else			   { State = IDIBUS_CUSTDEF_PSU_CH_STATE_DISABLE; }
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &State, 1);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_STATE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength != 1 )                { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; } 
 else {
	   this->CH[ChNum].MMES_Error = MMES.RxData[0];
	   if ( this->CH[ChNum].MMES_Error == IDIER_NOPE ) { this->CH[ChNum].STATUS.Enable = State; }
	  }
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void IdiBus_4DC_PSUCDevice::setAllChState(uint8_t State)
{
 if ( State != 0 ) { State = IDIBUS_CUSTDEF_PSU_CH_STATE_ENABLE; }
 else			   { State = IDIBUS_CUSTDEF_PSU_CH_STATE_DISABLE; }
 
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &State, 1);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.CHNL.ALLSAME  = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_STATE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE )  { this->CH[I].STATUS.Enable = State; }
		}
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void IdiBus_4DC_PSUCDevice::setAllChState(uint8_t Ch1State, uint8_t Ch2State, uint8_t Ch3State, uint8_t Ch4State)
{
 uint8_t State[IDIBUS_4DC_CH_COUNT] = { Ch1State, Ch2State, Ch3State, Ch4State };
 for (uint8_t I=0; I<IDIBUS_4DC_CH_COUNT; I++)
	{
	 if ( State[I] != 0 ) { State[I] = IDIBUS_CUSTDEF_PSU_CH_STATE_ENABLE; }
	 else			      { State[I] = IDIBUS_CUSTDEF_PSU_CH_STATE_DISABLE; }
	}
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &State[0], IDIBUS_4DC_CH_COUNT);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_STATE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE )  { this->CH[I].STATUS.Enable = State[I]; }
		}
	}
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::setChVoltage(uint8_t ChNum, uint16_t TargetVoltage)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 if ( (TargetVoltage < IDIBUS_PSU_CH_TARG_V_MIN_mV) || (TargetVoltage > IDIBUS_PSU_CH_TARG_V_MAX_mV) )
	{
	 this->CH[ChNum].MMES_Error = IDIERMST_INVALID_TX_PARAM;
	 return IDIERMST_INVALID_TX_PARAM;
	}
 uint8_t TxData[2];
 TxData[0] = (uint8_t)(TargetVoltage >> 8);
 TxData[1] = (uint8_t)(TargetVoltage);
 
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], 2);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_TARGET_VOLTAGE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength != 1 )                { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; } 
 else {
	   this->CH[ChNum].MMES_Error = MMES.RxData[0];
	   if ( this->CH[ChNum].MMES_Error == IDIER_NOPE ) { this->CH[ChNum].TargetVoltage = TargetVoltage; }
	  }
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		
void IdiBus_4DC_PSUCDevice::setAllChVoltage(uint16_t TargetVoltage)
{
 if ( (TargetVoltage < IDIBUS_PSU_CH_TARG_V_MIN_mV) || (TargetVoltage > IDIBUS_PSU_CH_TARG_V_MAX_mV) ) { this->setAllPsuChErr(IDIERMST_INVALID_TX_PARAM); return; }
 uint8_t TxData[2];
 TxData[0] = (uint8_t)(TargetVoltage >> 8);
 TxData[1] = (uint8_t)(TargetVoltage);
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], 2);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.CHNL.ALLSAME  = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_TARGET_VOLTAGE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE )  { this->CH[I].TargetVoltage = TargetVoltage; }
		}
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		
void IdiBus_4DC_PSUCDevice::setAllChVoltage(uint16_t TV_CH1, uint16_t TV_CH2, uint16_t TV_CH3, uint16_t TV_CH4)
{
 uint16_t TargetV[IDIBUS_4DC_CH_COUNT] = { TV_CH1, TV_CH2, TV_CH3, TV_CH4 };
 uint8_t  TxData[IDIBUS_4DC_CH_COUNT * 2];
 for (uint8_t I=0, J=0; I<IDIBUS_4DC_CH_COUNT; I++, J+=2 )
	{
	 TxData[J]   = (uint8_t)(TargetV[I] >> 8);
	 TxData[J+1] = (uint8_t)(TargetV[I]);
	}
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], IDIBUS_4DC_CH_COUNT * 2);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_TARGET_VOLTAGE;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE )  { this->CH[I].TargetVoltage = TargetV[I]; }
		}
	}
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::setChCurrentLimit(uint8_t ChNum, uint16_t CurrentLimit)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 if ( (CurrentLimit < IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MIN) || (CurrentLimit > IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MAX) )
	{
	 this->CH[ChNum].MMES_Error = IDIERMST_INVALID_TX_PARAM;
	 return IDIERMST_INVALID_TX_PARAM;
	}	
 uint8_t TxData[2];
 TxData[0] = (uint8_t)(CurrentLimit >> 8);
 TxData[1] = (uint8_t)(CurrentLimit);
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], 2);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_CURRENT_LIMIT;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength != 1 )                { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; } 
 else {
	   this->CH[ChNum].MMES_Error = MMES.RxData[0];
	   if ( this->CH[ChNum].MMES_Error == IDIER_NOPE ) { this->CH[ChNum].CurrentLimit = CurrentLimit; }
	  }
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		
void IdiBus_4DC_PSUCDevice::setAllChCurrentLimit(uint16_t CurrentLimit)
{
 if ( (CurrentLimit < IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MIN) || (CurrentLimit > IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MAX) ) { this->setAllPsuChErr(IDIERMST_INVALID_TX_PARAM); return; }
 uint8_t TxData[2];
 TxData[0] = (uint8_t)(CurrentLimit >> 8);
 TxData[1] = (uint8_t)(CurrentLimit);
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], 2);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.CHNL.ALLSAME  = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_CURRENT_LIMIT;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE )  { this->CH[I].CurrentLimit = CurrentLimit; }
		}
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		
void IdiBus_4DC_PSUCDevice::setAllChCurrentLimit(uint16_t CL_CH1, uint16_t CL_CH2, uint16_t CL_CH3, uint16_t CL_CH4)
{
 uint16_t CurrentL[IDIBUS_4DC_CH_COUNT] = { CL_CH1, CL_CH2, CL_CH3, CL_CH4 };
 uint8_t  TxData[IDIBUS_4DC_CH_COUNT * 2];
 for (uint8_t I=0, J=0; I<IDIBUS_4DC_CH_COUNT; I++, J+=2 )
	{
	 TxData[J]   = (uint8_t)(CurrentL[I] >> 8);
	 TxData[J+1] = (uint8_t)(CurrentL[I]);
	}
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], IDIBUS_4DC_CH_COUNT * 2);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_CURRENT_LIMIT;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE )  { this->CH[I].CurrentLimit = CurrentL[I]; }
		}
	}	
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
uint8_t IdiBus_4DC_PSUCDevice::setChVoltageAndCurrentLimit(uint8_t ChNum, uint16_t TargetVoltage, uint16_t CurrentLimit)
{
 if ( ChNum >= IDIBUS_4DC_CH_COUNT ) { return IDIERMST_INVALID_CHN_NUM; }
 if ( (CurrentLimit < IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MIN) || (CurrentLimit > IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MAX) ||
	  (TargetVoltage < IDIBUS_PSU_CH_TARG_V_MIN_mV)            || (TargetVoltage > IDIBUS_PSU_CH_TARG_V_MAX_mV) )
	{
	 this->CH[ChNum].MMES_Error = IDIERMST_INVALID_TX_PARAM;
	 return IDIERMST_INVALID_TX_PARAM;
	}
 uint8_t TxData[4];
 TxData[0] = (uint8_t)(TargetVoltage >> 8);
 TxData[1] = (uint8_t)(TargetVoltage);
 TxData[2] = (uint8_t)(CurrentLimit >> 8);
 TxData[3] = (uint8_t)(CurrentLimit);
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], 4);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.CHNL.NUM      = ChNum;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_ALL;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError   != IDIER_NOPE )          { this->CH[ChNum].MMES_Error = RequestError;   }
 else if ( MMES.RxDataLength != 1 )                { this->CH[ChNum].MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT; } 
 else {
	   this->CH[ChNum].MMES_Error = MMES.RxData[0];
	   if ( this->CH[ChNum].MMES_Error == IDIER_NOPE ) { this->CH[ChNum].TargetVoltage = TargetVoltage; this->CH[ChNum].CurrentLimit = CurrentLimit; }
	  }
 return this->CH[ChNum].MMES_Error;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		
void IdiBus_4DC_PSUCDevice::setAllChVoltageAndCurrentLimit(uint16_t TargetVoltage, uint16_t CurrentLimit)
{
 if ( (CurrentLimit < IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MIN) || (CurrentLimit > IDIBUS_PSU_CH_AVERAGE_CURRENT_LIMIT_MAX) ||
	  (TargetVoltage < IDIBUS_PSU_CH_TARG_V_MIN_mV)            || (TargetVoltage > IDIBUS_PSU_CH_TARG_V_MAX_mV) )  { this->setAllPsuChErr(IDIERMST_INVALID_TX_PARAM); return; }
 uint8_t TxData[4];
 TxData[0] = (uint8_t)(TargetVoltage >> 8);
 TxData[1] = (uint8_t)(TargetVoltage);
 TxData[2] = (uint8_t)(CurrentLimit >> 8);
 TxData[3] = (uint8_t)(CurrentLimit);
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], 4);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.CHNL.ALLSAME  = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_ALL;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE ) { this->CH[I].TargetVoltage = TargetVoltage; this->CH[I].CurrentLimit = CurrentLimit; }
		}
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------		
void IdiBus_4DC_PSUCDevice::setAllChVoltageAndCurrentLimit(uint16_t VCH1, uint16_t CCH1, uint16_t VCH2, uint16_t CCH2, uint16_t VCH3, uint16_t CCH3, uint16_t VCH4, uint16_t CCH4)
{
 uint16_t CurrentL[IDIBUS_4DC_CH_COUNT] = { CCH1, CCH2, CCH3, CCH4 };
 uint16_t TargetV[IDIBUS_4DC_CH_COUNT] =  { VCH1, VCH2, VCH3, VCH4 };
 uint8_t  TxData[IDIBUS_4DC_CH_COUNT * 4];
 for (uint8_t I=0, J=0; I<IDIBUS_4DC_CH_COUNT; I++, J+=4 )
	{
	 TxData[J]   = (uint8_t)(TargetV[I] >> 8);
	 TxData[J+1] = (uint8_t)(TargetV[I]);
	 TxData[J+2] = (uint8_t)(CurrentL[I] >> 8);
	 TxData[J+3] = (uint8_t)(CurrentL[I]);
	}
 IdiBusMMES MMES( static_cast<IdiBusSlave*>(this->Module)->getAddress() , &TxData[0], IDIBUS_4DC_CH_COUNT * 4);
 MMES.DEV.NUM       = IDIBUS_PSU_CNTRL_DEV;
 MMES.DEV.ALLCH     = 1;
 MMES.ComFunc       = IDIBUS_CUSTDEF_FUNC_CODE_PSU_CH_SET_ALL;
 uint8_t RequestError = static_cast<IdiBusSlave*>(this->Module)->SendRequestMMES(&MMES);
 if      ( RequestError != IDIER_NOPE )             { this->setAllPsuChErr(RequestError); }
 else if (MMES.RxDataLength != IDIBUS_4DC_CH_COUNT) { this->setAllPsuChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); }
 else
	{
	 for (uint8_t I = 0; I < IDIBUS_4DC_CH_COUNT; I++)
		{
		 this->CH[I].MMES_Error = MMES.RxData[I];
		 if ( this->CH[I].MMES_Error == IDIER_NOPE ) { this->CH[I].TargetVoltage = TargetV[I]; this->CH[I].CurrentLimit = CurrentL[I]; }
		}
	}	
}
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
void IdiBus_4DC_PSUCDevice::parsePsuChState(uint8_t *State, uint8_t ChNum)
{
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_EN_Pos)) != 0 )          { this->CH[ChNum].STATUS.Enable = 1; }
 else                                                                                                           { this->CH[ChNum].STATUS.Enable = 0; }
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_PG_Pos)) != 0 )          { this->CH[ChNum].STATUS.PowerGood = 1; }
 else                                                                                                           { this->CH[ChNum].STATUS.PowerGood = 0; }
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_PERIPH_ERR_Pos)) != 0 )  { this->CH[ChNum].STATUS.ERRORS.BF.PeripheryError = 1; }
 else                                                                                                           { this->CH[ChNum].STATUS.ERRORS.BF.PeripheryError = 0; }
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_OVERCURRENT_ERR_Pos)) != 0 ) { this->CH[ChNum].STATUS.ERRORS.BF.OvercurrentError = 1; }
 else                                                                                                               { this->CH[ChNum].STATUS.ERRORS.BF.OvercurrentError = 0; }
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_OVERVOLTAGE_ERR_Pos)) != 0 ) { this->CH[ChNum].STATUS.ERRORS.BF.OvervoltageError = 1; }
 else                                                                                                               { this->CH[ChNum].STATUS.ERRORS.BF.OvervoltageError = 0; }
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_OFFSTATELEAKAGE_ERR_Pos)) != 0 ) { this->CH[ChNum].STATUS.ERRORS.BF.OffStateCurrentLeakage = 1; }
 else                                                                                                                   { this->CH[ChNum].STATUS.ERRORS.BF.OffStateCurrentLeakage = 0; }
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_MEMORY_ERR_Pos)) != 0 )  { this->CH[ChNum].STATUS.ERRORS.BF.MemoryError = 1; }
 else                                                                                                           { this->CH[ChNum].STATUS.ERRORS.BF.MemoryError = 0; }
 if ( (State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos] & (1U << IDIBUS_CUSTDEF_PSUCH_STBUF_ST_INPV_ERR_Pos)) != 0 )    { this->CH[ChNum].STATUS.ERRORS.BF.InpVoltageError = 1; }
 else                                                                                                           { this->CH[ChNum].STATUS.ERRORS.BF.InpVoltageError = 0; }	 
 this->CH[ChNum].TargetVoltage = (uint16_t)( (uint16_t)((uint16_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_TARGET_VOLATGE_Pos] << 8) | State[IDIBUS_CUSTDEF_PSUCH_STBUF_TARGET_VOLATGE_Pos + 1] );
 this->CH[ChNum].CurrentLimit  = (uint16_t)( (uint16_t)((uint16_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_CURRENT_LIMIT_Pos] << 8) | State[IDIBUS_CUSTDEF_PSUCH_STBUF_CURRENT_LIMIT_Pos + 1] );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void IdiBus_4DC_PSUCDevice::parsePsuChAllState(uint8_t *State, uint8_t ChNum)
{
 this->parsePsuChState(&State[IDIBUS_CUSTDEF_PSUCH_STBUF_ST_Pos], ChNum);
 this->CH[ChNum].Voltage = (int32_t) (
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_VOLTAGE_Pos]     << 24) |
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_VOLTAGE_Pos + 1] << 16) |
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_VOLTAGE_Pos + 2] << 8)  |
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_VOLTAGE_Pos + 3])       );
 this->CH[ChNum].Current = (int32_t) (
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_CURRENT_Pos]     << 24) |
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_CURRENT_Pos + 1] << 16) |
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_CURRENT_Pos + 2] << 8)  |
						   (uint32_t)((uint32_t)State[IDIBUS_CUSTDEF_PSUCH_STBUF_OUTPUT_CURRENT_Pos + 3])       );
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void IdiBus_4DC_PSUCDevice::setAllPsuChErr(uint8_t ErrCode)
{
 for (uint8_t I=0; I<IDIBUS_4DC_CH_COUNT; I++) { this->CH[I].MMES_Error = ErrCode; }
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//#############################################################################################################################################################################################################

