> That's very helpful. The functions should be correct for data on the slave
> (it's little endian). If we cast host integers to char and use these
> functions would be incorrect.Â
Its been raining more than expected for this time of year so I've been
able to take my irrigation system offline for long enough to try a quick
hack. Note that this is a proof of concept, not a real fix.
I've added extra functions into util.c for UT_setbit_U and UT_getbit_U to
deal with UINTs rather than try and treat them as an array of bytes. I've
hacked up the modules that I think will have a bearing on handling
aggregate properties on a device and it works!! I can use PIO.A and PIO.B
of a ds2413 on big endian:)
There are a lot of modules that I think will require extra work (e.g.
ow_ds9097u.c) and the same problem arises with UT_get2bit() and
UT_set2bit() functions not being endian safe.
Cheers
--
Robin Gilks
diff -PurN owfs-2.8p13.orig/module/owlib/src/c/ow_byte.c owfs-2.8p13.new/module/owlib/src/c/ow_byte.c
--- owfs-2.8p13.orig/module/owlib/src/c/ow_byte.c 2010-09-25 09:04:24.000000000 +1200
+++ owfs-2.8p13.new/module/owlib/src/c/ow_byte.c 2014-03-02 11:26:30.000000000 +1300
@@ -24,7 +24,7 @@
}
for ( extension = 0 ; extension < elements ; ++extension ) {
- UT_setbit( (BYTE *) &OWQ_U(owq_byte), extension, OWQ_array_Y(owq_all,extension) ) ;
+ UT_setbit_U( &OWQ_U(owq_byte), extension, OWQ_array_Y(owq_all,extension) ) ;
}
return owq_byte ;
}
@@ -40,7 +40,7 @@
}
for ( extension = 0 ; extension < elements ; ++extension ) {
- OWQ_array_Y(owq_all,extension) = UT_getbit( (BYTE *) &OWQ_U(owq_byte), extension ) ;
+ OWQ_array_Y(owq_all,extension) = UT_getbit_U( &OWQ_U(owq_byte), extension ) ;
}
return owq_all ;
}
diff -PurN owfs-2.8p13.orig/module/owlib/src/c/ow_read.c owfs-2.8p13.new/module/owlib/src/c/ow_read.c
--- owfs-2.8p13.orig/module/owlib/src/c/ow_read.c 2011-07-28 08:43:34.000000000 +1200
+++ owfs-2.8p13.new/module/owlib/src/c/ow_read.c 2014-03-02 11:29:34.000000000 +1300
@@ -563,7 +563,7 @@
size_t extension;
for ( extension=0 ; extension < elements ; ++extension ) {
- OWQ_array_Y(owq_all,extension) = UT_getbit( (BYTE *) &OWQ_U(owq_byte), extension ) ;
+ OWQ_array_Y(owq_all,extension) = UT_getbit_U( &OWQ_U(owq_byte), extension ) ;
}
return 0 ;
}
@@ -622,7 +622,7 @@
return -EINVAL ;
}
for (extension = 0; extension < elements; ++extension) {
- OWQ_array_Y(owq_all,extension) = UT_getbit( (BYTE *) &OWQ_U(owq_part), extension ) ;
+ OWQ_array_Y(owq_all,extension) = UT_getbit_U( &OWQ_U(owq_part), extension ) ;
}
OWQ_destroy( owq_part ) ;
return 0 ;
@@ -690,7 +690,7 @@
OWQ_destroy(owq_bit);
return -EINVAL;
}
- UT_setbit( (BYTE *) &OWQ_U(owq_byte), extension, OWQ_Y(owq_bit) ) ;
+ UT_setbit_U( &OWQ_U(owq_byte), extension, OWQ_Y(owq_bit) ) ;
}
OWQ_destroy(owq_bit);
@@ -711,7 +711,7 @@
/* read the UINT */
if ( FS_read_owq(owq_byte) >= 0) {
- OWQ_Y(owq_bit) = UT_getbit((void *) &OWQ_U(owq_byte), pn->extension) ;
+ OWQ_Y(owq_bit) = UT_getbit_U( &OWQ_U(owq_byte), pn->extension) ;
z_or_e = 0 ;
}
diff -PurN owfs-2.8p13.orig/module/owlib/src/c/ow_util.c owfs-2.8p13.new/module/owlib/src/c/ow_util.c
--- owfs-2.8p13.orig/module/owlib/src/c/ow_util.c 2011-04-22 14:48:31.000000000 +1200
+++ owfs-2.8p13.new/module/owlib/src/c/ow_util.c 2014-03-02 11:38:08.000000000 +1300
@@ -69,6 +69,10 @@
}
}
+int UT_getbit_U(const UINT * buf, const int loc)
+{
+ return ((*buf >> loc) & 0x01);
+}
// #define UT_getbit(buf, loc) ( ( (buf)[(loc)>>3]>>((loc)&0x7) ) &0x01 )
int UT_getbit(const BYTE * buf, const int loc)
{
@@ -78,6 +82,16 @@
{
return (((buf[loc >> 2]) >> ((loc & 0x3) << 1)) & 0x03);
}
+
+void UT_setbit_U(UINT * buf, const int loc, const int bit)
+{
+ if (bit) {
+ *buf |= (0x01 << loc);
+ } else {
+ *buf &= ~(0x01 << loc);
+ }
+}
+
void UT_setbit(BYTE * buf, const int loc, const int bit)
{
if (bit) {
diff -PurN owfs-2.8p13.orig/module/owlib/src/c/ow_write.c owfs-2.8p13.new/module/owlib/src/c/ow_write.c
--- owfs-2.8p13.orig/module/owlib/src/c/ow_write.c 2011-07-28 08:44:27.000000000 +1200
+++ owfs-2.8p13.new/module/owlib/src/c/ow_write.c 2014-03-02 11:28:41.000000000 +1300
@@ -600,7 +600,7 @@
for ( extension = 0 ; extension < elements ; ++extension ) {
ZERO_OR_ERROR z ;
OWQ_pn(owq_bit).extension = extension ;
- OWQ_Y(owq_bit) = UT_getbit( (BYTE *) &OWQ_U(owq_byte), extension ) ;
+ OWQ_Y(owq_bit) = UT_getbit_U( &OWQ_U(owq_byte), extension ) ;
z = FS_write_owq( owq_bit ) ;
if ( z != 0 ) {
z_or_e = z ;
@@ -634,7 +634,7 @@
if ( owq_byte != NO_ONE_WIRE_QUERY ) {
if ( FS_read_local( owq_byte ) >= 0 ) {
- UT_setbit( (BYTE *) &OWQ_U( owq_byte ), OWQ_pn(owq_bit).extension, OWQ_Y(owq_bit) ) ;
+ UT_setbit_U( &OWQ_U( owq_byte ), OWQ_pn(owq_bit).extension, OWQ_Y(owq_bit) ) ;
z_or_e = FS_write_owq( owq_byte ) ;
}
OWQ_destroy( owq_byte ) ;
diff -PurN owfs-2.8p13.orig/module/owlib/src/include/ow_functions.h owfs-2.8p13.new/module/owlib/src/include/ow_functions.h
--- owfs-2.8p13.orig/module/owlib/src/include/ow_functions.h 2011-04-22 14:48:31.000000000 +1200
+++ owfs-2.8p13.new/module/owlib/src/include/ow_functions.h 2014-03-02 11:33:35.000000000 +1300
@@ -93,8 +93,10 @@
void string2bytes(const char *str, BYTE * b, const int bytes);
void bytes2string(char *str, const BYTE * b, const int bytes);
int UT_getbit(const BYTE * buf, const int loc);
+int UT_getbit_U(const UINT * buf, const int loc);
int UT_get2bit(const BYTE * buf, const int loc);
void UT_setbit(BYTE * buf, const int loc, const int bit);
+void UT_setbit_U(UINT * buf, const int loc, const int bit);
void UT_set2bit(BYTE * buf, const int loc, const int bits);
void UT_fromDate(const _DATE D, BYTE * data);
_DATE UT_toDate(const BYTE * date);------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers