How is this 'C' BXOR calculation working? How would I do this in Clarion? 
Author Message
 How is this 'C' BXOR calculation working? How would I do this in Clarion?

The sio array is passed 'STX4030109141652ETX'

The calculated result field CRC contains the value 39.

int  chk_crc   ( char *sio , int cmpr )
{
     int  i , ix;
     unsigned char ck0 , ck1 , ck2 , uc , crc;

     if ( type == 'S' )
     {    i = 0;
          while ( sio[i] != STX )
          {    i++;
          }
          i++;
          crc = 0;
          while ( sio[i] != ETX )
          {    crc ^= sio[i++];
          }
          crc ^= sio[i++];
          if ( crc < 32 )
               crc += 32;
          if ( diag )
               printf("My crc = %2.2x\n",crc);
          if ( cmpr )
          {    if ( sio[i] == crc )
                    return(1);
               else
                    return(0);
          }
          else
          {    sio[i] = crc;
               i++;
               sio[i] = 0;
               return(i);
          }
     }
     else

TIA,
Peter Steiner



Wed, 29 Jun 2005 02:40:42 GMT  
 How is this 'C' BXOR calculation working? How would I do this in Clarion?
Peter,

From what you included this shows how to calculate the crc.
In your source string, 'STX4030109141652ETX', the STX and ETX are CHR(02) and CHR(03)
respectively.

CalcCRC    PROCEDURE(*STRING sio)
i           LONG,AUTO
cbSio       LONG,AUTO
STX         EQUATE('<02>')
ETX         EQUATE('<03>')
crc         BYTE,AUTO
  CODE
  cbSio = LEN(CLIP(sio))
  !Skip everything up to and including STX
  LOOP i = 1 TO cbSio
    IF sio[i] = STX
      i += 1
      BREAK
    END
  END

  !use the rest of the values including the ETX in the crc
  crc = 0
  LOOP i = i TO cbSio
    crc = BXOR(crc, VAL(sio[i]))
    IF sio[i] = ETX THEN BREAK.
  END
  IF crc < 32
    crc += 32
  END
  RETURN crc

This returns 39h given your sample string.
HTH
Larry Sand

| The sio array is passed 'STX4030109141652ETX'
|
| The calculated result field CRC contains the value 39.
|
| int  chk_crc   ( char *sio , int cmpr )
| {
|      int  i , ix;
|      unsigned char ck0 , ck1 , ck2 , uc , crc;
|
|      if ( type == 'S' )
|      {    i = 0;
|           while ( sio[i] != STX )
|           {    i++;
|           }
|           i++;
|           crc = 0;
|           while ( sio[i] != ETX )
|           {    crc ^= sio[i++];
|           }
|           crc ^= sio[i++];
|           if ( crc < 32 )
|                crc += 32;
|           if ( diag )
|                printf("My crc = %2.2x\n",crc);
|           if ( cmpr )
|           {    if ( sio[i] == crc )
|                     return(1);
|                else
|                     return(0);
|           }
|           else
|           {    sio[i] = crc;
|                i++;
|                sio[i] = 0;
|                return(i);
|           }
|      }
|      else
|
| TIA,
| Peter Steiner



Fri, 01 Jul 2005 05:12:46 GMT  
 How is this 'C' BXOR calculation working? How would I do this in Clarion?
Peter,

|   cbSio = LEN(CLIP(sio))
|

Sorry about that, don't clip the string.  What you do depends on how the buffer is
declared.  I like to have the calling function pass in the length of the buffer to prevent
overruns.

Larry Sand



Fri, 01 Jul 2005 07:36:56 GMT  
 How is this 'C' BXOR calculation working? How would I do this in Clarion?
Larry,

Thank You :) your code was simple compared to what I had come up with.
I thought I needed to convert to hex than submit each character of the
hex value for the bxor. I see that the problem is easily handled in
decimal.

I really appreciate your help.

Peter Steiner

Quote:

> Peter,

> |   cbSio = LEN(CLIP(sio))
> |

> Sorry about that, don't clip the string.  What you do depends on how the buffer is
> declared.  I like to have the calling function pass in the length of the buffer to prevent
> overruns.

> Larry Sand



Sat, 02 Jul 2005 14:19:22 GMT  
 How is this 'C' BXOR calculation working? How would I do this in Clarion?
Peter,

| Thank You :) your code was simple compared to what I had come up with.
| I thought I needed to convert to hex than submit each character of the
| hex value for the bxor. I see that the problem is easily handled in
| decimal.

You're welcome.  It really doesn't matter if you use hex or decimal they're all the same
bits! <g>
For your information, using VAL() in a computation like this is very efficient.  It
compiles to just a few lines of ASM code.

Larry Sand



Sun, 03 Jul 2005 23:43:56 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. .cs create polygon $xy does'nt work

2. Clarion 5.5 What am I doing wrong????

3. errors when doing 'make test'

4. Have you ever done 'namespace delete ::'?

5. 'who am i' from unix

6. Scintilla / Clarion 7: Find's all working

7. I'm looking for work in Clarion

8. Anyone done work on Vehicle Tracking with Clarion?

9. A2P, keep getting an error message 'EMX not found'. What am I doing wrong?

10. Dolphin Applet's don't work...

11. match works, don't match doesn't

12. Bevel Buttons' icon doesn't work

 

 
Powered by phpBB® Forum Software