#include "IDIBUS_1xGen.h"

IdiBus_1xGen::IdiBus_1xGen (IdiBusSerialLine *SlaveLine, uint8_t SlaveAddress) : IdiBusSlave(SlaveLine, SlaveAddress)
{
	TMP.MMES_Error = 0;
	TMP.RXlen = 0;
}

IdiBus_1xGen::IdiBus_1xGen () : IdiBusSlave()
{
	TMP.MMES_Error = 0;
	TMP.RXlen = 0;
}

IDIBUS_1xGEN_DATA_TYPE IdiBus_1xGen::getData(void)
{
	return this->TMP;
}

uint8_t IdiBus_1xGen::start_SPI(uint8_t *buf) {
	IdiBusMMES MMES(this->Address);
	MMES.DEV.NUM	= IDIBUS_1xGen_DEV;
	MMES.CHNL.NUM   = 0;
	MMES.ComFunc    = 0x01;
	MMES.TxDataLength = 10;
	MMES.TxData = buf;
	uint8_t RequestError = this->SendRequestMMES(&MMES);
	
	if      ( RequestError   != IDIER_NOPE )          { this->TMP.MMES_Error = RequestError;   }
	else if ( MMES.RxDataLength == 1 )                { this->TMP.MMES_Error = MMES.RxData[0]; }
	else {
		this->TMP.MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT;
	}
	return this->TMP.MMES_Error;
}

uint8_t IdiBus_1xGen::reset_STM() {
	IdiBusMMES MMES(this->Address);
	MMES.DEV.NUM	= IDIBUS_1xGen_DEV;
	MMES.CHNL.NUM   = 0;
	MMES.ComFunc    = 0x02;
	
	uint8_t ChDataSize = 0;
	uint8_t RequestError = this->SendRequestMMES(&MMES);
	
	if      ( RequestError   != IDIER_NOPE )          { this->TMP.MMES_Error = RequestError;   }
	else if ( MMES.RxDataLength == 1 )                { this->TMP.MMES_Error = MMES.RxData[0]; }
	else {
		this->TMP.MMES_Error = IDIERMST_INVALID_RX_REQUEST_FORMAT;
	}
	return this->TMP.MMES_Error;
}