<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>You could open the file descriptor and use the select() call to wait on input. When I wrote multithreaded servers, I would use this with the non-blocking mode. In your case, you probably want to set a timeout on the select(). If the timeout occurs, you do something, if the FD is ready to be read you read it and do something else.<br>
<br></div>I'll try to dig up the code tonight, but in my case this was <br></div>- open the sockets (or any other file descriptor)<br></div>- add the FD to the select() as read<br></div>- call select() to wait.<br></div>
- when select ends.<br></div>- check if it was a read opportunity.<br></div>- if yes spawn a thread (or pass the read FD to a thread) to be read and do something with the data.<br></div>- check if it was a timeout (because a timeout and a read opportunity can happen simultaneously, which I found out the hard way).<br>
</div>- if yes do what you do on a timeout<br></div>- go back to wait on select()<br><br></div>I'm not sure this will help, but its my $0.02.<br><br></div>Bill<br><br><div><div><div><div><div><div><div><div><div><div>
<br> </div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 17, 2014 at 10:17 AM, Mel Wilson <span dir="ltr"><<a href="mailto:mwilson@vex.net" target="_blank">mwilson-Ja3L+HSX0kI@public.gmane.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Thu, 2014-01-16 at 21:25 -0500, Jamon Camisso wrote:<br>
> On 16/01/14 08:43 PM, Mel Wilson wrote:<br>
</div>> [ ... ]<br>
<div class="im">> I'm using a DS18B20 as well, hence that float rounding - it's supposed<br>
> to be accurate to +/- 0.5C through most of it's range, but I've measured<br>
> with other thermometers and it's close enough to 1/10th for my purposes.<br>
><br>
> I've used it with an Ardunino as well with the Dallas 1-wire scanning<br>
> library. Is that what you used?<br>
<br>
</div>My apologies. I'm way too shambolic in running these projects. The<br>
RHT03 temperature/humidity sensor (with its host of part-numbers) with<br>
the Arduino is the setup I've got results from. My DS18B20 project is<br>
still only prototype code that will be run on an AVR. Both of these<br>
setups use bit-banged interfaces.<br>
<br>
You're working farther up the food chain than I am.<br>
<br>
Without actual results, just to post something, here's my initial<br>
DS18B20 code (Some of those newlines are from the mail client. Can't<br>
get them out):<br>
<br>
<br>
//=====================================<br>
#ifndef DS18B20_H<br>
#define DS19B20<br>
<br>
#include <stdint.h><br>
<br>
typedef uint8_t romcode_t [8];<br>
<br>
extern void delay_msec (int msec);<br>
extern void delay_usec (int usec);<br>
<br>
<br>
void bus_setup ();<br>
uint16_t read_temperature (romcode_t device_rom);<br>
<br>
#endif // DS18B20<br>
<br>
<br>
//=====================================<br>
#include <stdint.h><br>
#include "ds18b20.h"<br>
<br>
#define bit_set(F,B) (F |= (1<<(B)))<br>
#define bit_clr(F,B) (F &= ~(1<<(B)))<br>
#define bit_tst(F,B) (F & (1<<(B)))<br>
#define bit_val(F,B) (bit_tst(F,B) != 0)<br>
#define pin_clr(P) (bit_clr (P))<br>
#define pin_set(P) (bit_set (P))<br>
<br>
#define BUS_OUTPUT_PIN PORTB,2<br>
#define BUS_INPUT_PIN PINB,2<br>
#define BUS_DDR_OUT (bit_set (DDRB,2))<br>
#define BUS_DDR_IN (bit_clr (DDRB,2))<br>
<br>
<br>
void bus_setup ()<br>
{<br>
BUS_DDR_IN;<br>
pin_clr (BUS_OUTPUT_PIN);<br>
} // bus_setup<br>
<br>
<br>
static void bus_low ()<br>
{<br>
BUS_DDR_OUT;<br>
} // bus_low<br>
<br>
static void bus_release ()<br>
{<br>
BUS_DDR_IN;<br>
} // bus_release<br>
<br>
static uint8_t bus_pin ()<br>
{<br>
return bit_val (BUS_INPUT_PIN);<br>
} // bus_pin<br>
<br>
static void master_write (uint8_t bit_val)<br>
{<br>
bus_low();<br>
if (bit_val) { // write "1" bit<br>
delay_usec (2);<br>
bus_release();<br>
delay_usec (58);<br>
}<br>
else { // write "0" bit<br>
delay_usec (60);<br>
bus_release();<br>
}<br>
} // master_write<br>
<br>
static int master_read ()<br>
{<br>
uint8_t val;<br>
bus_low();<br>
delay_usec (1);<br>
bus_release();<br>
delay_usec (14);<br>
val = bus_pin();<br>
if (!val) // slave is driving bus pin low<br>
delay_usec (45);<br>
return val;<br>
}// master_read<br>
<br>
static uint8_t transaction_initialization()<br>
{<br>
uint8_t delay_count;<br>
uint8_t slave_present;<br>
bus_low();<br>
delay_usec (480); // reset pulse<br>
bus_release();<br>
while (!bus_pin()) ;<br>
delay_usec (14);<br>
slave_present = 0;<br>
for (delay_count=0; delay_count < 240; ++delay_count) {<br>
if (!bus_pin())<br>
slave_present = 1;<br>
}<br>
delay_usec (480 - 14 - delay_count);<br>
return slave_present;<br>
} // transaction_initialization<br>
<br>
static void transmit_uint8 (uint8_t data)<br>
{<br>
uint8_t i;<br>
for (i=0; i < 8; ++i) {<br>
master_write (data & 1);<br>
data >>= 1;<br>
}<br>
} // transmit_uint8<br>
<br>
static uint8_t receive_uint8 ()<br>
{<br>
uint8_t i, val;<br>
for (i=0; i < 8; ++i)<br>
val = val | (bus_pin() << i);<br>
} // receive_uint8<br>
<br>
uint8_t transaction (uint8_t rom_command, uint8_t function_command)<br>
{<br>
if (!transaction_initialization())<br>
return 0;<br>
transmit_uint8 (rom_command);<br>
return 1;<br>
} // transaction<br>
<br>
uint16_t read_temperature (const romcode_t *device_rom)<br>
{<br>
uint8_t scratchpad [9];<br>
if (!transaction_initialization())<br>
return 0xFFFF;<br>
transmit_uint8 (0x55); // Match ROM<br>
for (i=0; i < 8; ++i)<br>
transmit_uint8 (device_rom [8-i]);<br>
transmit_uint8 (0x44); // Convert T<br>
delay_msec (750); // delay until conversion has been finished<br>
transaction_initialization();<br>
<br>
transmit_uint8 (0x55); // match ROM<br>
for (i=0; i < 8; ++i)<br>
transmit_uint8 (device_rom [8-i]);<br>
<br>
transmit_uint8 (0xBE); // read scratchpad<br>
for (i=0; i < 9; ++i)<br>
scratchpad [9-i] = receive_uint8();<br>
// ??? verify checksum<br>
return scratchpad[1] << 8 | scratchpad[0];<br>
} // read_temperature<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
--<br>
The Toronto Linux Users Group. Meetings: <a href="http://gtalug.org/" target="_blank">http://gtalug.org/</a><br>
TLUG requests: Linux topics, No HTML, wrap text below 80 columns<br>
How to UNSUBSCRIBE: <a href="http://gtalug.org/wiki/Mailing_lists" target="_blank">http://gtalug.org/wiki/Mailing_lists</a><br>
</div></div></blockquote></div><br></div>