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

union/struct problem

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







union/struct problem
PostPosted: Thu May 19, 2005 9:22 pm     Reply with quote

I am trying to use a struct pointer and it gives me the error below (MsgPtr->Res = 0; // Is Not a Member. Anyone have a solution?

union J1939_MESSAGE_UNION {
struct {
int8 PDUFormat_Top : 3; // This needs pre and post processing.
int8 DataPage : 1;
int8 Res : 1;
int8 Priority : 3;
char PDUFormat; // CA should use only PDUFormat.
char PDUSpecific;
char SourceAddress;
int8 DataLength : 4;
int8 RTR : 4; // RTR bit, value always 0x00
char Data[J1939_DATA_LENGTH];
};
char Array[J1939_MSG_LENGTH + J1939_DATA_LENGTH];
};

#define GroupExtension PDUSpecific
#define DestinationAddress PDUSpecific
typedef union J1939_MESSAGE_UNION J1939_MESSAGE;


union J1939_FLAGS_UNION {
struct {
int8 CannotClaimAddress : 1;
int8 WaitingForAddressClaimContention : 1;
int8 GettingCommandedAddress : 1;
int8 GotFirstDataPacket : 1;
int8 ReceivedMessagesDropped : 1;
};
char FlagVal;
};

typedef union J1939_FLAGS_UNION J1939_FLAG;


void SendOneMessage( J1939_MESSAGE *MsgPtr ) {
char Loop;
char *RegPtr;
char Temp;

// Set up the final pieces of the message and make sure DataLength isn't
// out of spec.
MsgPtr->Res = 0; // ERROR, THE COMPILER SAYS THIS IS NOT A MEMBER HELP!
MsgPtr->RTR = 0;
if (MsgPtr->DataLength > 8)
MsgPtr->DataLength = 8;

// Put PDUFormat into the structure to match the J1939-CAN format. This
// involves splitting the original value in PDUFormat into two pieces,
// leaving some holes for the TXBnSIDL register, and setting the EXIDE bit.
MsgPtr->PDUFormat_Top = MsgPtr->PDUFormat >> 5; // Put the top three bits into SID5-3
Temp = MsgPtr->PDUFormat & 0x03; // Save the bottom two bits.
MsgPtr->PDUFormat = (MsgPtr->PDUFormat & 0x1C) << 3; // Move up bits 4-2 into SID2-0.
MsgPtr->PDUFormat |= Temp | 0x08; // Put back EID17-16, set EXIDE.

// Wait until the requested buffer can be used to transmit. We shouldn't
// need a time-out here unless something else in the design isn't working
// (or we have to send a LOT of network management messages).
while (MAPPED_CONbits.MAPPED_TXREQ);

// Load the message buffer. Load the first 5 bytes of the message,
// then load whatever part of the data is necessary.
RegPtr = &MAPPED_SIDH;
for (Loop=0; Loop<J1939_MSG_LENGTH+MsgPtr->DataLength; Loop++, RegPtr++)
*RegPtr = MsgPtr->Array[Loop];

// Now tell the module to send the message.
MAPPED_CONbits.MAPPED_TXREQ = 1;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 19, 2005 11:01 pm     Reply with quote

I think you need to add the items shown in bold below.
Quote:
union J1939_MESSAGE_UNION {
struct {
int8 PDUFormat_Top : 3; // This needs pre and post processing.
int8 DataPage : 1;
int8 Res : 1;
int8 Priority : 3;
char PDUFormat; // CA should use only PDUFormat.
char PDUSpecific;
char SourceAddress;
int8 DataLength : 4;
int8 RTR : 4; // RTR bit, value always 0x00
char Data[J1939_DATA_LENGTH];
}J1939_MSG_STRUCT;
char Array[J1939_MSG_LENGTH + J1939_DATA_LENGTH];
};


Quote:
void SendOneMessage( J1939_MESSAGE *MsgPtr ) {
char Loop;
char *RegPtr;
char Temp;

// Set up the final pieces of the message and make sure DataLength isn't
// out of spec.
MsgPtr->J1939_MSG_STRUCT.Res = 0;
MsgPtr->J1939_MSG_STRUCT.RTR = 0;
mike holeton
Guest







PostPosted: Fri May 20, 2005 9:29 am     Reply with quote

Thank You, I'll give it a try.
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