CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

FCS Frame Check Sequence help !

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
horizontech



Joined: 09 Nov 2003
Posts: 13

View user's profile Send private message Send e-mail

FCS Frame Check Sequence help !
PostPosted: Tue Jun 01, 2004 5:31 pm     Reply with quote

Hi !

I need to send 12 bytes true rs232 with 2 extra byte as FCS frame check

i looking for example to understand how to compute the 2 FCS bytes ?

I have read the string on other transmiter :

255 255 000 008 000 034 000 000 000 002 001 255 176 038

255 255 000 008 000 034 000 000 000 002 002 255 173 040

the last 2 bytes on each example is FCS !


Thank you very munch for all your help !

Alain Tanguay
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Jun 01, 2004 5:45 pm     Reply with quote

It seems you are using HDLC, correct? This is how I calculated fcs in a project long time ago...

Code:

unsigned int check (char *frame, int nbytes)
{
   unsigned char ch;
   unsigned bit, fcs;
   int i, j;

   /*
     * Initialize the fcs.
   */
   fcs = 0xFFFF;
   /*
     * Look at each character in the frame.
   */
   for (i = 0; i < nbytes; ++i)
   {
      ch = frame [i];

      fcs ^= ch;

      /*
        * Look at the LSB of the fcs 8 times.
      */
      for (j = 0; j < 8; ++j)
      {
         bit = fcs % 2;
         fcs >>= 1;
         /*
           * Now, do an exclusive-OR between this bit and bits 3, 10, and 15 of the
           * fcs, without disturbing the other bits.
         */
         if (bit) fcs ^= 0x8408;
      }
   }
   /*
     * Lastly, take the ones complement of the fcs.
   */
    fcs = ~fcs;
    return (fcs);
}
horizontech



Joined: 09 Nov 2003
Posts: 13

View user's profile Send private message Send e-mail

FCS Frame Check Sequence help !
PostPosted: Wed Jun 02, 2004 6:15 pm     Reply with quote

Thanks for info

I looking for a step by step calculation for understand how is work ?

Thanks for your time

Alain tanguay
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Jun 02, 2004 8:11 pm     Reply with quote

I think the comments in the code are pretty intuitive, I can't give you any more information than it's already there Very Happy

Bear in mind that what I posted is the FCS algorithm for HDLC. Yours might be different. Does it return the same result as you are expecting?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group