#include "IDIBUS_1Wire.h" IdiBus_1Wire::IdiBus_1Wire (IdiBusSerialLine *SlaveLine, uint8_t SlaveAddress) : IdiBusSlave(SlaveLine, SlaveAddress) { for (uint8_t I=0; ICH[I].MMES_Error = 0; this->CH[I].Temperature = 0; //this->CH[I].STATUS.Enable = 0; } } IdiBus_1Wire::IdiBus_1Wire () : IdiBusSlave() { for (uint8_t I=0; ICH[I].MMES_Error = 0; this->CH[I].Temperature = 0; //this->CH[I].STATUS.Enable = 0; } } IDIBUS_1Wire_DATA_TYPE IdiBus_1Wire::getChData(uint8_t ChNum){ if ( ChNum < IDIBUS_1Wire_CH_COUNT ) { return this->CH[ChNum]; } else { return this->CH[IDIBUS_1Wire_CH3_NUM]; } } void IdiBus_1Wire::changeAllAutomatiocConversionStates() { IdiBusMMES MMES(this->Address); MMES.DEV.NUM = IDIBUS_1Wire_CNTRL_DEV; MMES.DEV.ALLCH = 1; MMES.ComFunc = 0x01; uint8_t ChDataSize = 1; uint8_t RequestError = this->SendRequestMMES(&MMES); if ( RequestError != IDIER_NOPE ) { this->setAllChErr(RequestError); return; } else if (MMES.RxDataLength < IDIBUS_1Wire_CH_COUNT) { this->setAllChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; } else { uint8_t ExpDataLength = IDIBUS_1Wire_CH_COUNT; // Errors for (uint8_t I=0; IsetAllChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; } } uint8_t ErrorPos = 0; uint8_t DataPos = ErrorPos + IDIBUS_1Wire_CH_COUNT; for (uint8_t I = 0; I < IDIBUS_1Wire_CH_COUNT; I++) { this->CH[I].MMES_Error = MMES.RxData[ErrorPos]; ErrorPos = (uint8_t)(ErrorPos + 1); } } void IdiBus_1Wire::startAllOneShotConversions() { IdiBusMMES MMES(this->Address); MMES.DEV.NUM = IDIBUS_1Wire_CNTRL_DEV; MMES.DEV.ALLCH = 1; MMES.ComFunc = 0x02; uint8_t ChDataSize = 0; uint8_t RequestError = this->SendRequestMMES(&MMES); if ( RequestError != IDIER_NOPE ) { this->setAllChErr(RequestError); return; } else if (MMES.RxDataLength < IDIBUS_1Wire_CH_COUNT) { this->setAllChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; } else { uint8_t ExpDataLength = IDIBUS_1Wire_CH_COUNT; // Errors for (uint8_t I=0; IsetAllChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; } } uint8_t ErrorPos = 0; uint8_t DataPos = ErrorPos + IDIBUS_1Wire_CH_COUNT; for (uint8_t I = 0; I < IDIBUS_1Wire_CH_COUNT; I++) { this->CH[I].MMES_Error = MMES.RxData[ErrorPos]; ErrorPos = (uint8_t)(ErrorPos + 1); } } uint8_t IdiBus_1Wire::getTemperature(uint8_t ChNum) { if (ChNum >= IDIBUS_1Wire_CH_COUNT) { return IDIERMST_INVALID_CHN_NUM; } IdiBusMMES MMES(this->Address); MMES.DEV.NUM = IDIBUS_1Wire_CNTRL_DEV; MMES.CHNL.NUM = ChNum; MMES.ComFunc = 0x03; //Get Value uint8_t ChDataSize = 2; //int16_t uint8_t RequestError = this->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].Temperature = (int16_t) ( ((int16_t)MMES.RxData[1]<<8) | ((int16_t)MMES.RxData[2])); } } return this->CH[ChNum].MMES_Error; } void IdiBus_1Wire::getAllChTemperature(void) { IdiBusMMES MMES(this->Address); MMES.DEV.NUM = IDIBUS_1Wire_CNTRL_DEV; MMES.DEV.ALLCH = 1; MMES.ComFunc = 0x03; uint8_t ChDataSize = 2; //int16_t uint8_t RequestError = this->SendRequestMMES(&MMES); if ( RequestError != IDIER_NOPE ) { this->setAllChErr(RequestError); return; } else if (MMES.RxDataLength < IDIBUS_1Wire_CH_COUNT) { this->setAllChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; } else { uint8_t ExpDataLength = IDIBUS_1Wire_CH_COUNT; // Errors for (uint8_t I=0; IsetAllChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); return; } } uint8_t ErrorPos = 0; uint8_t DataPos = ErrorPos + IDIBUS_1Wire_CH_COUNT; for (uint8_t I = 0; I < IDIBUS_1Wire_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].Temperature = (uint16_t) ( (uint16_t)((uint16_t)MMES.RxData[DataPos] << 8) | (uint16_t)((uint16_t)MMES.RxData[DataPos+1]) ); DataPos = (uint8_t)(DataPos + ChDataSize); } } } void IdiBus_1Wire::setAllChErr(uint8_t ErrCode) { for (uint8_t I=0; ICH[I].MMES_Error = ErrCode; } } /* void IdiBus_1Wire::initAllChs(void) { //uint8_t TxData[2]; //TxData[0] = (uint8_t)(CurrentLimit >> 8); //TxData[1] = (uint8_t)(CurrentLimit); IdiBusMMES MMES(this->Address); MMES.DEV.NUM = IDIBUS_1Wire_CNTRL_DEV; MMES.DEV.ALLCH = 1; MMES.ComFunc = 0x01; uint8_t RequestError = this->SendRequestMMES(&MMES); if ( RequestError != IDIER_NOPE ) { this->setAllChErr(RequestError); } else if (MMES.RxDataLength != IDIBUS_1Wire_CH_COUNT) { this->setAllChErr(IDIERMST_INVALID_RX_REQUEST_FORMAT); } else { for (uint8_t I = 0; I < IDIBUS_1Wire_CH_COUNT; I++) { this->CH[I].MMES_Error = MMES.RxData[I]; //if ( this->CH[I].MMES_Error == IDIER_NOPE ) } } } */