netmaster19 / libxbee

Automatically exported from code.google.com/p/libxbee
0 stars 0 forks source link

sleep function in examples #14

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The sample codes contains references to the sleep() function which 
implementation on Linux cannot be found. Some of the sample codes also uses the 
usleep function. 
I would like to request replacing these sleep calls with usleep to make it 
compilable on Linux. 

All sleep calls are called wit 1 as argument so replacing them is easy with the 
following command:
find . -name "*.c*" -exec sed -i "s/sleep(1);/usleep(1000);/g" '{}' \;

Original issue reported on code.google.com by martonmi...@gmail.com on 7 Nov 2013 at 6:33

GoogleCodeExporter commented 8 years ago
I have mistaked the command,the correct command should be:
find . -name "*.c*" -exec sed -i "s/sleep(1);/usleep(1000000);/g" '{}' \;

Original comment by martonmi...@gmail.com on 7 Nov 2013 at 6:57

GoogleCodeExporter commented 8 years ago
You've got to be careful of running commands like that...
Example:
diff --git a/sample/xbee1/7.broadcast/main.c b/sample/xbee1/7.broadcast/main.c
index fd2ec34..87329b4 100644
--- a/sample/xbee1/7.broadcast/main.c
+++ b/sample/xbee1/7.broadcast/main.c
@@ -62,7 +62,7 @@ int main(void) {
                xbee_conTx(con, NULL, "%d\r\n", i);

                /* XBee Series 1 modules don't use meshing, so you can broadcast much faster than Series 2 */
-               usleep(10000); /* 10ms */
+               uusleep(10000000000); /* 10ms */
        }

        if ((ret = xbee_conEnd(con)) != XBEE_ENONE) {

Also, it's worth noting that usleep() isn't always suitable for times greater 
than 1 second:
"The type useconds_t shall be an unsigned integer type capable of storing 
values at least in the range [0, 1000000]."

I have however made this change.

Original comment by attie@attie.co.uk on 7 Nov 2013 at 8:45