Skip to content

Commit

Permalink
Use void pointer for attribute encoding data parameters.
Browse files Browse the repository at this point in the history
Pointers to these functions are used as the encode_function
argument to InsertAttribute(), which is defined with a void data
pointer. Most of these functions cast the data pointer to the
correct type anyway; a cast was added if not. Resolves incompatible
pointer type warnings.
  • Loading branch information
jvalenzuela authored and MartinMelikMerkumians committed Oct 10, 2023
1 parent a2858f3 commit e2a2ac2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
49 changes: 25 additions & 24 deletions source/src/cip/cipcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,82 +577,82 @@ EipStatus GetAttributeSingle(CipInstance *RESTRICT const instance,
return kEipStatusOkSend;
}

void EncodeCipBool(const CipBool *const data,
void EncodeCipBool(const void *const data,
ENIPMessage *const outgoing_message) {
AddSintToMessage(*(EipUint8 *) (data), outgoing_message);
}

void EncodeCipByte(const CipByte *const data,
void EncodeCipByte(const void *const data,
ENIPMessage *const outgoing_message) {
AddSintToMessage(*(EipUint8 *) (data), outgoing_message);
}

void EncodeCipWord(const CipWord *const data,
void EncodeCipWord(const void *const data,
ENIPMessage *const outgoing_message) {
AddIntToMessage(*(EipUint16 *) (data), outgoing_message);
}

void EncodeCipDword(const CipDword *const data,
void EncodeCipDword(const void *const data,
ENIPMessage *const outgoing_message) {
AddDintToMessage(*(EipUint32 *) (data), outgoing_message);
}

void EncodeCipLword(const CipLword *const data,
void EncodeCipLword(const void *const data,
ENIPMessage *const outgoing_message) {
AddLintToMessage(*(EipUint64 *) (data), outgoing_message);
}

void EncodeCipUsint(const CipUsint *const data,
void EncodeCipUsint(const void *const data,
ENIPMessage *const outgoing_message) {
AddSintToMessage(*(EipUint8 *) (data), outgoing_message);
}

void EncodeCipUint(const CipUint *const data,
void EncodeCipUint(const void *const data,
ENIPMessage *const outgoing_message) {
AddIntToMessage(*(EipUint16 *) (data), outgoing_message);
}

void EncodeCipUdint(const CipUdint *const data,
void EncodeCipUdint(const void *const data,
ENIPMessage *const outgoing_message) {
AddDintToMessage(*(EipUint32 *) (data), outgoing_message);
}

void EncodeCipUlint(const CipUlint *const data,
void EncodeCipUlint(const void *const data,
ENIPMessage *const outgoing_message) {
AddLintToMessage(*(EipUint64 *) (data), outgoing_message);
}

void EncodeCipSint(const CipSint *const data,
void EncodeCipSint(const void *const data,
ENIPMessage *const outgoing_message) {
AddSintToMessage(*(EipUint8 *) (data), outgoing_message);
}

void EncodeCipInt(const CipInt *const data,
void EncodeCipInt(const void *const data,
ENIPMessage *const outgoing_message) {
AddIntToMessage(*(EipUint16 *) (data), outgoing_message);
}

void EncodeCipDint(const CipDint *const data,
void EncodeCipDint(const void *const data,
ENIPMessage *const outgoing_message) {
AddDintToMessage(*(EipUint32 *) (data), outgoing_message);
}

void EncodeCipLint(const CipLint *const data,
void EncodeCipLint(const void *const data,
ENIPMessage *const outgoing_message) {
AddLintToMessage(*(EipUint64 *) (data), outgoing_message);
}

void EncodeCipReal(const CipReal *const data,
void EncodeCipReal(const void *const data,
ENIPMessage *const outgoing_message) {
AddDintToMessage(*(EipUint32 *) (data), outgoing_message);
}

void EncodeCipLreal(const CipLreal *const data,
void EncodeCipLreal(const void *const data,
ENIPMessage *const outgoing_message) {
AddLintToMessage(*(EipUint64 *) (data), outgoing_message);
}

void EncodeCipShortString(const CipShortString *const data,
void EncodeCipShortString(const void *const data,
ENIPMessage *const outgoing_message) {
CipShortString *const short_string = (CipShortString *) data;

Expand All @@ -665,7 +665,7 @@ void EncodeCipShortString(const CipShortString *const data,
outgoing_message->used_message_length += short_string->length;
}

void EncodeCipString(const CipString *const data,
void EncodeCipString(const void *const data,
ENIPMessage *const outgoing_message) {
CipString *const string = (CipString *) data;

Expand All @@ -684,7 +684,7 @@ void EncodeCipString(const CipString *const data,
}
}

void EncodeCipString2(const CipString2 *const data,
void EncodeCipString2(const void *const data,
ENIPMessage *const outgoing_message) {
/* Suppress unused parameter compiler warning. */
(void)data;
Expand All @@ -693,7 +693,7 @@ void EncodeCipString2(const CipString2 *const data,
OPENER_ASSERT(false); /* Not implemented yet */
}

void EncodeCipStringN(const CipStringN *const data,
void EncodeCipStringN(const void *const data,
ENIPMessage *const outgoing_message) {
/* Suppress unused parameter compiler warning. */
(void)data;
Expand All @@ -711,7 +711,7 @@ static void CipStringIHeaderEncoding(const CipStringIStruct *const string,
EncodeCipUint(&(string->character_set), outgoing_message);
}

void EncodeCipStringI(const CipStringI *const data,
void EncodeCipStringI(const void *const data,
ENIPMessage *const outgoing_message) {
const CipStringI *const string_i = data;
EncodeCipUsint(&(string_i->number_of_strings), outgoing_message);
Expand Down Expand Up @@ -742,7 +742,7 @@ void EncodeCipStringI(const CipStringI *const data,
}
}

void EncodeCipByteArray(const CipByteArray *const data,
void EncodeCipByteArray(const void *const data,
ENIPMessage *const outgoing_message) {
OPENER_TRACE_INFO(" -> get attribute byte array\r\n");
CipByteArray *cip_byte_array = (CipByteArray *) data;
Expand All @@ -753,9 +753,9 @@ void EncodeCipByteArray(const CipByteArray *const data,
outgoing_message->used_message_length += cip_byte_array->length;
}

void EncodeCipEPath(const CipEpath *const data,
void EncodeCipEPath(const void *const data,
ENIPMessage *const outgoing_message) {
AddIntToMessage(data->path_size, outgoing_message);
AddIntToMessage( ( (CipEpath *)data )->path_size, outgoing_message );
EncodeEPath( (CipEpath *) data, outgoing_message );
}

Expand Down Expand Up @@ -1336,8 +1336,9 @@ EipStatus SetAttributeList(CipInstance *instance,
return kEipStatusOkSend;
}

void EncodeEPath(const CipEpath *const epath,
void EncodeEPath(const void *const data,
ENIPMessage *const message) {
const CipEpath *const epath = (CipEpath *)data;
unsigned int length = epath->path_size;
size_t start_length = message->used_message_length;

Expand Down
46 changes: 23 additions & 23 deletions source/src/opener_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,73 +385,73 @@ void InsertGetSetCallback(CipClass *const cip_class,
* @param message_router_response The message router response construct
*/

void EncodeCipBool(const CipBool *const data,
void EncodeCipBool(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipByte(const CipByte *const data,
void EncodeCipByte(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipWord(const CipWord *const data,
void EncodeCipWord(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipDword(const CipDword *const data,
void EncodeCipDword(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipLword(const CipLword *const data,
void EncodeCipLword(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipUsint(const CipUsint *const data,
void EncodeCipUsint(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipUint(const CipUint *const data,
void EncodeCipUint(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipUdint(const CipUdint *const data,
void EncodeCipUdint(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipUlint(const CipUlint *const data,
void EncodeCipUlint(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipSint(const CipSint *const data,
void EncodeCipSint(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipInt(const CipInt *const data,
void EncodeCipInt(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipDint(const CipDint *const data,
void EncodeCipDint(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipLint(const CipLint *const data,
void EncodeCipLint(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipReal(const CipReal *const data,
void EncodeCipReal(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipLreal(const CipLreal *const data,
void EncodeCipLreal(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipShortString(const CipShortString *const data,
void EncodeCipShortString(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipString(const CipString *const data,
void EncodeCipString(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipString2(const CipString2 *const data,
void EncodeCipString2(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipStringN(const CipStringN *const data,
void EncodeCipStringN(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipStringI(const CipStringI *const data,
void EncodeCipStringI(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipByteArray(const CipByteArray *const data,
void EncodeCipByteArray(const void *const data,
ENIPMessage *const outgoing_message);

void EncodeCipEPath(const CipEpath *const data,
void EncodeCipEPath(const void *const data,
ENIPMessage *const outgoing_message); //path_size UINT

void EncodeEPath(const CipEpath *const data,
void EncodeEPath(const void *const data,
ENIPMessage *const outgoing_message); //path_size not encoded

void EncodeCipEthernetLinkPhyisicalAddress(const void *const data,
Expand Down

0 comments on commit e2a2ac2

Please sign in to comment.