indented.

This commit is contained in:
skarg
2007-11-29 16:39:48 +00:00
parent 06d23fcf1f
commit 1477603af6
123 changed files with 1994 additions and 1688 deletions
+15 -16
View File
@@ -214,8 +214,7 @@ static char *winsock_error_code_text(
case WSAEDISCON:
return "Disconnect.";
case WSAHOST_NOT_FOUND:
return "Host not found. "
"This message indicates that the key "
return "Host not found. " "This message indicates that the key "
"(name, address, and so on) was not found.";
case WSATRY_AGAIN:
return "Nonauthoritative host not found. "
@@ -251,8 +250,8 @@ bool bip_init(
/*Result = WSAStartup(MAKEWORD(2,2), &wd); */
if (Result != 0) {
Code = WSAGetLastError();
printf("TCP/IP stack initialization failed\n"
" error code: %i %s\n", Code, winsock_error_code_text(Code));
printf("TCP/IP stack initialization failed\n" " error code: %i %s\n",
Code, winsock_error_code_text(Code));
exit(1);
}
atexit(cleanup);
@@ -265,8 +264,8 @@ bool bip_init(
address.s_addr = gethostaddr();
if (address.s_addr == (unsigned) -1) {
Code = WSAGetLastError();
printf("Get host address failed\n"
" error code: %i %s\n", Code, winsock_error_code_text(Code));
printf("Get host address failed\n" " error code: %i %s\n", Code,
winsock_error_code_text(Code));
exit(1);
}
bip_set_addr(address.s_addr);
@@ -282,8 +281,8 @@ bool bip_init(
broadcast_address.s_addr = htonl(bip_get_broadcast_addr());
fprintf(stderr, "IP Broadcast Address: %s\n",
inet_ntoa(broadcast_address));
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
bip_get_port(), bip_get_port());
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", bip_get_port(),
bip_get_port());
}
/* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@@ -294,8 +293,8 @@ bool bip_init(
}
/* Allow us to use the same socket for sending and receiving */
/* This makes sure that the src port is correct when sending */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n");
close(sock_fd);
@@ -303,8 +302,8 @@ bool bip_init(
return false;
}
/* allow us to send a broadcast */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set BROADCAST socket option.\n");
close(sock_fd);
@@ -315,8 +314,8 @@ bool bip_init(
/* probably only for Apple... */
/* rebind a port that is already in use.
Note: all users of the port must specify this flag */
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT,
(char *) &value, sizeof(value));
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT, (char *) &value,
sizeof(value));
if (rv < 0) {
fprintf(stderr, "bip: failed to set REUSEPORT socket option.\n");
close(sock_fd);
@@ -347,8 +346,8 @@ bool bip_init(
#endif
sin.sin_port = htons(bip_get_port());
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
rv = bind(sock_fd,
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
rv = bind(sock_fd, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
if (rv < 0) {
fprintf(stderr, "bip: failed to bind to %s port %hd\n",
inet_ntoa(sin.sin_addr), bip_get_port());
+20 -24
View File
@@ -144,13 +144,12 @@ uint16_t dlmstp_receive(
if (Receive_Packet.pdu_len) {
MSTP_Packets++;
if (src) {
memmove(src,
&Receive_Packet.address,
memmove(src, &Receive_Packet.address,
sizeof(Receive_Packet.address));
}
if (pdu) {
memmove(pdu,
&Receive_Packet.pdu, sizeof(Receive_Packet.pdu));
memmove(pdu, &Receive_Packet.pdu,
sizeof(Receive_Packet.pdu));
}
pdu_len = Receive_Packet.pdu_len;
}
@@ -301,11 +300,9 @@ uint16_t MSTP_Get_Send(
}
/* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize,
Transmit_Packet.frame_type,
destination,
mstp_port->This_Station,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
mstp_port->OutputBufferSize, Transmit_Packet.frame_type, destination,
mstp_port->This_Station, &Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len);
Transmit_Packet.ready = false;
return pdu_len;
@@ -336,8 +333,9 @@ bool dlmstp_compare_data_expecting_reply(
/* decode the request data */
request.address.mac[0] = src_address;
request.address.mac_len = 1;
offset = npdu_decode(&request_pdu[0],
NULL, &request.address, &request.npdu_data);
offset =
npdu_decode(&request_pdu[0], NULL, &request.address,
&request.npdu_data);
if (request.npdu_data.network_layer_message) {
return false;
}
@@ -353,8 +351,8 @@ bool dlmstp_compare_data_expecting_reply(
request.service_choice = request_pdu[offset + 3];
/* decode the reply data */
bacnet_address_copy(&reply.address, dest_address);
offset = npdu_decode(&reply_pdu[0],
&reply.address, NULL, &reply.npdu_data);
offset =
npdu_decode(&reply_pdu[0], &reply.address, NULL, &reply.npdu_data);
if (reply.npdu_data.network_layer_message) {
return false;
}
@@ -443,19 +441,18 @@ uint16_t MSTP_Get_Reply(
return 0;
}
/* is this the reply to the DER? */
matched = dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->DataLength,
mstp_port->SourceAddress,
&Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len, &Transmit_Packet.address);
matched =
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
mstp_port->DataLength, mstp_port->SourceAddress,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len,
&Transmit_Packet.address);
if (!matched)
return 0;
/* convert the PDU into the MSTP Frame */
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
mstp_port->OutputBufferSize,
Transmit_Packet.frame_type,
destination, mstp_port->This_Station,
&Transmit_Packet.pdu[0], Transmit_Packet.pdu_len);
mstp_port->OutputBufferSize, Transmit_Packet.frame_type, destination,
mstp_port->This_Station, &Transmit_Packet.pdu[0],
Transmit_Packet.pdu_len);
Transmit_Packet.ready = false;
return pdu_len;
@@ -721,8 +718,7 @@ int main(
for (;;) {
pdu_len = dlmstp_receive(NULL, NULL, 0, INFINITE);
#if 0
MSTP_Create_And_Send_Frame(&MSTP_Port,
FRAME_TYPE_TEST_REQUEST,
MSTP_Create_And_Send_Frame(&MSTP_Port, FRAME_TYPE_TEST_REQUEST,
MSTP_Port.SourceAddress, MSTP_Port.This_Station, NULL, 0);
#endif
}
+10 -12
View File
@@ -155,8 +155,8 @@ bool ethernet_init(
*/
/* Retrieve the device list */
if (pcap_findalldevs(&pcap_all_if, pcap_errbuf) == -1) {
sprintf(msgBuf,
"ethernet.c: error in pcap_findalldevs: %s\n", pcap_errbuf);
sprintf(msgBuf, "ethernet.c: error in pcap_findalldevs: %s\n",
pcap_errbuf);
LogError(msgBuf);
return false;
}
@@ -167,8 +167,8 @@ bool ethernet_init(
}
pcap_freealldevs(pcap_all_if); /* we don't need it anymore */
if (dev == NULL) {
sprintf(msgBuf,
"ethernet.c: specified interface not found: %s\n", if_name);
sprintf(msgBuf, "ethernet.c: specified interface not found: %s\n",
if_name);
LogError(msgBuf);
return false;
}
@@ -180,8 +180,8 @@ bool ethernet_init(
lpAdapter = PacketOpenAdapter(if_name);
if (lpAdapter == NULL) {
ethernet_cleanup();
sprintf(msgBuf,
"ethernet.c: error in PacketOpenAdapter(\"%s\")\n", if_name);
sprintf(msgBuf, "ethernet.c: error in PacketOpenAdapter(\"%s\")\n",
if_name);
LogError(msgBuf);
return false;
}
@@ -284,8 +284,7 @@ int ethernet_send(
if (pcap_sendpacket(pcap_eth802_fp, mtu, mtu_len) != 0) {
/* did it get sent? */
char msgBuf[200];
sprintf(msgBuf,
"ethernet.c: error sending packet: %s\n",
sprintf(msgBuf, "ethernet.c: error sending packet: %s\n",
pcap_geterr(pcap_eth802_fp));
LogError(msgBuf);
return -5;
@@ -342,8 +341,7 @@ uint16_t ethernet_receive(
res = pcap_next_ex(pcap_eth802_fp, &header, &pkt_data);
if (res < 0) {
char msgBuf[200];
sprintf(msgBuf,
"ethernet.c: error in receiving packet: %s\n",
sprintf(msgBuf, "ethernet.c: error in receiving packet: %s\n",
pcap_geterr(pcap_eth802_fp));
return 0;
} else if (res == 0)
@@ -445,8 +443,8 @@ void ethernet_debug_address(
}
/* if */
if (dest) {
sprintf(msgBuf,
"Address:\n MAC Length=%d\n MAC Address=", dest->mac_len);
sprintf(msgBuf, "Address:\n MAC Length=%d\n MAC Address=",
dest->mac_len);
LogInfo(msgBuf);
for (i = 0; i < MAX_MAC_LEN; i++) {
sprintf(msgBuf, "%02X ", (unsigned) dest->mac[i]);
+5 -4
View File
@@ -105,8 +105,8 @@ static void Read_Properties(
next_device = true;
else {
status = Send_Read_Property_Request(device_id, /* destination device */
OBJECT_DEVICE,
device_id, object_props[property], BACNET_ARRAY_ALL);
OBJECT_DEVICE, device_id, object_props[property],
BACNET_ARRAY_ALL);
if (status)
property++;
}
@@ -137,8 +137,9 @@ static void LocalIAmHandler(
(void) src;
(void) service_len;
len = iam_decode_service_request(service_request,
&device_id, &max_apdu, &segmentation, &vendor_id);
len =
iam_decode_service_request(service_request, &device_id, &max_apdu,
&segmentation, &vendor_id);
fprintf(stderr, "Received I-Am Request");
if (len != -1) {
fprintf(stderr, " from %u!\n", device_id);
+3 -2
View File
@@ -190,8 +190,9 @@ static void RS485_Configure_Status(
void RS485_Initialize(
void)
{
RS485_Handle = CreateFile(RS485_Port_Name,
GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
RS485_Handle =
CreateFile(RS485_Port_Name, GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING,
/*FILE_FLAG_OVERLAPPED */ 0,
0);
if (RS485_Handle == INVALID_HANDLE_VALUE) {
+5 -9
View File
@@ -129,20 +129,16 @@ static void print_received_packet(
/* Data CRC: (present only if Length is non-zero) two octets, */
/* least significant octet first */
/* (pad): (optional) at most one octet of padding: X'FF' */
fprintf(stderr,
"55 FF %02X %02X %02X %02X %02X %02X ",
mstp_port->FrameType,
mstp_port->DestinationAddress,
mstp_port->SourceAddress,
HI_BYTE(mstp_port->DataLength),
fprintf(stderr, "55 FF %02X %02X %02X %02X %02X %02X ",
mstp_port->FrameType, mstp_port->DestinationAddress,
mstp_port->SourceAddress, HI_BYTE(mstp_port->DataLength),
LO_BYTE(mstp_port->DataLength), mstp_port->HeaderCRCActual);
if (mstp_port->DataLength) {
for (i = 0; i < mstp_port->DataLength; i++) {
fprintf(stderr, "%02X ", mstp_port->InputBuffer[i]);
}
fprintf(stderr,
"%02X %02X ",
mstp_port->DataCRCActualMSB, mstp_port->DataCRCActualLSB);
fprintf(stderr, "%02X %02X ", mstp_port->DataCRCActualMSB,
mstp_port->DataCRCActualLSB);
}
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
fprintf(stderr, "\n");