Indented according to standard indent rules for this project.
This commit is contained in:
@@ -52,9 +52,9 @@ void handler_i_am_add(
|
||||
#endif
|
||||
if (len != -1) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, " from %u, MAC = %d.%d.%d.%d.%d.%d\n",device_id,
|
||||
src->mac[0],src->mac[1],src->mac[2],
|
||||
src->mac[3],src->mac[4],src->mac[5]);
|
||||
fprintf(stderr, " from %u, MAC = %d.%d.%d.%d.%d.%d\n", device_id,
|
||||
src->mac[0], src->mac[1], src->mac[2], src->mac[3], src->mac[4],
|
||||
src->mac[5]);
|
||||
#endif
|
||||
address_add(device_id, max_apdu, src);
|
||||
} else {
|
||||
|
||||
@@ -43,12 +43,12 @@ bool handler_lso(
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||
{
|
||||
BACNET_LSO_DATA data;
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
int bytes_sent = 0;
|
||||
BACNET_ADDRESS my_address;
|
||||
BACNET_LSO_DATA data;
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
int bytes_sent = 0;
|
||||
BACNET_ADDRESS my_address;
|
||||
|
||||
/* encode the NPDU portion of the packet */
|
||||
datalink_get_my_address(&my_address);
|
||||
@@ -84,24 +84,20 @@ bool handler_lso(
|
||||
goto LSO_ABORT;
|
||||
}
|
||||
|
||||
/*
|
||||
** Process Life Safety Operation Here
|
||||
*/
|
||||
/*
|
||||
** Process Life Safety Operation Here
|
||||
*/
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"Life Safety Operation: Received operation %d from process id %d for object %id\n",
|
||||
data.operation,
|
||||
data.processId,
|
||||
data.targetObject.instance);
|
||||
"Life Safety Operation: Received operation %d from process id %d for object %id\n",
|
||||
data.operation, data.processId, data.targetObject.instance);
|
||||
#endif
|
||||
|
||||
len =
|
||||
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id,
|
||||
SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"Life Safety Operation: " "Sending Simple Ack!\n");
|
||||
fprintf(stderr, "Life Safety Operation: " "Sending Simple Ack!\n");
|
||||
#endif
|
||||
|
||||
LSO_ABORT:
|
||||
@@ -111,11 +107,9 @@ bool handler_lso(
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0)
|
||||
fprintf(stderr,
|
||||
"Life Safety Operation: " "Failed to send PDU (%s)!\n",
|
||||
fprintf(stderr, "Life Safety Operation: " "Failed to send PDU (%s)!\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -421,15 +421,14 @@ void handler_read_property_multiple(
|
||||
/* handle the error code - but use the special property */
|
||||
len =
|
||||
RPM_Encode_Property(&Handler_Transmit_Buffer[0],
|
||||
npdu_len + apdu_len, MAX_APDU,
|
||||
object_type, object_instance, object_property,
|
||||
array_index);
|
||||
npdu_len + apdu_len, MAX_APDU, object_type,
|
||||
object_instance, object_property, array_index);
|
||||
if (len > 0) {
|
||||
apdu_len += len;
|
||||
} else {
|
||||
apdu_len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
|
||||
service_data->invoke_id,
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer
|
||||
[npdu_len], service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
goto RPM_ABORT;
|
||||
}
|
||||
@@ -440,9 +439,8 @@ void handler_read_property_multiple(
|
||||
special_object_property, index);
|
||||
len =
|
||||
RPM_Encode_Property(&Handler_Transmit_Buffer[0],
|
||||
npdu_len + apdu_len, MAX_APDU,
|
||||
object_type, object_instance, object_property,
|
||||
array_index);
|
||||
npdu_len + apdu_len, MAX_APDU, object_type,
|
||||
object_instance, object_property, array_index);
|
||||
if (len > 0) {
|
||||
apdu_len += len;
|
||||
} else {
|
||||
|
||||
@@ -50,10 +50,10 @@ static int rpm_ack_decode_service_request(
|
||||
BACNET_READ_ACCESS_DATA * read_access_data)
|
||||
{
|
||||
int decoded_len = 0; /* return value */
|
||||
uint32_t error_value = 0; /* decoded error value */
|
||||
uint32_t error_value = 0; /* decoded error value */
|
||||
int len = 0; /* number of bytes returned from decoding */
|
||||
uint8_t tag_number = 0; /* decoded tag number */
|
||||
uint32_t len_value = 0; /* decoded length value */
|
||||
uint8_t tag_number = 0; /* decoded tag number */
|
||||
uint32_t len_value = 0; /* decoded length value */
|
||||
BACNET_READ_ACCESS_DATA *rpm_object;
|
||||
BACNET_READ_ACCESS_DATA *old_rpm_object;
|
||||
BACNET_PROPERTY_REFERENCE *rpm_property;
|
||||
@@ -108,12 +108,12 @@ static int rpm_ack_decode_service_request(
|
||||
while (value && (apdu_len > 0)) {
|
||||
if (decode_is_context_specific(apdu)) {
|
||||
len =
|
||||
bacapp_decode_context_data(
|
||||
apdu, apdu_len, value,
|
||||
rpm_property->propertyIdentifier);
|
||||
bacapp_decode_context_data(apdu, apdu_len, value,
|
||||
rpm_property->propertyIdentifier);
|
||||
} else {
|
||||
len =
|
||||
bacapp_decode_application_data(apdu, apdu_len, value);
|
||||
bacapp_decode_application_data(apdu, apdu_len,
|
||||
value);
|
||||
}
|
||||
decoded_len += len;
|
||||
apdu_len -= len;
|
||||
@@ -137,8 +137,7 @@ static int rpm_ack_decode_service_request(
|
||||
apdu++;
|
||||
/* decode the class and code sequence */
|
||||
len =
|
||||
decode_tag_number_and_value(apdu, &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(apdu, &tag_number, &len_value);
|
||||
decoded_len += len;
|
||||
apdu_len -= len;
|
||||
apdu += len;
|
||||
@@ -149,13 +148,12 @@ static int rpm_ack_decode_service_request(
|
||||
apdu_len -= len;
|
||||
apdu += len;
|
||||
len =
|
||||
decode_tag_number_and_value(apdu, &tag_number,
|
||||
&len_value);
|
||||
decode_tag_number_and_value(apdu, &tag_number, &len_value);
|
||||
decoded_len += len;
|
||||
apdu_len -= len;
|
||||
apdu += len;
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len = decode_enumerated(apdu, len_value, &error_value);
|
||||
len = decode_enumerated(apdu, len_value, &error_value);
|
||||
rpm_property->error.error_code = error_value;
|
||||
decoded_len += len;
|
||||
apdu_len -= len;
|
||||
@@ -242,10 +240,10 @@ static void PrintReadPropertyMultipleData(
|
||||
#if PRINT_ENABLED
|
||||
/* AccessError */
|
||||
fprintf(stdout, "BACnet Error: %s: %s\r\n",
|
||||
bactext_error_class_name(
|
||||
(int)listOfProperties->error.error_class),
|
||||
bactext_error_code_name(
|
||||
(int)listOfProperties->error.error_code));
|
||||
bactext_error_class_name((int) listOfProperties->error.
|
||||
error_class),
|
||||
bactext_error_code_name((int) listOfProperties->error.
|
||||
error_code));
|
||||
#endif
|
||||
}
|
||||
listOfProperties = listOfProperties->next;
|
||||
|
||||
@@ -325,8 +325,7 @@ static void address_parse(BACNET_ADDRESS * dst,
|
||||
dst->mac_len = 6;
|
||||
for (index = 0; index < 4; index++) {
|
||||
dst->mac[index] = mac[index];
|
||||
}
|
||||
encode_unsigned16(&dst->mac[4],
|
||||
} encode_unsigned16(&dst->mac[4],
|
||||
port);
|
||||
} else {
|
||||
count =
|
||||
|
||||
@@ -99,11 +99,12 @@ static void dlmstp_millisecond_timer(
|
||||
}
|
||||
|
||||
#if !defined (_WIN32)
|
||||
void Sleep(unsigned long milliseconds)
|
||||
void Sleep(
|
||||
unsigned long milliseconds)
|
||||
{
|
||||
struct timespec timeOut, remains;
|
||||
|
||||
timeOut.tv_sec = milliseconds/1000;
|
||||
timeOut.tv_sec = milliseconds / 1000;
|
||||
timeOut.tv_nsec = (milliseconds - (timeOut.tv_sec * 1000)) * 10000000;
|
||||
nanosleep(&timeOut, &remains);
|
||||
}
|
||||
@@ -165,7 +166,8 @@ uint16_t MSTP_Get_Reply(
|
||||
static char Capture_Filename[32] = "mstp_20090123091200.cap";
|
||||
static FILE *pFile = NULL; /* stream pointer */
|
||||
|
||||
static void filename_create(char *filename)
|
||||
static void filename_create(
|
||||
char *filename)
|
||||
{
|
||||
time_t my_time;
|
||||
struct tm *today;
|
||||
@@ -173,13 +175,9 @@ static void filename_create(char *filename)
|
||||
if (filename) {
|
||||
my_time = time(NULL);
|
||||
today = localtime(&my_time);
|
||||
sprintf(filename,"mstp_%04d%02d%02d%02d%02d%02d.cap",
|
||||
1900+today->tm_year,
|
||||
1+today->tm_mon,
|
||||
today->tm_mday,
|
||||
today->tm_hour,
|
||||
today->tm_min,
|
||||
today->tm_sec);
|
||||
sprintf(filename, "mstp_%04d%02d%02d%02d%02d%02d.cap",
|
||||
1900 + today->tm_year, 1 + today->tm_mon, today->tm_mday,
|
||||
today->tm_hour, today->tm_min, today->tm_sec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,13 +196,13 @@ static void write_global_header(
|
||||
/* create a new file. */
|
||||
pFile = fopen(filename, "wb");
|
||||
if (pFile) {
|
||||
(void)fwrite(&magic_number, sizeof(magic_number), 1, pFile);
|
||||
(void)fwrite(&version_major, sizeof(version_major), 1, pFile);
|
||||
(void)fwrite(&version_minor, sizeof(version_minor), 1, pFile);
|
||||
(void)fwrite(&thiszone, sizeof(thiszone), 1, pFile);
|
||||
(void)fwrite(&sigfigs, sizeof(sigfigs), 1, pFile);
|
||||
(void)fwrite(&snaplen, sizeof(snaplen), 1, pFile);
|
||||
(void)fwrite(&network, sizeof(network), 1, pFile);
|
||||
(void) fwrite(&magic_number, sizeof(magic_number), 1, pFile);
|
||||
(void) fwrite(&version_major, sizeof(version_major), 1, pFile);
|
||||
(void) fwrite(&version_minor, sizeof(version_minor), 1, pFile);
|
||||
(void) fwrite(&thiszone, sizeof(thiszone), 1, pFile);
|
||||
(void) fwrite(&sigfigs, sizeof(sigfigs), 1, pFile);
|
||||
(void) fwrite(&snaplen, sizeof(snaplen), 1, pFile);
|
||||
(void) fwrite(&network, sizeof(network), 1, pFile);
|
||||
fflush(pFile);
|
||||
fprintf(stdout, "mstpcap: saving capture to %s\n", filename);
|
||||
} else {
|
||||
@@ -228,16 +226,16 @@ static void write_received_packet(
|
||||
gettimeofday(&tv, NULL);
|
||||
ts_sec = tv.tv_sec;
|
||||
ts_usec = tv.tv_usec;
|
||||
(void)fwrite(&ts_sec, sizeof(ts_sec), 1, pFile);
|
||||
(void)fwrite(&ts_usec, sizeof(ts_usec), 1, pFile);
|
||||
(void) fwrite(&ts_sec, sizeof(ts_sec), 1, pFile);
|
||||
(void) fwrite(&ts_usec, sizeof(ts_usec), 1, pFile);
|
||||
if (mstp_port->DataLength) {
|
||||
max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength);
|
||||
incl_len = orig_len = 8 + max_data + 2;
|
||||
} else {
|
||||
incl_len = orig_len = 8;
|
||||
}
|
||||
(void)fwrite(&incl_len, sizeof(incl_len), 1, pFile);
|
||||
(void)fwrite(&orig_len, sizeof(orig_len), 1, pFile);
|
||||
(void) fwrite(&incl_len, sizeof(incl_len), 1, pFile);
|
||||
(void) fwrite(&orig_len, sizeof(orig_len), 1, pFile);
|
||||
header[0] = 0x55;
|
||||
header[1] = 0xFF;
|
||||
header[2] = mstp_port->FrameType;
|
||||
@@ -246,11 +244,11 @@ static void write_received_packet(
|
||||
header[5] = HI_BYTE(mstp_port->DataLength);
|
||||
header[6] = LO_BYTE(mstp_port->DataLength);
|
||||
header[7] = mstp_port->HeaderCRCActual;
|
||||
(void)fwrite(header, sizeof(header), 1, pFile);
|
||||
(void) fwrite(header, sizeof(header), 1, pFile);
|
||||
if (mstp_port->DataLength) {
|
||||
(void)fwrite(mstp_port->InputBuffer, max_data, 1, pFile);
|
||||
(void)fwrite((char *) &mstp_port->DataCRCActualMSB, 1, 1, pFile);
|
||||
(void)fwrite((char *) &mstp_port->DataCRCActualLSB, 1, 1, pFile);
|
||||
(void) fwrite(mstp_port->InputBuffer, max_data, 1, pFile);
|
||||
(void) fwrite((char *) &mstp_port->DataCRCActualMSB, 1, 1, pFile);
|
||||
(void) fwrite((char *) &mstp_port->DataCRCActualLSB, 1, 1, pFile);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "mstpcap: failed to open %s: %s\n", Capture_Filename,
|
||||
@@ -287,7 +285,8 @@ void signal_init(
|
||||
}
|
||||
#endif
|
||||
|
||||
void filename_create_new(void)
|
||||
void filename_create_new(
|
||||
void)
|
||||
{
|
||||
if (pFile) {
|
||||
fclose(pFile);
|
||||
@@ -320,14 +319,11 @@ int main(
|
||||
"Captures MS/TP packets from a serial interface\r\n"
|
||||
"and save them to a file. Saves packets in a\r\n"
|
||||
"filename mstp_20090123091200.cap that has data and time.\r\n"
|
||||
"After receiving 65535 packets, a new file is created.\r\n"
|
||||
"\r\n"
|
||||
"Command line options:\r\n"
|
||||
"[interface] - serial interface.\r\n"
|
||||
"After receiving 65535 packets, a new file is created.\r\n" "\r\n"
|
||||
"Command line options:\r\n" "[interface] - serial interface.\r\n"
|
||||
" defaults to COM4 on Windows, and /dev/ttyUSB0 on linux.\r\n"
|
||||
"[baud] - baud rate. 9600, 19200, 38400, 57600, 115200\r\n"
|
||||
" defaults to 38400.\r\n"
|
||||
"");
|
||||
" defaults to 38400.\r\n" "");
|
||||
return 0;
|
||||
}
|
||||
if (argc > 1) {
|
||||
|
||||
@@ -174,14 +174,14 @@ static void Init_DataLink(
|
||||
pEnv = getenv("BACNET_MSTP_BAUD");
|
||||
if (pEnv) {
|
||||
RS485_Set_Baud_Rate(strtol(pEnv, NULL, 0));
|
||||
fprintf(stderr, "BACNET_MSTP_BAUD=%s\r\n",pEnv);
|
||||
fprintf(stderr, "BACNET_MSTP_BAUD=%s\r\n", pEnv);
|
||||
} else {
|
||||
RS485_Set_Baud_Rate(38400);
|
||||
}
|
||||
pEnv = getenv("BACNET_APDU_TIMEOUT");
|
||||
if (pEnv) {
|
||||
apdu_timeout_set(strtol(pEnv, NULL, 0));
|
||||
fprintf(stderr, "BACNET_APDU_TIMEOUT=%s\r\n",pEnv);
|
||||
fprintf(stderr, "BACNET_APDU_TIMEOUT=%s\r\n", pEnv);
|
||||
}
|
||||
pEnv = getenv("BACNET_MSTP_MAC");
|
||||
if (pEnv) {
|
||||
|
||||
@@ -230,7 +230,8 @@ void cleanup(void) {
|
||||
old_rpm_property = rpm_property;
|
||||
rpm_property = rpm_property->next;
|
||||
free(old_rpm_property);
|
||||
} old_rpm_object = rpm_object;
|
||||
}
|
||||
old_rpm_object = rpm_object;
|
||||
rpm_object = rpm_object->next;
|
||||
free(old_rpm_object);
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ int main(int argc, char *argv[]) {
|
||||
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
|
||||
return 0;
|
||||
}
|
||||
/* decode the command line parameters */ cov_data.
|
||||
subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
|
||||
/* decode the command line parameters */
|
||||
cov_data.subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
|
||||
cov_data.initiatingDeviceIdentifier = strtol(argv[2], NULL, 0);
|
||||
cov_data.monitoredObjectIdentifier.type = strtol(argv[3], NULL, 0);
|
||||
cov_data.monitoredObjectIdentifier.instance = strtol(argv[4], NULL, 0);
|
||||
|
||||
Reference in New Issue
Block a user