Am Mittwoch, 13. Dezember 2006 17:33 schrieb Paul Alfille:
>
> Many of the adapters have an id chip included, so this technique will only
> work on DS2409 branches or the "more than one".
>
I added two additional nodes "present_ds2400" and "single_ds2400", to support 
both the "0x33 read ROM" and the older "0x0F read ROM" command.
Please see the attached file for reference.

When hooking up a key directly to the DS2482-800, both single and 
single_ds2400 work fine. present and present_ds2400, too.

Now I encountered a problem when using the DS2409 and the "present" and 
"single" node. I attached two of my locks with the DS2409 (and a DS2408, too) 
to the onewire backbone. On each main output, a single ds2401 key is 
attached. Now, only "present_ds2400" and "single_ds2400" work fine.

Transcript:



janskiste:~ # tclsh
% package require ow ; OW::init /dev/i2c-1 ; OW::get uncached
bus.7/,bus.6/,bus.5/,bus.4/,bus.3/,bus.2/,bus.1/,bus.0/,29.5E4101000000/,29.8F4101000000/,1F.071B05000000/,1F.0F1B05000000/,alarm/
% OW::get 1F.071B05000000/main/simultaneous/single
FS_r_single (simultaneous) dat=01.020100000000 crc8=00 crc8c=9e
% OW::get 1F.071B05000000/main/simultaneous/single_ds2400
FS_r_single (simultaneous) dat=01.ba79a6080000 crc8=ee crc8c=ee
01.BA79A6080000
% OW::get 1F.0F1B05000000/main/simultaneous/single
FS_r_single (simultaneous) dat=01.020100000000 crc8=00 crc8c=9e
% OW::get 1F.0F1B05000000/main/simultaneous/single_ds2400
FS_r_single (simultaneous) dat=01.7abfa6080000 crc8=cf crc8c=cf
01.7ABFA6080000

--- now disconnect the ds2401 keys ---

% OW::get 1F.0F1B05000000/main/simultaneous/single
FS_r_single (simultaneous) dat=09.060101000000 crc8=00 crc8c=3c
% OW::get 1F.071B05000000/main/simultaneous/single
FS_r_single (simultaneous) dat=09.060101000000 crc8=00 crc8c=3c
%



The _ds2400 nodes work fine because they use the 0x0F command, which no other 
chip than the DS2401 in the currently selected branch understands. The 0x33 
command seems to activate the other chips on the backbone, too. 09.... is the 
wired AND from 29 and 1F, 06 is the wired AND of 5E, 8F, 07 and 0F etc. 
That's just the kind of garbage I would expect from that problem.

I think it's possible to keep the backbone chips silent with the "Smart-On" 
command of the DS2409, but it doesn't seem to work this way with owfs. Hmmmm. 
A problem with the bus selection scheme and "simultaneous" perhaps?

This problem applies to the other "simultaneous" nodes, too, I think.


>
> If I understand correctly it should be possible to return an error code
> from
>
> > FS_output_ascii (without "_z"). I'll try this for the new "single"
> > (really "single", not "id"?) node.
> >
> > "single" = "" if 0, -EFAULT if >1, else name(id)
>
> Correct (though not valid C syntax, of course). A bigger question is should
> the function return an error if it was used correctly?
>
Hm. It doesn't seem to work this way, still getting the glibc()...
But responding nothing is an option, too.


Kind regards

        Jan
-- 
Windows ist Kommunismus: Es hört sich gut an, funktioniert aber nicht.
/*
$Id: ow_simultaneous.c,v 1.32 2006/12/13 04:27:51 alfille Exp $
    OWFS -- One-Wire filesystem
    OWHTTPD -- One-Wire Web Server
    Written 2003 Paul H Alfille
    email: [EMAIL PROTECTED]
    Released under the GPL
    See the header file: ow.h for full attribution
    1wire/iButton system from Dallas Semiconductor
*/

/* General Device File format:
    This device file corresponds to a specific 1wire/iButton chip type
    ( or a closely related family of chips )

    The connection to the larger program is through the "device" data structure,
      which must be declared in the acompanying header file.

    The device structure holds the
      family code,
      name,
      device type (chip, interface or pseudo)
      number of properties,
      list of property structures, called "filetype".

    Each filetype structure holds the
      name,
      estimated length (in bytes),
      aggregate structure pointer,
      data format,
      read function,
      write funtion,
      generic data pointer

    The aggregate structure, is present for properties that several members
    (e.g. pages of memory or entries in a temperature log. It holds:
      number of elements
      whether the members are lettered or numbered
      whether the elements are stored together and split, or separately and joined
*/

/* Simultaneous is a trigger to do a mass conversion on all the devices in the specified path */

/* Added "present" From Jan Kandziora to search for any devices */

#include <config.h>
#include "owfs_config.h"
#include "ow_simultaneous.h"

/* ------- Prototypes ----------- */
/* Statistics reporting */
 yREAD_FUNCTION( FS_r_convert ) ;
yWRITE_FUNCTION( FS_w_convert ) ;
 yREAD_FUNCTION( FS_r_present ) ;
 aREAD_FUNCTION( FS_r_single  ) ;

/* -------- Structures ---------- */
struct filetype simultaneous[] = {
    {"temperature"     ,  1, NULL  , ft_yesno, fc_volatile, {y:FS_r_convert}, {y:FS_w_convert}, {i: simul_temp} , } ,
    {"voltage"         ,  1, NULL  , ft_yesno, fc_volatile, {y:FS_r_convert}, {y:FS_w_convert}, {i: simul_volt} , } ,
    {"present"         ,  1, NULL  , ft_yesno, fc_volatile, {y:FS_r_present}, {v:NULL},         {i: 0 }         , } ,
    {"present_ds2400"  ,  1, NULL  , ft_yesno, fc_volatile, {y:FS_r_present}, {v:NULL},         {i: 1 }         , } ,
    {"single"          , 15, NULL  , ft_ascii, fc_volatile, {a:FS_r_single} , {v:NULL},         {i: 0 }         , } ,
    {"single_ds2400"   , 15, NULL  , ft_ascii, fc_volatile, {a:FS_r_single} , {v:NULL},         {i: 1 }         , } ,
} ;
DeviceEntry( simultaneous, simultaneous ) ;

/* ------- Functions ------------ */
struct internal_prop ipSimul[] = {
    {"temperature",fc_volatile},
    {"voltage",fc_volatile},
};

/* returns 0 if valid conversion exists */
int Simul_Test( const enum simul_type type, UINT msec, const struct parsedname * pn ) {
    struct parsedname pn2 ;
    struct timeval tv,now ;
    long int diff ;
    int ret ;
    memcpy( &pn2, pn , sizeof(struct parsedname)) ; // shallow copy
    FS_LoadPath(pn2.sn,&pn2) ;
    if ( (ret=Cache_Get_Internal_Strict(&tv, sizeof( struct timeval ), &ipSimul[type],&pn2)) ) {
        LEVEL_DEBUG("No simultaneous conversion valid.\n") ;
        return ret ;
    }
    LEVEL_DEBUG("Simultaneous conversion IS valid.\n") ;
    gettimeofday(&now, NULL) ;
    diff =  1000*(now.tv_sec-tv.tv_sec) + (now.tv_usec-tv.tv_usec)/1000 ;
    if ( diff<(long int)msec ) UT_delay(msec-diff) ;
    return 0 ;
}

static int FS_w_convert(const int * y , const struct parsedname * pn) {
    struct parsedname pn2 ;
    enum simul_type type = (enum simul_type) pn->ft->data.i ;
    memcpy( &pn2, pn , sizeof(struct parsedname)) ; // shallow copy
    FS_LoadPath(pn2.sn,&pn2) ;
    pn2.dev = NULL ; /* only branch select done, not actual device */
    /* Since writing to /simultaneous/temperature is done recursive to all
    * adapters, we have to fake a successful write even if it's detected
    * as a bad adapter. */
    if ( y[0] ) {
        if ( pn->in->Adapter != adapter_Bad ) {
            int ret = 1 ; // set just to block compiler errors
            switch ( type ) {
                case simul_temp: {
                    const BYTE cmd_temp[] = { 0xCC, 0x44 } ;
                    struct transaction_log t[] = {
                        TRXN_START,
                        {cmd_temp, NULL, 2, trxn_match, } ,
                        TRXN_END ,
                    } ;
                    ret = BUS_transaction(t,&pn2) ;
                    //printf("CONVERT (simultaneous temp) ret=%d\n",ret) ;
                }
                break ;
                case simul_volt: {
                    BYTE cmd_volt[] = { 0xCC, 0x3C, 0x0F, 0x00, 0xFF, 0xFF } ;
                    struct transaction_log t[] = {
                        TRXN_START,
                        {cmd_volt, NULL, 4, trxn_match, } ,
                        {NULL, &cmd_volt[4], 2, trxn_read, } ,
                        TRXN_END ,
                    } ;
                    ret = BUS_transaction(t,&pn2) || CRC16( &cmd_volt[1],5 ) ;
                    //printf("CONVERT (simultaneous volt) ret=%d\n",ret) ;
                }
                break ;
            }
            if ( ret==0 ) {
                struct timeval tv ;
                gettimeofday(&tv, NULL) ;
                Cache_Add_Internal(&tv,sizeof(struct timeval),&ipSimul[type],&pn2) ;
            }
        }
    } else {
        //printf("CONVERT (simulateous) turning off\n") ;
        Cache_Del_Internal(&ipSimul[type],&pn2) ;
    }
    return 0 ;
}

static int FS_r_convert(int * y , const struct parsedname * pn) {
    struct parsedname pn2 ;
    struct timeval tv ;
    memcpy( &pn2, pn , sizeof(struct parsedname)) ; // shallow copy
    FS_LoadPath(pn2.sn,&pn2) ;
    y[0] = ( Cache_Get_Internal_Strict(&tv,sizeof(struct timeval),&ipSimul[pn->ft->data.i],&pn2) == 0 ) ;
    return 0 ;
}

static int FS_r_present( int * y , const struct parsedname * pn ) {
    if ( pn->in->Adapter == adapter_fake ) {
        y[0] = (pn->in->connin.fake.db.devices > 0) ;
    } else {
        struct parsedname pn2 ;
        BYTE read_ROM[] = { 0x33, } ;
        BYTE resp[8] ;
        BYTE match[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, } ;
        struct transaction_log t[] = {
            TRXN_START ,
            { read_ROM, NULL, 1, trxn_match, } ,
            { NULL, resp, 8, trxn_read, } ,
            TRXN_END ,
        } ;

        /* check if DS2400 compatibility is needed */
        if ( pn->ft->data.i ) read_ROM[0] = 0x0F; 
				
	      memcpy( &pn2, pn, sizeof(struct parsedname) ) ; // shallow copy
        FS_LoadPath(pn2.sn,&pn2) ;
        pn2.dev = NULL ; // directory only
        if ( BUS_transaction( t, &pn2 ) ) return -EINVAL ;
        if ( memcmp(resp, match, 8 ) ) { // some device(s) complained
            y[0] = 1 ; // YES present
            if ( CRC8(resp, 8 ) ) return 0 ; // crc8 error -- more than one device
            memcpy( pn2.sn, resp, 8 ) ;
            Cache_Add_Device( pn2.in->index, &pn2 ) ; // single device -- mark it's presence
        } else { // no devices
            y[0] = 0 ;
        }
    }
    return 0 ;
}

static int FS_r_single(char *buf, const size_t size, const off_t offset , const struct parsedname * pn) {
    if ( pn->in->Adapter == adapter_fake ) {
        return (pn->in->connin.fake.db.devices > 0) ;
    } else {
    		ASCII ret_string[15] ;
        struct parsedname pn2 ;
        BYTE read_ROM[] = { 0x33, } ;
        BYTE resp[8] ;
        BYTE match[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, } ;
        struct transaction_log t[] = {
            TRXN_START ,
            { read_ROM, NULL, 1, trxn_match, } ,
            { NULL, resp, 8, trxn_read, } ,
            TRXN_END ,
        } ;

        /* check if DS2400 compatibility is needed */
        if ( pn->ft->data.i ) read_ROM[0] = 0x0F; 
		
        memcpy( &pn2, pn, sizeof(struct parsedname) ) ; // shallow copy
        FS_LoadPath(pn2.sn,&pn2) ;
        pn2.dev = NULL ; // directory only
        if ( BUS_transaction( t, &pn2 ) ) return -EINVAL ;
				printf("FS_r_single (simultaneous) dat=%02x.%02x%02x%02x%02x%02x%02x crc8=%02x crc8c=%02x\n",resp[0],resp[1],resp[2],resp[3],resp[4],resp[5],resp[6],resp[7],CRC8(resp,7)) ;
        if ( memcmp(resp, match, 8 ) ) { // some device(s) complained
            if ( CRC8(resp, 8 ) ) { // crc8 error -- more than one device
				      ret_string[0]='\0';
              return FS_output_ascii( buf, size, offset, ret_string, 1 ) ;
            }
						
            memcpy( pn2.sn, resp, 8 ) ;
            Cache_Add_Device( pn2.in->index, &pn2 ) ; // single device -- mark it's presence
						
						/* Return device id. */
            bytes2string( ret_string, resp, 1 ) ;
            ret_string[2]='.';
            bytes2string( &ret_string[3], &resp[1], 6 ) ;
            return FS_output_ascii( buf, size, offset, ret_string, 15 ) ;
        } else { //no devices
				    ret_string[0]='\0';
            return FS_output_ascii( buf, size, offset, ret_string, 1 ) ;
        }
				
    }		
    return 0 ;
}

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to