Skip to content

Commit 96f6cd7

Browse files
Fix cpplint issues
Signed-off-by: Martin Melik Merkumians <martin.melik@gmail.com>
1 parent 247db74 commit 96f6cd7

20 files changed

Lines changed: 142 additions & 153 deletions

source/src/cip/cipconnectionmanager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "enet_encap/cpf.h"
2525
#include "enet_encap/encap.h"
2626
#include "enet_encap/endianconv.h"
27-
#include "opener_api.h"
27+
#include "api/opener_api.h"
2828
#include "opener_user_conf.h"
2929
#include "ports/generic_networkhandler.h"
3030
#include "utils/xorshiftrandom.h"

source/src/enet_encap/cpf.h

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* All rights reserved.
44
*
55
******************************************************************************/
6-
#ifndef OPENER_CPF_H_
7-
#define OPENER_CPF_H_
6+
#ifndef ENET_ENCAP_CPF_H_
7+
#define ENET_ENCAP_CPF_H_
88

9-
#include "ciptypes.h"
9+
#include "cip/ciptypes.h"
1010
#include "core/typedefs.h"
11-
#include "encap.h"
11+
#include "enet_encap/encap.h"
1212

1313
/** @ingroup ENCAP
1414
* @brief CPF is Common Packet Format
@@ -23,22 +23,17 @@
2323
/** @brief Definition of Item ID numbers used for address and data items in CPF
2424
* structures */
2525
typedef enum {
26-
kCipItemIdNullAddress = 0x0000U, /**< Type: Address; Indicates that
27-
encapsulation routing is not needed. */
26+
kCipItemIdNullAddress =
27+
0x0000U, ///< Type: Address; Indicates that encapsulation routing is not needed.
2828
kCipItemIdListIdentityResponse = 0x000CU,
2929
kCipItemIdConnectionAddress =
30-
0x00A1U, /**< Type: Address; Connection-based, used for connected messages,
31-
see Vol.2, p.42 */
32-
kCipItemIdConnectedDataItem =
33-
0x00B1U, /**< Type: Data; Connected data item, see Vol.2, p.43 */
34-
kCipItemIdUnconnectedDataItem =
35-
0x00B2U, /**< Type: Data; Unconnected message */
30+
0x00A1U, ///< Type: Address; Connection-based, used for connected messages, see Vol.2, p.42
31+
kCipItemIdConnectedDataItem = 0x00B1U, ///< Type: Data; Connected data item, see Vol.2, p.43
32+
kCipItemIdUnconnectedDataItem = 0x00B2U, ///< Type: Data; Unconnected message
3633
kCipItemIdListServiceResponse = 0x0100U,
37-
kCipItemIdSocketAddressInfoOriginatorToTarget =
38-
0x8000U, /**< Type: Data; Sockaddr info item originator to target */
39-
kCipItemIdSocketAddressInfoTargetToOriginator =
40-
0x8001U, /**< Type: Data; Sockaddr info item target to originator */
41-
kCipItemIdSequencedAddressItem = 0x8002U /**< Sequenced Address item */
34+
kCipItemIdSocketAddressInfoOriginatorToTarget = 0x8000U, ///< Type: Data; Sockaddr info item originator to target
35+
kCipItemIdSocketAddressInfoTargetToOriginator = 0x8001U, ///< Type: Data; Sockaddr info item target to originator
36+
kCipItemIdSequencedAddressItem = 0x8002U ///< Sequenced Address item
4237
} CipItemId;
4338

4439
typedef struct {
@@ -62,24 +57,24 @@ typedef struct {
6257
*
6358
*/
6459
typedef struct {
65-
CipUint type_id; /**< Either 0x8000 for O->T or 0x8001 for T->O */
66-
CipUint length; /**< Length shall be 16 bytes */
67-
CipInt sin_family; /**< Shall be AF_INET = 2 in big endian order */
68-
CipUint sin_port; /**< For point-to-point connection this shall be set to the
69-
used UDP port (recommended port = 0x08AE). For multicast
70-
this shall be set to 0x08AE and treated by the receiver
71-
as don't care. Big endian order */
72-
CipUdint sin_addr; /**< For multicast connections shall be set to the
73-
multicast address. For point-to-point shall be treated
74-
as don't care, recommended value 0. Big endian order. */
75-
CipUsint nasin_zero[8]; /**< Length of 8, Recommended value zero */
60+
CipUint type_id; ///< Either 0x8000 for O->T or 0x8001 for T->O
61+
CipUint length; ///< Length shall be 16 bytes
62+
CipInt sin_family; ///< Shall be AF_INET = 2 in big endian order
63+
CipUint sin_port; ///< For point-to-point connection this shall be set to the
64+
///< used UDP port (recommended port = 0x08AE). For multicast
65+
///< this shall be set to 0x08AE and treated by the receiver
66+
///< as don't care. Big endian order
67+
CipUdint sin_addr; ///< For multicast connections shall be set to the
68+
///< multicast address. For point-to-point shall be treated
69+
///< as don't care, recommended value 0. Big endian order.
70+
CipUsint nasin_zero[8]; ///< Length of 8, Recommended value zero
7671
} SocketAddressInfoItem;
7772

7873
/* this one case of a CPF packet is supported:*/
7974
/** @brief A variant of a CPF packet, including item count, one address item,
8075
* one data item, and two Sockaddr Info items */
8176
typedef struct {
82-
EipUint16 item_count; /**< Up to four for this structure allowed */
77+
EipUint16 item_count; ///< Up to four for this structure allowed
8378
AddressItem address_item;
8479
DataItem data_item;
8580
SocketAddressInfoItem address_info_item[2];
@@ -171,4 +166,4 @@ EipStatus AssembleLinearMessage(
171166
*/
172167
extern CipCommonPacketFormatData g_common_packet_format_data_item;
173168

174-
#endif /* OPENER_CPF_H_ */
169+
#endif // ENET_ENCAP_CPF_H_

source/src/enet_encap/encap.c

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
* All rights reserved.
44
*
55
******************************************************************************/
6-
#include "encap.h"
6+
#include "enet_encap/encap.h"
77

88
#include <stdbool.h>
99
#include <stdlib.h>
1010
#include <string.h>
1111

12-
#include "cipcommon.h"
13-
#include "cipconnectionmanager.h"
14-
#include "cipidentity.h"
15-
#include "cipmessagerouter.h"
16-
#include "ciptcpipinterface.h"
17-
#include "cpf.h"
18-
#include "endianconv.h"
19-
#include "generic_networkhandler.h"
20-
#include "opener_api.h"
21-
#include "opener_error.h"
12+
#include "cip/cipcommon.h"
13+
#include "cip/cipconnectionmanager.h"
14+
#include "cip/cipidentity.h"
15+
#include "cip/cipmessagerouter.h"
16+
#include "cip/ciptcpipinterface.h"
17+
#include "enet_encap/cpf.h"
18+
#include "enet_encap/endianconv.h"
19+
#include "ports/generic_networkhandler.h"
20+
#include "api/opener_api.h"
21+
#include "ports/opener_error.h"
2222
#include "opener_user_conf.h"
23-
#include "socket_timer.h"
24-
#include "trace.h"
23+
#include "ports/socket_timer.h"
24+
#include "core/trace.h"
2525

2626
/* IP address data taken from TCPIPInterfaceObject*/
2727
const EipUint16 kSupportedProtocolVersion =
@@ -581,12 +581,12 @@ void HandleReceivedRegisterSessionCommand(
581581

582582
if (kSessionStatusInvalid != session_index) {
583583
session_index = GetFreeSessionIndex();
584-
if (kSessionStatusInvalid ==
585-
session_index) /* no more sessions available */
586-
{
584+
if (kSessionStatusInvalid == session_index) {
585+
// no more sessions available
587586
encapsulation_protocol_status =
588587
kEncapsulationProtocolInsufficientMemory;
589-
} else { /* successful session registered */
588+
} else {
589+
// successful session registered
590590
SocketTimer* socket_timer = SocketTimerArrayGetEmptySocketTimer(
591591
g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
592592
SocketTimerSetSocket(socket_timer, socket);
@@ -597,7 +597,8 @@ void HandleReceivedRegisterSessionCommand(
597597
encapsulation_protocol_status = kEncapsulationProtocolSuccess;
598598
}
599599
}
600-
} else { /* protocol not supported */
600+
} else {
601+
// protocol not supported
601602
encapsulation_protocol_status = kEncapsulationProtocolUnsupportedProtocol;
602603
}
603604

@@ -631,7 +632,7 @@ EipStatus HandleReceivedUnregisterSessionCommand(
631632
}
632633
}
633634

634-
/* no such session registered */
635+
// no such session registered
635636
GenerateEncapsulationHeader(receive_data,
636637
0,
637638
receive_data->session_handle,
@@ -649,42 +650,35 @@ EipStatus HandleReceivedSendUnitDataCommand(
649650
const EncapsulationData* const receive_data,
650651
const struct sockaddr* const originator_address,
651652
ENIPMessage* const outgoing_message) {
652-
EipStatus return_value = kEipStatusOkSend;
653-
/*EipStatus*/ return_value =
654-
kEipStatusOk; /* TODO: Shouldn't this be kEipStatusOk cause we must not
655-
send any response if data_length < 6? */
653+
// EipStatus return_value = kEipStatusOkSend;
654+
// TODO(MartinMelikMerkumians): Shouldn't this be kEipStatusOk cause we must not send any response if data_length < 6?
655+
EipStatus return_value = kEipStatusOk;
656656

657657
if (receive_data->data_length >= 6) {
658-
/* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF
659-
* packets */
660-
/* don't use the data yet */
661-
GetDintFromMessage(
662-
(const EipUint8** const)&receive_data
663-
->current_communication_buffer_position); /* skip over null
664-
interface handle*/
665-
GetIntFromMessage(
666-
(const EipUint8** const)&receive_data
667-
->current_communication_buffer_position); /* skip over unused
668-
timeout value*/
669-
((EncapsulationData* const)receive_data)->data_length -=
670-
6; /* the rest is in CPF format*/
671-
672-
if (kSessionStatusValid ==
673-
CheckRegisteredSessions(
674-
receive_data)) /* see if the EIP session is registered*/
675-
{
658+
// Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF packets
659+
// don't use the data yet
660+
661+
// skip over null interface handle
662+
GetDintFromMessage((const EipUint8** const)&receive_data->current_communication_buffer_position);
663+
// skip over unused timeout value
664+
GetIntFromMessage((const EipUint8** const)&receive_data->current_communication_buffer_position);
665+
// the rest is in CPF format
666+
((EncapsulationData* const)receive_data)->data_length -= 6;
667+
668+
// see if the EIP session is registered
669+
if (kSessionStatusValid == CheckRegisteredSessions(receive_data)) {
676670
return_value = NotifyConnectedCommonPacketFormat(
677671
receive_data, originator_address, outgoing_message);
678-
} else { /* received a package with non registered session handle */
672+
} else {
673+
// received a package with non registered session handle
679674
InitializeENIPMessage(outgoing_message);
680675
GenerateEncapsulationHeader(receive_data,
681676
0,
682677
receive_data->session_handle,
683678
kEncapsulationProtocolInvalidSessionHandle,
684679
outgoing_message);
685-
return_value =
686-
kEipStatusOkSend; /* TODO: Needs to be here if line with first TODO of
687-
this function is adjusted. */
680+
// TODO(MartinMelikMerkumians): Needs to be here if line with first TODO of this function is adjusted.
681+
return_value = kEipStatusOkSend;
688682
}
689683
}
690684
return return_value;
@@ -702,30 +696,23 @@ EipStatus HandleReceivedSendRequestResponseDataCommand(
702696
const EncapsulationData* const receive_data,
703697
const struct sockaddr* const originator_address,
704698
ENIPMessage* const outgoing_message) {
705-
EipStatus return_value = kEipStatusOkSend;
706-
/* EipStatus*/ return_value =
707-
kEipStatusOk; /* TODO: Shouldn't this be kEipStatusOk cause we must not
708-
send any response if data_length < 6? */
699+
// EipStatus return_value = kEipStatusOkSend;
700+
// TODO(MartinMelikMerkumians): Shouldn't this be kEipStatusOk cause we must not send any response if data_length < 6?
701+
EipStatus = kEipStatusOk;
709702

710703
if (receive_data->data_length >= 6) {
711-
/* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF
712-
* packets */
713-
/* don't use the data yet */
714-
GetDintFromMessage(
715-
(const EipUint8** const)&receive_data
716-
->current_communication_buffer_position); /* skip over null
717-
interface handle*/
718-
GetIntFromMessage(
719-
(const EipUint8** const)&receive_data
720-
->current_communication_buffer_position); /* skip over unused
721-
timeout value*/
722-
((EncapsulationData* const)receive_data)->data_length -=
723-
6; /* the rest is in CPF format*/
724-
725-
if (kSessionStatusValid ==
726-
CheckRegisteredSessions(
727-
receive_data)) /* see if the EIP session is registered*/
728-
{
704+
// Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF packets
705+
// don't use the data yet
706+
707+
// skip over null interface handle
708+
GetDintFromMessage((const EipUint8** const)&receive_data->current_communication_buffer_position);
709+
// skip over unused timeout value
710+
GetIntFromMessage((const EipUint8** const)&receive_data->current_communication_buffer_position);
711+
// the rest is in CPF format
712+
((EncapsulationData* const)receive_data)->data_length -= 6;
713+
714+
// see if the EIP session is registered
715+
if (kSessionStatusValid == CheckRegisteredSessions(receive_data)) {
729716
return_value = NotifyCommonPacketFormat(
730717
receive_data, originator_address, outgoing_message);
731718
} else { /* received a package with non registered session handle */
@@ -735,9 +722,8 @@ EipStatus HandleReceivedSendRequestResponseDataCommand(
735722
receive_data->session_handle,
736723
kEncapsulationProtocolInvalidSessionHandle,
737724
outgoing_message);
738-
return_value =
739-
kEipStatusOkSend; /* TODO: Needs to be here if line with first TODO of
740-
this function is adjusted. */
725+
// TODO(MartinMelikMerkumians): Needs to be here if line with first TODO of this function is adjusted.
726+
return_value = kEipStatusOkSend;
741727
}
742728
}
743729
return return_value;

source/src/ports/MINGW/networkconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
* This file contains the network configuration for the MinGW platform.
1212
*/
1313

14-
#endif // PORTS_MINGW_NETWORKCONFIG_H_
14+
#endif // PORTS_MINGW_NETWORKCONFIG_H_

source/src/ports/POSIX/networkconfig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static EipStatus GetGatewayFromRoute(
122122
unsigned long tmp_gw; // NOLINT(runtime/int)
123123
char* end;
124124
// The gateway string is a hex number in network byte order.
125-
errno = 0; // To distinguish success / failure later
125+
errno = 0; // To distinguish success / failure later
126126
tmp_gw = strtoul(gateway_string, &end, 16);
127127

128128
if ((errno == ERANGE && tmp_gw == ULONG_MAX) || /* overflow */

source/src/ports/POSIX/networkconfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
* All rights reserved.
44
*
55
******************************************************************************/
6+
7+
#ifndef PORTS_POSIX_NETWORKCONFIG_H_
8+
#define PORTS_POSIX_NETWORKCONFIG_H_
9+
/** @file POSIX/networkconfig.h
10+
* @brief Network configuration for POSIX platform
11+
* This file contains the network configuration for the POSIX platform.
12+
*/
13+
14+
#endif // PORTS_POSIX_NETWORKCONFIG_H_

source/src/ports/POSIX/sample_application/ethlinkcbs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
*****************************************************************************/
66

7-
#ifndef PORTS_POSIX_SAMPLE_APPLICATION_ETHLINKCBS_H_
7+
#ifndef PORTS_POSIX_SAMPLE_APPLICATION_ETHLINKCBS_H_
88
#define PORTS_POSIX_SAMPLE_APPLICATION_ETHLINKCBS_H_
99

1010
/** @file

source/src/ports/STM32/opener.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
#include "ports/STM32/opener.h"
88

9+
#include "api/opener_api.h"
910
#include "cip/cipconnectionobject.h"
1011
#include "cip/cipethernetlink.h"
1112
#include "cip/ciptcpipinterface.h"
12-
#include "utils/doublylinkedlist.h"
13-
#include "ports/generic_networkhandler.h"
14-
#include "ports/STM32/networkconfig.h"
15-
#include "api/opener_api.h"
1613
#include "core/trace.h"
14+
#include "ports/STM32/networkconfig.h"
15+
#include "ports/generic_networkhandler.h"
16+
#include "utils/doublylinkedlist.h"
1717

1818
#define OPENER_THREAD_PRIO osPriorityAboveNormal
1919
#define OPENER_STACK_SIZE 2000

source/src/ports/STM32/opener_error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
// Force the use of the XSI compliant strerror_r() function.
14+
// Force the use of the XSI compliant strerror_r() function.
1515
#undef _GNU_SOURCE
1616

1717
#include "opener_error.h"

source/src/ports/WIN32/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#include <stdlib.h>
99
#include <time.h>
1010

11-
#include "cipconnectionobject.h"
12-
#include "cipethernetlink.h"
13-
#include "ciptcpipinterface.h"
14-
#include "doublylinkedlist.h"
15-
#include "generic_networkhandler.h"
16-
#include "networkconfig.h"
17-
#include "nvdata.h"
18-
#include "opener_api.h"
19-
#include "trace.h"
11+
#include "cip/cipconnectionobject.h"
12+
#include "cip/cipethernetlink.h"
13+
#include "cip/ciptcpipinterface.h"
14+
#include "utils/doublylinkedlist.h"
15+
#include "ports/generic_networkhandler.h"
16+
#include "ports/WIN32/networkconfig.h"
17+
#include "ports/nvdata/nvdata.h"
18+
#include "api/opener_api.h"
19+
#include "core/trace.h"
2020

2121
#define BringupNetwork(if_name, method, if_cfg, hostname) (0)
2222
#define ShutdownNetwork(if_name) (0)

0 commit comments

Comments
 (0)