M
mrhicks
Hello all,
I need some advice/help on a particular problem I am having. I have
a basic struct called "indv_rpt_rply" that holds information for a
particular device in our system which I will call INDV. The struct
looks like
// Some info used for the struct
typedef unsigned char uint8; /* 8 bits */
typedef unsigned short int uint16; /* 16 bits */
struct indv_rpt_rply {
struct generic_cmd_req header; // another struct that is common
a
// header routing info for each
msg
// that goes over the wire.
uint8 ecbPrgmRating :8;
uint16 voltage :16,
current :16;
uint8 notUsed :1,
exist :1,
comm :1,
sfault :1,
tripCause :1,
state :3,
ecbNum :8;
};
There are five Units within the system that hold different count of
these INDV. For each Unit I have following struct.
struct unitDev {
uint8 numOfINDVs;
struct indv_rpt_rply** rpt;
};
So for each INDV and Unit I have a declaration like
struct idv_rpt_rply strIndvInUnit1[MAX_NUM_OF_INDV_IN_UNIT1], //
23
strIndvInUnit2[MAX_NUM_OF_INDV_IN_UNIT2], //
22
strIndvInUnit3[MAX_NUM_OF_INDV_IN_UNIT3], //
10
strIndvInUnit4[MAX_NUM_OF_INDV_IN_UNIT4], //
35
strIndvInUnit5[MAX_NUM_OF_INDV_IN_UNIT5], //
31
struct unitDev strUnitDev[MAX_NUM_OF_UNITS];
This will keep track of the number of INDV within the unit and
basically have a pointer to an array of structs. I am having problems
equating the "pointer to an array of struct" (struct idv_rpt_rply**
rpt) to the each of the individual INDV array. The following code will
compile, but obvously doesn't work correctly. Is this scheme even
possible? What would be a better approach?
struct unitDev strUnitDev[0].rpt = (struct
idv_rpt_rply**)&strIndvInUnit1;
but when I test my code using Green Hills Simulator I get the
following...
int test;
strIndvInUnit1[0].current = 0xAB;
test = strIndvInUnit1[0].current; <= once executed test equates to
0xAB;
test = strUnitDev[0].rpt[0]->current; <= once executed test equates
to 0x0;
Mark
I need some advice/help on a particular problem I am having. I have
a basic struct called "indv_rpt_rply" that holds information for a
particular device in our system which I will call INDV. The struct
looks like
// Some info used for the struct
typedef unsigned char uint8; /* 8 bits */
typedef unsigned short int uint16; /* 16 bits */
struct indv_rpt_rply {
struct generic_cmd_req header; // another struct that is common
a
// header routing info for each
msg
// that goes over the wire.
uint8 ecbPrgmRating :8;
uint16 voltage :16,
current :16;
uint8 notUsed :1,
exist :1,
comm :1,
sfault :1,
tripCause :1,
state :3,
ecbNum :8;
};
There are five Units within the system that hold different count of
these INDV. For each Unit I have following struct.
struct unitDev {
uint8 numOfINDVs;
struct indv_rpt_rply** rpt;
};
So for each INDV and Unit I have a declaration like
struct idv_rpt_rply strIndvInUnit1[MAX_NUM_OF_INDV_IN_UNIT1], //
23
strIndvInUnit2[MAX_NUM_OF_INDV_IN_UNIT2], //
22
strIndvInUnit3[MAX_NUM_OF_INDV_IN_UNIT3], //
10
strIndvInUnit4[MAX_NUM_OF_INDV_IN_UNIT4], //
35
strIndvInUnit5[MAX_NUM_OF_INDV_IN_UNIT5], //
31
struct unitDev strUnitDev[MAX_NUM_OF_UNITS];
This will keep track of the number of INDV within the unit and
basically have a pointer to an array of structs. I am having problems
equating the "pointer to an array of struct" (struct idv_rpt_rply**
rpt) to the each of the individual INDV array. The following code will
compile, but obvously doesn't work correctly. Is this scheme even
possible? What would be a better approach?
struct unitDev strUnitDev[0].rpt = (struct
idv_rpt_rply**)&strIndvInUnit1;
but when I test my code using Green Hills Simulator I get the
following...
int test;
strIndvInUnit1[0].current = 0xAB;
test = strIndvInUnit1[0].current; <= once executed test equates to
0xAB;
test = strUnitDev[0].rpt[0]->current; <= once executed test equates
to 0x0;
Mark