🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5149

Re: Another delphi translation please!

#5149
From: Bruce Knowles
Date: Mon, 26 Sep 2005 13:57
96 lines
3466 bytes
Hi ScOe,

Andrue Cope's query of my posting triggered a recognition of an error that I 
had made in the code previously supplied. Herewith an updated version of 
that code that should now suffice.

Thanks to Andrue Cope for his observation.

Regards

Bruce Knowles


// try to find all the ds1820's on this bus -- Private Method ??
int __fastcall TxSensorBus::FindROMCode(TxROMCode *RomCode, int *done, int 
*lastDiscrep, int nCmd)
{
    char val;
    int  i;
    int  b;
    int  sb;
    int  bitPos;
    int  discrep     =  0;
    int  Result      = -1;

    Reset();

    if (!SendCommand(nCmd)) return(Result);

    for (bitPos = 1; bitPos <= 64; bitPos++) {
        b = bitPos - 1;
        i = b / 8;

        // Search for the bit
        sb = WriteBit(1) << 1;

        if (sb >= 0) sb |= WriteBit(1);

        if (sb == -1) return(Result); // Error

        // Get the Sernumbit
        val = RomCode[i] & (1 << (b % 8));

        if (sb == 3) { // 11
            return(0);
        }

        if (sb == 0) {
            if (bitPos == *lastDiscrep) {
                // Set the SernumBit on
                RomCode[i] |= (1 << (b % 8));
            } else {
                if (bitPos > *lastDiscrep) {
                    // Set the SernumBit off
                    RomCode[i] &= ~(1 << (b % 8));
                    discrep = bitPos;
                } else {
                    if (val == 0) discrep = bitPos;
                }
            }
        } else {
            if (sb & 0xFE) {
                // Set the SernumBit on
                RomCode[i] |= (1 << (b % 8));
            } else {
                // Set the SernumBit off
                RomCode[i] &= ~(1 << (b % 8));
            }
        }

        val   = RomCode[i] & (1 << (b % 8));
        val >>= (b % 8);

        if (WriteBit(val) != val) return(Result);
    }

    *lastDiscrep = discrep;

    if (discrep == 0) *done = 1;

    return(1);
}

void __fastcall TxSensorBus::EnumSensors(int nCmd, TEnumSensorsProc Proc, 
void *pParam)
{
    TxROMCode RomCode = (TxROMCode)0;
    int  done                          = 0;
    int  lastDiscrep                 = 0;

    while (done == 0 && (FindROMCode(&RomCode, &done, &lastDiscrep, nCmd) == 
1)) {
        Assert(ValidateCRC(&RomCode, 8));
        Proc(pParam, &RomCode);
    }
}
Technical Details
Message-ID: <4337fdd8@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed3.newsreader.com!newsreader.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43370a81@newsgroups.borland.com> <4337b0dd$1@newsgroups.borland.com> <4337e343@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6ea8b2c4d2578842
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Bruce Knowles" <knowle_b@mtn.co.za>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <43370a81@newsgroups.borland.com> <4337b0dd$1@newsgroups.borland.com> <4337e343@newsgroups.borland.com>
Subject: Re: Another delphi translation please!
Date: Mon, 26 Sep 2005 15:57:01 +0200
Lines: 98
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 196.11.239.43
Message-ID: <4337fdd8@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1127742936 196.11.239.43 (26 Sep 2005 06:55:36 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed3.newsreader.com!newsreader.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail