7 struct timeval wait_tv;
11 select(0, NULL, NULL, NULL, &wait_tv);
27 return (fd != INVALID_HANDLE_VALUE);
35 "Error, could not get baudrate!",
36 "Error, could not set baudrate!",
37 "Error, serial port does not exist!",
38 "Error, you don't have rw permission to access serial port!",
39 "Error, failed to open serial port device!",
40 "Error, sensor not found!",
41 "Error, sensor CRC mismatch!",
42 "Warining, not expected sensor response!",
43 "Error, could not send data!"
46 static unsigned char lsb_crc8(
unsigned char *data_in,
unsigned int len,
const unsigned char generator)
49 unsigned char crc = 0;
51 for (i = 0; i < len; i++)
53 crc ^= *(data_in + i);
54 unsigned char bit_counter = 8;
57 crc = (((crc >> 1) & 0x7f) ^ generator);
60 crc = (crc >> 1) & 0x7f;
63 }
while (bit_counter > 0);
101 if ((*(sp + 4) & 0x9f) != 0x1f) {
134 *p = 0x1f | ((
unsigned char)(precision - 9) << 5);
154 for (i = 0; i < 4; i++) {
183 T = (sp_sensor[1] << 8) + (sp_sensor[0] & 0xff);
184 if ((T >> 15) & 0x01) {
189 *temperature = (float)T / 16;
196 unsigned char i, crc;
222 return owOpen(serial_port);
unsigned char owRead(int fd)
int owOpen(const char *serial_port)
int owWrite(int fd, unsigned char wbuff)
static unsigned char lsb_crc8(unsigned char *data_in, unsigned int len, const unsigned char generator)
static int DS18B20_start(HANDLE fd)
static int DS18B20_sp(HANDLE fd, unsigned char *sp)
char * DS18B20_errmsg(void)
int DS18B20_setprecision(HANDLE fd, int precision)
int DS18B20_acquire(HANDLE fd, float *temperature)
int DS18B20_measure(HANDLE fd)
HANDLE DS18B20_open(const char *serial_port)
void DS18B20_close(HANDLE fd)
int is_fd_valid(HANDLE fd)
int DS18B20_rom(HANDLE fd, unsigned char *rom)
#define DS18B20_SP_CONFIG
#define DS18X20_GENERATOR