unsigned char C1WireByKernel::ThreadReadRawDataDualChannelAddressableSwitch(const std::string& deviceFileName) const { static const unsigned char CmdReadPioRegisters[]={0xF5}; unsigned char answer[1]; if (!sendAndReceiveByRwFile(deviceFileName,CmdReadPioRegisters,sizeof(CmdReadPioRegisters),answer,sizeof(answer))) throw OneWireReadErrorException(deviceFileName); // Check received data : datasheet says that b[7-4] is complement to b[3-0] if ((answer[0]&0xF0)!=(((~answer[0])&0x0F)<<4)) throw OneWireReadErrorException(deviceFileName); return answer[0]; }
unsigned char C1WireByKernel::ThreadReadRawData8ChannelAddressableSwitch(const std::string& deviceFileName) const { static const unsigned char CmdReadPioRegisters[]={0xF5}; unsigned char answer[33]; if (!sendAndReceiveByRwFile(deviceFileName,CmdReadPioRegisters,sizeof(CmdReadPioRegisters),answer,sizeof(answer))) throw OneWireReadErrorException(deviceFileName); // Now check the Crc unsigned char crcData[33]; crcData[0]=CmdReadPioRegisters[0]; for(int i=0;i<32;i++) crcData[i+1]=answer[i]; if (Crc16(crcData,sizeof(crcData))!=answer[32]) throw OneWireReadErrorException(deviceFileName); return answer[0]; }
float C1WireByKernel::ThreadReadRawDataHighPrecisionDigitalThermometer(const std::string& deviceFileName) const { // The only native-supported device (by w1-therm module) std::string data; bool bFoundCrcOk=false; static const std::string tag("t="); std::ifstream file; std::string fileName=deviceFileName; fileName+="/w1_slave"; file.open(fileName.c_str()); if (file.is_open()) { std::string sLine; while (!file.eof()) { getline(file, sLine); int tpos; if (sLine.find("crc=")!=std::string::npos) { if (sLine.find("YES")!=std::string::npos) bFoundCrcOk=true; } else if ((tpos=sLine.find(tag))!=std::string::npos) { data = sLine.substr(tpos+tag.length()); } } file.close(); } if (bFoundCrcOk) { if (is_number(data)) return (float)atoi(data.c_str()) / 1000.0f; // Temperature given by kernel is in thousandths of degrees } throw OneWireReadErrorException(deviceFileName); }