indented using indent.sh script to get uniform looking code for release

This commit is contained in:
skarg
2013-03-13 22:17:13 +00:00
parent 2de46521b8
commit ba3242aafd
120 changed files with 3382 additions and 3299 deletions
+2 -1
View File
@@ -211,7 +211,8 @@ int main(
} }
/* at least one second has passed */ /* at least one second has passed */
if (current_seconds != last_seconds) if (current_seconds != last_seconds)
tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); tsm_timer_milliseconds((uint16_t) ((current_seconds -
last_seconds) * 1000));
if (Error_Detected) if (Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
+17 -12
View File
@@ -141,7 +141,8 @@ static struct property_value_list_t Property_Value_List[] = {
{-1, NULL} {-1, NULL}
}; };
static BACNET_APPLICATION_DATA_VALUE *object_property_value(int32_t property_id) static BACNET_APPLICATION_DATA_VALUE *object_property_value(
int32_t property_id)
{ {
BACNET_APPLICATION_DATA_VALUE *value = NULL; BACNET_APPLICATION_DATA_VALUE *value = NULL;
int32_t index = 0; int32_t index = 0;
@@ -414,8 +415,10 @@ void CheckIsWritableProperty(
bIsWritable = true; bIsWritable = true;
} }
} else if (object_type == OBJECT_NETWORK_SECURITY) { } else if (object_type == OBJECT_NETWORK_SECURITY) {
if ((rpm_property->propertyIdentifier == PROP_BASE_DEVICE_SECURITY_POLICY) || if ((rpm_property->propertyIdentifier ==
(rpm_property->propertyIdentifier == PROP_NETWORK_ACCESS_SECURITY_POLICIES) || PROP_BASE_DEVICE_SECURITY_POLICY) ||
(rpm_property->propertyIdentifier ==
PROP_NETWORK_ACCESS_SECURITY_POLICIES) ||
(rpm_property->propertyIdentifier == PROP_SECURITY_TIME_WINDOW) || (rpm_property->propertyIdentifier == PROP_SECURITY_TIME_WINDOW) ||
(rpm_property->propertyIdentifier == PROP_PACKET_REORDER_TIME) || (rpm_property->propertyIdentifier == PROP_PACKET_REORDER_TIME) ||
(rpm_property->propertyIdentifier == PROP_LAST_KEY_SERVER) || (rpm_property->propertyIdentifier == PROP_LAST_KEY_SERVER) ||
@@ -434,7 +437,8 @@ void CheckIsWritableProperty(
} }
static const char *protocol_services_supported_text(size_t bit_index) static const char *protocol_services_supported_text(
size_t bit_index)
{ {
bool is_confirmed = false; bool is_confirmed = false;
size_t text_index = 0; size_t text_index = 0;
@@ -1155,8 +1159,7 @@ void PrintHeading(
printf("Product Description: \"%s\"\r\n\r\n", printf("Product Description: \"%s\"\r\n\r\n",
characterstring_value(&value->type.Character_String)); characterstring_value(&value->type.Character_String));
} else { } else {
printf( printf("Product Description: "
"Product Description: "
"\"your product description here\"\r\n\r\n"); "\"your product description here\"\r\n\r\n");
} }
printf("BIBBs Supported:\r\n"); printf("BIBBs Supported:\r\n");
@@ -1220,7 +1223,8 @@ void PrintHeading(
printf("-- SubscribeCOVProperty Initiate Execute\r\n"); printf("-- SubscribeCOVProperty Initiate Execute\r\n");
#ifdef BAC_ROUTING #ifdef BAC_ROUTING
if (Target_Address.net == 0) { if (Target_Address.net == 0) {
printf("-- Note: The following Routing Services are Supported:\r\n"); printf
("-- Note: The following Routing Services are Supported:\r\n");
printf("-- Who-Is-Router-To-Network Initiate Execute\r\n"); printf("-- Who-Is-Router-To-Network Initiate Execute\r\n");
printf("-- I-Am-Router-To-Network Initiate Execute\r\n"); printf("-- I-Am-Router-To-Network Initiate Execute\r\n");
printf("-- Initialize-Routing-Table Execute\r\n"); printf("-- Initialize-Routing-Table Execute\r\n");
@@ -1441,7 +1445,8 @@ int main(
current_seconds = time(NULL); current_seconds = time(NULL);
/* Has at least one second passed ? */ /* Has at least one second passed ? */
if (current_seconds != last_seconds) { if (current_seconds != last_seconds) {
tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); tsm_timer_milliseconds((uint16_t) ((current_seconds -
last_seconds) * 1000));
} }
/* OK to proceed; see what we are up to now */ /* OK to proceed; see what we are up to now */
@@ -1629,11 +1634,11 @@ int main(
(Request_Invoke_ID == (Request_Invoke_ID ==
Read_Property_Multiple_Data.service_data.invoke_id)) { Read_Property_Multiple_Data.service_data.invoke_id)) {
Read_Property_Multiple_Data.new_data = false; Read_Property_Multiple_Data.new_data = false;
PrintReadPropertyData PrintReadPropertyData(Read_Property_Multiple_Data.
(Read_Property_Multiple_Data.rpm_data->object_type, rpm_data->object_type,
Read_Property_Multiple_Data.rpm_data->object_instance, Read_Property_Multiple_Data.rpm_data->object_instance,
Read_Property_Multiple_Data. Read_Property_Multiple_Data.rpm_data->
rpm_data->listOfProperties); listOfProperties);
if (tsm_invoke_id_free(Request_Invoke_ID)) { if (tsm_invoke_id_free(Request_Invoke_ID)) {
Request_Invoke_ID = 0; Request_Invoke_ID = 0;
} else { } else {
+2 -2
View File
@@ -125,8 +125,8 @@ void handler_ccov_notification(
fprintf(stderr, "CCOV: "); fprintf(stderr, "CCOV: ");
if (pProperty_value->propertyIdentifier < 512) { if (pProperty_value->propertyIdentifier < 512) {
fprintf(stderr, "%s ", fprintf(stderr, "%s ",
bactext_property_name(pProperty_value-> bactext_property_name
propertyIdentifier)); (pProperty_value->propertyIdentifier));
} else { } else {
fprintf(stderr, "proprietary %u ", fprintf(stderr, "proprietary %u ",
pProperty_value->propertyIdentifier); pProperty_value->propertyIdentifier);
+13 -12
View File
@@ -408,8 +408,8 @@ static void cov_lifetime_expiration_handler(
fprintf(stderr, "COVtimer: PID=%u ", fprintf(stderr, "COVtimer: PID=%u ",
COV_Subscriptions[index].subscriberProcessIdentifier); COV_Subscriptions[index].subscriberProcessIdentifier);
fprintf(stderr, "%s %u ", fprintf(stderr, "%s %u ",
bactext_object_type_name( bactext_object_type_name(COV_Subscriptions[index].
COV_Subscriptions[index].monitoredObjectIdentifier.type), monitoredObjectIdentifier.type),
COV_Subscriptions[index].monitoredObjectIdentifier.instance); COV_Subscriptions[index].monitoredObjectIdentifier.instance);
fprintf(stderr, "time remaining=%u seconds ", fprintf(stderr, "time remaining=%u seconds ",
COV_Subscriptions[index].lifetime); COV_Subscriptions[index].lifetime);
@@ -497,8 +497,8 @@ void handler_cov_task(
object_type = (BACNET_OBJECT_TYPE) object_type = (BACNET_OBJECT_TYPE)
COV_Subscriptions[index].monitoredObjectIdentifier.type; COV_Subscriptions[index].monitoredObjectIdentifier.type;
object_instance = object_instance =
COV_Subscriptions[index].monitoredObjectIdentifier. COV_Subscriptions[index].
instance; monitoredObjectIdentifier.instance;
status = Device_COV(object_type, object_instance); status = Device_COV(object_type, object_instance);
if (status) { if (status) {
COV_Subscriptions[index].flag.send_requested = true; COV_Subscriptions[index].flag.send_requested = true;
@@ -520,8 +520,8 @@ void handler_cov_task(
object_type = (BACNET_OBJECT_TYPE) object_type = (BACNET_OBJECT_TYPE)
COV_Subscriptions[index].monitoredObjectIdentifier.type; COV_Subscriptions[index].monitoredObjectIdentifier.type;
object_instance = object_instance =
COV_Subscriptions[index].monitoredObjectIdentifier. COV_Subscriptions[index].
instance; monitoredObjectIdentifier.instance;
Device_COV_Clear(object_type, object_instance); Device_COV_Clear(object_type, object_instance);
} }
index++; index++;
@@ -537,8 +537,9 @@ void handler_cov_task(
(COV_Subscriptions[index].invokeID)) { (COV_Subscriptions[index].invokeID)) {
if (tsm_invoke_id_free(COV_Subscriptions[index].invokeID)) { if (tsm_invoke_id_free(COV_Subscriptions[index].invokeID)) {
COV_Subscriptions[index].invokeID = 0; COV_Subscriptions[index].invokeID = 0;
} else if (tsm_invoke_id_failed(COV_Subscriptions[index]. } else
invokeID)) { if (tsm_invoke_id_failed(COV_Subscriptions
[index].invokeID)) {
tsm_free_invoke_id(COV_Subscriptions[index].invokeID); tsm_free_invoke_id(COV_Subscriptions[index].invokeID);
COV_Subscriptions[index].invokeID = 0; COV_Subscriptions[index].invokeID = 0;
} }
@@ -566,11 +567,11 @@ void handler_cov_task(
} }
if (send) { if (send) {
object_type = (BACNET_OBJECT_TYPE) object_type = (BACNET_OBJECT_TYPE)
COV_Subscriptions[index].monitoredObjectIdentifier. COV_Subscriptions[index].
type; monitoredObjectIdentifier.type;
object_instance = object_instance =
COV_Subscriptions[index].monitoredObjectIdentifier. COV_Subscriptions[index].
instance; monitoredObjectIdentifier.instance;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "COVtask: Sending...\n"); fprintf(stderr, "COVtask: Sending...\n");
#endif #endif
+3 -4
View File
@@ -66,10 +66,9 @@ void get_alarm_summary_ack_handler(
BACNET_GET_ALARM_SUMMARY_DATA data; BACNET_GET_ALARM_SUMMARY_DATA data;
while (service_len - len) { while (service_len - len) {
apdu_len = get_alarm_summary_ack_decode_apdu_data( apdu_len =
&service_request[len], get_alarm_summary_ack_decode_apdu_data(&service_request[len],
service_len - len, service_len - len, &data);
&data);
len += apdu_len; len += apdu_len;
+6 -6
View File
@@ -221,8 +221,8 @@ void rpm_ack_print_data(
#if PRINT_ENABLED #if PRINT_ENABLED
if (listOfProperties->propertyIdentifier < 512) { if (listOfProperties->propertyIdentifier < 512) {
fprintf(stdout, " %s: ", fprintf(stdout, " %s: ",
bactext_property_name bactext_property_name(listOfProperties->
(listOfProperties->propertyIdentifier)); propertyIdentifier));
} else { } else {
fprintf(stdout, " proprietary %u: ", fprintf(stdout, " proprietary %u: ",
(unsigned) listOfProperties->propertyIdentifier); (unsigned) listOfProperties->propertyIdentifier);
@@ -269,10 +269,10 @@ void rpm_ack_print_data(
#if PRINT_ENABLED #if PRINT_ENABLED
/* AccessError */ /* AccessError */
fprintf(stdout, "BACnet Error: %s: %s\r\n", fprintf(stdout, "BACnet Error: %s: %s\r\n",
bactext_error_class_name((int) listOfProperties->error. bactext_error_class_name((int) listOfProperties->
error_class), error.error_class),
bactext_error_code_name((int) listOfProperties->error. bactext_error_code_name((int) listOfProperties->
error_code)); error.error_code));
#endif #endif
} }
listOfProperties = listOfProperties->next; listOfProperties = listOfProperties->next;
+2 -2
View File
@@ -104,8 +104,8 @@ void handler_ucov_notification(
fprintf(stderr, "UCOV: "); fprintf(stderr, "UCOV: ");
if (pProperty_value->propertyIdentifier < 512) { if (pProperty_value->propertyIdentifier < 512) {
fprintf(stderr, "%s ", fprintf(stderr, "%s ",
bactext_property_name(pProperty_value-> bactext_property_name
propertyIdentifier)); (pProperty_value->propertyIdentifier));
} else { } else {
fprintf(stderr, "proprietary %u ", fprintf(stderr, "proprietary %u ",
pProperty_value->propertyIdentifier); pProperty_value->propertyIdentifier);
+3 -2
View File
@@ -65,8 +65,9 @@ static void match_name_or_object(
} else { } else {
/* valid object_name copy in my device? */ /* valid object_name copy in my device? */
found = found =
Device_Object_Name_Copy((BACNET_OBJECT_TYPE) data->object. Device_Object_Name_Copy((BACNET_OBJECT_TYPE) data->
identifier.type, data->object.identifier.instance, &object_name); object.identifier.type, data->object.identifier.instance,
&object_name);
if (found) { if (found) {
Send_I_Have(Device_Object_Instance_Number(), Send_I_Have(Device_Object_Instance_Number(),
(BACNET_OBJECT_TYPE) data->object.identifier.type, (BACNET_OBJECT_TYPE) data->object.identifier.type,
+3 -4
View File
@@ -175,10 +175,9 @@ void handler_write_property_multiple(
fprintf(stderr, "WPM: Sending Abort!\n"); fprintf(stderr, "WPM: Sending Abort!\n");
#endif #endif
} else if (len == BACNET_STATUS_ERROR) { } else if (len == BACNET_STATUS_ERROR) {
apdu_len = wpm_error_ack_encode_apdu( apdu_len =
&Handler_Transmit_Buffer[npdu_len], wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, service_data->invoke_id, &wp_data);
&wp_data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Error!\n"); fprintf(stderr, "WPM: Sending Error!\n");
#endif #endif
+3 -4
View File
@@ -157,10 +157,9 @@ uint8_t Send_Read_Property_Request(
/* is the device bound? */ /* is the device bound? */
status = address_get_by_device(device_id, &max_apdu, &dest); status = address_get_by_device(device_id, &max_apdu, &dest);
if (status) { if (status) {
invoke_id = Send_Read_Property_Request_Address( invoke_id =
&dest, max_apdu, object_type, Send_Read_Property_Request_Address(&dest, max_apdu, object_type,
object_instance, object_property, object_instance, object_property, array_index);
array_index);
} }
return invoke_id; return invoke_id;
+3 -2
View File
@@ -157,8 +157,9 @@ uint8_t Send_Write_Property_Request(
#if PRINT_ENABLED_DEBUG #if PRINT_ENABLED_DEBUG
fprintf(stderr, "WriteProperty service: " "%s tag=%d\n", fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
(object_value->context_specific ? "context" : "application"), (object_value->context_specific ? "context" : "application"),
(int) (object_value->context_specific ? object_value-> (int) (object_value->
context_tag : object_value->tag)); context_specific ? object_value->context_tag : object_value->
tag));
#endif #endif
len = bacapp_encode_data(&application_data[apdu_len], object_value); len = bacapp_encode_data(&application_data[apdu_len], object_value);
if ((len + apdu_len) < MAX_APDU) { if ((len + apdu_len) < MAX_APDU) {
+66 -72
View File
@@ -352,11 +352,11 @@ int Analog_Input_Read_Property(
case PROP_LIMIT_ENABLE: case PROP_LIMIT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, 0, bitstring_set_bit(&bit_string, 0,
(CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : (CurrentAI->
false); Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false);
bitstring_set_bit(&bit_string, 1, bitstring_set_bit(&bit_string, 1,
(CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : (CurrentAI->
false); Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
@@ -364,14 +364,14 @@ int Analog_Input_Read_Property(
case PROP_EVENT_ENABLE: case PROP_EVENT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : (CurrentAI->
false); Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(CurrentAI->Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : (CurrentAI->
false); Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : (CurrentAI->
false); Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
@@ -379,8 +379,8 @@ int Analog_Input_Read_Property(
case PROP_ACKED_TRANSITIONS: case PROP_ACKED_TRANSITIONS:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
CurrentAI-> CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
@@ -922,17 +922,17 @@ void Analog_Input_Intrinsic_Reporting(
event_data.notificationParams.outOfRange.exceedingValue = event_data.notificationParams.outOfRange.exceedingValue =
PresentVal; PresentVal;
/* Status_Flags of the referenced object. */ /* Status_Flags of the referenced object. */
bitstring_init(&event_data.notificationParams. bitstring_init(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags); statusFlags);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_IN_ALARM, statusFlags, STATUS_FLAG_IN_ALARM,
CurrentAI->Event_State ? true : false); CurrentAI->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_FAULT, false); statusFlags, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_OVERRIDDEN, false); statusFlags, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_OUT_OF_SERVICE, statusFlags, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAI->Out_Of_Service); CurrentAI->Out_Of_Service);
/* Deadband used for limit checking. */ /* Deadband used for limit checking. */
event_data.notificationParams.outOfRange.deadband = event_data.notificationParams.outOfRange.deadband =
@@ -952,30 +952,24 @@ void Analog_Input_Intrinsic_Reporting(
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAI-> CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = bIsAcked = false;
false; CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
CurrentAI-> Time_Stamp = event_data.timeStamp.value.dateTime;
Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp =
event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAI-> CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].
Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = bIsAcked = false;
false; CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].
CurrentAI-> Time_Stamp = event_data.timeStamp.value.dateTime;
Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp =
event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAI-> CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].
Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = bIsAcked = false;
false; CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].
CurrentAI-> Time_Stamp = event_data.timeStamp.value.dateTime;
Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp =
event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -1002,12 +996,12 @@ int Analog_Input_Event_Information(
/* Acked_Transitions property, which has at least one of the bits /* Acked_Transitions property, which has at least one of the bits
(TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */
IsNotAckedTransitions = IsNotAckedTransitions =
(AI_Descr[index]. (AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == bIsAcked ==
false) | (AI_Descr[index]. false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].
Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == bIsAcked ==
false) | (AI_Descr[index]. false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].
Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); bIsAcked == false);
} else } else
return -1; /* end of list */ return -1; /* end of list */
@@ -1022,8 +1016,8 @@ int Analog_Input_Event_Information(
bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_init(&getevent_data->acknowledgedTransitions);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_OFFNORMAL, TRANSITION_TO_OFFNORMAL,
AI_Descr[index]. AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_FAULT, TRANSITION_TO_FAULT,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
@@ -1041,14 +1035,14 @@ int Analog_Input_Event_Information(
/* Event Enable */ /* Event Enable */
bitstring_init(&getevent_data->eventEnable); bitstring_init(&getevent_data->eventEnable);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL,
(AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : (AI_Descr[index].
false); Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT,
(AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : (AI_Descr[index].
false); Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL,
(AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : (AI_Descr[index].
false); Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
/* Event Priorities */ /* Event Priorities */
Notification_Class_Get_Priorities(AI_Descr[index].Notification_Class, Notification_Class_Get_Priorities(AI_Descr[index].Notification_Class,
getevent_data->eventPriorities); getevent_data->eventPriorities);
@@ -1068,8 +1062,8 @@ int Analog_Input_Alarm_Ack(
object_index = object_index =
Analog_Input_Instance_To_Index(alarmack_data-> Analog_Input_Instance_To_Index(alarmack_data->eventObjectIdentifier.
eventObjectIdentifier.instance); instance);
if (object_index < MAX_ANALOG_INPUTS) if (object_index < MAX_ANALOG_INPUTS)
CurrentAI = &AI_Descr[object_index]; CurrentAI = &AI_Descr[object_index];
@@ -1082,22 +1076,22 @@ int Analog_Input_Alarm_Ack(
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
if (CurrentAI-> if (CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { bIsAcked == false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) { if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if (datetime_compare(&CurrentAI->Acked_Transitions if (datetime_compare(&CurrentAI->
[TRANSITION_TO_OFFNORMAL].Time_Stamp, Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) { &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* FIXME: Send ack notification */ /* FIXME: Send ack notification */
CurrentAI-> CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; bIsAcked = true;
} else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
@@ -1111,8 +1105,8 @@ int Analog_Input_Alarm_Ack(
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if (datetime_compare(&CurrentAI->Acked_Transitions if (datetime_compare(&CurrentAI->
[TRANSITION_TO_FAULT].Time_Stamp, Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) { &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
@@ -1134,8 +1128,8 @@ int Analog_Input_Alarm_Ack(
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if (datetime_compare(&CurrentAI->Acked_Transitions if (datetime_compare(&CurrentAI->
[TRANSITION_TO_NORMAL].Time_Stamp, Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) { &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
@@ -1180,16 +1174,16 @@ int Analog_Input_Alarm_Summary(
bitstring_init(&getalarm_data->acknowledgedTransitions); bitstring_init(&getalarm_data->acknowledgedTransitions);
bitstring_set_bit(&getalarm_data->acknowledgedTransitions, bitstring_set_bit(&getalarm_data->acknowledgedTransitions,
TRANSITION_TO_OFFNORMAL, TRANSITION_TO_OFFNORMAL,
AI_Descr[index]. AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); bIsAcked);
bitstring_set_bit(&getalarm_data->acknowledgedTransitions, bitstring_set_bit(&getalarm_data->acknowledgedTransitions,
TRANSITION_TO_FAULT, TRANSITION_TO_FAULT,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. AI_Descr[index].
bIsAcked); Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getalarm_data->acknowledgedTransitions, bitstring_set_bit(&getalarm_data->acknowledgedTransitions,
TRANSITION_TO_NORMAL, TRANSITION_TO_NORMAL,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. AI_Descr[index].
bIsAcked); Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
return 1; /* active alarm */ return 1; /* active alarm */
} else } else
+4 -4
View File
@@ -451,11 +451,11 @@ bool Analog_Output_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Analog_Output_Instance_To_Index(wp_data-> Analog_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
status = status =
Analog_Output_Present_Value_Relinquish(wp_data-> Analog_Output_Present_Value_Relinquish
object_instance, wp_data->priority); (wp_data->object_instance, wp_data->priority);
if (!status) { if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
+66 -72
View File
@@ -424,11 +424,11 @@ int Analog_Value_Read_Property(
case PROP_LIMIT_ENABLE: case PROP_LIMIT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, 0, bitstring_set_bit(&bit_string, 0,
(CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : (CurrentAV->
false); Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false);
bitstring_set_bit(&bit_string, 1, bitstring_set_bit(&bit_string, 1,
(CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : (CurrentAV->
false); Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
@@ -436,14 +436,14 @@ int Analog_Value_Read_Property(
case PROP_EVENT_ENABLE: case PROP_EVENT_ENABLE:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : (CurrentAV->
false); Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : (CurrentAV->
false); Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : (CurrentAV->
false); Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
@@ -451,8 +451,8 @@ int Analog_Value_Read_Property(
case PROP_ACKED_TRANSITIONS: case PROP_ACKED_TRANSITIONS:
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
CurrentAV-> CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
@@ -1017,17 +1017,17 @@ void Analog_Value_Intrinsic_Reporting(
event_data.notificationParams.outOfRange.exceedingValue = event_data.notificationParams.outOfRange.exceedingValue =
PresentVal; PresentVal;
/* Status_Flags of the referenced object. */ /* Status_Flags of the referenced object. */
bitstring_init(&event_data.notificationParams. bitstring_init(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags); statusFlags);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_IN_ALARM, statusFlags, STATUS_FLAG_IN_ALARM,
CurrentAV->Event_State ? true : false); CurrentAV->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_FAULT, false); statusFlags, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_OVERRIDDEN, false); statusFlags, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams. bitstring_set_bit(&event_data.notificationParams.outOfRange.
outOfRange.statusFlags, STATUS_FLAG_OUT_OF_SERVICE, statusFlags, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAV->Out_Of_Service); CurrentAV->Out_Of_Service);
/* Deadband used for limit checking. */ /* Deadband used for limit checking. */
event_data.notificationParams.outOfRange.deadband = event_data.notificationParams.outOfRange.deadband =
@@ -1047,30 +1047,24 @@ void Analog_Value_Intrinsic_Reporting(
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAV-> CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = bIsAcked = false;
false; CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
CurrentAV-> Time_Stamp = event_data.timeStamp.value.dateTime;
Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp =
event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAV-> CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = bIsAcked = false;
false; CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
CurrentAV-> Time_Stamp = event_data.timeStamp.value.dateTime;
Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp =
event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAV-> CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = bIsAcked = false;
false; CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
CurrentAV-> Time_Stamp = event_data.timeStamp.value.dateTime;
Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp =
event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -1097,12 +1091,12 @@ int Analog_Value_Event_Information(
/* Acked_Transitions property, which has at least one of the bits /* Acked_Transitions property, which has at least one of the bits
(TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */
IsNotAckedTransitions = IsNotAckedTransitions =
(AV_Descr[index]. (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == bIsAcked ==
false) | (AV_Descr[index]. false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].
Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == bIsAcked ==
false) | (AV_Descr[index]. false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].
Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); bIsAcked == false);
} else } else
return -1; /* end of list */ return -1; /* end of list */
@@ -1117,8 +1111,8 @@ int Analog_Value_Event_Information(
bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_init(&getevent_data->acknowledgedTransitions);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_OFFNORMAL, TRANSITION_TO_OFFNORMAL,
AV_Descr[index]. AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_FAULT, TRANSITION_TO_FAULT,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
@@ -1136,14 +1130,14 @@ int Analog_Value_Event_Information(
/* Event Enable */ /* Event Enable */
bitstring_init(&getevent_data->eventEnable); bitstring_init(&getevent_data->eventEnable);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : (AV_Descr[index].
false); Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : (AV_Descr[index].
false); Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false);
bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL,
(AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : (AV_Descr[index].
false); Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false);
/* Event Priorities */ /* Event Priorities */
Notification_Class_Get_Priorities(AV_Descr[index].Notification_Class, Notification_Class_Get_Priorities(AV_Descr[index].Notification_Class,
getevent_data->eventPriorities); getevent_data->eventPriorities);
@@ -1162,8 +1156,8 @@ int Analog_Value_Alarm_Ack(
object_index = object_index =
Analog_Value_Instance_To_Index(alarmack_data-> Analog_Value_Instance_To_Index(alarmack_data->eventObjectIdentifier.
eventObjectIdentifier.instance); instance);
if (object_index < MAX_ANALOG_VALUES) if (object_index < MAX_ANALOG_VALUES)
CurrentAV = &AV_Descr[object_index]; CurrentAV = &AV_Descr[object_index];
@@ -1176,22 +1170,22 @@ int Analog_Value_Alarm_Ack(
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
if (CurrentAV-> if (CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { bIsAcked == false) {
if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) { if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if (datetime_compare(&CurrentAV->Acked_Transitions if (datetime_compare(&CurrentAV->
[TRANSITION_TO_OFFNORMAL].Time_Stamp, Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) { &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
/* Clean transitions flag. */ /* Clean transitions flag. */
CurrentAV-> CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; bIsAcked = true;
} else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
@@ -1205,8 +1199,8 @@ int Analog_Value_Alarm_Ack(
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if (datetime_compare(&CurrentAV->Acked_Transitions if (datetime_compare(&CurrentAV->
[TRANSITION_TO_NORMAL].Time_Stamp, Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) { &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
@@ -1228,8 +1222,8 @@ int Analog_Value_Alarm_Ack(
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
} }
if (datetime_compare(&CurrentAV->Acked_Transitions if (datetime_compare(&CurrentAV->
[TRANSITION_TO_FAULT].Time_Stamp, Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
&alarmack_data->eventTimeStamp.value.dateTime) > 0) { &alarmack_data->eventTimeStamp.value.dateTime) > 0) {
*error_code = ERROR_CODE_INVALID_TIME_STAMP; *error_code = ERROR_CODE_INVALID_TIME_STAMP;
return -1; return -1;
@@ -1277,16 +1271,16 @@ int Analog_Value_Alarm_Summary(
bitstring_init(&getalarm_data->acknowledgedTransitions); bitstring_init(&getalarm_data->acknowledgedTransitions);
bitstring_set_bit(&getalarm_data->acknowledgedTransitions, bitstring_set_bit(&getalarm_data->acknowledgedTransitions,
TRANSITION_TO_OFFNORMAL, TRANSITION_TO_OFFNORMAL,
AV_Descr[index]. AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); bIsAcked);
bitstring_set_bit(&getalarm_data->acknowledgedTransitions, bitstring_set_bit(&getalarm_data->acknowledgedTransitions,
TRANSITION_TO_FAULT, TRANSITION_TO_FAULT,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. AV_Descr[index].
bIsAcked); Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getalarm_data->acknowledgedTransitions, bitstring_set_bit(&getalarm_data->acknowledgedTransitions,
TRANSITION_TO_NORMAL, TRANSITION_TO_NORMAL,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. AV_Descr[index].
bIsAcked); Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
return 1; /* active alarm */ return 1; /* active alarm */
} else } else
+4 -4
View File
@@ -383,8 +383,8 @@ bool Binary_Output_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = (BACNET_BINARY_PV) value.type.Enumerated; level = (BACNET_BINARY_PV) value.type.Enumerated;
object_index = object_index =
Binary_Output_Instance_To_Index(wp_data-> Binary_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Binary_Output_Level[object_index][priority] = level; Binary_Output_Level[object_index][priority] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
@@ -410,8 +410,8 @@ bool Binary_Output_Write_Property(
if (status) { if (status) {
level = BINARY_NULL; level = BINARY_NULL;
object_index = object_index =
Binary_Output_Instance_To_Index(wp_data-> Binary_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
+4 -4
View File
@@ -366,8 +366,8 @@ bool Binary_Value_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = (BACNET_BINARY_PV) value.type.Enumerated; level = (BACNET_BINARY_PV) value.type.Enumerated;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Binary_Value_Level[object_index][priority] = level; Binary_Value_Level[object_index][priority] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
@@ -393,8 +393,8 @@ bool Binary_Value_Write_Property(
if (status) { if (status) {
level = BINARY_NULL; level = BINARY_NULL;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
+6 -6
View File
@@ -357,8 +357,8 @@ int CharacterString_Value_Read_Property(
break; break;
case PROP_OUT_OF_SERVICE: case PROP_OUT_OF_SERVICE:
object_index = object_index =
CharacterString_Value_Instance_To_Index(rpdata-> CharacterString_Value_Instance_To_Index
object_instance); (rpdata->object_instance);
state = Out_Of_Service[object_index]; state = Out_Of_Service[object_index];
apdu_len = encode_application_boolean(&apdu[0], state); apdu_len = encode_application_boolean(&apdu[0], state);
break; break;
@@ -406,8 +406,8 @@ bool CharacterString_Value_Write_Property(
&wp_data->error_code); &wp_data->error_code);
if (status) { if (status) {
status = status =
CharacterString_Value_Present_Value_Set(wp_data-> CharacterString_Value_Present_Value_Set
object_instance, &value.type.Character_String); (wp_data->object_instance, &value.type.Character_String);
if (!status) { if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -419,8 +419,8 @@ bool CharacterString_Value_Write_Property(
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
CharacterString_Value_Out_Of_Service_Set(wp_data-> CharacterString_Value_Out_Of_Service_Set
object_instance, value.type.Boolean); (wp_data->object_instance, value.type.Boolean);
} }
break; break;
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
+12 -12
View File
@@ -1454,8 +1454,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* FIXME: we could send an I-Am broadcast to let the world know */ /* FIXME: we could send an I-Am broadcast to let the world know */
} else { } else {
status = false; status = false;
@@ -1488,8 +1488,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
/* FIXME: bounds check? */ /* FIXME: bounds check? */
Device_Set_Vendor_Identifier((uint16_t) value.type. Device_Set_Vendor_Identifier((uint16_t) value.
Unsigned_Int); type.Unsigned_Int);
} }
break; break;
case PROP_SYSTEM_STATUS: case PROP_SYSTEM_STATUS:
@@ -1539,8 +1539,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_LOC_LEN, true, WPValidateString(&value, MAX_DEV_LOC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Location(characterstring_value(&value.type. Device_Set_Location(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -1550,8 +1550,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_DESC_LEN, true, WPValidateString(&value, MAX_DEV_DESC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Description(characterstring_value(&value.type. Device_Set_Description(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -1560,8 +1560,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_MOD_LEN, true, WPValidateString(&value, MAX_DEV_MOD_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Model_Name(characterstring_value(&value.type. Device_Set_Model_Name(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -1573,8 +1573,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if (value.type.Unsigned_Int <= 255) { if (value.type.Unsigned_Int <= 255) {
dlmstp_set_max_info_frames((uint8_t) value.type. dlmstp_set_max_info_frames((uint8_t) value.
Unsigned_Int); type.Unsigned_Int);
} else { } else {
status = false; status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
+2 -6
View File
@@ -440,15 +440,11 @@ extern "C" {
* - The interface between the implemented Objects and the BAC-stack services, * - The interface between the implemented Objects and the BAC-stack services,
* specifically the handlers, which are mediated through function calls to * specifically the handlers, which are mediated through function calls to
* the Device object. * the Device object.
*/ *//** @defgroup ObjHelpers Object Helper Functions
/** @defgroup ObjHelpers Object Helper Functions
* @ingroup ObjFrmwk * @ingroup ObjFrmwk
* This section describes the function templates for the helper functions that * This section describes the function templates for the helper functions that
* provide common object support. * provide common object support.
*/ *//** @defgroup ObjIntf Handler-to-Object Interface Functions
/** @defgroup ObjIntf Handler-to-Object Interface Functions
* @ingroup ObjFrmwk * @ingroup ObjFrmwk
* This section describes the fairly limited set of functions that link the * This section describes the fairly limited set of functions that link the
* BAC-stack handlers to the BACnet Object instances. All of these calls are * BAC-stack handlers to the BACnet Object instances. All of these calls are
+4 -4
View File
@@ -492,8 +492,8 @@ bool Routed_Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Routed_Device_Set_Object_Instance_Number(value. (Routed_Device_Set_Object_Instance_Number(value.type.
type.Object_Id.instance))) { Object_Id.instance))) {
/* FIXME: we could send an I-Am broadcast to let the world know */ /* FIXME: we could send an I-Am broadcast to let the world know */
} else { } else {
status = false; status = false;
@@ -507,8 +507,8 @@ bool Routed_Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_NAME_LEN, false, WPValidateString(&value, MAX_DEV_NAME_LEN, false,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Routed_Device_Set_Object_Name(characterstring_encoding Routed_Device_Set_Object_Name(characterstring_encoding(&value.
(&value.type.Character_String), type.Character_String),
characterstring_value(&value.type.Character_String), characterstring_value(&value.type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
+8 -8
View File
@@ -466,8 +466,8 @@ int Lighting_Output_Read_Property(
object_index = object_index =
Lighting_Output_Instance_To_Index(rpdata->object_instance); Lighting_Output_Instance_To_Index(rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Lighting_Output_Level[object_index][rpdata-> if (Lighting_Output_Level[object_index][rpdata->array_index
array_index - 1] == LIGHTING_LEVEL_NULL) - 1] == LIGHTING_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]); apdu_len = encode_application_null(&apdu[0]);
else { else {
real_value = Lighting_Output_Level[object_index] real_value = Lighting_Output_Level[object_index]
@@ -551,11 +551,11 @@ bool Lighting_Output_Write_Property(
if (status) { if (status) {
level = LIGHTING_LEVEL_NULL; level = LIGHTING_LEVEL_NULL;
object_index = object_index =
Lighting_Output_Instance_To_Index(wp_data-> Lighting_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
status = status =
Lighting_Output_Present_Value_Relinquish(wp_data-> Lighting_Output_Present_Value_Relinquish
object_instance, wp_data->priority); (wp_data->object_instance, wp_data->priority);
if (wp_data->priority == 6) { if (wp_data->priority == 6) {
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off
algorithm and may not be used for other purposes in any algorithm and may not be used for other purposes in any
@@ -582,8 +582,8 @@ bool Lighting_Output_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Lighting_Output_Instance_To_Index(wp_data-> Lighting_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
Lighting_Output_Out_Of_Service[object_index] = Lighting_Output_Out_Of_Service[object_index] =
value.type.Boolean; value.type.Boolean;
} }
+4 -4
View File
@@ -338,8 +338,8 @@ bool Life_Safety_Point_Write_Property(
if (status) { if (status) {
if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) { if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) {
object_index = object_index =
Life_Safety_Point_Instance_To_Index(wp_data-> Life_Safety_Point_Instance_To_Index
object_instance); (wp_data->object_instance);
Life_Safety_Point_Mode[object_index] = Life_Safety_Point_Mode[object_index] =
value.type.Enumerated; value.type.Enumerated;
} else { } else {
@@ -355,8 +355,8 @@ bool Life_Safety_Point_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Life_Safety_Point_Instance_To_Index(wp_data-> Life_Safety_Point_Instance_To_Index
object_instance); (wp_data->object_instance);
Life_Safety_Point_Out_Of_Service[object_index] = Life_Safety_Point_Out_Of_Service[object_index] =
value.type.Boolean; value.type.Boolean;
} }
+41 -45
View File
@@ -277,10 +277,9 @@ static bool Multistate_Input_Description_Write(
if (length <= sizeof(Object_Description[index])) { if (length <= sizeof(Object_Description[index])) {
encoding = characterstring_encoding(char_string); encoding = characterstring_encoding(char_string);
if (encoding == CHARACTER_UTF8) { if (encoding == CHARACTER_UTF8) {
status = characterstring_ansi_copy( status =
Object_Description[index], characterstring_ansi_copy(Object_Description[index],
sizeof(Object_Description[index]), sizeof(Object_Description[index]), char_string);
char_string);
if (!status) { if (!status) {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -361,10 +360,9 @@ static bool Multistate_Input_Object_Name_Write(
if (length <= sizeof(Object_Name[index])) { if (length <= sizeof(Object_Name[index])) {
encoding = characterstring_encoding(char_string); encoding = characterstring_encoding(char_string);
if (encoding == CHARACTER_UTF8) { if (encoding == CHARACTER_UTF8) {
status = characterstring_ansi_copy( status =
Object_Name[index], characterstring_ansi_copy(Object_Name[index],
sizeof(Object_Name[index]), sizeof(Object_Name[index]), char_string);
char_string);
if (!status) { if (!status) {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -451,10 +449,9 @@ static bool Multistate_Input_State_Text_Write(
if (length <= sizeof(State_Text[index][state_index])) { if (length <= sizeof(State_Text[index][state_index])) {
encoding = characterstring_encoding(char_string); encoding = characterstring_encoding(char_string);
if (encoding == CHARACTER_UTF8) { if (encoding == CHARACTER_UTF8) {
status = characterstring_ansi_copy( status =
State_Text[index][state_index], characterstring_ansi_copy(State_Text[index][state_index],
sizeof(State_Text[index][state_index]), sizeof(State_Text[index][state_index]), char_string);
char_string);
if (!status) { if (!status) {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -562,7 +559,8 @@ int Multistate_Input_Read_Property(
} else if (rpdata->array_index == BACNET_ARRAY_ALL) { } else if (rpdata->array_index == BACNET_ARRAY_ALL) {
/* if no index was specified, then try to encode the entire list */ /* if no index was specified, then try to encode the entire list */
/* into one packet. */ /* into one packet. */
max_states = Multistate_Input_Max_States(rpdata->object_instance); max_states =
Multistate_Input_Max_States(rpdata->object_instance);
for (i = 1; i <= max_states; i++) { for (i = 1; i <= max_states; i++) {
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Multistate_Input_State_Text(rpdata->object_instance, Multistate_Input_State_Text(rpdata->object_instance,
@@ -582,7 +580,8 @@ int Multistate_Input_Read_Property(
} }
} }
} else { } else {
max_states = Multistate_Input_Max_States(rpdata->object_instance); max_states =
Multistate_Input_Max_States(rpdata->object_instance);
if (rpdata->array_index <= max_states) { if (rpdata->array_index <= max_states) {
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Multistate_Input_State_Text(rpdata->object_instance, Multistate_Input_State_Text(rpdata->object_instance,
@@ -661,11 +660,10 @@ bool Multistate_Input_Write_Property(
wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME;
} }
} else { } else {
status = Multistate_Input_Object_Name_Write( status =
wp_data->object_instance, Multistate_Input_Object_Name_Write(wp_data->
&value.type.Character_String, object_instance, &value.type.Character_String,
&wp_data->error_class, &wp_data->error_class, &wp_data->error_code);
&wp_data->error_code);
} }
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -674,11 +672,10 @@ bool Multistate_Input_Write_Property(
break; break;
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = Multistate_Input_Description_Write( status =
wp_data->object_instance, Multistate_Input_Description_Write(wp_data->
&value.type.Character_String, object_instance, &value.type.Character_String,
&wp_data->error_class, &wp_data->error_class, &wp_data->error_code);
&wp_data->error_code);
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
@@ -690,8 +687,8 @@ bool Multistate_Input_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
status = status =
Multistate_Input_Present_Value_Set(wp_data-> Multistate_Input_Present_Value_Set
object_instance, value.type.Unsigned_Int); (wp_data->object_instance, value.type.Unsigned_Int);
if (!status) { if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -716,44 +713,43 @@ bool Multistate_Input_Write_Property(
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
} else if (wp_data->array_index == BACNET_ARRAY_ALL) { } else if (wp_data->array_index == BACNET_ARRAY_ALL) {
max_states = Multistate_Input_Max_States( max_states =
wp_data->object_instance); Multistate_Input_Max_States(wp_data->object_instance);
array_index = 1; array_index = 1;
element_len = len; element_len = len;
do { do {
if (element_len) { if (element_len) {
status = Multistate_Input_State_Text_Write( status =
wp_data->object_instance, Multistate_Input_State_Text_Write(wp_data->
array_index, object_instance, array_index,
&value.type.Character_String, &value.type.Character_String,
&wp_data->error_class, &wp_data->error_class, &wp_data->error_code);
&wp_data->error_code);
} }
max_states--; max_states--;
array_index++; array_index++;
if (max_states) { if (max_states) {
element_len = bacapp_decode_application_data( element_len =
&wp_data->application_data[len], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len-len, application_data[len],
&value); wp_data->application_data_len - len, &value);
if (element_len < 0) { if (element_len < 0) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code =
ERROR_CODE_VALUE_OUT_OF_RANGE;
break; break;
} }
len += element_len; len += element_len;
} }
} while (max_states); } while (max_states);
} else { } else {
max_states = Multistate_Input_Max_States( max_states =
wp_data->object_instance); Multistate_Input_Max_States(wp_data->object_instance);
if (wp_data->array_index <= max_states) { if (wp_data->array_index <= max_states) {
status = Multistate_Input_State_Text_Write( status =
wp_data->object_instance, Multistate_Input_State_Text_Write(wp_data->
wp_data->array_index, object_instance, wp_data->array_index,
&value.type.Character_String, &value.type.Character_String,
&wp_data->error_class, &wp_data->error_class, &wp_data->error_code);
&wp_data->error_code);
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
+10 -10
View File
@@ -268,8 +268,8 @@ int Multistate_Output_Read_Property(
/* into one packet. */ /* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) { else if (rpdata->array_index == BACNET_ARRAY_ALL) {
object_index = object_index =
Multistate_Output_Instance_To_Index(rpdata-> Multistate_Output_Instance_To_Index
object_instance); (rpdata->object_instance);
for (i = 0; i < BACNET_MAX_PRIORITY; i++) { for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
/* FIXME: check if we have room before adding it to APDU */ /* FIXME: check if we have room before adding it to APDU */
if (Multistate_Output_Level[object_index][i] == if (Multistate_Output_Level[object_index][i] ==
@@ -294,8 +294,8 @@ int Multistate_Output_Read_Property(
} }
} else { } else {
object_index = object_index =
Multistate_Output_Instance_To_Index(rpdata-> Multistate_Output_Instance_To_Index
object_instance); (rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Multistate_Output_Level[object_index] if (Multistate_Output_Level[object_index]
[rpdata->array_index - 1] == MULTISTATE_NULL) [rpdata->array_index - 1] == MULTISTATE_NULL)
@@ -386,8 +386,8 @@ bool Multistate_Output_Write_Property(
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) { (value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
level = value.type.Unsigned_Int; level = value.type.Unsigned_Int;
object_index = object_index =
Multistate_Output_Instance_To_Index(wp_data-> Multistate_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Multistate_Output_Level[object_index][priority] = Multistate_Output_Level[object_index][priority] =
(uint8_t) level; (uint8_t) level;
@@ -414,8 +414,8 @@ bool Multistate_Output_Write_Property(
if (status) { if (status) {
level = MULTISTATE_NULL; level = MULTISTATE_NULL;
object_index = object_index =
Multistate_Output_Instance_To_Index(wp_data-> Multistate_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
@@ -441,8 +441,8 @@ bool Multistate_Output_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
object_index = object_index =
Multistate_Output_Instance_To_Index(wp_data-> Multistate_Output_Instance_To_Index
object_instance); (wp_data->object_instance);
Multistate_Output_Out_Of_Service[object_index] = Multistate_Output_Out_Of_Service[object_index] =
value.type.Boolean; value.type.Boolean;
} }
+6 -6
View File
@@ -438,8 +438,8 @@ int Multistate_Value_Read_Property(
/* if no index was specified, then try to encode the entire list */ /* if no index was specified, then try to encode the entire list */
/* into one packet. */ /* into one packet. */
object_index = object_index =
Multistate_Value_Instance_To_Index(rpdata-> Multistate_Value_Instance_To_Index
object_instance); (rpdata->object_instance);
for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) { for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) {
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Multistate_Value_State_Text(rpdata->object_instance, Multistate_Value_State_Text(rpdata->object_instance,
@@ -460,8 +460,8 @@ int Multistate_Value_Read_Property(
} }
} else { } else {
object_index = object_index =
Multistate_Value_Instance_To_Index(rpdata-> Multistate_Value_Instance_To_Index
object_instance); (rpdata->object_instance);
if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) { if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) {
characterstring_init_ansi(&char_string, characterstring_init_ansi(&char_string,
Multistate_Value_State_Text(rpdata->object_instance, Multistate_Value_State_Text(rpdata->object_instance,
@@ -528,8 +528,8 @@ bool Multistate_Value_Write_Property(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
status = status =
Multistate_Value_Present_Value_Set(wp_data-> Multistate_Value_Present_Value_Set
object_instance, value.type.Unsigned_Int); (wp_data->object_instance, value.type.Unsigned_Int);
if (!status) { if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
+57 -50
View File
@@ -189,8 +189,8 @@ int Notification_Class_Read_Property(
apdu = rpdata->application_data; apdu = rpdata->application_data;
CurrentNotify = CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index &NC_Info[Notification_Class_Instance_To_Index(rpdata->
(rpdata->object_instance)]; object_instance)];
switch (rpdata->object_property) { switch (rpdata->object_property) {
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
@@ -400,8 +400,8 @@ bool Notification_Class_Write_Property(
CurrentNotify = CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index &NC_Info[Notification_Class_Instance_To_Index(wp_data->
(wp_data->object_instance)]; object_instance)];
/* decode the some of the request /* decode the some of the request
*/ */
@@ -467,8 +467,9 @@ bool Notification_Class_Write_Property(
while (iOffset < wp_data->application_data_len) { while (iOffset < wp_data->application_data_len) {
/* Decode Valid Days */ /* Decode Valid Days */
len = len =
bacapp_decode_application_data(&wp_data->application_data bacapp_decode_application_data(&wp_data->
[iOffset], wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) {
@@ -491,8 +492,9 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Decode From Time */ /* Decode From Time */
len = len =
bacapp_decode_application_data(&wp_data->application_data bacapp_decode_application_data(&wp_data->
[iOffset], wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
@@ -506,8 +508,9 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Decode To Time */ /* Decode To Time */
len = len =
bacapp_decode_application_data(&wp_data->application_data bacapp_decode_application_data(&wp_data->
[iOffset], wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
@@ -526,8 +529,9 @@ bool Notification_Class_Write_Property(
RECIPIENT_TYPE_DEVICE; RECIPIENT_TYPE_DEVICE;
/* Decode Network Number */ /* Decode Network Number */
len = len =
bacapp_decode_context_data(&wp_data->application_data bacapp_decode_context_data(&wp_data->
[iOffset], wp_data->application_data_len, &value, application_data[iOffset],
wp_data->application_data_len, &value,
PROP_RECIPIENT_LIST); PROP_RECIPIENT_LIST);
if ((len == 0) || if ((len == 0) ||
@@ -538,21 +542,21 @@ bool Notification_Class_Write_Property(
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].Recipient. TmpNotify.Recipient_List[idx].Recipient._.
_.DeviceIdentifier = value.type.Object_Id.instance; DeviceIdentifier = value.type.Object_Id.instance;
iOffset += len; iOffset += len;
} }
/* opening tag [1] - Recipient */ /* opening tag [1] - Recipient */
else if (decode_is_opening_tag_number else if (decode_is_opening_tag_number(&wp_data->
(&wp_data->application_data[iOffset], 1)) { application_data[iOffset], 1)) {
iOffset++; iOffset++;
TmpNotify.Recipient_List[idx].Recipient.RecipientType = TmpNotify.Recipient_List[idx].Recipient.RecipientType =
RECIPIENT_TYPE_ADDRESS; RECIPIENT_TYPE_ADDRESS;
/* Decode Network Number */ /* Decode Network Number */
len = len =
bacapp_decode_application_data bacapp_decode_application_data(&wp_data->
(&wp_data->application_data[iOffset], application_data[iOffset],
wp_data->application_data_len, &value); wp_data->application_data_len, &value);
if ((len == 0) || if ((len == 0) ||
@@ -569,8 +573,8 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Decode Address */ /* Decode Address */
len = len =
bacapp_decode_application_data bacapp_decode_application_data(&wp_data->
(&wp_data->application_data[iOffset], application_data[iOffset],
wp_data->application_data_len, &value); wp_data->application_data_len, &value);
if ((len == 0) || if ((len == 0) ||
@@ -581,16 +585,16 @@ bool Notification_Class_Write_Property(
return false; return false;
} }
/* store value */ /* store value */
if (TmpNotify.Recipient_List[idx].Recipient._. if (TmpNotify.Recipient_List[idx].Recipient._.Address.
Address.net == 0) { net == 0) {
memcpy(TmpNotify.Recipient_List[idx].Recipient. memcpy(TmpNotify.Recipient_List[idx].Recipient._.
_.Address.mac, value.type.Octet_String.value, Address.mac, value.type.Octet_String.value,
value.type.Octet_String.length); value.type.Octet_String.length);
TmpNotify.Recipient_List[idx].Recipient._. TmpNotify.Recipient_List[idx].Recipient._.Address.
Address.mac_len = value.type.Octet_String.length; mac_len = value.type.Octet_String.length;
} else { } else {
memcpy(TmpNotify.Recipient_List[idx].Recipient. memcpy(TmpNotify.Recipient_List[idx].Recipient._.
_.Address.adr, value.type.Octet_String.value, Address.adr, value.type.Octet_String.value,
value.type.Octet_String.length); value.type.Octet_String.length);
TmpNotify.Recipient_List[idx].Recipient._.Address.len = TmpNotify.Recipient_List[idx].Recipient._.Address.len =
value.type.Octet_String.length; value.type.Octet_String.length;
@@ -598,8 +602,8 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* closing tag [1] - Recipient */ /* closing tag [1] - Recipient */
if (decode_is_closing_tag_number(&wp_data->application_data if (decode_is_closing_tag_number(&wp_data->
[iOffset], 1)) application_data[iOffset], 1))
iOffset++; iOffset++;
else { else {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
@@ -616,8 +620,9 @@ bool Notification_Class_Write_Property(
/* Process Identifier */ /* Process Identifier */
len = len =
bacapp_decode_application_data(&wp_data->application_data bacapp_decode_application_data(&wp_data->
[iOffset], wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
@@ -633,8 +638,9 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Issue Confirmed Notifications */ /* Issue Confirmed Notifications */
len = len =
bacapp_decode_application_data(&wp_data->application_data bacapp_decode_application_data(&wp_data->
[iOffset], wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) { (value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) {
@@ -650,8 +656,9 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Transitions */ /* Transitions */
len = len =
bacapp_decode_application_data(&wp_data->application_data bacapp_decode_application_data(&wp_data->
[iOffset], wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) {
@@ -692,16 +699,16 @@ bool Notification_Class_Write_Property(
CurrentNotify->Recipient_List[idx] = CurrentNotify->Recipient_List[idx] =
TmpNotify.Recipient_List[idx]; TmpNotify.Recipient_List[idx];
if (CurrentNotify->Recipient_List[idx]. if (CurrentNotify->Recipient_List[idx].Recipient.
Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { RecipientType == RECIPIENT_TYPE_DEVICE) {
/* copy Device_ID */ /* copy Device_ID */
DeviceID = DeviceID =
CurrentNotify->Recipient_List[idx].Recipient. CurrentNotify->Recipient_List[idx].Recipient._.
_.DeviceIdentifier; DeviceIdentifier;
address_bind_request(DeviceID, &max_apdu, &src); address_bind_request(DeviceID, &max_apdu, &src);
} else if (CurrentNotify->Recipient_List[idx]. } else if (CurrentNotify->Recipient_List[idx].Recipient.
Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { RecipientType == RECIPIENT_TYPE_ADDRESS) {
/* copy Address */ /* copy Address */
/* src = CurrentNotify->Recipient_List[idx].Recipient._.Address; */ /* src = CurrentNotify->Recipient_List[idx].Recipient._.Address; */
/* address_bind_request(BACNET_MAX_INSTANCE, &max_apdu, &src); */ /* address_bind_request(BACNET_MAX_INSTANCE, &max_apdu, &src); */
@@ -824,16 +831,16 @@ void Notification_Class_common_reporting_function(
event_data->priority = event_data->priority =
CurrentNotify->Priority[TRANSITION_TO_NORMAL]; CurrentNotify->Priority[TRANSITION_TO_NORMAL];
event_data->ackRequired = event_data->ackRequired =
(CurrentNotify->Ack_Required & TRANSITION_TO_NORMAL_MASKED) ? (CurrentNotify->
true : false; Ack_Required & TRANSITION_TO_NORMAL_MASKED) ? true : false;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
event_data->priority = event_data->priority =
CurrentNotify->Priority[TRANSITION_TO_FAULT]; CurrentNotify->Priority[TRANSITION_TO_FAULT];
event_data->ackRequired = event_data->ackRequired =
(CurrentNotify->Ack_Required & TRANSITION_TO_FAULT_MASKED) ? (CurrentNotify->
true : false; Ack_Required & TRANSITION_TO_FAULT_MASKED) ? true : false;
break; break;
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
@@ -918,13 +925,13 @@ void Notification_Class_find_recipient(
RECIPIENT_TYPE_DEVICE) { RECIPIENT_TYPE_DEVICE) {
/* Device ID */ /* Device ID */
DeviceID = DeviceID =
CurrentNotify->Recipient_List[idx].Recipient. CurrentNotify->Recipient_List[idx].Recipient._.
_.DeviceIdentifier; DeviceIdentifier;
/* Send who_ is request only when address of device is unknown. */ /* Send who_ is request only when address of device is unknown. */
if (!address_bind_request(DeviceID, &max_apdu, &src)) if (!address_bind_request(DeviceID, &max_apdu, &src))
Send_WhoIs(DeviceID, DeviceID); Send_WhoIs(DeviceID, DeviceID);
} else if (CurrentNotify->Recipient_List[idx]. } else if (CurrentNotify->Recipient_List[idx].Recipient.
Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { RecipientType == RECIPIENT_TYPE_ADDRESS) {
} }
} }
+7 -7
View File
@@ -743,9 +743,9 @@ bool Trend_Log_Write_Property(
if (wp_data->application_data_len != 0) { if (wp_data->application_data_len != 0) {
iOffset += len; iOffset += len;
len = len =
bacapp_decode_context_data(&wp_data-> bacapp_decode_context_data(&wp_data->application_data
application_data[iOffset], wp_data->application_data_len, [iOffset], wp_data->application_data_len, &value,
&value, PROP_LOG_DEVICE_OBJECT_PROPERTY); PROP_LOG_DEVICE_OBJECT_PROPERTY);
if ((len == 0) || ((value.context_tag != 2) && if ((len == 0) || ((value.context_tag != 2) &&
(value.context_tag != 3))) { (value.context_tag != 3))) {
/* Bad decode or wrong tag */ /* Bad decode or wrong tag */
@@ -762,8 +762,8 @@ bool Trend_Log_Write_Property(
if (wp_data->application_data_len != 0) { if (wp_data->application_data_len != 0) {
iOffset += len; iOffset += len;
len = len =
bacapp_decode_context_data(&wp_data-> bacapp_decode_context_data
application_data[iOffset], (&wp_data->application_data[iOffset],
wp_data->application_data_len, &value, wp_data->application_data_len, &value,
PROP_LOG_DEVICE_OBJECT_PROPERTY); PROP_LOG_DEVICE_OBJECT_PROPERTY);
if ((len == 0) || (value.context_tag != 3)) { if ((len == 0) || (value.context_tag != 3)) {
@@ -1105,8 +1105,8 @@ int rr_trend_log_encode(
pRequest->ItemCount = 0; /* Start out with nothing */ pRequest->ItemCount = 0; /* Start out with nothing */
/* Bail out now if nowt - should never happen for a Trend Log but ... */ /* Bail out now if nowt - should never happen for a Trend Log but ... */
if (LogInfo[Trend_Log_Instance_To_Index(pRequest->object_instance)]. if (LogInfo[Trend_Log_Instance_To_Index(pRequest->
ulRecordCount == 0) object_instance)].ulRecordCount == 0)
return (0); return (0);
if ((pRequest->RequestType == RR_BY_POSITION) || if ((pRequest->RequestType == RR_BY_POSITION) ||
+4 -4
View File
@@ -223,10 +223,10 @@ void rpm_ack_extract_data(
} else { } else {
/* AccessError */ /* AccessError */
sprintf(ackString, "BACnet Error: %s: %s", sprintf(ackString, "BACnet Error: %s: %s",
bactext_error_class_name((int) listOfProperties->error. bactext_error_class_name((int) listOfProperties->
error_class), error.error_class),
bactext_error_code_name((int) listOfProperties->error. bactext_error_code_name((int) listOfProperties->
error_code)); error.error_code));
LogError(ackString); LogError(ackString);
} }
listOfProperties = listOfProperties->next; listOfProperties = listOfProperties->next;
+6 -9
View File
@@ -126,16 +126,14 @@ int main(
return 0; return 0;
} }
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("Send a Read-Broadcast-Distribution-Table message to a BBMD.\r\n" printf
"\r\n" ("Send a Read-Broadcast-Distribution-Table message to a BBMD.\r\n"
"IP:\r\n" "\r\n" "IP:\r\n"
"IP address of the BBMD in dotted decimal notation\r\n" "IP address of the BBMD in dotted decimal notation\r\n"
"[port]\r\n" "[port]\r\n"
"optional BACnet/IP port number (default=47808=0xBAC0)\r\n" "optional BACnet/IP port number (default=47808=0xBAC0)\r\n" "\r\n"
"\r\n"
"To send a Read-Broadcast-Distribution-Table message to a BBMD\r\n" "To send a Read-Broadcast-Distribution-Table message to a BBMD\r\n"
"at 192.168.0.1 using port 47808:\r\n" "at 192.168.0.1 using port 47808:\r\n" "%s 192.168.0.1 47808\r\n",
"%s 192.168.0.1 47808\r\n",
filename_remove_path(argv[0])); filename_remove_path(argv[0]));
return 0; return 0;
} }
@@ -143,8 +141,7 @@ int main(
if (argc > 1) { if (argc > 1) {
Target_BBMD_Address = inet_addr(argv[1]); Target_BBMD_Address = inet_addr(argv[1]);
if (Target_BBMD_Address == (-1)) { if (Target_BBMD_Address == (-1)) {
fprintf(stderr, "IP=%s - failed to convert address.\r\n", fprintf(stderr, "IP=%s - failed to convert address.\r\n", argv[1]);
argv[1]);
return 1; return 1;
} }
} }
+2 -1
View File
@@ -258,7 +258,8 @@ int main(
/* at least one second has passed */ /* at least one second has passed */
if (current_seconds != last_seconds) if (current_seconds != last_seconds)
tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); tsm_timer_milliseconds((uint16_t) ((current_seconds -
last_seconds) * 1000));
if (Error_Detected) if (Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
+50 -23
View File
@@ -23,7 +23,8 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
#ifdef TEST_PACKET #ifdef TEST_PACKET
uint8_t test_packet[] = { 0x81, 0x0a, 0x00, 0x16, /* BVLC header */ uint8_t test_packet[] = { 0x81, 0x0a, 0x00, 0x16, /* BVLC header */
0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */ 0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */
0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55}; /* APDU */ 0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55
}; /* APDU */
#endif #endif
extern int get_local_address_ioctl( extern int get_local_address_ioctl(
@@ -31,7 +32,9 @@ extern int get_local_address_ioctl(
struct in_addr *addr, struct in_addr *addr,
int request); int request);
void* dl_ip_thread(void *pArgs) { void *dl_ip_thread(
void *pArgs)
{
MSGBOX_ID msgboxid; MSGBOX_ID msgboxid;
BACMSG msg_storage, *bacmsg = NULL; BACMSG msg_storage, *bacmsg = NULL;
MSG_DATA *msg_data; MSG_DATA *msg_data;
@@ -77,9 +80,11 @@ void* dl_ip_thread(void *pArgs) {
msg_data = (MSG_DATA *) bacmsg->data; msg_data = (MSG_DATA *) bacmsg->data;
memmove(&address.net, &msg_data->dest.net, 2); memmove(&address.net, &msg_data->dest.net, 2);
memmove(&address.mac_len, &msg_data->dest.len, 1); memmove(&address.mac_len, &msg_data->dest.len, 1);
memmove(&address.mac[0], &msg_data->dest.adr[0], MAX_MAC_LEN); memmove(&address.mac[0], &msg_data->dest.adr[0],
MAX_MAC_LEN);
dl_ip_send(&ip_data, &address, msg_data->pdu, msg_data->pdu_len); dl_ip_send(&ip_data, &address, msg_data->pdu,
msg_data->pdu_len);
check_data(msg_data); check_data(msg_data);
@@ -123,8 +128,10 @@ void* dl_ip_thread(void *pArgs) {
return NULL; return NULL;
} }
bool dl_ip_init(ROUTER_PORT *port, bool dl_ip_init(
IP_DATA *ip_data) { ROUTER_PORT * port,
IP_DATA * ip_data)
{
struct sockaddr_in sin; struct sockaddr_in sin;
int socket_opt = 0; int socket_opt = 0;
int status = 0; /* for error checking */ int status = 0; /* for error checking */
@@ -133,12 +140,16 @@ bool dl_ip_init(ROUTER_PORT *port,
ip_data->port = htons(port->params.bip_params.port); ip_data->port = htons(port->params.bip_params.port);
/* get local address */ /* get local address */
status = get_local_address_ioctl(port->iface, &ip_data->local_addr, SIOCGIFADDR); status =
get_local_address_ioctl(port->iface, &ip_data->local_addr,
SIOCGIFADDR);
if (status < 0) { if (status < 0) {
return false; return false;
} }
/* get broadcast address */ /* get broadcast address */
status = get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, SIOCGIFBRDADDR); status =
get_local_address_ioctl(port->iface, &ip_data->broadcast_addr,
SIOCGIFBRDADDR);
if (status < 0) { if (status < 0) {
return false; return false;
} }
@@ -150,13 +161,17 @@ bool dl_ip_init(ROUTER_PORT *port,
/* setup socket options */ /* setup socket options */
socket_opt = 1; socket_opt = 1;
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, sizeof(socket_opt)); status =
setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt,
sizeof(socket_opt));
if (status < 0) { if (status < 0) {
close(ip_data->socket); close(ip_data->socket);
return false; return false;
} }
status = setsockopt(ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt, sizeof(socket_opt)); status =
setsockopt(ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt,
sizeof(socket_opt));
if (status < 0) { if (status < 0) {
close(ip_data->socket); close(ip_data->socket);
return false; return false;
@@ -169,7 +184,9 @@ bool dl_ip_init(ROUTER_PORT *port,
memset(&sin.sin_zero, '\0', sizeof(sin.sin_zero)); memset(&sin.sin_zero, '\0', sizeof(sin.sin_zero));
status = bind(ip_data->socket, (const struct sockaddr *) &sin, sizeof(struct sockaddr)); status =
bind(ip_data->socket, (const struct sockaddr *) &sin,
sizeof(struct sockaddr));
if (status < 0) { if (status < 0) {
close(ip_data->socket); close(ip_data->socket);
return false; return false;
@@ -182,14 +199,16 @@ bool dl_ip_init(ROUTER_PORT *port,
PRINT(INFO, "Interface: %s\n", port->iface); PRINT(INFO, "Interface: %s\n", port->iface);
PRINT(INFO, "IP Address: %s\n", inet_ntoa(ip_data->local_addr)); PRINT(INFO, "IP Address: %s\n", inet_ntoa(ip_data->local_addr));
PRINT(INFO, "IP Broadcast Address: %s\n", inet_ntoa(ip_data->broadcast_addr)); PRINT(INFO, "IP Broadcast Address: %s\n",
inet_ntoa(ip_data->broadcast_addr));
PRINT(INFO, "UDP Port: 0x%04X [%hu]\n", (port->params.bip_params.port), PRINT(INFO, "UDP Port: 0x%04X [%hu]\n", (port->params.bip_params.port),
(port->params.bip_params.port)); (port->params.bip_params.port));
return true; return true;
} }
int dl_ip_send(IP_DATA *data, int dl_ip_send(
IP_DATA * data,
BACNET_ADDRESS * dest, BACNET_ADDRESS * dest,
uint8_t * pdu, uint8_t * pdu,
unsigned pdu_len) unsigned pdu_len)
@@ -253,7 +272,8 @@ int dl_ip_recv(
if (timeout >= 1000) { if (timeout >= 1000) {
select_timeout.tv_sec = timeout / 1000; select_timeout.tv_sec = timeout / 1000;
select_timeout.tv_usec = 1000 * (timeout - select_timeout.tv_sec * 1000); select_timeout.tv_usec =
1000 * (timeout - select_timeout.tv_sec * 1000);
} else { } else {
select_timeout.tv_sec = 0; select_timeout.tv_sec = 0;
select_timeout.tv_usec = 1000 * timeout; select_timeout.tv_usec = 1000 * timeout;
@@ -265,7 +285,8 @@ int dl_ip_recv(
#ifdef TEST_PACKET #ifdef TEST_PACKET
received_bytes = sizeof(test_packet); received_bytes = sizeof(test_packet);
memmove(data->buff, &test_packet, received_bytes); memmove(data->buff, &test_packet, received_bytes);
sin.sin_addr.s_addr = 0x7E1D40A; sin.sin_port = 0xC0BA; sin.sin_addr.s_addr = 0x7E1D40A;
sin.sin_port = 0xC0BA;
#else #else
int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout); int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout);
/* see if there is a packet for us */ /* see if there is a packet for us */
@@ -308,10 +329,13 @@ int dl_ip_recv(
/* allocate data message stucture */ /* allocate data message stucture */
(*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA)); (*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA));
(*msg_data)->pdu_len = buff_len; (*msg_data)->pdu_len = buff_len;
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len); (*msg_data)->pdu =
(uint8_t *) malloc((*msg_data)->pdu_len);
/* fill up data message structure */ /* fill up data message structure */
memmove(&(*msg_data)->pdu[0], &data->buff[4], (*msg_data)->pdu_len); memmove(&(*msg_data)->pdu[0], &data->buff[4],
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS)); (*msg_data)->pdu_len);
memmove(&(*msg_data)->src, src,
sizeof(BACNET_ADDRESS));
} }
/* ignore packets that are too large */ /* ignore packets that are too large */
else { else {
@@ -342,10 +366,13 @@ int dl_ip_recv(
/* allocate data message stucture */ /* allocate data message stucture */
(*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA)); (*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA));
(*msg_data)->pdu_len = buff_len; (*msg_data)->pdu_len = buff_len;
(*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len); (*msg_data)->pdu =
(uint8_t *) malloc((*msg_data)->pdu_len);
/* fill up data message structure */ /* fill up data message structure */
memmove(&(*msg_data)->pdu, &data->buff[4+6], (*msg_data)->pdu_len); memmove(&(*msg_data)->pdu, &data->buff[4 + 6],
memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS)); (*msg_data)->pdu_len);
memmove(&(*msg_data)->src, src,
sizeof(BACNET_ADDRESS));
} else { } else {
/* ignore packets that are too large */ /* ignore packets that are too large */
buff_len = 0; buff_len = 0;
@@ -363,7 +390,8 @@ int dl_ip_recv(
} }
void dl_ip_cleanup( void dl_ip_cleanup(
IP_DATA *ip_data) { IP_DATA * ip_data)
{
/* free buffer */ /* free buffer */
if (ip_data->buff) if (ip_data->buff)
free(ip_data->buff); free(ip_data->buff);
@@ -372,4 +400,3 @@ void dl_ip_cleanup(
close(ip_data->socket); close(ip_data->socket);
return; return;
} }
+147 -77
View File
@@ -46,7 +46,8 @@ ROUTER_PORT *head = NULL; /* pointer to list of router ports */
int port_count; int port_count;
void print_help(); void print_help(
);
bool read_config( bool read_config(
char *filepath); char *filepath);
@@ -58,9 +59,11 @@ bool parse_cmd(
void init_port_threads( void init_port_threads(
ROUTER_PORT * port_list); ROUTER_PORT * port_list);
bool init_router(); bool init_router(
);
void cleanup(); void cleanup(
);
void print_msg( void print_msg(
BACMSG * msg); BACMSG * msg);
@@ -70,9 +73,11 @@ uint16_t process_msg(
MSG_DATA * data, MSG_DATA * data,
uint8_t ** buff); uint8_t ** buff);
uint16_t get_next_free_dnet(); uint16_t get_next_free_dnet(
);
int kbhit(); int kbhit(
);
inline bool is_network_msg( inline bool is_network_msg(
BACMSG * msg); BACMSG * msg);
@@ -91,20 +96,19 @@ int main(
atexit(cleanup); atexit(cleanup);
if (!parse_cmd(argc, argv)) if (!parse_cmd(argc, argv)) {
{
printf("parse cmd failed\r\n"); printf("parse cmd failed\r\n");
return -1; return -1;
} }
if(!init_router()) if (!init_router()) {
{
printf("init_router failed\r\n"); printf("init_router failed\r\n");
return -1; return -1;
} }
send_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, msg_data, &buff, NULL); send_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, msg_data,
&buff, NULL);
while (true) { while (true) {
if (kbhit()) { if (kbhit()) {
@@ -132,7 +136,9 @@ int main(
print_msg(bacmsg); print_msg(bacmsg);
if (is_network_msg(bacmsg)) { if (is_network_msg(bacmsg)) {
buff_len = process_network_message(bacmsg, msg_data, &buff); buff_len =
process_network_message(bacmsg, msg_data,
&buff);
if (buff_len == 0) { if (buff_len == 0) {
free_data(bacmsg->data); free_data(bacmsg->data);
break; break;
@@ -159,26 +165,33 @@ int main(
if (is_network_msg(bacmsg)) { if (is_network_msg(bacmsg)) {
msg_data->ref_count = 1; msg_data->ref_count = 1;
send_to_msgbox(msg_src, &msg_storage); send_to_msgbox(msg_src, &msg_storage);
} else if (msg_data->dest.net != BACNET_BROADCAST_NETWORK) { } else if (msg_data->dest.net !=
BACNET_BROADCAST_NETWORK) {
msg_data->ref_count = 1; msg_data->ref_count = 1;
port = find_dnet(msg_data->dest.net, &msg_data->dest); port =
find_dnet(msg_data->dest.net,
&msg_data->dest);
send_to_msgbox(port->port_id, &msg_storage); send_to_msgbox(port->port_id, &msg_storage);
} else { } else {
port = head; port = head;
msg_data->ref_count = port_count - 1; msg_data->ref_count = port_count - 1;
while (port != NULL) { while (port != NULL) {
if (port->port_id == msg_src || port->state == FINISHED) { if (port->port_id == msg_src ||
port->state == FINISHED) {
port = port->next; port = port->next;
continue; continue;
} }
send_to_msgbox(port->port_id, &msg_storage); send_to_msgbox(port->port_id,
&msg_storage);
port = port->next; port = port->next;
} }
} }
} else if (buff_len == -1) { } else if (buff_len == -1) {
uint16_t net = msg_data->dest.net; /* NET to find */ uint16_t net = msg_data->dest.net; /* NET to find */
PRINT(INFO, "Searching NET...\n"); PRINT(INFO, "Searching NET...\n");
send_network_message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, msg_data, &buff, &net); send_network_message
(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK,
msg_data, &buff, &net);
} else { } else {
/* if invalid message send Reject-Message-To-Network */ /* if invalid message send Reject-Message-To-Network */
PRINT(ERROR, "Error: Invalid message\n"); PRINT(ERROR, "Error: Invalid message\n");
@@ -197,10 +210,10 @@ int main(
} }
void print_help() void print_help(
)
{ {
printf("Usage: router <init_method> [init_parameters]\n" printf("Usage: router <init_method> [init_parameters]\n" "\ninit_method:\n"
"\ninit_method:\n"
"-c, --config <filepath>\n\tinitialize router with a configuration file (.cfg) located at <filepath>\n" "-c, --config <filepath>\n\tinitialize router with a configuration file (.cfg) located at <filepath>\n"
"-D, --device <dev_type> <iface> [params]\n\tinitialize a <dev_type> device using an <iface> interface specified with\n\t[params]\n" "-D, --device <dev_type> <iface> [params]\n\tinitialize a <dev_type> device using an <iface> interface specified with\n\t[params]\n"
"\ninit_parameters:\n" "\ninit_parameters:\n"
@@ -225,7 +238,8 @@ bool read_config(
/* open configuration file */ /* open configuration file */
if (!config_read_file(&cfg, filepath)) { if (!config_read_file(&cfg, filepath)) {
PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg), config_error_text(&cfg)); PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg),
config_error_text(&cfg));
config_destroy(&cfg); config_destroy(&cfg);
return false; return false;
} }
@@ -265,19 +279,22 @@ bool read_config(
result = config_setting_lookup_string(port, "device", &iface); result = config_setting_lookup_string(port, "device", &iface);
if (result) { if (result) {
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char)); current->iface =
(char *) malloc((strlen(iface) + 1) * sizeof(char));
strcpy(current->iface, iface); strcpy(current->iface, iface);
/* check if interface is valid */ /* check if interface is valid */
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd) { if (fd) {
struct ifreq ifr; struct ifreq ifr;
strncpy(ifr.ifr_name, current->iface, sizeof(ifr.ifr_name)-1); strncpy(ifr.ifr_name, current->iface,
sizeof(ifr.ifr_name) - 1);
result = ioctl(fd, SIOCGIFADDR, &ifr); result = ioctl(fd, SIOCGIFADDR, &ifr);
if (result != -1) { if (result != -1) {
close(fd); close(fd);
} else { } else {
PRINT(ERROR, "Error: Invalid interface for BIP device\n"); PRINT(ERROR,
"Error: Invalid interface for BIP device\n");
return false; return false;
} }
} }
@@ -285,13 +302,15 @@ bool read_config(
current->iface = "eth0"; current->iface = "eth0";
} }
result = config_setting_lookup_int(port, "port", (int*)&param); result =
config_setting_lookup_int(port, "port", (int *) &param);
if (result) { if (result) {
current->params.bip_params.port = param; current->params.bip_params.port = param;
} else { } else {
current->params.bip_params.port = 0xBAC0; current->params.bip_params.port = 0xBAC0;
} }
result = config_setting_lookup_int(port, "network", (int*)&param); result =
config_setting_lookup_int(port, "network", (int *) &param);
if (result) { if (result) {
current->route_info.net = param; current->route_info.net = param;
} else { } else {
@@ -303,7 +322,8 @@ bool read_config(
result = config_setting_lookup_string(port, "device", &iface); result = config_setting_lookup_string(port, "device", &iface);
if (result) { if (result) {
current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char)); current->iface =
(char *) malloc((strlen(iface) + 1) * sizeof(char));
strcpy(current->iface, iface); strcpy(current->iface, iface);
/* check if interface is valid */ /* check if interface is valid */
@@ -311,13 +331,15 @@ bool read_config(
if (fd != -1) { if (fd != -1) {
close(fd); close(fd);
} else { } else {
PRINT(ERROR, "Error: Invalid interface for MSTP device\n"); PRINT(ERROR,
"Error: Invalid interface for MSTP device\n");
return false; return false;
} }
} else { } else {
current->iface = "/dev/ttyS0"; current->iface = "/dev/ttyS0";
} }
result = config_setting_lookup_int(port, "mac", (int*)&param); result =
config_setting_lookup_int(port, "mac", (int *) &param);
if (result) { if (result) {
current->route_info.mac[0] = param; current->route_info.mac[0] = param;
current->route_info.mac_len = 1; current->route_info.mac_len = 1;
@@ -325,25 +347,31 @@ bool read_config(
current->route_info.mac[0] = 127; current->route_info.mac[0] = 127;
current->route_info.mac_len = 1; current->route_info.mac_len = 1;
} }
result = config_setting_lookup_int(port, "max_master", (int*)&param); result =
config_setting_lookup_int(port, "max_master",
(int *) &param);
if (result) { if (result) {
current->params.mstp_params.max_master = param; current->params.mstp_params.max_master = param;
} else { } else {
current->params.mstp_params.max_master = 127; current->params.mstp_params.max_master = 127;
} }
result = config_setting_lookup_int(port, "max_frames", (int*)&param); result =
config_setting_lookup_int(port, "max_frames",
(int *) &param);
if (result) { if (result) {
current->params.mstp_params.max_frames = param; current->params.mstp_params.max_frames = param;
} else { } else {
current->params.mstp_params.max_frames = 1; current->params.mstp_params.max_frames = 1;
} }
result = config_setting_lookup_int(port, "baud", (int*)&param); result =
config_setting_lookup_int(port, "baud", (int *) &param);
if (result) { if (result) {
current->params.mstp_params.baudrate = param; current->params.mstp_params.baudrate = param;
} else { } else {
current->params.mstp_params.baudrate = 9600; current->params.mstp_params.baudrate = 9600;
} }
result = config_setting_lookup_string(port, "parity", &str_param); result =
config_setting_lookup_string(port, "parity", &str_param);
if (result) { if (result) {
switch (str_param[0]) { switch (str_param[0]) {
case 'E': case 'E':
@@ -359,19 +387,24 @@ bool read_config(
} else { } else {
current->params.mstp_params.parity = PARITY_NONE; current->params.mstp_params.parity = PARITY_NONE;
} }
result = config_setting_lookup_int(port, "databits", (int*)&param); result =
config_setting_lookup_int(port, "databits",
(int *) &param);
if (result && param >= 5 && param <= 8) { if (result && param >= 5 && param <= 8) {
current->params.mstp_params.databits = param; current->params.mstp_params.databits = param;
} else { } else {
current->params.mstp_params.databits = 8; current->params.mstp_params.databits = 8;
} }
result = config_setting_lookup_int(port, "stopbits", (int*)&param); result =
config_setting_lookup_int(port, "stopbits",
(int *) &param);
if (result && param >= 1 && param <= 2) { if (result && param >= 1 && param <= 2) {
current->params.mstp_params.stopbits = param; current->params.mstp_params.stopbits = param;
} else { } else {
current->params.mstp_params.stopbits = 1; current->params.mstp_params.stopbits = 1;
} }
result = config_setting_lookup_int(port, "network", (int*)&param); result =
config_setting_lookup_int(port, "network", (int *) &param);
if (result) { if (result) {
current->route_info.net = param; current->route_info.net = param;
} else { } else {
@@ -383,8 +416,7 @@ bool read_config(
return false; return false;
} }
} }
} } else {
else {
config_destroy(&cfg); config_destroy(&cfg);
return false; return false;
} }
@@ -466,23 +498,27 @@ bool parse_cmd(
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd) { if (fd) {
struct ifreq ifr; struct ifreq ifr;
strncpy(ifr.ifr_name, current->iface, sizeof(ifr.ifr_name)-1); strncpy(ifr.ifr_name, current->iface,
sizeof(ifr.ifr_name) - 1);
result = ioctl(fd, SIOCGIFADDR, &ifr); result = ioctl(fd, SIOCGIFADDR, &ifr);
if (result != -1) { if (result != -1) {
close(fd); close(fd);
} else { } else {
PRINT(ERROR, "Error: Invalid interface for BIP device \n"); PRINT(ERROR,
"Error: Invalid interface for BIP device \n");
return false; return false;
} }
} }
dev_opt = getopt_long(argc, argv, bipString, Options, &index); dev_opt =
getopt_long(argc, argv, bipString, Options, &index);
while (dev_opt != -1 && dev_opt != 'd') { while (dev_opt != -1 && dev_opt != 'd') {
switch (dev_opt) { switch (dev_opt) {
case 'P': case 'P':
result = atoi(optarg); result = atoi(optarg);
if (result) { if (result) {
current->params.bip_params.port = (uint16_t)result; current->params.bip_params.port =
(uint16_t) result;
} else { } else {
current->params.bip_params.port = 0xBAC0; /* 47808 */ current->params.bip_params.port = 0xBAC0; /* 47808 */
} }
@@ -490,13 +526,16 @@ bool parse_cmd(
case 'n': case 'n':
result = atoi(optarg); result = atoi(optarg);
if (result) { if (result) {
current->route_info.net = (uint16_t)result; current->route_info.net =
(uint16_t) result;
} else { } else {
current->route_info.net = port_count; current->route_info.net = port_count;
} }
break; break;
} }
dev_opt = getopt_long(argc, argv, bipString, Options, &index); dev_opt =
getopt_long(argc, argv, bipString, Options,
&index);
} }
opt = dev_opt; opt = dev_opt;
} else if (strcmp(optarg, "mstp") == 0) { } else if (strcmp(optarg, "mstp") == 0) {
@@ -513,7 +552,8 @@ bool parse_cmd(
if (fd != -1) { if (fd != -1) {
close(fd); close(fd);
} else { } else {
PRINT(ERROR, "Error: Invalid interface for MSTP device\n"); PRINT(ERROR,
"Error: Invalid interface for MSTP device\n");
return false; return false;
} }
@@ -528,63 +568,81 @@ bool parse_cmd(
current->params.mstp_params.stopbits = 1; current->params.mstp_params.stopbits = 1;
current->route_info.net = get_next_free_dnet(); current->route_info.net = get_next_free_dnet();
dev_opt = getopt_long(argc, argv, mstpString, Options, &index); dev_opt =
getopt_long(argc, argv, mstpString, Options, &index);
while (dev_opt != -1 && dev_opt != 'D') { while (dev_opt != -1 && dev_opt != 'D') {
switch (dev_opt) { switch (dev_opt) {
case 'm': case 'm':
result = atoi(optarg); result = atoi(optarg);
if (result) { if (result) {
current->route_info.mac[0] = (uint8_t)result; current->route_info.mac[0] =
(uint8_t) result;
} }
if (argv[optind][0] != '-') { if (argv[optind][0] != '-') {
current->params.mstp_params.max_master = (uint8_t)atoi(argv[optind]); current->params.mstp_params.max_master =
if (current->params.mstp_params.max_master < current->route_info.mac[0]) (uint8_t) atoi(argv[optind]);
current->params.mstp_params.max_master = current->route_info.mac[0]; if (current->params.mstp_params.
max_master <
current->route_info.mac[0])
current->params.mstp_params.
max_master =
current->route_info.mac[0];
if (argv[optind + 1][0] != '-') { if (argv[optind + 1][0] != '-') {
current->params.mstp_params.max_frames = (uint8_t)atoi(argv[optind+1]); current->params.mstp_params.
max_frames =
(uint8_t) atoi(argv[optind + 1]);
} }
} }
break; break;
case 'b': case 'b':
result = atoi(optarg); result = atoi(optarg);
if (result) { if (result) {
current->params.mstp_params.baudrate = (uint32_t)result; current->params.mstp_params.baudrate =
(uint32_t) result;
} }
break; break;
case 'p': case 'p':
switch (optarg[0]) { switch (optarg[0]) {
case 'E': case 'E':
current->params.mstp_params.parity = PARITY_EVEN; current->params.mstp_params.parity =
PARITY_EVEN;
break; break;
case 'O': case 'O':
current->params.mstp_params.parity = PARITY_ODD; current->params.mstp_params.parity =
PARITY_ODD;
break; break;
default: default:
current->params.mstp_params.parity = PARITY_NONE; current->params.mstp_params.parity =
PARITY_NONE;
break; break;
} }
break; break;
case 'd': case 'd':
result = atoi(optarg); result = atoi(optarg);
if (result >= 5 && result <= 8) { if (result >= 5 && result <= 8) {
current->params.mstp_params.databits = (uint8_t)result; current->params.mstp_params.databits =
(uint8_t) result;
} }
break; break;
case 's': case 's':
result = atoi(optarg); result = atoi(optarg);
if (result >= 1 && result <= 2) { if (result >= 1 && result <= 2) {
current->params.mstp_params.stopbits = (uint8_t)result; current->params.mstp_params.stopbits =
(uint8_t) result;
} }
break; break;
case 'n': case 'n':
result = atoi(optarg); result = atoi(optarg);
if (result) { if (result) {
current->route_info.net = (uint16_t)result; current->route_info.net =
(uint16_t) result;
} }
break; break;
} }
dev_opt = getopt_long(argc, argv, mstpString, Options, &index); dev_opt =
getopt_long(argc, argv, mstpString, Options,
&index);
} }
opt = dev_opt; opt = dev_opt;
} else { } else {
@@ -598,7 +656,8 @@ bool parse_cmd(
} }
void init_port_threads( void init_port_threads(
ROUTER_PORT* port_list) { ROUTER_PORT * port_list)
{
ROUTER_PORT *port = port_list; ROUTER_PORT *port = port_list;
pthread_t *thread; pthread_t *thread;
@@ -614,10 +673,7 @@ void init_port_threads(
port->state = INIT; port->state = INIT;
thread = (pthread_t *) malloc(sizeof(pthread_t)); thread = (pthread_t *) malloc(sizeof(pthread_t));
pthread_create(thread, pthread_create(thread, NULL, port->func, port);
NULL,
port->func,
port);
pthread_detach(*thread); /* for proper thread termination */ pthread_detach(*thread); /* for proper thread termination */
@@ -625,7 +681,9 @@ void init_port_threads(
} }
} }
bool init_router() { bool init_router(
)
{
MSGBOX_ID msgboxid; MSGBOX_ID msgboxid;
ROUTER_PORT *port; ROUTER_PORT *port;
@@ -661,7 +719,9 @@ bool init_router() {
return true; return true;
} }
void cleanup() { void cleanup(
)
{
ROUTER_PORT *port; ROUTER_PORT *port;
BACMSG msg; BACMSG msg;
@@ -696,7 +756,9 @@ void cleanup() {
pthread_mutex_destroy(&msg_lock); pthread_mutex_destroy(&msg_lock);
} }
void print_msg(BACMSG *msg) { void print_msg(
BACMSG * msg)
{
if (msg->type == DATA) { if (msg->type == DATA) {
int i; int i;
MSG_DATA *data = (MSG_DATA *) msg->data; MSG_DATA *data = (MSG_DATA *) msg->data;
@@ -710,9 +772,11 @@ void print_msg(BACMSG *msg) {
} }
} }
uint16_t process_msg(BACMSG *msg, uint16_t process_msg(
BACMSG * msg,
MSG_DATA * data, MSG_DATA * data,
uint8_t **buff) { uint8_t ** buff)
{
BACNET_ADDRESS addr; BACNET_ADDRESS addr;
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
@@ -737,14 +801,16 @@ uint16_t process_msg(BACMSG *msg,
data->src.net = srcport->route_info.net; data->src.net = srcport->route_info.net;
/* if received from another router save real source address (not other router source address) */ /* if received from another router save real source address (not other router source address) */
if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && data->src.net != addr.net) if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK &&
data->src.net != addr.net)
memmove(&data->src, &addr, sizeof(BACNET_ADDRESS)); memmove(&data->src, &addr, sizeof(BACNET_ADDRESS));
/* encode both source and destination for broadcast and router-to-router communication */ /* encode both source and destination for broadcast and router-to-router communication */
if (data->dest.net == BACNET_BROADCAST_NETWORK || destport->route_info.net != data->dest.net) { if (data->dest.net == BACNET_BROADCAST_NETWORK ||
npdu_len = npdu_encode_pdu(npdu, &data->dest, &data->src, &npdu_data); destport->route_info.net != data->dest.net) {
} npdu_len =
else { npdu_encode_pdu(npdu, &data->dest, &data->src, &npdu_data);
} else {
npdu_len = npdu_encode_pdu(npdu, NULL, &data->src, &npdu_data); npdu_len = npdu_encode_pdu(npdu, NULL, &data->src, &npdu_data);
} }
@@ -765,7 +831,8 @@ uint16_t process_msg(BACMSG *msg,
return buff_len; return buff_len;
} }
int kbhit() int kbhit(
)
{ {
static const int STDIN = 0; static const int STDIN = 0;
static bool initialized = false; static bool initialized = false;
@@ -785,7 +852,9 @@ int kbhit()
return bytesWaiting; return bytesWaiting;
} }
bool is_network_msg(BACMSG *msg) { bool is_network_msg(
BACMSG * msg)
{
uint8_t control_byte; /* NPDU control byte */ uint8_t control_byte; /* NPDU control byte */
MSG_DATA *data = (MSG_DATA *) msg->data; MSG_DATA *data = (MSG_DATA *) msg->data;
@@ -795,7 +864,9 @@ bool is_network_msg(BACMSG *msg) {
return control_byte & 0x80; /* check 7th bit */ return control_byte & 0x80; /* check 7th bit */
} }
uint16_t get_next_free_dnet() { uint16_t get_next_free_dnet(
)
{
ROUTER_PORT *port = head; ROUTER_PORT *port = head;
uint16_t i = 1; uint16_t i = 1;
@@ -810,4 +881,3 @@ uint16_t get_next_free_dnet() {
} }
return i; return i;
} }
+13 -6
View File
@@ -23,7 +23,9 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
pthread_mutex_t msg_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t msg_lock = PTHREAD_MUTEX_INITIALIZER;
MSGBOX_ID create_msgbox() { MSGBOX_ID create_msgbox(
)
{
MSGBOX_ID msgboxid; MSGBOX_ID msgboxid;
msgboxid = msgget(IPC_PRIVATE, 0666 | IPC_CREAT); msgboxid = msgget(IPC_PRIVATE, 0666 | IPC_CREAT);
@@ -36,7 +38,8 @@ MSGBOX_ID create_msgbox() {
bool send_to_msgbox( bool send_to_msgbox(
MSGBOX_ID dest, MSGBOX_ID dest,
BACMSG *msg) { BACMSG * msg)
{
int err; int err;
@@ -49,7 +52,8 @@ bool send_to_msgbox(
BACMSG *recv_from_msgbox( BACMSG *recv_from_msgbox(
MSGBOX_ID src, MSGBOX_ID src,
BACMSG *msg) { BACMSG * msg)
{
int recv_bytes; int recv_bytes;
@@ -62,7 +66,8 @@ BACMSG* recv_from_msgbox(
} }
void del_msgbox( void del_msgbox(
MSGBOX_ID msgboxid) { MSGBOX_ID msgboxid)
{
if (msgboxid == INVALID_MSGBOX_ID) if (msgboxid == INVALID_MSGBOX_ID)
return; return;
@@ -71,7 +76,8 @@ void del_msgbox(
} }
void free_data( void free_data(
MSG_DATA *data) { MSG_DATA * data)
{
if (data->pdu) { if (data->pdu) {
free(data->pdu); free(data->pdu);
@@ -84,7 +90,8 @@ void free_data(
} }
void check_data( void check_data(
MSG_DATA *data) { MSG_DATA * data)
{
/* lock and decrement messages reference count */ /* lock and decrement messages reference count */
pthread_mutex_lock(&msg_lock); pthread_mutex_lock(&msg_lock);
+2 -1
View File
@@ -59,7 +59,8 @@ typedef struct _msg_data {
uint8_t ref_count; uint8_t ref_count;
} MSG_DATA; } MSG_DATA;
MSGBOX_ID create_msgbox(); MSGBOX_ID create_msgbox(
);
/* returns sent byte count */ /* returns sent byte count */
bool send_to_msgbox( bool send_to_msgbox(
+20 -21
View File
@@ -29,7 +29,9 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
#define mstp_thread_debug(...) #define mstp_thread_debug(...)
#endif #endif
void* dl_mstp_thread(void* pArgs) { void *dl_mstp_thread(
void *pArgs)
{
ROUTER_PORT *port = (ROUTER_PORT *) pArgs; ROUTER_PORT *port = (ROUTER_PORT *) pArgs;
struct mstp_port_struct_t mstp_port = { (MSTP_RECEIVE_STATE) 0 }; struct mstp_port_struct_t mstp_port = { (MSTP_RECEIVE_STATE) 0 };
@@ -76,7 +78,8 @@ void* dl_mstp_thread(void* pArgs) {
mstp_port.UserData = (void *) &shared_port_data; mstp_port.UserData = (void *) &shared_port_data;
dlmstp_set_baud_rate(&mstp_port, port->params.mstp_params.baudrate); dlmstp_set_baud_rate(&mstp_port, port->params.mstp_params.baudrate);
dlmstp_set_mac_address(&mstp_port, port->route_info.mac[0]); dlmstp_set_mac_address(&mstp_port, port->route_info.mac[0]);
dlmstp_set_max_info_frames(&mstp_port, port->params.mstp_params.max_frames); dlmstp_set_max_info_frames(&mstp_port,
port->params.mstp_params.max_frames);
dlmstp_set_max_master(&mstp_port, port->params.mstp_params.max_master); dlmstp_set_max_master(&mstp_port, port->params.mstp_params.max_master);
if (!dlmstp_init(&mstp_port, port->iface)) if (!dlmstp_init(&mstp_port, port->iface))
printf("MSTP %s init failed. Stop.\n", port->iface); printf("MSTP %s init failed. Stop.\n", port->iface);
@@ -96,24 +99,20 @@ void* dl_mstp_thread(void* pArgs) {
bacmsg = recv_from_msgbox(port->port_id, &msg_storage); bacmsg = recv_from_msgbox(port->port_id, &msg_storage);
if(bacmsg) if (bacmsg) {
{ switch (bacmsg->type) {
switch(bacmsg->type)
{
case DATA: case DATA:
msg_data = (MSG_DATA *) bacmsg->data; msg_data = (MSG_DATA *) bacmsg->data;
if(msg_data->dest.net == BACNET_BROADCAST_NETWORK) if (msg_data->dest.net == BACNET_BROADCAST_NETWORK) {
{
dlmstp_get_broadcast_address(&(msg_data->dest)); dlmstp_get_broadcast_address(&(msg_data->dest));
} } else {
else
{
msg_data->dest.mac[0] = msg_data->dest.adr[0]; msg_data->dest.mac[0] = msg_data->dest.adr[0];
msg_data->dest.mac_len = 1; msg_data->dest.mac_len = 1;
} }
dlmstp_send_pdu(&mstp_port, &(msg_data->dest), msg_data->pdu, msg_data->pdu_len); dlmstp_send_pdu(&mstp_port, &(msg_data->dest),
msg_data->pdu, msg_data->pdu_len);
check_data(msg_data); check_data(msg_data);
@@ -132,19 +131,20 @@ void* dl_mstp_thread(void* pArgs) {
continue; continue;
break; break;
} }
} } else {
else
{
pdu_len = dlmstp_receive(&mstp_port, NULL, NULL, 0, 1000); pdu_len = dlmstp_receive(&mstp_port, NULL, NULL, 0, 1000);
if(pdu_len > 0) if (pdu_len > 0) {
{
msg_data = (MSG_DATA *) malloc(sizeof(MSG_DATA)); msg_data = (MSG_DATA *) malloc(sizeof(MSG_DATA));
memmove(&(msg_data->src), (const void*)&(shared_port_data.Receive_Packet.address), sizeof(shared_port_data.Receive_Packet.address)); memmove(&(msg_data->src),
(const void *) &(shared_port_data.Receive_Packet.address),
sizeof(shared_port_data.Receive_Packet.address));
msg_data->src.adr[0] = msg_data->src.mac[0]; msg_data->src.adr[0] = msg_data->src.mac[0];
msg_data->src.len = 1; msg_data->src.len = 1;
msg_data->pdu = (uint8_t *) malloc(pdu_len); msg_data->pdu = (uint8_t *) malloc(pdu_len);
memmove(msg_data->pdu, (const void*)&(shared_port_data.Receive_Packet.pdu), pdu_len); memmove(msg_data->pdu,
(const void *) &(shared_port_data.Receive_Packet.pdu),
pdu_len);
msg_data->pdu_len = pdu_len; msg_data->pdu_len = pdu_len;
msg_storage.type = DATA; msg_storage.type = DATA;
@@ -152,8 +152,7 @@ void* dl_mstp_thread(void* pArgs) {
msg_storage.origin = port->port_id; msg_storage.origin = port->port_id;
msg_storage.data = msg_data; msg_storage.data = msg_data;
if(!send_to_msgbox(port->main_id, &msg_storage)) if (!send_to_msgbox(port->main_id, &msg_storage)) {
{
free_data(msg_data); free_data(msg_data);
} }
} }
+32 -16
View File
@@ -23,7 +23,8 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
uint16_t process_network_message( uint16_t process_network_message(
BACMSG * msg, BACMSG * msg,
MSG_DATA * data, MSG_DATA * data,
uint8_t **buff) { uint8_t ** buff)
{
BACNET_NPDU_DATA npdu_data; BACNET_NPDU_DATA npdu_data;
ROUTER_PORT *srcport; ROUTER_PORT *srcport;
@@ -58,8 +59,10 @@ uint16_t process_network_message(
if (destport) { if (destport) {
/* if TRUE send reply */ /* if TRUE send reply */
PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, buff_len =
data, buff, &net); create_network_message
(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff,
&net);
} else { } else {
data->dest.net = net; /* NET to look for */ data->dest.net = net; /* NET to look for */
return -1; /* else initiate NET search procedure */ return -1; /* else initiate NET search procedure */
@@ -67,8 +70,9 @@ uint16_t process_network_message(
} else { } else {
/* if NET is omitted (message sent with -1) */ /* if NET is omitted (message sent with -1) */
PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); PRINT(INFO, "Sending I-Am-Router-To-Network message\n");
buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, buff_len =
data, buff, NULL); create_network_message
(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff, NULL);
} }
break; break;
@@ -121,9 +125,13 @@ uint16_t process_network_message(
else else
i = i + 4; i = i + 4;
} }
buff_len = create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, NULL); buff_len =
create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK,
data, buff, NULL);
} else } else
buff_len = create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, &buff); buff_len =
create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK,
data, buff, &buff);
break; break;
case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: case NETWORK_MESSAGE_INIT_RT_TABLE_ACK:
@@ -163,7 +171,8 @@ uint16_t create_network_message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type, BACNET_NETWORK_MESSAGE_TYPE network_message_type,
MSG_DATA * data, MSG_DATA * data,
uint8_t ** buff, uint8_t ** buff,
void *val) { void *val)
{
int16_t buff_len; int16_t buff_len;
bool data_expecting_reply = false; bool data_expecting_reply = false;
@@ -194,23 +203,26 @@ uint16_t create_network_message(
uint8_t *valptr = (uint8_t *) val; uint8_t *valptr = (uint8_t *) val;
uint16_t val16 = (valptr[0]) + (valptr[1] << 8); uint16_t val16 = (valptr[0]) + (valptr[1] << 8);
buff_len += encode_unsigned16(*buff + buff_len, val16); buff_len += encode_unsigned16(*buff + buff_len, val16);
} } else {
else {
ROUTER_PORT *port = head; ROUTER_PORT *port = head;
DNET *dnet; DNET *dnet;
while (port != NULL) { while (port != NULL) {
if (port->route_info.net != data->src.net) { if (port->route_info.net != data->src.net) {
buff_len += encode_unsigned16(*buff+buff_len, port->route_info.net); buff_len +=
encode_unsigned16(*buff + buff_len,
port->route_info.net);
dnet = port->route_info.dnets; dnet = port->route_info.dnets;
while (dnet != NULL) { while (dnet != NULL) {
buff_len += encode_unsigned16(*buff+buff_len, dnet->net); buff_len +=
encode_unsigned16(*buff + buff_len, dnet->net);
dnet = dnet->next; dnet = dnet->next;
} }
port = port->next; port = port->next;
} else { } else {
dnet = port->route_info.dnets; dnet = port->route_info.dnets;
while (dnet != NULL) { while (dnet != NULL) {
buff_len += encode_unsigned16(*buff+buff_len, dnet->net); buff_len +=
encode_unsigned16(*buff + buff_len, dnet->net);
dnet = dnet->next; dnet = dnet->next;
} }
port = port->next; port = port->next;
@@ -236,7 +248,9 @@ uint16_t create_network_message(
uint8_t portID = 1; uint8_t portID = 1;
while (port != NULL) { while (port != NULL) {
buff_len += encode_unsigned16(*buff+buff_len, port->route_info.net); buff_len +=
encode_unsigned16(*buff + buff_len,
port->route_info.net);
(*buff)[buff_len++] = portID++; (*buff)[buff_len++] = portID++;
(*buff)[buff_len++] = 0; (*buff)[buff_len++] = 0;
port = port->next; port = port->next;
@@ -263,7 +277,8 @@ void send_network_message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type, BACNET_NETWORK_MESSAGE_TYPE network_message_type,
MSG_DATA * data, MSG_DATA * data,
uint8_t ** buff, uint8_t ** buff,
void *val) { void *val)
{
BACMSG msg; BACMSG msg;
ROUTER_PORT *port = head; ROUTER_PORT *port = head;
@@ -297,7 +312,8 @@ void send_network_message(
void init_npdu( void init_npdu(
BACNET_NPDU_DATA * npdu_data, BACNET_NPDU_DATA * npdu_data,
BACNET_NETWORK_MESSAGE_TYPE network_message_type, BACNET_NETWORK_MESSAGE_TYPE network_message_type,
bool data_expecting_reply) { bool data_expecting_reply)
{
if (npdu_data) { if (npdu_data) {
npdu_data->data_expecting_reply = data_expecting_reply; npdu_data->data_expecting_reply = data_expecting_reply;
+8 -4
View File
@@ -20,7 +20,8 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv
#include "portthread.h" #include "portthread.h"
ROUTER_PORT *find_snet( ROUTER_PORT *find_snet(
MSGBOX_ID id) { MSGBOX_ID id)
{
ROUTER_PORT *port = head; ROUTER_PORT *port = head;
@@ -35,7 +36,8 @@ ROUTER_PORT* find_snet(
ROUTER_PORT *find_dnet( ROUTER_PORT *find_dnet(
uint16_t net, uint16_t net,
BACNET_ADDRESS *addr) { BACNET_ADDRESS * addr)
{
ROUTER_PORT *port = head; ROUTER_PORT *port = head;
DNET *dnet; DNET *dnet;
@@ -73,7 +75,8 @@ ROUTER_PORT* find_dnet(
void add_dnet( void add_dnet(
RT_ENTRY * route_info, RT_ENTRY * route_info,
uint16_t net, uint16_t net,
BACNET_ADDRESS addr) { BACNET_ADDRESS addr)
{
DNET *dnet = route_info->dnets; DNET *dnet = route_info->dnets;
DNET *tmp; DNET *tmp;
@@ -105,7 +108,8 @@ void add_dnet(
} }
void cleanup_dnets( void cleanup_dnets(
DNET *dnets) { DNET * dnets)
{
DNET *dnet = dnets; DNET *dnet = dnets;
while (dnet != NULL) { while (dnet != NULL) {
+2 -1
View File
@@ -48,7 +48,8 @@ typedef enum {
} PORT_STATE; } PORT_STATE;
/* router port thread function */ /* router port thread function */
typedef void* (*PORT_FUNC)( typedef void *(
*PORT_FUNC) (
void *); void *);
typedef enum { typedef enum {
+14 -24
View File
@@ -113,8 +113,7 @@ static void print_usage(
char *filename) char *filename)
{ {
printf("Usage: %s [device-instance-min device-instance-min] " printf("Usage: %s [device-instance-min device-instance-min] "
"<object-type object-instance | object-name> [--help]\r\n", "<object-type object-instance | object-name> [--help]\r\n", filename);
filename);
} }
static void print_help( static void print_help(
@@ -123,12 +122,12 @@ static void print_help(
print_usage(filename); print_usage(filename);
printf("Send BACnet WhoHas request to devices, \r\n" printf("Send BACnet WhoHas request to devices, \r\n"
"and wait %u milliseconds (BACNET_APDU_TIMEOUT) for responses.\r\n" "and wait %u milliseconds (BACNET_APDU_TIMEOUT) for responses.\r\n"
"The device-instance-min or max can be 0 to %d.\r\n" "The device-instance-min or max can be 0 to %d.\r\n" "\r\n"
"\r\n" "Use either:\r\n" "The object-type can be 0 to %d.\r\n" "Use either:\r\n" "The object-type can be 0 to %d.\r\n"
"The object-instance can be 0 to %d.\r\n" "or:\r\n" "The object-instance can be 0 to %d.\r\n" "or:\r\n"
"The object-name can be any string of characters.\r\n", "The object-name can be any string of characters.\r\n",
BACNET_MAX_INSTANCE, (unsigned)apdu_timeout(), BACNET_MAX_INSTANCE, (unsigned) apdu_timeout(), BACNET_MAX_OBJECT,
BACNET_MAX_OBJECT, BACNET_MAX_INSTANCE); BACNET_MAX_INSTANCE);
} }
int main( int main(
@@ -152,8 +151,7 @@ int main(
return 0; return 0;
} }
/* print help if requested */ /* print help if requested */
for (argi = 1; argi < argc; argi++) for (argi = 1; argi < argc; argi++) {
{
if (strcmp(argv[argi], "--help") == 0) { if (strcmp(argv[argi], "--help") == 0) {
print_help(filename_remove_path(argv[0])); print_help(filename_remove_path(argv[0]));
return 0; return 0;
@@ -162,14 +160,12 @@ int main(
/* decode the command line parameters */ /* decode the command line parameters */
if (argc < 3) { if (argc < 3) {
/* bacwh "name" */ /* bacwh "name" */
Target_Object_Instance_Min = Target_Object_Instance_Min = Target_Object_Instance_Max = -1;
Target_Object_Instance_Max = -1;
Target_Object_Name = argv[1]; Target_Object_Name = argv[1];
by_name = true; by_name = true;
} else if (argc < 4) { } else if (argc < 4) {
/* bacwh 8 1234 */ /* bacwh 8 1234 */
Target_Object_Instance_Min = Target_Object_Instance_Min = Target_Object_Instance_Max = -1;
Target_Object_Instance_Max = -1;
Target_Object_Type = strtol(argv[1], NULL, 0); Target_Object_Type = strtol(argv[1], NULL, 0);
Target_Object_Instance = strtol(argv[2], NULL, 0); Target_Object_Instance = strtol(argv[2], NULL, 0);
} else if (argc < 5) { } else if (argc < 5) {
@@ -212,14 +208,12 @@ int main(
} }
} }
if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) { if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) {
fprintf(stderr, fprintf(stderr, "object-instance-min=%u - it must be less than %u\r\n",
"object-instance-min=%u - it must be less than %u\r\n",
Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1);
return 1; return 1;
} }
if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) { if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) {
fprintf(stderr, fprintf(stderr, "object-instance-max=%u - it must be less than %u\r\n",
"object-instance-max=%u - it must be less than %u\r\n",
Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1);
return 1; return 1;
} }
@@ -233,15 +227,11 @@ int main(
timeout_seconds = apdu_timeout() / 1000; timeout_seconds = apdu_timeout() / 1000;
/* send the request */ /* send the request */
if (by_name) { if (by_name) {
Send_WhoHas_Name( Send_WhoHas_Name(Target_Object_Instance_Min,
Target_Object_Instance_Min, Target_Object_Instance_Max, Target_Object_Name);
Target_Object_Instance_Max,
Target_Object_Name);
} else { } else {
Send_WhoHas_Object( Send_WhoHas_Object(Target_Object_Instance_Min,
Target_Object_Instance_Min, Target_Object_Instance_Max, Target_Object_Type,
Target_Object_Instance_Max,
Target_Object_Type,
Target_Object_Instance); Target_Object_Instance);
} }
/* loop forever */ /* loop forever */
+59 -87
View File
@@ -73,19 +73,18 @@ struct address_entry {
static struct address_table { static struct address_table {
struct address_entry *first; struct address_entry *first;
struct address_entry *last; struct address_entry *last;
} Address_Table = {0}; } Address_Table = {
0};
struct address_entry * alloc_address_entry(void) struct address_entry *alloc_address_entry(
void)
{ {
struct address_entry *rval; struct address_entry *rval;
rval = (struct address_entry *) calloc(1, sizeof(struct address_entry)); rval = (struct address_entry *) calloc(1, sizeof(struct address_entry));
if(Address_Table.first == 0) if (Address_Table.first == 0) {
{
Address_Table.first = Address_Table.last = rval; Address_Table.first = Address_Table.last = rval;
} } else {
else
{
Address_Table.last->next = rval; Address_Table.last->next = rval;
Address_Table.last = rval; Address_Table.last = rval;
} }
@@ -94,11 +93,15 @@ struct address_entry * alloc_address_entry(void)
bool bacnet_address_matches(BACNET_ADDRESS * a1, BACNET_ADDRESS * a2) bool bacnet_address_matches(
BACNET_ADDRESS * a1,
BACNET_ADDRESS * a2)
{ {
int i = 0; int i = 0;
if(a1->net != a2->net) return false; if (a1->net != a2->net)
if(a1->len != a2->len) return false; return false;
if (a1->len != a2->len)
return false;
for (; i < a1->len; i++) for (; i < a1->len; i++)
if (a1->adr[i] != a2->adr[i]) if (a1->adr[i] != a2->adr[i])
return false; return false;
@@ -115,8 +118,7 @@ void address_table_add(
pMatch = Address_Table.first; pMatch = Address_Table.first;
while (pMatch) { while (pMatch) {
if (pMatch->device_id == device_id) if (pMatch->device_id == device_id) {
{
if (bacnet_address_matches(&pMatch->address, src)) if (bacnet_address_matches(&pMatch->address, src))
return; return;
flags |= BAC_ADDRESS_MULT; flags |= BAC_ADDRESS_MULT;
@@ -219,20 +221,20 @@ static void init_service_handlers(
apdu_set_reject_handler(MyRejectHandler); apdu_set_reject_handler(MyRejectHandler);
} }
void print_macaddr(uint8_t * addr, int len) void print_macaddr(
uint8_t * addr,
int len)
{ {
int j = 0; int j = 0;
while(j < len) while (j < len) {
{
if (j != 0) { if (j != 0) {
printf(":"); printf(":");
} }
printf("%02X", addr[j]); printf("%02X", addr[j]);
j++; j++;
} }
while(j < MAX_MAC_LEN) while (j < MAX_MAC_LEN) {
{
printf(" "); printf(" ");
j++; j++;
} }
@@ -250,23 +252,19 @@ static void print_address_cache(
/* NOTE: this string format is parsed by src/address.c, /* NOTE: this string format is parsed by src/address.c,
so these must be compatible. */ so these must be compatible. */
printf(";%-7s %-20s %-5s %-20s %-4s\n", printf(";%-7s %-20s %-5s %-20s %-4s\n", "Device", "MAC (hex)", "SNET",
"Device", "MAC (hex)", "SNET", "SADR (hex)", "APDU"); "SADR (hex)", "APDU");
printf(";-------- -------------------- ----- -------------------- ----\n"); printf(";-------- -------------------- ----- -------------------- ----\n");
addr = Address_Table.first; addr = Address_Table.first;
while (addr) while (addr) {
{
bacnet_address_copy(&address, &addr->address); bacnet_address_copy(&address, &addr->address);
total_addresses++; total_addresses++;
if(addr->Flags & BAC_ADDRESS_MULT) if (addr->Flags & BAC_ADDRESS_MULT) {
{
dup_addresses++; dup_addresses++;
printf(";"); printf(";");
} } else {
else
{
printf(" "); printf(" ");
} }
printf(" %-7u ", addr->device_id); printf(" %-7u ", addr->device_id);
@@ -288,54 +286,41 @@ static void print_address_cache(
} }
} }
static int print_usage(char* exe_name){ static int print_usage(
printf( char *exe_name)
"Usage:\n" {
"\n" printf("Usage:\n" "\n" "%s [[network]:[address]] "
"%s [[network]:[address]] " "[device-instance-min [device-instance-max]] [--help]\n", exe_name);
"[device-instance-min [device-instance-max]] [--help]\n" ,
exe_name);
return 1; return 1;
} }
static int print_help(char* exe_name){ static int print_help(
printf( char *exe_name)
"Usage:\n" {
"\n" printf("Usage:\n" "\n" "%s [[network]:[address]] "
"%s [[network]:[address]] " "[device-instance-min [device-instance-max]] [--help]\n" "\n"
"[device-instance-min [device-instance-max]] [--help]\n"
"\n"
" Send BACnet WhoIs service request to a device or multiple devices, and wait\n" " Send BACnet WhoIs service request to a device or multiple devices, and wait\n"
" for responses. Displays any devices found and their network information.\n" " for responses. Displays any devices found and their network information.\n"
"\n" "\n" "device-instance:\r\n"
"device-instance:\r\n"
" BACnet Device Object Instance number that you are trying to send a Who-Is\n" " BACnet Device Object Instance number that you are trying to send a Who-Is\n"
" service request. The value should be in the range of 0 to 4194303. A range\n" " service request. The value should be in the range of 0 to 4194303. A range\n"
" of values can also be specified by using a minimum value and a maximum value.\n" " of values can also be specified by using a minimum value and a maximum value.\n"
"\n" "\n" "network:\n"
"network:\n"
" BACnet network number for directed requests. Valid range is from 0 to 65535\n" " BACnet network number for directed requests. Valid range is from 0 to 65535\n"
" where 0 is the local connection and 65535 is network broadcast.\n" " where 0 is the local connection and 65535 is network broadcast.\n"
"\n" "\n" "address:\n"
"address:\n"
" BACnet mac address number. Valid ranges are from 0 to 255 or a IP connection \n" " BACnet mac address number. Valid ranges are from 0 to 255 or a IP connection \n"
" string including port number like 10.1.2.3:47808.\n" " string including port number like 10.1.2.3:47808.\n" "\n"
"\n" "Examples:\n\n" "To send a WhoIs request to Network 123:\n"
"Examples:\n\n" "%s 123:\n\n" "To send a WhoIs request to Network 123 Address 5:\n"
"To send a WhoIs request to Network 123:\n" "%s 123:5\n\n" "To send a WhoIs request to Device 123:\n" "%s 123\n\n"
"%s 123:\n\n"
"To send a WhoIs request to Network 123 Address 5:\n"
"%s 123:5\n\n"
"To send a WhoIs request to Device 123:\n"
"%s 123\n\n"
"To send a WhoIs request to Devices from 1000 to 9000:\n" "To send a WhoIs request to Devices from 1000 to 9000:\n"
"%s 1000 9000\n\n" "%s 1000 9000\n\n"
"To send a WhoIs request to Devices from 1000 to 9000 on Network 123:\n" "To send a WhoIs request to Devices from 1000 to 9000 on Network 123:\n"
"%s 123: 1000 9000\n\n" "%s 123: 1000 9000\n\n" "To send a WhoIs request to all devices:\n"
"To send a WhoIs request to all devices:\n" "%s\n\n", exe_name, exe_name, exe_name, exe_name, exe_name, exe_name,
"%s\n\n", exe_name);
exe_name,exe_name,exe_name,exe_name,exe_name,exe_name,exe_name);
return 1; return 1;
} }
@@ -356,26 +341,18 @@ static int parse_bac_address(
dest->len = 0; dest->len = 0;
if (c==1) if (c == 1) {
{ if (a[0] < 256) { /* mstp */
if( a[0] < 256 ) /* mstp */
{
dest->adr[0] = a[0]; dest->adr[0] = a[0];
dest->len = 1; dest->len = 1;
} } else if (a[0] < 0x0FFFF) { /* lon */
else if ( a[0] < 0x0FFFF ) /* lon */
{
s = htons((uint16_t) a[0]); s = htons((uint16_t) a[0]);
memcpy(&dest->adr[0], &s, 2); memcpy(&dest->adr[0], &s, 2);
dest->len = 2; dest->len = 2;
} } else
else
return 0; return 0;
} } else if (c == 5) { /* ip address */
else if (c==5) /* ip address */ for (i = 0; i < 4; i++) {
{
for(i=0;i<4;i++)
{
if (a[i] == 0 || a[i] > 255) if (a[i] == 0 || a[i] > 255)
return 0; return 0;
@@ -408,8 +385,7 @@ int main(
int argi; int argi;
/* print help if requested */ /* print help if requested */
for (argi = 1; argi < argc; argi++) for (argi = 1; argi < argc; argi++) {
{
if (strcmp(argv[argi], "--help") == 0) { if (strcmp(argv[argi], "--help") == 0) {
print_help(filename_remove_path(argv[0])); print_help(filename_remove_path(argv[0]));
return 0; return 0;
@@ -422,16 +398,13 @@ int main(
if (argc >= 2) { if (argc >= 2) {
char *s; char *s;
long v = strtol(argv[1], &s, 0); long v = strtol(argv[1], &s, 0);
if(*s++ == ':') if (*s++ == ':') {
{
if (argv[1][0] != ':') if (argv[1][0] != ':')
dest.net = (uint16_t) v; dest.net = (uint16_t) v;
dest.mac_len = 0; dest.mac_len = 0;
if (isdigit(*s)) if (isdigit(*s))
parse_bac_address(&dest, s); parse_bac_address(&dest, s);
} } else {
else
{
Target_Object_Instance_Min = Target_Object_Instance_Max = v; Target_Object_Instance_Min = Target_Object_Instance_Max = v;
} }
} }
@@ -440,8 +413,8 @@ int main(
/* empty */ /* empty */
} else if (argc == 3) { } else if (argc == 3) {
if (Target_Object_Instance_Min == -1) if (Target_Object_Instance_Min == -1)
Target_Object_Instance_Min = Target_Object_Instance_Min = Target_Object_Instance_Max =
Target_Object_Instance_Max = strtol(argv[2], NULL, 0); strtol(argv[2], NULL, 0);
else else
Target_Object_Instance_Max = strtol(argv[2], NULL, 0); Target_Object_Instance_Max = strtol(argv[2], NULL, 0);
} else if (argc == 4) { } else if (argc == 4) {
@@ -453,14 +426,12 @@ int main(
} }
if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) { if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) {
fprintf(stderr, fprintf(stderr, "device-instance-min=%u - it must be less than %u\r\n",
"device-instance-min=%u - it must be less than %u\r\n",
Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1);
return 1; return 1;
} }
if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) { if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) {
fprintf(stderr, fprintf(stderr, "device-instance-max=%u - it must be less than %u\r\n",
"device-instance-max=%u - it must be less than %u\r\n",
Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1);
return 1; return 1;
} }
@@ -475,7 +446,8 @@ int main(
last_seconds = time(NULL); last_seconds = time(NULL);
timeout_seconds = apdu_timeout() / 1000; timeout_seconds = apdu_timeout() / 1000;
/* send the request */ /* send the request */
Send_WhoIs_To_Network(&dest,Target_Object_Instance_Min, Target_Object_Instance_Max); Send_WhoIs_To_Network(&dest, Target_Object_Instance_Min,
Target_Object_Instance_Max);
/* loop forever */ /* loop forever */
for (;;) { for (;;) {
/* increment timer - exit if timed out */ /* increment timer - exit if timed out */
+2 -1
View File
@@ -180,7 +180,8 @@ int main(
if (argc < 4) { if (argc < 4) {
/* FIXME: what about access method - record or stream? */ /* FIXME: what about access method - record or stream? */
printf("%s device-instance file-instance local-name [octet count] [pad value]\r\n", printf
("%s device-instance file-instance local-name [octet count] [pad value]\r\n",
filename_remove_path(argv[0])); filename_remove_path(argv[0]));
return 0; return 0;
} }
+2 -1
View File
@@ -345,7 +345,8 @@ int main(
/* at least one second has passed */ /* at least one second has passed */
if (current_seconds != last_seconds) if (current_seconds != last_seconds)
tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); tsm_timer_milliseconds((uint16_t) ((current_seconds -
last_seconds) * 1000));
if (Error_Detected) if (Error_Detected)
break; break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
+2 -6
View File
@@ -94,9 +94,7 @@ extern "C" {
* *
* The network management BIBBs prescribe the BACnet capabilities required to * The network management BIBBs prescribe the BACnet capabilities required to
* interoperably perform network management functions. * interoperably perform network management functions.
*/ *//** @defgroup DMDCC Device Management-Device Communication Control (DM-DCC)
/** @defgroup DMDCC Device Management-Device Communication Control (DM-DCC)
* @ingroup RDMS * @ingroup RDMS
* 16.1 DeviceCommunicationControl Service <br> * 16.1 DeviceCommunicationControl Service <br>
* The DeviceCommunicationControl service is used by a client BACnet-user to * The DeviceCommunicationControl service is used by a client BACnet-user to
@@ -109,9 +107,7 @@ extern "C" {
* "indefinite," meaning communication must be re-enabled by a * "indefinite," meaning communication must be re-enabled by a
* DeviceCommunicationControl or, if supported, ReinitializeDevice service, * DeviceCommunicationControl or, if supported, ReinitializeDevice service,
* not by time. * not by time.
*/ *//** @defgroup NMRC Network Management-Router Configuration (NM-RC)
/** @defgroup NMRC Network Management-Router Configuration (NM-RC)
* @ingroup RDMS * @ingroup RDMS
* The A device may query and change the configuration of routers and * The A device may query and change the configuration of routers and
* half-routers. * half-routers.
+2 -6
View File
@@ -202,9 +202,7 @@ extern "C" {
* These BIBBs prescribe the BACnet capabilities required to interoperably * These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the alarm and event management functions enumerated in 22.2.1.2 * perform the alarm and event management functions enumerated in 22.2.1.2
* for the BACnet devices defined therein. * for the BACnet devices defined therein.
*/ *//** @defgroup EVNOTFCN Alarm and Event-Notification (AE-N)
/** @defgroup EVNOTFCN Alarm and Event-Notification (AE-N)
* @ingroup ALMEVNT * @ingroup ALMEVNT
* 13.6 ConfirmedCOVNotification Service <br> * 13.6 ConfirmedCOVNotification Service <br>
* The ConfirmedCOVNotification service is used to notify subscribers about * The ConfirmedCOVNotification service is used to notify subscribers about
@@ -221,9 +219,7 @@ extern "C" {
* For unsubscribed notifications, the algorithm for determining when to issue * For unsubscribed notifications, the algorithm for determining when to issue
* this service is a local matter and may be based on a change of value, * this service is a local matter and may be based on a change of value,
* periodic updating, or some other criteria. * periodic updating, or some other criteria.
*/ *//** @defgroup ALMACK Alarm and Event-ACK (AE-ACK)
/** @defgroup ALMACK Alarm and Event-ACK (AE-ACK)
* @ingroup ALMEVNT * @ingroup ALMEVNT
* 13.5 AcknowledgeAlarm Service <br> * 13.5 AcknowledgeAlarm Service <br>
* In some systems a device may need to know that an operator has seen the alarm * In some systems a device may need to know that an operator has seen the alarm
+24 -12
View File
@@ -31,40 +31,52 @@ typedef struct fifo_buffer_t FIFO_BUFFER;
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
unsigned FIFO_Count(FIFO_BUFFER const *b); unsigned FIFO_Count(
FIFO_BUFFER const *b);
bool FIFO_Full(FIFO_BUFFER const *b); bool FIFO_Full(
FIFO_BUFFER const *b);
bool FIFO_Available(FIFO_BUFFER const *b, bool FIFO_Available(
FIFO_BUFFER const *b,
unsigned count); unsigned count);
bool FIFO_Empty(FIFO_BUFFER const *b); bool FIFO_Empty(
FIFO_BUFFER const *b);
uint8_t FIFO_Peek(FIFO_BUFFER const *b); uint8_t FIFO_Peek(
FIFO_BUFFER const *b);
uint8_t FIFO_Get(FIFO_BUFFER * b); uint8_t FIFO_Get(
FIFO_BUFFER * b);
unsigned FIFO_Pull(FIFO_BUFFER * b, unsigned FIFO_Pull(
FIFO_BUFFER * b,
uint8_t * data_bytes, uint8_t * data_bytes,
unsigned length); unsigned length);
bool FIFO_Put(FIFO_BUFFER * b, bool FIFO_Put(
FIFO_BUFFER * b,
uint8_t data_byte); uint8_t data_byte);
bool FIFO_Add(FIFO_BUFFER * b, bool FIFO_Add(
FIFO_BUFFER * b,
uint8_t * data_bytes, uint8_t * data_bytes,
unsigned count); unsigned count);
void FIFO_Flush(FIFO_BUFFER * b); void FIFO_Flush(
FIFO_BUFFER * b);
/* note: buffer_len must be a power of two */ /* note: buffer_len must be a power of two */
void FIFO_Init(FIFO_BUFFER * b, void FIFO_Init(
FIFO_BUFFER * b,
volatile uint8_t * buffer, volatile uint8_t * buffer,
unsigned buffer_len); unsigned buffer_len);
#ifdef TEST #ifdef TEST
#include "ctest.h" #include "ctest.h"
void testFIFOBuffer(Test * pTest); void testFIFOBuffer(
Test * pTest);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
+6 -3
View File
@@ -189,11 +189,14 @@ extern "C" {
int handler_timesync_encode_recipients( int handler_timesync_encode_recipients(
uint8_t * apdu, uint8_t * apdu,
int max_apdu); int max_apdu);
void handler_timesync_task(void); void handler_timesync_task(
void handler_timesync_init(void); void);
void handler_timesync_init(
void);
bool handler_timesync_recipient_write( bool handler_timesync_recipient_write(
BACNET_WRITE_PROPERTY_DATA * wp_data); BACNET_WRITE_PROPERTY_DATA * wp_data);
bool handler_timesync_interval_set(uint32_t minutes); bool handler_timesync_interval_set(
uint32_t minutes);
bool handler_timesync_recipient_address_set( bool handler_timesync_recipient_address_set(
unsigned index, unsigned index,
BACNET_ADDRESS * address); BACNET_ADDRESS * address);
+1 -3
View File
@@ -162,9 +162,7 @@ extern "C" {
* These BIBBs prescribe the BACnet capabilities required to interoperably * These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the trending functions enumerated in clause 22.2.1.4 for the * perform the trending functions enumerated in clause 22.2.1.4 for the
* BACnet devices defined therein. * BACnet devices defined therein.
*/ *//** @defgroup TrendReadRange Trending -Read Range Service (eg, in T-VMT)
/** @defgroup TrendReadRange Trending -Read Range Service (eg, in T-VMT)
* @ingroup Trend * @ingroup Trend
* 15.8 ReadRange Service <br> * 15.8 ReadRange Service <br>
* The ReadRange service is used by a client BACnet-user to read a specific * The ReadRange service is used by a client BACnet-user to read a specific
+1 -3
View File
@@ -125,9 +125,7 @@ extern "C" {
* These BIBBs prescribe the BACnet capabilities required to interoperably * These BIBBs prescribe the BACnet capabilities required to interoperably
* perform the data sharing functions enumerated in 22.2.1.1 for the BACnet * perform the data sharing functions enumerated in 22.2.1.1 for the BACnet
* devices defined therein. * devices defined therein.
*/ *//** @defgroup DSRP Data Sharing -Read Property Service (DS-RP)
/** @defgroup DSRP Data Sharing -Read Property Service (DS-RP)
* @ingroup DataShare * @ingroup DataShare
* 15.5 ReadProperty Service <br> * 15.5 ReadProperty Service <br>
* The ReadProperty service is used by a client BACnet-user to request the * The ReadProperty service is used by a client BACnet-user to request the
+2 -2
View File
@@ -367,8 +367,8 @@ bool Analog_Value_Write_Property(
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
level = (uint8_t) value.type.Real; level = (uint8_t) value.type.Real;
object_index = object_index =
Analog_Value_Instance_To_Index(wp_data-> Analog_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Present_Value[object_index] = level; Present_Value[object_index] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
+2 -2
View File
@@ -278,8 +278,8 @@ bool Binary_Value_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = value.type.Enumerated; level = value.type.Enumerated;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = level; Present_Value[object_index] = level;
+6 -6
View File
@@ -855,8 +855,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
@@ -908,13 +908,13 @@ bool Device_Write_Property_Local(
characterstring_encoding(&value.type.Character_String); characterstring_encoding(&value.type.Character_String);
if (encoding < MAX_CHARACTER_STRING_ENCODING) { if (encoding < MAX_CHARACTER_STRING_ENCODING) {
/* All the object names in a device must be unique. */ /* All the object names in a device must be unique. */
if (Device_Valid_Object_Name(&value. if (Device_Valid_Object_Name(&value.type.
type.Character_String, NULL, NULL)) { Character_String, NULL, NULL)) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME;
} else { } else {
Device_Set_Object_Name(&value. Device_Set_Object_Name(&value.type.
type.Character_String); Character_String);
status = true; status = true;
} }
} else { } else {
+2 -2
View File
@@ -218,8 +218,8 @@ bool Binary_Value_Write_Property(
if ((value.type.Enumerated == BINARY_ACTIVE) || if ((value.type.Enumerated == BINARY_ACTIVE) ||
(value.type.Enumerated == BINARY_INACTIVE)) { (value.type.Enumerated == BINARY_INACTIVE)) {
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = Present_Value[object_index] =
(BACNET_BINARY_PV) value.type.Enumerated; (BACNET_BINARY_PV) value.type.Enumerated;
+2 -2
View File
@@ -386,8 +386,8 @@ bool Device_Write_Property(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
+2 -2
View File
@@ -211,8 +211,8 @@ bool Binary_Value_Write_Property(
if ((value.type.Enumerated == BINARY_ACTIVE) || if ((value.type.Enumerated == BINARY_ACTIVE) ||
(value.type.Enumerated == BINARY_INACTIVE)) { (value.type.Enumerated == BINARY_INACTIVE)) {
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = Present_Value[object_index] =
(BACNET_BINARY_PV) value.type.Enumerated; (BACNET_BINARY_PV) value.type.Enumerated;
+2 -4
View File
@@ -169,13 +169,11 @@ int Analog_Input_Read_Property(
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
Analog_Input_Object_Name(rpdata->object_instance, &char_string); Analog_Input_Object_Name(rpdata->object_instance, &char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], encode_application_character_string(&apdu[0], &char_string);
&char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = apdu_len =
encode_application_enumerated(&apdu[0], encode_application_enumerated(&apdu[0], rpdata->object_type);
rpdata->object_type);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
apdu_len = apdu_len =
+2 -4
View File
@@ -221,13 +221,11 @@ int Analog_Value_Read_Property(
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
Analog_Value_Object_Name(rpdata->object_instance, &char_string); Analog_Value_Object_Name(rpdata->object_instance, &char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], encode_application_character_string(&apdu[0], &char_string);
&char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = apdu_len =
encode_application_enumerated(&apdu[0], encode_application_enumerated(&apdu[0], rpdata->object_type);
rpdata->object_type);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
real_value = Analog_Value_Present_Value(rpdata->object_instance); real_value = Analog_Value_Present_Value(rpdata->object_instance);
+2 -1
View File
@@ -65,7 +65,8 @@ static bool seeprom_version_test(
rv = seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2); rv = seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2);
if (rv > 0) { if (rv > 0) {
rv = seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *) & version, 2); rv = seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *) & version,
2);
} }
if ((rv > 0) && (id == SEEPROM_ID) && (version == SEEPROM_VERSION)) { if ((rv > 0) && (id == SEEPROM_ID) && (version == SEEPROM_VERSION)) {
+2 -4
View File
@@ -198,13 +198,11 @@ int Binary_Input_Read_Property(
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
Binary_Input_Object_Name(rpdata->object_instance, &char_string); Binary_Input_Object_Name(rpdata->object_instance, &char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], encode_application_character_string(&apdu[0], &char_string);
&char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = apdu_len =
encode_application_enumerated(&apdu[0], encode_application_enumerated(&apdu[0], rpdata->object_type);
rpdata->object_type);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
value = Binary_Input_Present_Value(rpdata->object_instance); value = Binary_Input_Present_Value(rpdata->object_instance);
+4 -6
View File
@@ -272,13 +272,11 @@ int Binary_Output_Read_Property(
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
Binary_Output_Object_Name(rpdata->object_instance, &char_string); Binary_Output_Object_Name(rpdata->object_instance, &char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], encode_application_character_string(&apdu[0], &char_string);
&char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = apdu_len =
encode_application_enumerated(&apdu[0], encode_application_enumerated(&apdu[0], rpdata->object_type);
rpdata->object_type);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
present_value = present_value =
@@ -461,8 +459,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
Binary_Output_Present_Value_Set(wp_data-> Binary_Output_Present_Value_Set
object_instance, level, priority); (wp_data->object_instance, level, priority);
} else if (priority == 6) { } else if (priority == 6) {
status = false; status = false;
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off
+6 -10
View File
@@ -584,13 +584,11 @@ int Device_Read_Property_Local(
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
Device_Object_Name(rpdata->object_instance, &char_string); Device_Object_Name(rpdata->object_instance, &char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], encode_application_character_string(&apdu[0], &char_string);
&char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = apdu_len =
encode_application_enumerated(&apdu[0], encode_application_enumerated(&apdu[0], rpdata->object_type);
rpdata->object_type);
break; break;
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string, bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string,
@@ -805,8 +803,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
eeprom_bytes_write(NV_EEPROM_DEVICE_0, eeprom_bytes_write(NV_EEPROM_DEVICE_0,
(uint8_t *) & value.type.Object_Id.instance, 4); (uint8_t *) & value.type.Object_Id.instance, 4);
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
@@ -855,10 +853,8 @@ bool Device_Write_Property_Local(
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = status =
bacnet_name_write_unique(NV_EEPROM_DEVICE_NAME, bacnet_name_write_unique(NV_EEPROM_DEVICE_NAME,
wp_data->object_type, wp_data->object_type, wp_data->object_instance,
wp_data->object_instance, &value.type.Character_String, &wp_data->error_class,
&value.type.Character_String,
&wp_data->error_class,
&wp_data->error_code); &wp_data->error_code);
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
+7 -6
View File
@@ -1129,8 +1129,8 @@ static bool MSTP_Master_Node_FSM(
if (pkt != NULL) { if (pkt != NULL) {
matched = matched =
dlmstp_compare_data_expecting_reply(&InputBuffer[0], dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength, SourceAddress, &pkt->buffer[0], pkt->length, DataLength, SourceAddress, &pkt->buffer[0],
pkt->destination_mac); pkt->length, pkt->destination_mac);
} else { } else {
matched = false; matched = false;
} }
@@ -1146,10 +1146,12 @@ static bool MSTP_Master_Node_FSM(
if (pkt->data_expecting_reply) { if (pkt->data_expecting_reply) {
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY; frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
} else { } else {
frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; frame_type =
FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
} }
MSTP_Send_Frame(frame_type, pkt->destination_mac, This_Station, MSTP_Send_Frame(frame_type, pkt->destination_mac,
(uint8_t *) & pkt->buffer[0], pkt->length); This_Station, (uint8_t *) & pkt->buffer[0],
pkt->length);
Master_State = MSTP_MASTER_STATE_IDLE; Master_State = MSTP_MASTER_STATE_IDLE;
/* clear our flag we were holding for comparison */ /* clear our flag we were holding for comparison */
MSTP_Flag.ReceivedValidFrame = false; MSTP_Flag.ReceivedValidFrame = false;
@@ -1354,4 +1356,3 @@ void dlmstp_get_broadcast_address(
return; return;
} }
+10 -11
View File
@@ -43,14 +43,13 @@
bool BIP_Debug = true; bool BIP_Debug = true;
void * void *get_addr_ptr(
get_addr_ptr (struct sockaddr * sockaddr_ptr) struct sockaddr *sockaddr_ptr)
{ {
void *addr_ptr; void *addr_ptr;
if (sockaddr_ptr->sa_family == AF_INET) { if (sockaddr_ptr->sa_family == AF_INET) {
addr_ptr = &((struct sockaddr_in *) sockaddr_ptr)->sin_addr; addr_ptr = &((struct sockaddr_in *) sockaddr_ptr)->sin_addr;
} } else if (sockaddr_ptr->sa_family == AF_INET6) {
else if (sockaddr_ptr->sa_family == AF_INET6) {
addr_ptr = &((struct sockaddr_in6 *) sockaddr_ptr)->sin6_addr; addr_ptr = &((struct sockaddr_in6 *) sockaddr_ptr)->sin6_addr;
} }
return addr_ptr; return addr_ptr;
@@ -81,7 +80,9 @@ long bip_getaddrbyname(
* @param request [in] addr broadaddr netmask * @param request [in] addr broadaddr netmask
*/ */
static int get_local_address( static int get_local_address(
char *ifname,struct in_addr *addr,char *request) char *ifname,
struct in_addr *addr,
char *request)
{ {
char rv; /* return value */ char rv; /* return value */
@@ -90,8 +91,8 @@ static int get_local_address(
int status; int status;
status = getifaddrs(&ifaddrs_ptr); status = getifaddrs(&ifaddrs_ptr);
if (status == -1) { if (status == -1) {
fprintf (stderr, "Error in 'getifaddrs': %d (%s)\n", fprintf(stderr, "Error in 'getifaddrs': %d (%s)\n", errno,
errno, strerror (errno)); strerror(errno));
} }
while (ifaddrs_ptr) { while (ifaddrs_ptr) {
if ((ifaddrs_ptr->ifa_addr->sa_family == AF_INET) && if ((ifaddrs_ptr->ifa_addr->sa_family == AF_INET) &&
@@ -102,11 +103,9 @@ static int get_local_address(
} }
if (strcmp(request, "addr") == 0) { if (strcmp(request, "addr") == 0) {
addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_addr); addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_addr);
} } else if (strcmp(request, "broadaddr") == 0) {
else if (strcmp(request, "broadaddr") == 0) {
addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_broadaddr); addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_broadaddr);
} } else if (strcmp(request, "netmask") == 0) {
else if (strcmp(request, "netmask") == 0) {
addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_netmask); addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_netmask);
} }
if (addr_ptr) { if (addr_ptr) {
+88 -91
View File
@@ -53,14 +53,13 @@ uint32_t Timer_Silence(
{ {
struct timeval now, tmp_diff; struct timeval now, tmp_diff;
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return -1; return -1;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return -1; return -1;
} }
@@ -77,14 +76,13 @@ void Timer_Silence_Reset(
void *poPort) void *poPort)
{ {
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return; return;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return; return;
} }
@@ -109,19 +107,19 @@ void dlmstp_cleanup(
void *poPort) void *poPort)
{ {
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return; return;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return; return;
} }
/* restore the old port settings */ /* restore the old port settings */
tcsetattr(poSharedData->RS485_Handle, TCSANOW, &poSharedData->RS485_oldtio); tcsetattr(poSharedData->RS485_Handle, TCSANOW,
&poSharedData->RS485_oldtio);
close(poSharedData->RS485_Handle); close(poSharedData->RS485_Handle);
pthread_cond_destroy(&poSharedData->Received_Frame_Flag); pthread_cond_destroy(&poSharedData->Received_Frame_Flag);
@@ -143,20 +141,20 @@ int dlmstp_send_pdu(
struct mstp_pdu_packet *pkt; struct mstp_pdu_packet *pkt;
unsigned i = 0; unsigned i = 0;
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return 0; return 0;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return 0; return 0;
} }
pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&poSharedData->PDU_Queue); pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&poSharedData->PDU_Queue);
if (pkt) { if (pkt) {
pkt->data_expecting_reply = BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]); pkt->data_expecting_reply =
BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]);
for (i = 0; i < pdu_len; i++) { for (i = 0; i < pdu_len; i++) {
pkt->buffer[i] = pdu[i]; pkt->buffer[i] = pdu[i];
} }
@@ -179,22 +177,21 @@ uint16_t dlmstp_receive(
struct timespec abstime; struct timespec abstime;
int rv = 0; int rv = 0;
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return 0; return 0;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return 0; return 0;
} }
(void) max_pdu; (void) max_pdu;
/* see if there is a packet available, and a place /* see if there is a packet available, and a place
to put the reply (if necessary) and process it */ to put the reply (if necessary) and process it */
get_abstime(&abstime, timeout); get_abstime(&abstime, timeout);
rv = pthread_cond_timedwait(&poSharedData->Receive_Packet_Flag, &poSharedData->Receive_Packet_Mutex, rv = pthread_cond_timedwait(&poSharedData->Receive_Packet_Flag,
&abstime); &poSharedData->Receive_Packet_Mutex, &abstime);
if (rv == 0) { if (rv == 0) {
if (poSharedData->Receive_Packet.ready) { if (poSharedData->Receive_Packet.ready) {
if (poSharedData->Receive_Packet.pdu_len) { if (poSharedData->Receive_Packet.pdu_len) {
@@ -222,14 +219,13 @@ void *dlmstp_receive_fsm_task(
bool received_frame; bool received_frame;
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg; struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg;
if(!mstp_port) if (!mstp_port) {
{
return NULL; return NULL;
} }
poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)pArg)->UserData; poSharedData =
if(!poSharedData) (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) pArg)->UserData;
{ if (!poSharedData) {
return NULL; return NULL;
} }
@@ -239,7 +235,8 @@ void *dlmstp_receive_fsm_task(
(mstp_port->ReceivedInvalidFrame == false)) { (mstp_port->ReceivedInvalidFrame == false)) {
do { do {
RS485_Check_UART_Data(mstp_port); RS485_Check_UART_Data(mstp_port);
MSTP_Receive_Frame_FSM((volatile struct mstp_port_struct_t*)pArg); MSTP_Receive_Frame_FSM((volatile struct mstp_port_struct_t *)
pArg);
received_frame = mstp_port->ReceivedValidFrame || received_frame = mstp_port->ReceivedValidFrame ||
mstp_port->ReceivedInvalidFrame; mstp_port->ReceivedInvalidFrame;
if (received_frame) { if (received_frame) {
@@ -260,14 +257,13 @@ void *dlmstp_master_fsm_task(
bool run_master = false; bool run_master = false;
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg; struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg;
if(!mstp_port) if (!mstp_port) {
{
return NULL; return NULL;
} }
poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)pArg)->UserData; poSharedData =
if(!poSharedData) (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) pArg)->UserData;
{ if (!poSharedData) {
return NULL; return NULL;
} }
@@ -345,8 +341,7 @@ uint16_t MSTP_Put_Receive(
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return 0; return 0;
} }
@@ -378,8 +373,7 @@ uint16_t MSTP_Get_Send(
struct mstp_pdu_packet *pkt; struct mstp_pdu_packet *pkt;
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return 0; return 0;
} }
@@ -567,8 +561,7 @@ uint16_t MSTP_Get_Reply(
struct mstp_pdu_packet *pkt; struct mstp_pdu_packet *pkt;
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return 0; return 0;
} }
@@ -603,9 +596,9 @@ void dlmstp_set_mac_address(
uint8_t mac_address) uint8_t mac_address)
{ {
/* SHARED_MSTP_DATA * poSharedData; */ /* SHARED_MSTP_DATA * poSharedData; */
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return; return;
} }
/* /*
@@ -634,9 +627,9 @@ uint8_t dlmstp_mac_address(
void *poPort) void *poPort)
{ {
/* SHARED_MSTP_DATA * poSharedData; */ /* SHARED_MSTP_DATA * poSharedData; */
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return 0; return 0;
} }
/* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; /* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
@@ -661,9 +654,9 @@ void dlmstp_set_max_info_frames(
uint8_t max_info_frames) uint8_t max_info_frames)
{ {
/* SHARED_MSTP_DATA * poSharedData; */ /* SHARED_MSTP_DATA * poSharedData; */
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return; return;
} }
/* /*
@@ -689,9 +682,9 @@ uint8_t dlmstp_max_info_frames(
void *poPort) void *poPort)
{ {
/* SHARED_MSTP_DATA * poSharedData; */ /* SHARED_MSTP_DATA * poSharedData; */
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return 0; return 0;
} }
/* /*
@@ -714,9 +707,9 @@ void dlmstp_set_max_master(
uint8_t max_master) uint8_t max_master)
{ {
/* SHARED_MSTP_DATA * poSharedData; */ /* SHARED_MSTP_DATA * poSharedData; */
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return; return;
} }
/* /*
@@ -744,9 +737,9 @@ uint8_t dlmstp_max_master(
void *poPort) void *poPort)
{ {
/* SHARED_MSTP_DATA * poSharedData; */ /* SHARED_MSTP_DATA * poSharedData; */
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return 0; return 0;
} }
/* /*
@@ -765,14 +758,13 @@ void dlmstp_set_baud_rate(
uint32_t baud) uint32_t baud)
{ {
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return; return;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return; return;
} }
@@ -801,14 +793,13 @@ uint32_t dlmstp_baud_rate(
void *poPort) void *poPort)
{ {
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return false; return false;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return false; return false;
} }
@@ -833,14 +824,13 @@ void dlmstp_get_my_address(
{ {
int i = 0; /* counter */ int i = 0; /* counter */
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return; return;
} }
poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return; return;
} }
my_address->mac_len = 1; my_address->mac_len = 1;
@@ -879,22 +869,24 @@ bool dlmstp_init(
unsigned long hThread = 0; unsigned long hThread = 0;
int rv = 0; int rv = 0;
SHARED_MSTP_DATA *poSharedData; SHARED_MSTP_DATA *poSharedData;
struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t*)poPort; struct mstp_port_struct_t *mstp_port =
if(!mstp_port) (struct mstp_port_struct_t *) poPort;
{ if (!mstp_port) {
return false; return false;
} }
poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)mstp_port)->UserData; poSharedData =
if(!poSharedData) (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) mstp_port)->
{ UserData;
if (!poSharedData) {
return false; return false;
} }
poSharedData->RS485_Port_Name = ifname; poSharedData->RS485_Port_Name = ifname;
/* initialize PDU queue */ /* initialize PDU queue */
Ringbuf_Init(&poSharedData->PDU_Queue, (uint8_t *) & poSharedData->PDU_Buffer, Ringbuf_Init(&poSharedData->PDU_Queue,
sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT); (uint8_t *) & poSharedData->PDU_Buffer, sizeof(struct mstp_pdu_packet),
MSTP_PDU_PACKET_COUNT);
/* initialize packet queue */ /* initialize packet queue */
poSharedData->Receive_Packet.ready = false; poSharedData->Receive_Packet.ready = false;
poSharedData->Receive_Packet.pdu_len = 0; poSharedData->Receive_Packet.pdu_len = 0;
@@ -918,7 +910,9 @@ bool dlmstp_init(
Open device for reading and writing. Open device for reading and writing.
Blocking mode - more CPU effecient Blocking mode - more CPU effecient
*/ */
poSharedData->RS485_Handle = open(poSharedData->RS485_Port_Name, O_RDWR | O_NOCTTY | O_NONBLOCK/*| O_NDELAY */ ); poSharedData->RS485_Handle =
open(poSharedData->RS485_Port_Name,
O_RDWR | O_NOCTTY | O_NONBLOCK /*| O_NDELAY */ );
if (poSharedData->RS485_Handle < 0) { if (poSharedData->RS485_Handle < 0) {
perror(poSharedData->RS485_Port_Name); perror(poSharedData->RS485_Port_Name);
exit(-1); exit(-1);
@@ -941,7 +935,8 @@ bool dlmstp_init(
CLOCAL : local connection, no modem contol CLOCAL : local connection, no modem contol
CREAD : enable receiving characters CREAD : enable receiving characters
*/ */
newtio.c_cflag = poSharedData->RS485_Baud | poSharedData->RS485MOD | CLOCAL | CREAD; newtio.c_cflag =
poSharedData->RS485_Baud | poSharedData->RS485MOD | CLOCAL | CREAD;
/* Raw input */ /* Raw input */
newtio.c_iflag = 0; newtio.c_iflag = 0;
/* Raw output */ /* Raw output */
@@ -954,7 +949,8 @@ bool dlmstp_init(
usleep(200000); usleep(200000);
tcflush(poSharedData->RS485_Handle, TCIOFLUSH); tcflush(poSharedData->RS485_Handle, TCIOFLUSH);
/* ringbuffer */ /* ringbuffer */
FIFO_Init(&poSharedData->Rx_FIFO, poSharedData->Rx_Buffer, sizeof(poSharedData->Rx_Buffer)); FIFO_Init(&poSharedData->Rx_FIFO, poSharedData->Rx_Buffer,
sizeof(poSharedData->Rx_Buffer));
printf("=success!\n"); printf("=success!\n");
mstp_port->InputBuffer = &poSharedData->RxBuffer[0]; mstp_port->InputBuffer = &poSharedData->RxBuffer[0];
mstp_port->InputBufferSize = sizeof(poSharedData->RxBuffer); mstp_port->InputBufferSize = sizeof(poSharedData->RxBuffer);
@@ -967,7 +963,8 @@ bool dlmstp_init(
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "MS/TP MAC: %02X\n", mstp_port->This_Station); fprintf(stderr, "MS/TP MAC: %02X\n", mstp_port->This_Station);
fprintf(stderr, "MS/TP Max_Master: %02X\n", mstp_port->Nmax_master); fprintf(stderr, "MS/TP Max_Master: %02X\n", mstp_port->Nmax_master);
fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", mstp_port->Nmax_info_frames); fprintf(stderr, "MS/TP Max_Info_Frames: %u\n",
mstp_port->Nmax_info_frames);
#endif #endif
rv = pthread_create(&hThread, NULL, dlmstp_master_fsm_task, mstp_port); rv = pthread_create(&hThread, NULL, dlmstp_master_fsm_task, mstp_port);
+1 -3
View File
@@ -62,8 +62,7 @@ struct mstp_pdu_packet {
uint8_t buffer[MAX_MPDU]; uint8_t buffer[MAX_MPDU];
}; };
typedef struct shared_mstp_data typedef struct shared_mstp_data {
{
/* Number of MS/TP Packets Rx/Tx */ /* Number of MS/TP Packets Rx/Tx */
uint16_t MSTP_Packets; uint16_t MSTP_Packets;
@@ -206,5 +205,4 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /*DLMSTP_LINUX_H */ #endif /*DLMSTP_LINUX_H */
+10 -14
View File
@@ -221,8 +221,7 @@ uint32_t RS485_Get_Port_Baud_Rate(
{ {
uint32_t baud = 0; uint32_t baud = 0;
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
return 0; return 0;
} }
switch (poSharedData->RS485_Baud) { switch (poSharedData->RS485_Baud) {
@@ -393,8 +392,7 @@ void RS485_Send_Frame(
ssize_t written = 0; ssize_t written = 0;
int greska; int greska;
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
baud = RS485_Get_Baud_Rate(); baud = RS485_Get_Baud_Rate();
/* sleeping for turnaround time is necessary to give other devices /* sleeping for turnaround time is necessary to give other devices
time to change from sending to receiving state. */ time to change from sending to receiving state. */
@@ -419,9 +417,7 @@ void RS485_Send_Frame(
if (mstp_port) { if (mstp_port) {
mstp_port->SilenceTimerReset((void *) mstp_port); mstp_port->SilenceTimerReset((void *) mstp_port);
} }
} } else {
else
{
baud = RS485_Get_Port_Baud_Rate(mstp_port); baud = RS485_Get_Port_Baud_Rate(mstp_port);
/* sleeping for turnaround time is necessary to give other devices /* sleeping for turnaround time is necessary to give other devices
time to change from sending to receiving state. */ time to change from sending to receiving state. */
@@ -466,8 +462,7 @@ void RS485_Check_UART_Data(
int n; int n;
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
if(!poSharedData) if (!poSharedData) {
{
if (mstp_port->ReceiveError == true) { if (mstp_port->ReceiveError == true) {
/* do nothing but wait for state machine to clear the error */ /* do nothing but wait for state machine to clear the error */
/* burning time, so wait a longer time */ /* burning time, so wait a longer time */
@@ -499,9 +494,7 @@ void RS485_Check_UART_Data(
n = read(RS485_Handle, buf, sizeof(buf)); n = read(RS485_Handle, buf, sizeof(buf));
FIFO_Add(&Rx_FIFO, &buf[0], n); FIFO_Add(&Rx_FIFO, &buf[0], n);
} }
} } else {
else
{
if (mstp_port->ReceiveError == true) { if (mstp_port->ReceiveError == true) {
/* do nothing but wait for state machine to clear the error */ /* do nothing but wait for state machine to clear the error */
/* burning time, so wait a longer time */ /* burning time, so wait a longer time */
@@ -525,7 +518,8 @@ void RS485_Check_UART_Data(
/* grab bytes and stuff them into the FIFO every time */ /* grab bytes and stuff them into the FIFO every time */
FD_ZERO(&input); FD_ZERO(&input);
FD_SET(poSharedData->RS485_Handle, &input); FD_SET(poSharedData->RS485_Handle, &input);
n = select(poSharedData->RS485_Handle + 1, &input, NULL, NULL, &waiter); n = select(poSharedData->RS485_Handle + 1, &input, NULL, NULL,
&waiter);
if (n < 0) { if (n < 0) {
return; return;
} }
@@ -602,7 +596,9 @@ void RS485_Initialize(
round(((float) newserial.baud_base) / 76800); round(((float) newserial.baud_base) / 76800);
/* we must check that we calculated some sane value; /* we must check that we calculated some sane value;
small baud bases yield bad custom divisor values */ small baud bases yield bad custom divisor values */
baud_error = fabs (1 -((float)newserial.baud_base)/ baud_error =
fabs(1 -
((float) newserial.baud_base) /
((float) newserial.custom_divisor) / 76800); ((float) newserial.custom_divisor) / 76800);
if ((newserial.custom_divisor == 0) || (baud_error > 0.02)) { if ((newserial.custom_divisor == 0) || (baud_error > 0.02)) {
/* bad divisor */ /* bad divisor */
+4 -5
View File
@@ -219,8 +219,7 @@ void bip_server_callback(
if ((function == BVLC_ORIGINAL_UNICAST_NPDU) || if ((function == BVLC_ORIGINAL_UNICAST_NPDU) ||
(function == BVLC_ORIGINAL_BROADCAST_NPDU)) { (function == BVLC_ORIGINAL_BROADCAST_NPDU)) {
/* ignore messages from me */ /* ignore messages from me */
if ((addr->addr == BIP_Address.s_addr) && if ((addr->addr == BIP_Address.s_addr) && (port == BIP_Port)) {
(port == BIP_Port)) {
pdu_len = 0; pdu_len = 0;
} else { } else {
/* data in src->mac[] is in network format */ /* data in src->mac[] is in network format */
@@ -236,8 +235,7 @@ void bip_server_callback(
} else if (function == BVLC_FORWARDED_NPDU) { } else if (function == BVLC_FORWARDED_NPDU) {
bip_mac_to_addr(&sin_addr, &pdu[4]); bip_mac_to_addr(&sin_addr, &pdu[4]);
memcpy(&sin_port, &pdu[8], 2); memcpy(&sin_port, &pdu[8], 2);
if ((sin_addr.addr == BIP_Address.s_addr) && if ((sin_addr.addr == BIP_Address.s_addr) && (sin_port == BIP_Port)) {
(sin_port == BIP_Port)) {
/* ignore forwarded messages from me */ /* ignore forwarded messages from me */
pdu_len = 0; pdu_len = 0;
} else { } else {
@@ -331,7 +329,8 @@ bool bip_init(
Server_upcb = udp_new(); Server_upcb = udp_new();
if (Server_upcb == NULL) { if (Server_upcb == NULL) {
/* increase MEMP_NUM_UDP_PCB in lwipopts.h */ /* increase MEMP_NUM_UDP_PCB in lwipopts.h */
while(1) {}; while (1) {
};
} }
/* Bind the upcb to the UDP_PORT port */ /* Bind the upcb to the UDP_PORT port */
/* Using IP_ADDR_ANY allow the upcb to be used by any local interface */ /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
-1
View File
@@ -172,4 +172,3 @@ int Analog_Input_Read_Property(
return apdu_len; return apdu_len;
} }
+2 -2
View File
@@ -333,8 +333,8 @@ bool Analog_Value_Write_Property(
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
level = (uint8_t) value.type.Real; level = (uint8_t) value.type.Real;
object_index = object_index =
Analog_Value_Instance_To_Index(wp_data-> Analog_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
Present_Value[object_index] = level; Present_Value[object_index] = level;
/* Note: you could set the physical output here if we /* Note: you could set the physical output here if we
+4 -3
View File
@@ -158,7 +158,8 @@ int Binary_Value_Read_Property(
encode_application_enumerated(&apdu[0], OBJECT_BINARY_VALUE); encode_application_enumerated(&apdu[0], OBJECT_BINARY_VALUE);
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
present_value = Binary_Value_Present_Value(rpdata->object_instance); present_value =
Binary_Value_Present_Value(rpdata->object_instance);
apdu_len = encode_application_enumerated(&apdu[0], present_value); apdu_len = encode_application_enumerated(&apdu[0], present_value);
break; break;
case PROP_STATUS_FLAGS: case PROP_STATUS_FLAGS:
@@ -245,8 +246,8 @@ bool Binary_Value_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) { (value.type.Enumerated <= MAX_BINARY_PV)) {
level = value.type.Enumerated; level = value.type.Enumerated;
object_index = object_index =
Binary_Value_Instance_To_Index(wp_data-> Binary_Value_Instance_To_Index
object_instance); (wp_data->object_instance);
priority--; priority--;
/* NOTE: this Binary value has no priority array */ /* NOTE: this Binary value has no priority array */
Present_Value[object_index] = level; Present_Value[object_index] = level;
+8 -8
View File
@@ -420,10 +420,8 @@ int Device_Read_Property_Local(
} }
} }
} else { } else {
if (Device_Object_List_Identifier( if (Device_Object_List_Identifier(rpdata->array_index,
rpdata->array_index, &object_type, &instance))
&object_type,
&instance))
apdu_len = apdu_len =
encode_application_object_id(&apdu[0], object_type, encode_application_object_id(&apdu[0], object_type,
instance); instance);
@@ -586,8 +584,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
@@ -646,11 +644,13 @@ bool Device_Write_Property_Local(
the device. */ the device. */
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; wp_data->error_code =
ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
} }
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; wp_data->error_code =
ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
} }
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
+5 -6
View File
@@ -916,8 +916,7 @@ bool MSTP_Master_Node_FSM(
should be sent is unknown - so PollForMaster */ should be sent is unknown - so PollForMaster */
mstp_port->Poll_Station = next_this_station; mstp_port->Poll_Station = next_this_station;
MSTP_Create_And_Send_Frame(mstp_port, MSTP_Create_And_Send_Frame(mstp_port,
FRAME_TYPE_POLL_FOR_MASTER, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
mstp_port->Poll_Station,
mstp_port->This_Station, NULL, 0); mstp_port->This_Station, NULL, 0);
mstp_port->RetryCount = 0; mstp_port->RetryCount = 0;
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;
@@ -1150,10 +1149,10 @@ bool MSTP_Master_Node_FSM(
see if the message is that same APDU type see if the message is that same APDU type
along with the matching src/dest and invoke ID */ along with the matching src/dest and invoke ID */
matched = matched =
mstp_compare_data_expecting_reply(&mstp_port-> mstp_compare_data_expecting_reply(&mstp_port->InputBuffer
InputBuffer[0], mstp_port->DataLength, [0], mstp_port->DataLength, mstp_port->SourceAddress,
mstp_port->SourceAddress, &mstp_port->TxBuffer[0], &mstp_port->TxBuffer[0], mstp_port->TxLength,
mstp_port->TxLength, mstp_port->TxDestination); mstp_port->TxDestination);
} }
if (matched && mstp_port->TxReady) { if (matched && mstp_port->TxReady) {
/* Reply */ /* Reply */
+2 -1
View File
@@ -261,7 +261,8 @@ bool bip_init(
bip_set_port(htons((0xBAC0)); bip_set_port(htons((0xBAC0));
/* assumes that the driver has already been initialized */ /* assumes that the driver has already been initialized */
sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP); sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP);
bip_set_socket(sock_fd); if (sock_fd < 0) bip_set_socket(sock_fd);
if (sock_fd < 0)
return false; return false;
/* bind the socket to the local port number and IP address */ /* bind the socket to the local port number and IP address */
sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY);
+2 -2
View File
@@ -436,8 +436,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
Binary_Output_Present_Value_Set(wp_data-> Binary_Output_Present_Value_Set
object_instance, level, priority); (wp_data->object_instance, level, priority);
} else if (priority == 6) { } else if (priority == 6) {
status = false; status = false;
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off
+8 -8
View File
@@ -838,8 +838,8 @@ bool Device_Write_Property_Local(
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
@@ -873,8 +873,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_NAME_LEN, false, WPValidateString(&value, MAX_DEV_NAME_LEN, false,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Object_Name(characterstring_value(&value.type. Device_Set_Object_Name(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -883,8 +883,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_LOC_LEN, true, WPValidateString(&value, MAX_DEV_LOC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Location(characterstring_value(&value.type. Device_Set_Location(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
@@ -894,8 +894,8 @@ bool Device_Write_Property_Local(
WPValidateString(&value, MAX_DEV_DESC_LEN, true, WPValidateString(&value, MAX_DEV_DESC_LEN, true,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
Device_Set_Description(characterstring_value(&value.type. Device_Set_Description(characterstring_value(&value.
Character_String), type.Character_String),
characterstring_length(&value.type.Character_String)); characterstring_length(&value.type.Character_String));
} }
break; break;
+2 -2
View File
@@ -437,8 +437,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) { if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--; priority--;
Binary_Output_Present_Value_Set(wp_data-> Binary_Output_Present_Value_Set
object_instance, level, priority); (wp_data->object_instance, level, priority);
} else if (priority == 6) { } else if (priority == 6) {
status = false; status = false;
/* Command priority 6 is reserved for use by Minimum On/Off /* Command priority 6 is reserved for use by Minimum On/Off
+6 -6
View File
@@ -841,8 +841,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) && if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id. (Device_Set_Object_Instance_Number(value.type.
instance))) { Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */ /* we could send an I-Am broadcast to let the world know */
status = true; status = true;
} else { } else {
@@ -894,13 +894,13 @@ bool Device_Write_Property_Local(
characterstring_encoding(&value.type.Character_String); characterstring_encoding(&value.type.Character_String);
if (encoding < MAX_CHARACTER_STRING_ENCODING) { if (encoding < MAX_CHARACTER_STRING_ENCODING) {
/* All the object names in a device must be unique. */ /* All the object names in a device must be unique. */
if (Device_Valid_Object_Name(&value. if (Device_Valid_Object_Name(&value.type.
type.Character_String, NULL, NULL)) { Character_String, NULL, NULL)) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME;
} else { } else {
Device_Set_Object_Name(&value. Device_Set_Object_Name(&value.type.
type.Character_String); Character_String);
status = true; status = true;
} }
} else { } else {
+4 -2
View File
@@ -149,7 +149,8 @@ static struct Address_Cache_Entry *address_remove_oldest(
pMatch = Address_Cache; pMatch = Address_Cache;
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | if ((pMatch->
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) { BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) {
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */ if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
ulTime = pMatch->TimeToLive; ulTime = pMatch->TimeToLive;
@@ -168,7 +169,8 @@ static struct Address_Cache_Entry *address_remove_oldest(
/* Second pass - try in use and un bound as last resort */ /* Second pass - try in use and un bound as last resort */
pMatch = Address_Cache; pMatch = Address_Cache;
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | if ((pMatch->
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
BAC_ADDR_STATIC)) == BAC_ADDR_STATIC)) ==
((uint8_t) (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ))) { ((uint8_t) (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ))) {
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */ if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
+1 -2
View File
@@ -82,8 +82,7 @@ bool bacnet_address_same(
if (dest->adr[i] != src->adr[i]) if (dest->adr[i] != src->adr[i])
return false; return false;
} }
if (dest->net == 0) if (dest->net == 0) {
{
if (dest->mac_len != src->mac_len) if (dest->mac_len != src->mac_len)
return false; return false;
max_len = dest->mac_len; max_len = dest->mac_len;
+14 -14
View File
@@ -1103,8 +1103,8 @@ int bacapp_snprintf_value(
if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) { if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) {
ret_val = ret_val =
snprintf(str, str_len, "%s", snprintf(str, str_len, "%s",
bactext_object_type_name(value-> bactext_object_type_name(value->type.
type.Enumerated)); Enumerated));
} else if (value->type.Enumerated < 128) { } else if (value->type.Enumerated < 128) {
ret_val = ret_val =
snprintf(str, str_len, "reserved %lu", snprintf(str, str_len, "reserved %lu",
@@ -1124,8 +1124,8 @@ int bacapp_snprintf_value(
if (value->type.Enumerated < 256) { if (value->type.Enumerated < 256) {
ret_val = ret_val =
snprintf(str, str_len, "%s", snprintf(str, str_len, "%s",
bactext_engineering_unit_name(value->type. bactext_engineering_unit_name(value->
Enumerated)); type.Enumerated));
} else { } else {
ret_val = ret_val =
snprintf(str, str_len, "proprietary %lu", snprintf(str, str_len, "proprietary %lu",
@@ -1135,16 +1135,16 @@ int bacapp_snprintf_value(
case PROP_POLARITY: case PROP_POLARITY:
ret_val = ret_val =
snprintf(str, str_len, "%s", snprintf(str, str_len, "%s",
bactext_binary_polarity_name(value->type. bactext_binary_polarity_name(value->
Enumerated)); type.Enumerated));
break; break;
case PROP_PRESENT_VALUE: case PROP_PRESENT_VALUE:
case PROP_RELINQUISH_DEFAULT: case PROP_RELINQUISH_DEFAULT:
if (object_type < PROPRIETARY_BACNET_OBJECT_TYPE) { if (object_type < PROPRIETARY_BACNET_OBJECT_TYPE) {
ret_val = ret_val =
snprintf(str, str_len, "%s", snprintf(str, str_len, "%s",
bactext_binary_present_value_name(value-> bactext_binary_present_value_name(value->type.
type.Enumerated)); Enumerated));
} else { } else {
ret_val = ret_val =
snprintf(str, str_len, "%lu", snprintf(str, str_len, "%lu",
@@ -1159,8 +1159,8 @@ int bacapp_snprintf_value(
case PROP_SYSTEM_STATUS: case PROP_SYSTEM_STATUS:
ret_val = ret_val =
snprintf(str, str_len, "%s", snprintf(str, str_len, "%s",
bactext_device_status_name(value->type. bactext_device_status_name(value->
Enumerated)); type.Enumerated));
break; break;
case PROP_SEGMENTATION_SUPPORTED: case PROP_SEGMENTATION_SUPPORTED:
ret_val = ret_val =
@@ -1261,8 +1261,8 @@ int bacapp_snprintf_value(
break; break;
if (value->type.Object_Id.type < MAX_ASHRAE_OBJECT_TYPE) { if (value->type.Object_Id.type < MAX_ASHRAE_OBJECT_TYPE) {
if (!append_str(&p_str, &rem_str_len, if (!append_str(&p_str, &rem_str_len,
bactext_object_type_name(value->type.Object_Id. bactext_object_type_name(value->type.
type) Object_Id.type)
) )
) )
break; break;
@@ -1645,8 +1645,8 @@ void testBACnetApplicationData_Safe(
break; break;
case BACNET_APPLICATION_TAG_CHARACTER_STRING: case BACNET_APPLICATION_TAG_CHARACTER_STRING:
characterstring_init_ansi(&input_value[i]. characterstring_init_ansi(&input_value[i].type.
type.Character_String, "Hello There!"); Character_String, "Hello There!");
break; break;
case BACNET_APPLICATION_TAG_BIT_STRING: case BACNET_APPLICATION_TAG_BIT_STRING:
+1 -3
View File
@@ -1014,9 +1014,7 @@ int encode_bacnet_character_string(
uint8_t * apdu, uint8_t * apdu,
BACNET_CHARACTER_STRING * char_string) BACNET_CHARACTER_STRING * char_string)
{ {
return (int)encode_bacnet_character_string_safe( return (int) encode_bacnet_character_string_safe(apdu, MAX_APDU,
apdu,
MAX_APDU,
characterstring_encoding(char_string), characterstring_encoding(char_string),
characterstring_value(char_string), characterstring_value(char_string),
characterstring_length(char_string)); characterstring_length(char_string));
+2 -1
View File
@@ -1013,7 +1013,8 @@ INDTEXT_DATA bacnet_property_names[] = {
, ,
{PROP_LIGHTING_COMMAND, "lighting-command"} {PROP_LIGHTING_COMMAND, "lighting-command"}
, ,
{PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY, "lighting-command-default-priority"} {PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY,
"lighting-command-default-priority"}
, ,
{PROP_MAX_ACTUAL_VALUE, "max-actual-value"} {PROP_MAX_ACTUAL_VALUE, "max-actual-value"}
, ,
+2 -3
View File
@@ -166,9 +166,8 @@ int bip_send_pdu(
mtu[0] = BVLL_TYPE_BACNET_IP; mtu[0] = BVLL_TYPE_BACNET_IP;
bip_dest.sin_family = AF_INET; bip_dest.sin_family = AF_INET;
if ((dest->net == BACNET_BROADCAST_NETWORK) || if ((dest->net == BACNET_BROADCAST_NETWORK) || ((dest->net > 0) &&
((dest->net > 0) && (dest->len == 0)) || (dest->len == 0)) || (dest->mac_len == 0)) {
(dest->mac_len == 0)) {
/* broadcast */ /* broadcast */
address.s_addr = BIP_Broadcast_Address.s_addr; address.s_addr = BIP_Broadcast_Address.s_addr;
port = BIP_Port; port = BIP_Port;
+4 -5
View File
@@ -700,8 +700,8 @@ static void bvlc_bdt_forward_npdu(
mask in the BDT entry and logically ORing it with the mask in the BDT entry and logically ORing it with the
BBMD address of the same entry. */ BBMD address of the same entry. */
bip_dest.sin_addr.s_addr = bip_dest.sin_addr.s_addr =
((~BBMD_Table[i].broadcast_mask.s_addr) | BBMD_Table[i]. ((~BBMD_Table[i].broadcast_mask.
dest_address.s_addr); s_addr) | BBMD_Table[i].dest_address.s_addr);
bip_dest.sin_port = BBMD_Table[i].dest_port; bip_dest.sin_port = BBMD_Table[i].dest_port;
/* don't send to my broadcast address and same port */ /* don't send to my broadcast address and same port */
if ((bip_dest.sin_addr.s_addr == bip_get_broadcast_addr()) if ((bip_dest.sin_addr.s_addr == bip_get_broadcast_addr())
@@ -1179,9 +1179,8 @@ int bvlc_send_pdu(
/* mac_len = 0 is a broadcast address */ /* mac_len = 0 is a broadcast address */
/* net = 0 indicates local, net = 65535 indicates global */ /* net = 0 indicates local, net = 65535 indicates global */
/* net > 0 and net < 65535 are network specific broadcast if len = 0 */ /* net > 0 and net < 65535 are network specific broadcast if len = 0 */
if ((dest->net == BACNET_BROADCAST_NETWORK) || if ((dest->net == BACNET_BROADCAST_NETWORK) || ((dest->net > 0) &&
((dest->net > 0) && (dest->len == 0)) || (dest->len == 0)) || (dest->mac_len == 0)) {
(dest->mac_len == 0)) {
/* if we are a foreign device */ /* if we are a foreign device */
if (Remote_BBMD.sin_port) { if (Remote_BBMD.sin_port) {
mtu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK; mtu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK;
+2 -1
View File
@@ -202,7 +202,8 @@ bool datetime_is_valid(
if (bdate) { if (bdate) {
status = date_is_valid(bdate->year, bdate->month, bdate->day); status = date_is_valid(bdate->year, bdate->month, bdate->day);
if (status && btime) { if (status && btime) {
status = time_is_valid(btime->hour, btime->min, btime->sec, status =
time_is_valid(btime->hour, btime->min, btime->sec,
btime->hundredths); btime->hundredths);
} else { } else {
status = false; status = false;
+143 -138
View File
@@ -192,14 +192,14 @@ int event_notify_encode_service_request(
len = len =
encode_context_bitstring(&apdu[apdu_len], 0, encode_context_bitstring(&apdu[apdu_len], 0,
&data->notificationParams.changeOfBitstring. &data->notificationParams.
referencedBitString); changeOfBitstring.referencedBitString);
apdu_len += len; apdu_len += len;
len = len =
encode_context_bitstring(&apdu[apdu_len], 1, encode_context_bitstring(&apdu[apdu_len], 1,
&data->notificationParams.changeOfBitstring. &data->notificationParams.
statusFlags); changeOfBitstring.statusFlags);
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 0); len = encode_closing_tag(&apdu[apdu_len], 0);
@@ -223,8 +223,8 @@ int event_notify_encode_service_request(
len = len =
encode_context_bitstring(&apdu[apdu_len], 1, encode_context_bitstring(&apdu[apdu_len], 1,
&data->notificationParams.changeOfState. &data->notificationParams.
statusFlags); changeOfState.statusFlags);
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 1); len = encode_closing_tag(&apdu[apdu_len], 1);
@@ -242,8 +242,8 @@ int event_notify_encode_service_request(
case CHANGE_OF_VALUE_REAL: case CHANGE_OF_VALUE_REAL:
len = len =
encode_context_real(&apdu[apdu_len], 1, encode_context_real(&apdu[apdu_len], 1,
data->notificationParams.changeOfValue. data->notificationParams.
newValue.changeValue); changeOfValue.newValue.changeValue);
apdu_len += len; apdu_len += len;
break; break;
@@ -251,8 +251,8 @@ int event_notify_encode_service_request(
len = len =
encode_context_bitstring(&apdu[apdu_len], encode_context_bitstring(&apdu[apdu_len],
0, 0,
&data->notificationParams.changeOfValue. &data->notificationParams.
newValue.changedBits); changeOfValue.newValue.changedBits);
apdu_len += len; apdu_len += len;
break; break;
@@ -265,8 +265,8 @@ int event_notify_encode_service_request(
len = len =
encode_context_bitstring(&apdu[apdu_len], 1, encode_context_bitstring(&apdu[apdu_len], 1,
&data->notificationParams.changeOfValue. &data->notificationParams.
statusFlags); changeOfValue.statusFlags);
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 2); len = encode_closing_tag(&apdu[apdu_len], 2);
@@ -280,20 +280,20 @@ int event_notify_encode_service_request(
len = len =
encode_context_real(&apdu[apdu_len], 0, encode_context_real(&apdu[apdu_len], 0,
data->notificationParams.floatingLimit. data->notificationParams.
referenceValue); floatingLimit.referenceValue);
apdu_len += len; apdu_len += len;
len = len =
encode_context_bitstring(&apdu[apdu_len], 1, encode_context_bitstring(&apdu[apdu_len], 1,
&data->notificationParams.floatingLimit. &data->notificationParams.
statusFlags); floatingLimit.statusFlags);
apdu_len += len; apdu_len += len;
len = len =
encode_context_real(&apdu[apdu_len], 2, encode_context_real(&apdu[apdu_len], 2,
data->notificationParams.floatingLimit. data->notificationParams.
setPointValue); floatingLimit.setPointValue);
apdu_len += len; apdu_len += len;
len = len =
@@ -312,8 +312,8 @@ int event_notify_encode_service_request(
len = len =
encode_context_real(&apdu[apdu_len], 0, encode_context_real(&apdu[apdu_len], 0,
data->notificationParams.outOfRange. data->notificationParams.
exceedingValue); outOfRange.exceedingValue);
apdu_len += len; apdu_len += len;
len = len =
@@ -341,26 +341,26 @@ int event_notify_encode_service_request(
len = len =
encode_context_enumerated(&apdu[apdu_len], 0, encode_context_enumerated(&apdu[apdu_len], 0,
data->notificationParams.changeOfLifeSafety. data->notificationParams.
newState); changeOfLifeSafety.newState);
apdu_len += len; apdu_len += len;
len = len =
encode_context_enumerated(&apdu[apdu_len], 1, encode_context_enumerated(&apdu[apdu_len], 1,
data->notificationParams.changeOfLifeSafety. data->notificationParams.
newMode); changeOfLifeSafety.newMode);
apdu_len += len; apdu_len += len;
len = len =
encode_context_bitstring(&apdu[apdu_len], 2, encode_context_bitstring(&apdu[apdu_len], 2,
&data->notificationParams.changeOfLifeSafety. &data->notificationParams.
statusFlags); changeOfLifeSafety.statusFlags);
apdu_len += len; apdu_len += len;
len = len =
encode_context_enumerated(&apdu[apdu_len], 3, encode_context_enumerated(&apdu[apdu_len], 3,
data->notificationParams.changeOfLifeSafety. data->notificationParams.
operationExpected); changeOfLifeSafety.operationExpected);
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 8); len = encode_closing_tag(&apdu[apdu_len], 8);
@@ -374,20 +374,20 @@ int event_notify_encode_service_request(
len = len =
bacapp_encode_context_device_obj_property_ref(&apdu bacapp_encode_context_device_obj_property_ref(&apdu
[apdu_len], 0, [apdu_len], 0,
&data->notificationParams.bufferReady. &data->notificationParams.
bufferProperty); bufferReady.bufferProperty);
apdu_len += len; apdu_len += len;
len = len =
encode_context_unsigned(&apdu[apdu_len], 1, encode_context_unsigned(&apdu[apdu_len], 1,
data->notificationParams.bufferReady. data->notificationParams.
previousNotification); bufferReady.previousNotification);
apdu_len += len; apdu_len += len;
len = len =
encode_context_unsigned(&apdu[apdu_len], 2, encode_context_unsigned(&apdu[apdu_len], 2,
data->notificationParams.bufferReady. data->notificationParams.
currentNotification); bufferReady.currentNotification);
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 10); len = encode_closing_tag(&apdu[apdu_len], 10);
@@ -399,20 +399,20 @@ int event_notify_encode_service_request(
len = len =
encode_context_unsigned(&apdu[apdu_len], 0, encode_context_unsigned(&apdu[apdu_len], 0,
data->notificationParams.unsignedRange. data->notificationParams.
exceedingValue); unsignedRange.exceedingValue);
apdu_len += len; apdu_len += len;
len = len =
encode_context_bitstring(&apdu[apdu_len], 1, encode_context_bitstring(&apdu[apdu_len], 1,
&data->notificationParams.unsignedRange. &data->notificationParams.
statusFlags); unsignedRange.statusFlags);
apdu_len += len; apdu_len += len;
len = len =
encode_context_unsigned(&apdu[apdu_len], 2, encode_context_unsigned(&apdu[apdu_len], 2,
data->notificationParams.unsignedRange. data->notificationParams.
exceededLimit); unsignedRange.exceededLimit);
apdu_len += len; apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 11); len = encode_closing_tag(&apdu[apdu_len], 11);
@@ -595,16 +595,18 @@ int event_notify_decode_service_request(
case EVENT_CHANGE_OF_BITSTRING: case EVENT_CHANGE_OF_BITSTRING:
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 0, decode_context_bitstring(&apdu[len], 0,
&data->notificationParams. &data->
changeOfBitstring.referencedBitString))) { notificationParams.changeOfBitstring.
referencedBitString))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 1, decode_context_bitstring(&apdu[len], 1,
&data->notificationParams. &data->
changeOfBitstring.statusFlags))) { notificationParams.changeOfBitstring.
statusFlags))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -615,16 +617,16 @@ int event_notify_decode_service_request(
if (-1 == (section_length = if (-1 == (section_length =
bacapp_decode_context_property_state(&apdu bacapp_decode_context_property_state(&apdu
[len], 0, [len], 0,
&data->notificationParams.changeOfState. &data->notificationParams.
newState))) { changeOfState.newState))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 1, decode_context_bitstring(&apdu[len], 1,
&data->notificationParams.changeOfState. &data->notificationParams.
statusFlags))) { changeOfState.statusFlags))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -642,8 +644,9 @@ int event_notify_decode_service_request(
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 0, decode_context_bitstring(&apdu[len], 0,
&data->notificationParams. &data->
changeOfValue.newValue.changedBits))) { notificationParams.changeOfValue.
newValue.changedBits))) {
return -1; return -1;
} }
@@ -654,8 +657,9 @@ int event_notify_decode_service_request(
CHANGE_OF_VALUE_REAL)) { CHANGE_OF_VALUE_REAL)) {
if (-1 == (section_length = if (-1 == (section_length =
decode_context_real(&apdu[len], 1, decode_context_real(&apdu[len], 1,
&data->notificationParams. &data->
changeOfValue.newValue.changeValue))) { notificationParams.changeOfValue.
newValue.changeValue))) {
return -1; return -1;
} }
@@ -673,8 +677,8 @@ int event_notify_decode_service_request(
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 1, decode_context_bitstring(&apdu[len], 1,
&data->notificationParams.changeOfValue. &data->notificationParams.
statusFlags))) { changeOfValue.statusFlags))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -683,31 +687,31 @@ int event_notify_decode_service_request(
case EVENT_FLOATING_LIMIT: case EVENT_FLOATING_LIMIT:
if (-1 == (section_length = if (-1 == (section_length =
decode_context_real(&apdu[len], 0, decode_context_real(&apdu[len], 0,
&data->notificationParams.floatingLimit. &data->notificationParams.
referenceValue))) { floatingLimit.referenceValue))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 1, decode_context_bitstring(&apdu[len], 1,
&data->notificationParams.floatingLimit. &data->notificationParams.
statusFlags))) { floatingLimit.statusFlags))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_real(&apdu[len], 2, decode_context_real(&apdu[len], 2,
&data->notificationParams.floatingLimit. &data->notificationParams.
setPointValue))) { floatingLimit.setPointValue))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_real(&apdu[len], 3, decode_context_real(&apdu[len], 3,
&data->notificationParams.floatingLimit. &data->notificationParams.
errorLimit))) { floatingLimit.errorLimit))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -716,31 +720,31 @@ int event_notify_decode_service_request(
case EVENT_OUT_OF_RANGE: case EVENT_OUT_OF_RANGE:
if (-1 == (section_length = if (-1 == (section_length =
decode_context_real(&apdu[len], 0, decode_context_real(&apdu[len], 0,
&data->notificationParams.outOfRange. &data->notificationParams.
exceedingValue))) { outOfRange.exceedingValue))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 1, decode_context_bitstring(&apdu[len], 1,
&data->notificationParams.outOfRange. &data->notificationParams.
statusFlags))) { outOfRange.statusFlags))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_real(&apdu[len], 2, decode_context_real(&apdu[len], 2,
&data->notificationParams.outOfRange. &data->notificationParams.
deadband))) { outOfRange.deadband))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_real(&apdu[len], 3, decode_context_real(&apdu[len], 3,
&data->notificationParams.outOfRange. &data->notificationParams.
exceededLimit))) { outOfRange.exceededLimit))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -768,8 +772,9 @@ int event_notify_decode_service_request(
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 2, decode_context_bitstring(&apdu[len], 2,
&data->notificationParams. &data->
changeOfLifeSafety.statusFlags))) { notificationParams.changeOfLifeSafety.
statusFlags))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -779,8 +784,8 @@ int event_notify_decode_service_request(
&value))) { &value))) {
return -1; return -1;
} }
data->notificationParams.changeOfLifeSafety. data->notificationParams.
operationExpected = changeOfLifeSafety.operationExpected =
(BACNET_LIFE_SAFETY_OPERATION) value; (BACNET_LIFE_SAFETY_OPERATION) value;
len += section_length; len += section_length;
break; break;
@@ -789,24 +794,24 @@ int event_notify_decode_service_request(
if (-1 == (section_length = if (-1 == (section_length =
bacapp_decode_context_device_obj_property_ref bacapp_decode_context_device_obj_property_ref
(&apdu[len], 0, (&apdu[len], 0,
&data->notificationParams.bufferReady. &data->notificationParams.
bufferProperty))) { bufferReady.bufferProperty))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_unsigned(&apdu[len], 1, decode_context_unsigned(&apdu[len], 1,
&data->notificationParams.bufferReady. &data->notificationParams.
previousNotification))) { bufferReady.previousNotification))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_unsigned(&apdu[len], 2, decode_context_unsigned(&apdu[len], 2,
&data->notificationParams.bufferReady. &data->notificationParams.
currentNotification))) { bufferReady.currentNotification))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -815,24 +820,24 @@ int event_notify_decode_service_request(
case EVENT_UNSIGNED_RANGE: case EVENT_UNSIGNED_RANGE:
if (-1 == (section_length = if (-1 == (section_length =
decode_context_unsigned(&apdu[len], 0, decode_context_unsigned(&apdu[len], 0,
&data->notificationParams.unsignedRange. &data->notificationParams.
exceedingValue))) { unsignedRange.exceedingValue))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_bitstring(&apdu[len], 1, decode_context_bitstring(&apdu[len], 1,
&data->notificationParams.unsignedRange. &data->notificationParams.
statusFlags))) { unsignedRange.statusFlags))) {
return -1; return -1;
} }
len += section_length; len += section_length;
if (-1 == (section_length = if (-1 == (section_length =
decode_context_unsigned(&apdu[len], 2, decode_context_unsigned(&apdu[len], 2,
&data->notificationParams.unsignedRange. &data->notificationParams.
exceededLimit))) { unsignedRange.exceededLimit))) {
return -1; return -1;
} }
len += section_length; len += section_length;
@@ -1078,16 +1083,16 @@ void testEventEventState(
data.eventType = EVENT_CHANGE_OF_BITSTRING; data.eventType = EVENT_CHANGE_OF_BITSTRING;
bitstring_init(&data.notificationParams.changeOfBitstring. bitstring_init(&data.notificationParams.
referencedBitString); changeOfBitstring.referencedBitString);
bitstring_set_bit(&data.notificationParams.changeOfBitstring. bitstring_set_bit(&data.notificationParams.
referencedBitString, 0, true); changeOfBitstring.referencedBitString, 0, true);
bitstring_set_bit(&data.notificationParams.changeOfBitstring. bitstring_set_bit(&data.notificationParams.
referencedBitString, 1, false); changeOfBitstring.referencedBitString, 1, false);
bitstring_set_bit(&data.notificationParams.changeOfBitstring. bitstring_set_bit(&data.notificationParams.
referencedBitString, 2, true); changeOfBitstring.referencedBitString, 2, true);
bitstring_set_bit(&data.notificationParams.changeOfBitstring. bitstring_set_bit(&data.notificationParams.
referencedBitString, 2, false); changeOfBitstring.referencedBitString, 2, false);
bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags); bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags);
@@ -1111,8 +1116,8 @@ void testEventEventState(
testBaseEventState(pTest); testBaseEventState(pTest);
ct_test(pTest, ct_test(pTest,
bitstring_same(&data.notificationParams. bitstring_same(&data.notificationParams.changeOfBitstring.
changeOfBitstring.referencedBitString, referencedBitString,
&data2.notificationParams.changeOfBitstring.referencedBitString)); &data2.notificationParams.changeOfBitstring.referencedBitString));
ct_test(pTest, ct_test(pTest,
@@ -1175,16 +1180,16 @@ void testEventEventState(
data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS; data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS;
bitstring_init(&data.notificationParams.changeOfValue.newValue. bitstring_init(&data.notificationParams.changeOfValue.
changedBits); newValue.changedBits);
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. bitstring_set_bit(&data.notificationParams.changeOfValue.
changedBits, 0, true); newValue.changedBits, 0, true);
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. bitstring_set_bit(&data.notificationParams.changeOfValue.
changedBits, 1, false); newValue.changedBits, 1, false);
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. bitstring_set_bit(&data.notificationParams.changeOfValue.
changedBits, 2, false); newValue.changedBits, 2, false);
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. bitstring_set_bit(&data.notificationParams.changeOfValue.
changedBits, 3, false); newValue.changedBits, 3, false);
memset(buffer, 0, MAX_APDU); memset(buffer, 0, MAX_APDU);
inLen = event_notify_encode_service_request(&buffer[0], &data); inLen = event_notify_encode_service_request(&buffer[0], &data);
@@ -1205,8 +1210,8 @@ void testEventEventState(
data2.notificationParams.changeOfValue.tag); data2.notificationParams.changeOfValue.tag);
ct_test(pTest, ct_test(pTest,
bitstring_same(&data.notificationParams.changeOfValue. bitstring_same(&data.notificationParams.changeOfValue.newValue.
newValue.changedBits, changedBits,
&data2.notificationParams.changeOfValue.newValue.changedBits)); &data2.notificationParams.changeOfValue.newValue.changedBits));
/**********************************************************************************/ /**********************************************************************************/
@@ -1429,12 +1434,12 @@ void testEventEventState(
data.notificationParams.bufferReady.currentNotification = 2345; data.notificationParams.bufferReady.currentNotification = 2345;
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.type = data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.type =
OBJECT_DEVICE; OBJECT_DEVICE;
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier. data.notificationParams.bufferReady.bufferProperty.
instance = 500; deviceIndentifier.instance = 500;
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.type = data.notificationParams.bufferReady.bufferProperty.objectIdentifier.type =
OBJECT_ANALOG_INPUT; OBJECT_ANALOG_INPUT;
data.notificationParams.bufferReady.bufferProperty.objectIdentifier. data.notificationParams.bufferReady.bufferProperty.
instance = 100; objectIdentifier.instance = 100;
data.notificationParams.bufferReady.bufferProperty.propertyIdentifier = data.notificationParams.bufferReady.bufferProperty.propertyIdentifier =
PROP_PRESENT_VALUE; PROP_PRESENT_VALUE;
data.notificationParams.bufferReady.bufferProperty.arrayIndex = 0; data.notificationParams.bufferReady.bufferProperty.arrayIndex = 0;
@@ -1459,34 +1464,34 @@ void testEventEventState(
ct_test(pTest, ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier. data.notificationParams.bufferReady.bufferProperty.
type == deviceIndentifier.type ==
data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier. data2.notificationParams.bufferReady.bufferProperty.
type); deviceIndentifier.type);
ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
instance ==
data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
instance);
ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
instance ==
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier.
instance);
ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
type ==
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier.
type);
ct_test(pTest, ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty. data.notificationParams.bufferReady.bufferProperty.
propertyIdentifier == deviceIndentifier.instance ==
data2.notificationParams.bufferReady.bufferProperty. data2.notificationParams.bufferReady.bufferProperty.
propertyIdentifier); deviceIndentifier.instance);
ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty.
objectIdentifier.instance ==
data2.notificationParams.bufferReady.bufferProperty.
objectIdentifier.instance);
ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty.
objectIdentifier.type ==
data2.notificationParams.bufferReady.bufferProperty.
objectIdentifier.type);
ct_test(pTest,
data.notificationParams.bufferReady.
bufferProperty.propertyIdentifier ==
data2.notificationParams.bufferReady.
bufferProperty.propertyIdentifier);
ct_test(pTest, ct_test(pTest,
data.notificationParams.bufferReady.bufferProperty.arrayIndex == data.notificationParams.bufferReady.bufferProperty.arrayIndex ==
+26 -13
View File
@@ -101,7 +101,8 @@
* *
* @return Number of bytes in the FIFO * @return Number of bytes in the FIFO
*/ */
unsigned FIFO_Count(FIFO_BUFFER const *b) unsigned FIFO_Count(
FIFO_BUFFER const *b)
{ {
unsigned head, tail; /* used to avoid volatile decision */ unsigned head, tail; /* used to avoid volatile decision */
@@ -121,7 +122,8 @@ unsigned FIFO_Count(FIFO_BUFFER const *b)
* *
* @return true if the FIFO is full, false if it is not. * @return true if the FIFO is full, false if it is not.
*/ */
bool FIFO_Full(FIFO_BUFFER const *b) bool FIFO_Full(
FIFO_BUFFER const *b)
{ {
return (b ? (FIFO_Count(b) == b->buffer_len) : true); return (b ? (FIFO_Count(b) == b->buffer_len) : true);
} }
@@ -134,7 +136,8 @@ bool FIFO_Full(FIFO_BUFFER const *b)
* *
* @return true if the number of bytes sought is available * @return true if the number of bytes sought is available
*/ */
bool FIFO_Available(FIFO_BUFFER const *b, bool FIFO_Available(
FIFO_BUFFER const *b,
unsigned count) unsigned count)
{ {
return (b ? (count <= (b->buffer_len - FIFO_Count(b))) : false); return (b ? (count <= (b->buffer_len - FIFO_Count(b))) : false);
@@ -146,7 +149,8 @@ bool FIFO_Available(FIFO_BUFFER const *b,
* @param b - pointer to FIFO_BUFFER structure * @param b - pointer to FIFO_BUFFER structure
* @return true if the FIFO is empty, false if it is not. * @return true if the FIFO is empty, false if it is not.
*/ */
bool FIFO_Empty(FIFO_BUFFER const *b) bool FIFO_Empty(
FIFO_BUFFER const *b)
{ {
return (b ? (FIFO_Count(b) == 0) : true); return (b ? (FIFO_Count(b) == 0) : true);
} }
@@ -161,7 +165,8 @@ bool FIFO_Empty(FIFO_BUFFER const *b)
* *
* @return byte of data, or zero if nothing in the list * @return byte of data, or zero if nothing in the list
*/ */
uint8_t FIFO_Peek(FIFO_BUFFER const *b) uint8_t FIFO_Peek(
FIFO_BUFFER const *b)
{ {
unsigned index; unsigned index;
@@ -183,7 +188,8 @@ uint8_t FIFO_Peek(FIFO_BUFFER const *b)
* *
* @return the data * @return the data
*/ */
uint8_t FIFO_Get(FIFO_BUFFER * b) uint8_t FIFO_Get(
FIFO_BUFFER * b)
{ {
uint8_t data_byte = 0; uint8_t data_byte = 0;
unsigned index; unsigned index;
@@ -207,7 +213,8 @@ uint8_t FIFO_Get(FIFO_BUFFER * b)
* *
* @return the number of bytes actually pulled from the FIFO * @return the number of bytes actually pulled from the FIFO
*/ */
unsigned FIFO_Pull(FIFO_BUFFER * b, unsigned FIFO_Pull(
FIFO_BUFFER * b,
uint8_t * buffer, uint8_t * buffer,
unsigned length) unsigned length)
{ {
@@ -246,7 +253,8 @@ unsigned FIFO_Pull(FIFO_BUFFER * b,
* *
* @return true on successful add, false if not added * @return true on successful add, false if not added
*/ */
bool FIFO_Put(FIFO_BUFFER * b, bool FIFO_Put(
FIFO_BUFFER * b,
uint8_t data_byte) uint8_t data_byte)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
@@ -274,7 +282,8 @@ bool FIFO_Put(FIFO_BUFFER * b,
* *
* @return true if space available and added, false if not added * @return true if space available and added, false if not added
*/ */
bool FIFO_Add(FIFO_BUFFER * b, bool FIFO_Add(
FIFO_BUFFER * b,
uint8_t * buffer, uint8_t * buffer,
unsigned count) unsigned count)
{ {
@@ -303,7 +312,8 @@ bool FIFO_Add(FIFO_BUFFER * b,
* *
* @return none * @return none
*/ */
void FIFO_Flush(FIFO_BUFFER * b) void FIFO_Flush(
FIFO_BUFFER * b)
{ {
unsigned head; /* used to avoid volatile decision */ unsigned head; /* used to avoid volatile decision */
@@ -322,7 +332,8 @@ void FIFO_Flush(FIFO_BUFFER * b)
* *
* @return none * @return none
*/ */
void FIFO_Init(FIFO_BUFFER * b, void FIFO_Init(
FIFO_BUFFER * b,
volatile uint8_t * buffer, volatile uint8_t * buffer,
unsigned buffer_len) unsigned buffer_len)
{ {
@@ -347,7 +358,8 @@ void FIFO_Init(FIFO_BUFFER * b,
* *
* @param pTest - test tracking pointer * @param pTest - test tracking pointer
*/ */
void testFIFOBuffer(Test * pTest) void testFIFOBuffer(
Test * pTest)
{ {
/* FIFO data structure */ /* FIFO data structure */
FIFO_BUFFER test_buffer = { 0 }; FIFO_BUFFER test_buffer = { 0 };
@@ -466,7 +478,8 @@ void testFIFOBuffer(Test * pTest)
* *
* @return returns 0 on success, and non-zero on fail. * @return returns 0 on success, and non-zero on fail.
*/ */
int main(void) int main(
void)
{ {
Test *pTest; Test *pTest;
bool rc; bool rc;
+5 -7
View File
@@ -126,8 +126,7 @@ int get_alarm_summary_ack_decode_apdu_data(
/* tag 0 - Object Identifier */ /* tag 0 - Object Identifier */
apdu_len += apdu_len +=
bacapp_decode_application_data(&apdu[apdu_len], bacapp_decode_application_data(&apdu[apdu_len],
max_apdu - apdu_len, max_apdu - apdu_len, &value);
&value);
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
get_alarm_data->objectIdentifier = value.type.Object_Id; get_alarm_data->objectIdentifier = value.type.Object_Id;
} else { } else {
@@ -136,18 +135,17 @@ int get_alarm_summary_ack_decode_apdu_data(
/* tag 1 - Alarm State */ /* tag 1 - Alarm State */
apdu_len += apdu_len +=
bacapp_decode_application_data(&apdu[apdu_len], bacapp_decode_application_data(&apdu[apdu_len],
max_apdu - apdu_len, max_apdu - apdu_len, &value);
&value);
if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
get_alarm_data->alarmState = (BACNET_EVENT_STATE)value.type.Enumerated; get_alarm_data->alarmState =
(BACNET_EVENT_STATE) value.type.Enumerated;
} else { } else {
return BACNET_STATUS_ERROR; return BACNET_STATUS_ERROR;
} }
/* tag 2 - Acknowledged Transitions */ /* tag 2 - Acknowledged Transitions */
apdu_len += apdu_len +=
bacapp_decode_application_data(&apdu[apdu_len], bacapp_decode_application_data(&apdu[apdu_len],
max_apdu - apdu_len, max_apdu - apdu_len, &value);
&value);
if (value.tag == BACNET_APPLICATION_TAG_BIT_STRING) { if (value.tag == BACNET_APPLICATION_TAG_BIT_STRING) {
get_alarm_data->acknowledgedTransitions = value.type.Bit_String; get_alarm_data->acknowledgedTransitions = value.type.Bit_String;
} else { } else {
+13 -7
View File
@@ -330,7 +330,8 @@ void MSTP_Receive_Frame_FSM(
/* wait for the start of a frame. */ /* wait for the start of a frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
printf_receive_error("MSTP: Rx Header: SilenceTimer %u > %d\n", printf_receive_error("MSTP: Rx Header: SilenceTimer %u > %d\n",
(unsigned) mstp_port->SilenceTimer((void*)mstp_port), Tframe_abort); (unsigned) mstp_port->SilenceTimer((void *) mstp_port),
Tframe_abort);
} }
/* Error */ /* Error */
else if (mstp_port->ReceiveError == true) { else if (mstp_port->ReceiveError == true) {
@@ -474,7 +475,8 @@ void MSTP_Receive_Frame_FSM(
mstp_port->ReceivedInvalidFrame = true; mstp_port->ReceivedInvalidFrame = true;
printf_receive_error printf_receive_error
("MSTP: Rx Data: SilenceTimer %ums > %dms\n", ("MSTP: Rx Data: SilenceTimer %ums > %dms\n",
(unsigned) mstp_port->SilenceTimer((void*)mstp_port), Tframe_abort); (unsigned) mstp_port->SilenceTimer((void *) mstp_port),
Tframe_abort);
/* wait for the start of the next frame. */ /* wait for the start of the next frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
} }
@@ -925,8 +927,9 @@ bool MSTP_Master_Node_FSM(
Tno_token + (Tslot * (mstp_port->This_Station + 1)); Tno_token + (Tslot * (mstp_port->This_Station + 1));
mm_timeout = mm_timeout =
Tno_token + (Tslot * (mstp_port->Nmax_master + 1)); Tno_token + (Tslot * (mstp_port->Nmax_master + 1));
if ((mstp_port->SilenceTimer((void*)mstp_port) < ns_timeout) || if ((mstp_port->SilenceTimer((void *) mstp_port) < ns_timeout)
(mstp_port->SilenceTimer((void*)mstp_port) > mm_timeout)) { || (mstp_port->SilenceTimer((void *) mstp_port) >
mm_timeout)) {
/* GenerateToken */ /* GenerateToken */
/* Assume that this node is the lowest numerical address */ /* Assume that this node is the lowest numerical address */
/* on the network and is empowered to create a token. */ /* on the network and is empowered to create a token. */
@@ -990,7 +993,8 @@ bool MSTP_Master_Node_FSM(
transition_now = true; transition_now = true;
} }
mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedValidFrame = false;
} else if ((mstp_port->SilenceTimer((void*)mstp_port) > Tusage_timeout) || } else if ((mstp_port->SilenceTimer((void *) mstp_port) >
Tusage_timeout) ||
(mstp_port->ReceivedInvalidFrame == true)) { (mstp_port->ReceivedInvalidFrame == true)) {
if (mstp_port->SoleMaster == true) { if (mstp_port->SoleMaster == true) {
/* SoleMaster */ /* SoleMaster */
@@ -1059,7 +1063,8 @@ bool MSTP_Master_Node_FSM(
mstp_port->master_state = MSTP_MASTER_STATE_IDLE; mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
/* clear our flag we were holding for comparison */ /* clear our flag we were holding for comparison */
mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedValidFrame = false;
} else if (mstp_port->SilenceTimer((void*)mstp_port) > Treply_delay) { } else if (mstp_port->SilenceTimer((void *) mstp_port) >
Treply_delay) {
/* DeferredReply */ /* DeferredReply */
/* If no reply will be available from the higher layers */ /* If no reply will be available from the higher layers */
/* within Treply_delay after the reception of the */ /* within Treply_delay after the reception of the */
@@ -1126,7 +1131,8 @@ void MSTP_Slave_Node_FSM(
(uint16_t) length); (uint16_t) length);
/* clear our flag we were holding for comparison */ /* clear our flag we were holding for comparison */
mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedValidFrame = false;
} else if (mstp_port->SilenceTimer((void*)mstp_port) > Treply_delay) { } else if (mstp_port->SilenceTimer((void *) mstp_port) >
Treply_delay) {
/* If no reply will be available from the higher layers /* If no reply will be available from the higher layers
within Treply_delay after the reception of the final octet within Treply_delay after the reception of the final octet
of the requesting frame (the mechanism used to determine of the requesting frame (the mechanism used to determine
+2 -2
View File
@@ -59,8 +59,8 @@ int rp_encode_apdu(
/* check bounds so that we could create malformed /* check bounds so that we could create malformed
messages for testing */ messages for testing */
len = len =
encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type, encode_context_object_id(&apdu[apdu_len], 0,
rpdata->object_instance); rpdata->object_type, rpdata->object_instance);
apdu_len += len; apdu_len += len;
} }
if (rpdata->object_property <= 4194303) { if (rpdata->object_property <= 4194303) {
+22 -22
View File
@@ -152,7 +152,8 @@ int timesync_encode_timesync_recipients(
if (pRecipient->tag == 0) { if (pRecipient->tag == 0) {
if (max_apdu >= (1 + 4)) { if (max_apdu >= (1 + 4)) {
/* CHOICE - device [0] BACnetObjectIdentifier */ /* CHOICE - device [0] BACnetObjectIdentifier */
len = encode_context_object_id(&apdu[apdu_len], 0, len =
encode_context_object_id(&apdu[apdu_len], 0,
pRecipient->type.device.type, pRecipient->type.device.type,
pRecipient->type.device.instance); pRecipient->type.device.instance);
apdu_len += len; apdu_len += len;
@@ -188,7 +189,8 @@ int timesync_encode_timesync_recipients(
&pRecipient->type.address.mac[0], &pRecipient->type.address.mac[0],
pRecipient->type.address.mac_len); pRecipient->type.address.mac_len);
} }
len = encode_application_octet_string(&apdu[apdu_len], len =
encode_application_octet_string(&apdu[apdu_len],
&octet_string); &octet_string);
apdu_len += len; apdu_len += len;
/* CHOICE - address [1] BACnetAddress - closing */ /* CHOICE - address [1] BACnetAddress - closing */
@@ -247,7 +249,8 @@ int timesync_decode_timesync_recipients(
/* device [0] BACnetObjectIdentifier */ /* device [0] BACnetObjectIdentifier */
if (decode_is_context_tag(&apdu[apdu_len], 0)) { if (decode_is_context_tag(&apdu[apdu_len], 0)) {
pRecipient->tag = 0; pRecipient->tag = 0;
len = decode_context_object_id(&apdu[apdu_len], 0, len =
decode_context_object_id(&apdu[apdu_len], 0,
&pRecipient->type.device.type, &pRecipient->type.device.type,
&pRecipient->type.device.instance); &pRecipient->type.device.instance);
if (len < 0) { if (len < 0) {
@@ -265,7 +268,9 @@ int timesync_decode_timesync_recipients(
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) {
return BACNET_STATUS_ABORT; return BACNET_STATUS_ABORT;
} }
len = decode_unsigned(&apdu[apdu_len], len_value_type, &unsigned_value); len =
decode_unsigned(&apdu[apdu_len], len_value_type,
&unsigned_value);
pRecipient->type.address.net = unsigned_value; pRecipient->type.address.net = unsigned_value;
apdu_len += len; apdu_len += len;
/* mac-address OCTET STRING */ /* mac-address OCTET STRING */
@@ -276,23 +281,18 @@ int timesync_decode_timesync_recipients(
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) { if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) {
return BACNET_STATUS_ABORT; return BACNET_STATUS_ABORT;
} }
len = decode_octet_string(&apdu[0], len_value_type, len = decode_octet_string(&apdu[0], len_value_type, &octet_string);
&octet_string);
apdu_len += len; apdu_len += len;
if (octetstring_length(&octet_string) == 0) { if (octetstring_length(&octet_string) == 0) {
/* -- A string of length 0 indicates a broadcast */ /* -- A string of length 0 indicates a broadcast */
} else if (pRecipient->type.address.net) { } else if (pRecipient->type.address.net) {
pRecipient->type.address.len = pRecipient->type.address.len =
octetstring_copy_value( octetstring_copy_value(&pRecipient->type.address.adr[0],
&pRecipient->type.address.adr[0], sizeof(pRecipient->type.address.adr), &octet_string);
sizeof(pRecipient->type.address.adr),
&octet_string);
} else { } else {
pRecipient->type.address.mac_len = pRecipient->type.address.mac_len =
octetstring_copy_value( octetstring_copy_value(&pRecipient->type.address.mac[0],
&pRecipient->type.address.mac[0], sizeof(pRecipient->type.address.mac), &octet_string);
sizeof(pRecipient->type.address.mac),
&octet_string);
} }
} else { } else {
return BACNET_STATUS_ABORT; return BACNET_STATUS_ABORT;
@@ -320,15 +320,13 @@ void testTimeSyncRecipientData(
ct_test(pTest, recipient1->tag == recipient2->tag); ct_test(pTest, recipient1->tag == recipient2->tag);
if (recipient1->tag == 0) { if (recipient1->tag == 0) {
ct_test(pTest, ct_test(pTest,
recipient1->type.device.type == recipient1->type.device.type == recipient2->type.device.type);
recipient2->type.device.type);
ct_test(pTest, ct_test(pTest,
recipient1->type.device.instance == recipient1->type.device.instance ==
recipient2->type.device.instance); recipient2->type.device.instance);
} else if (recipient1->tag == 1) { } else if (recipient1->tag == 1) {
ct_test(pTest, ct_test(pTest,
recipient1->type.address.net == recipient1->type.address.net == recipient2->type.address.net);
recipient2->type.address.net);
if (recipient1->type.address.net == BACNET_BROADCAST_NETWORK) { if (recipient1->type.address.net == BACNET_BROADCAST_NETWORK) {
ct_test(pTest, ct_test(pTest,
recipient1->type.address.mac_len == recipient1->type.address.mac_len ==
@@ -400,12 +398,14 @@ void testTimeSyncRecipient(
recipient[2].type.address.mac[5] = 0xC1; recipient[2].type.address.mac[5] = 0xC1;
recipient[2].type.address.mac_len = 6; recipient[2].type.address.mac_len = 6;
/* perform positive test */ /* perform positive test */
len = timesync_encode_timesync_recipients(&apdu[0], len =
sizeof(apdu), &recipient[0]); timesync_encode_timesync_recipients(&apdu[0], sizeof(apdu),
&recipient[0]);
ct_test(pTest, len != BACNET_STATUS_ABORT); ct_test(pTest, len != BACNET_STATUS_ABORT);
ct_test(pTest, len > 0); ct_test(pTest, len > 0);
len = timesync_decode_timesync_recipients(&apdu[0], len =
sizeof(apdu), &test_recipient[0]); timesync_decode_timesync_recipients(&apdu[0], sizeof(apdu),
&test_recipient[0]);
ct_test(pTest, len != BACNET_STATUS_ABORT); ct_test(pTest, len != BACNET_STATUS_ABORT);
ct_test(pTest, len > 0); ct_test(pTest, len > 0);
testTimeSyncRecipientData(pTest, &recipient[0], &test_recipient[0]); testTimeSyncRecipientData(pTest, &recipient[0], &test_recipient[0]);