Thread: Help on C Function

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    4

    Help on C Function

    Hi Guys! I am new to C Programming and I currently tasked to write a function that can "decode" the following quad site protocol received. However I am stuck as to how to continue with the function. Here is the protocol.

    rs 1,1,1,10
    rs 10,1,1,10
    rs 1,1,1,10
    rs 1,1,1,1
    rs 10,1,10,7
    rs 1,1,7,10
    rs 1,1,10,1
    rs 10,1,10,10
    rs 1,10,10,1
    rs 1,10,7,1
    rs 1,1,1,5
    rs 1,1,1,1
    rs 1,1,1,1
    rs 1,1,1,7
    rs 1,1,1,5
    rs 1,1,1,1
    rs 1,10,1,1
    rs 1,1,1,1
    rs 1,1,1,5
    rs 1,1,1,1
    rs 1,1,1,5
    rs 6,1,7,1
    rs 6,1,1,1
    rs 1,1,1,1
    rs 1,7,1,1
    rs 6,1,1,1
    rs 1,1,1,5
    rs 1,1,1,1
    rs 1,1,10,5
    rs 1,10,1,10
    rs 1,10,1,10
    rs 10,10,1,10
    rs 1,10,1,10
    rs 1,1,1,1
    rs 1,1,10,5
    rs 1,1,1,10

    Currently my function can only support receiving dual site protocols. Like the following:

    rs 1,,,1
    rs 10,,,1
    rs 1,,,10
    rs 1,,,1
    rs 1,,,1
    rs 1,,,7
    rs 1,,,1
    rs 1,,,7

    Attached is my c code. I have tried using case to handle the extra quad site protocols but it seems like it is unable to support. I complie my code using SDCC. Attached are my original code for the dual site and code for the quad site. I would appreciate if someone could help me out on this. Thanks alot!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about writing a small test program which specifically focusses on the problem at hand.

    Not the 75K of source containing all sorts of irrelevance.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    I took one look at your quad site code, and I can tell you that most of the code is unnecessary due to extreme repetition and many ways to optimize it, using, for example, some simple arithmetic.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    Quote Originally Posted by Salem View Post
    How about writing a small test program which specifically focusses on the problem at hand.

    Not the 75K of source containing all sorts of irrelevance.
    I would love to but I can't. I have been thrown this pile of code to look at and I don't even know where to begin coz I am not trained in C!

    I think the problem lies with this line of code:
    Code:
    if(c=='r') //J750
    {
    command_detected=1;
    i=0;
    }
    because for dual site protocols, the signal transmitted is rs 10,,,1
    but for quad site protocols, the signal transmitted is €€Ïrs 10,1,10,10
    and the quad site protocol begins with this funny character €. I believe this funny character prevents the from executing, therefore it is unable to go inside into the if statements which are nested in it.

    Actually the rest of the codes are all relevant. They are used to communicate with a 8051 microcontroller. =)

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    Quote Originally Posted by IceDane View Post
    I took one look at your quad site code, and I can tell you that most of the code is unnecessary due to extreme repetition and many ways to optimize it, using, for example, some simple arithmetic.
    Maybe they could have been simpler but I have no idea as they are thrown at me so I am trying my best to understand but due to my limited knowledge, I have decided to seek help in this forum.
    I believe not all of the rest of the codes are redundant. Most of them are used to communicate with a 8051 Microcontroller. Thats the main purpose of this code.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > and I don't even know where to begin coz I am not trained in C!
    Does your boss know this?

    > I believe this funny character prevents the from executing,
    > therefore it is unable to go inside into the if statements which are nested in it.
    That's pretty much it.
    So all you need really is something like
    if ( c == 0xdc )

    Well you'll have to look up the actual numeric values for your "€€Ï" chars, but you get the general idea.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    Quote Originally Posted by Salem View Post
    > and I don't even know where to begin coz I am not trained in C!
    Does your boss know this?

    > I believe this funny character prevents the from executing,
    > therefore it is unable to go inside into the if statements which are nested in it.
    That's pretty much it.
    So all you need really is something like
    if ( c == 0xdc )

    Well you'll have to look up the actual numeric values for your "" chars, but you get the general idea.
    My boss knows my predicament. But he doesn't give a hoot about it. =( He expects me to deliver the goods.
    Anyway thanks for your suggestion. I'll go look for the actual numeric values for the "" chars.
    Anyway do you know whats this "" char stand for?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM