Page 1 of 1

LRC generation

Posted: Thu Aug 13, 2020 4:03 pm
by concord
Hi there,

Does anyone have any Jade code to generate a Longitudinal Redundancy Check?

Re: LRC generation

Posted: Thu Aug 20, 2020 3:11 pm
by concord
Oops, got tripped not realising ^ in Jade is different to almost all other languages.
The Binary primitive method was easy to put together...

Code: Select all

vars i : Integer; lrc : Integer; begin lrc := null; i := 1; while i <= self.length do lrc := lrc.bitXor (self[i]); i := i + 1; endwhile; return lrc.Character; end;

Re: LRC generation

Posted: Tue Aug 25, 2020 2:59 pm
by BeeJay
Hi Concord,

Actually the ^ symbol was used as the 'power of' for quite a lot of languages until more recently when some languages started using it for the bitwise logical exclusive or operation instead of the 'power of'... I was used to using ^ as power of long before I started coding in JADE.

If you've tried to turn the following C# code into your LRC routine, I wonder if you should assign lrc := 255; instead of lrc := null; so that the sample binary 02 30 30 31 23 03 results in 0xEC for the LRC character instead of 0x13 as per your current routine?

// 2012.06.11 C# Code from Edwards TurboPump Controller SCU-1600: Serial Communication LRC Logic.
// eg: Data (6bytes hexa): 02 30 30 31 23 03 should result in LRC of 0xEC

public byte MakeLRC ( byte[] bytes )
 {
  byte LRC = 0xff;

  for ( int i = 0 ; i < bytes.Length ; i++ )
   {
    LRC ^= bytes[ i ];
   }

  return LRC;
 }
Cheers,
BeeJay.