M
ma740988
How would I modify the TEST_CMD function to essentially return the
appropriate status?
Simply put. TEST_CMD could return either status1 or status2. The
return value will be passed to the Write function inside main. The
prototype for the Write function is highlighted below.
#define TRUE 1
#define FALSE 0
typedef struct
{
unsigned int field1 : 16;
unsigned int field2 : 10;
unsigned int field3 : 6;
} HEADER;
typedef struct
{
HEADER header;
unsigned int cmd_field1 : 1;
unsigned int cmd_field2 : 8;
unsigned int cmd_field3 : 16;
} CMD;
typedef struct
{
unsigned int status1_field1 : 1;
unsigned int status1_field2 : 32;
unsigned int status1_field3 : 5;
unsigned int status1_field4 : 27;
} STATUS1;
typedef struct
{
unsigned int status2_field1 : 1;
unsigned int status2_field2 : 31;
unsigned int status2_field3 : 16;
unsigned int status2_field4 : 16;
} STATUS2;
// 4 more. ie STATUS3, STATUS4, STATUS5, STATUS6
CMD cmd_msg;
STATUS1 status1;
STATUS2 status2;
//STATUS3 status3;
//STATUS4 status4;
void TEST_CMD ( const CMD *ptr_cmd ) // return type on this obviously
cant be 'void'
{
if ( ptr_cmd->header.field1 == 0 )
{
status1->status1_field1 = TRUE;
// return status1;
}
else if ( ptr_cmd->header_field2 != 0 )
{
status2->status2_field1 = FALSE;
// return status2;
}
// 4 more
}
int main ()
{
int channel;
//TEST_CMD ( &cmd_msg);
// The prototype for Write_Msg looks like
// Write_Msg ( int chan,
// void* src // pointer to the appropriate
data
// int len );
// So now assume channel 3.
channel = 3;
// Write_Msg ( channel, // return value from TEST_CMD,
// sizeof(return value from TEST_CMD) );
}
For a single STATUS object I could easily return a copy inside
TEST_CMD or perhaps pass a pointer of the object to TEST_CMD and
'write' to that pointer inside TEST_CMD.
NOTE: I cant modify any of the structs (STATUS/CMD/HEADER struct) to
add an addition 'bit field'. The bit fields form a part of a message
interface defined in a document which makes this interesting
appropriate status?
Simply put. TEST_CMD could return either status1 or status2. The
return value will be passed to the Write function inside main. The
prototype for the Write function is highlighted below.
#define TRUE 1
#define FALSE 0
typedef struct
{
unsigned int field1 : 16;
unsigned int field2 : 10;
unsigned int field3 : 6;
} HEADER;
typedef struct
{
HEADER header;
unsigned int cmd_field1 : 1;
unsigned int cmd_field2 : 8;
unsigned int cmd_field3 : 16;
} CMD;
typedef struct
{
unsigned int status1_field1 : 1;
unsigned int status1_field2 : 32;
unsigned int status1_field3 : 5;
unsigned int status1_field4 : 27;
} STATUS1;
typedef struct
{
unsigned int status2_field1 : 1;
unsigned int status2_field2 : 31;
unsigned int status2_field3 : 16;
unsigned int status2_field4 : 16;
} STATUS2;
// 4 more. ie STATUS3, STATUS4, STATUS5, STATUS6
CMD cmd_msg;
STATUS1 status1;
STATUS2 status2;
//STATUS3 status3;
//STATUS4 status4;
void TEST_CMD ( const CMD *ptr_cmd ) // return type on this obviously
cant be 'void'
{
if ( ptr_cmd->header.field1 == 0 )
{
status1->status1_field1 = TRUE;
// return status1;
}
else if ( ptr_cmd->header_field2 != 0 )
{
status2->status2_field1 = FALSE;
// return status2;
}
// 4 more
}
int main ()
{
int channel;
//TEST_CMD ( &cmd_msg);
// The prototype for Write_Msg looks like
// Write_Msg ( int chan,
// void* src // pointer to the appropriate
data
// int len );
// So now assume channel 3.
channel = 3;
// Write_Msg ( channel, // return value from TEST_CMD,
// sizeof(return value from TEST_CMD) );
}
For a single STATUS object I could easily return a copy inside
TEST_CMD or perhaps pass a pointer of the object to TEST_CMD and
'write' to that pointer inside TEST_CMD.
NOTE: I cant modify any of the structs (STATUS/CMD/HEADER struct) to
add an addition 'bit field'. The bit fields form a part of a message
interface defined in a document which makes this interesting