Thread: C Code to handle sequence of commands as structure elements

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    34

    C Code to handle sequence of commands as structure elements

    Hi Friends,

    I need help in C coding. I have to send a sequence of commands in a 8-bit microcontroller. Each command is 64- bit data.
    Code:
    typedef struct{
       uint16_t data0;
       uint16_t data1;
       uint16_t data2;
       uint16_t data3;  
    
    } command_data_t;
    Now, there are 5-6 commands, each having different data0, data1, data2, data3.

    Code:
    typedef struct{ //all made of different data0, data1, data2, data3.
       COMMAND1;   
       COMMAND2;
       COMMAND3;
       COMMAND4; 
       COMMAND5; 
    
    } command_t;
    Above commands are made of command_data_t type.

    I don't know how to write a C code so that I can send these commands one by one. Like once a command is send, send next command. Once all commands are sent start sending from the first command again.

    I need to write a function, which takes element of command_t, send it, then next one...Please provide me code if possible.

    Please help.

    Thanks,
    David.

  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
    To be honest, an array makes more sense (whenever you start putting numeric suffixes on variable names, it screams 'make me an array').
    Code:
    typedef struct{ //all made of different data0, data1, data2, data3.
       command_data_t commands[5];
    } command_t;
    After that, a simple for loop along the lines of this should suffice.
    sendACommand( &foo.commands[i] );
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. structure with array elements
    By l_l in forum C Programming
    Replies: 7
    Last Post: 09-07-2012, 07:55 PM
  2. giving value to structure elements
    By sarathius in forum C Programming
    Replies: 3
    Last Post: 04-21-2008, 01:24 AM
  3. Best way to handle incoming commands from a client.
    By ~Kyo~ in forum Game Programming
    Replies: 6
    Last Post: 07-26-2006, 12:24 PM
  4. How to handle structure padding
    By cdalten in forum C Programming
    Replies: 8
    Last Post: 03-17-2006, 09:29 PM
  5. How to compare structure elements
    By khpuce in forum C Programming
    Replies: 6
    Last Post: 04-10-2005, 11:40 AM

Tags for this Thread