Indented project.

This commit is contained in:
skarg
2011-08-17 02:27:11 +00:00
parent 7e503510c7
commit 3e1cb1847f
125 changed files with 3548 additions and 3353 deletions
+4 -4
View File
@@ -1172,11 +1172,11 @@ int main(
(invoke_id == (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(invoke_id)) { if (tsm_invoke_id_free(invoke_id)) {
invoke_id = 0; invoke_id = 0;
} else { } else {
+17 -13
View File
@@ -119,7 +119,6 @@ void handler_alarm_ack(
#endif #endif
goto AA_ABORT; goto AA_ABORT;
} }
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"Alarm Ack Operation: Received acknowledge for object id (%d, %lu) from %s for process id %lu \n", "Alarm Ack Operation: Received acknowledge for object id (%d, %lu) from %s for process id %lu \n",
@@ -131,22 +130,26 @@ void handler_alarm_ack(
if (Alarm_Ack[data.eventObjectIdentifier.type]) { if (Alarm_Ack[data.eventObjectIdentifier.type]) {
ack_result = Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code); ack_result =
Alarm_Ack[data.eventObjectIdentifier.type] (&data, &error_code);
switch (ack_result) switch (ack_result) {
{
case 1: case 1:
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: " "Sending Simple Ack!\n"); fprintf(stderr, "Alarm Acknowledge: " "Sending Simple Ack!\n");
#endif #endif
break; break;
case -1: case -1:
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
ERROR_CLASS_OBJECT, error_code); service_data->invoke_id,
SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT,
error_code);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: error %s!\n", fprintf(stderr, "Alarm Acknowledge: error %s!\n",
bactext_error_code_name(error_code)); bactext_error_code_name(error_code));
@@ -154,16 +157,17 @@ void handler_alarm_ack(
break; break;
default: default:
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], len =
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true); service_data->invoke_id, ABORT_REASON_OTHER, true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Alarm Acknowledge: abort other!\n"); fprintf(stderr, "Alarm Acknowledge: abort other!\n");
#endif #endif
break; break;
} }
} } else {
else { len =
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM,
ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED); ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED);
#if PRINT_ENABLED #if PRINT_ENABLED
+12 -16
View File
@@ -419,32 +419,31 @@ void handler_cov_task(
COV_Subscriptions[index].monitoredObjectIdentifier.type; COV_Subscriptions[index].monitoredObjectIdentifier.type;
object_instance = object_instance =
COV_Subscriptions[index].monitoredObjectIdentifier.instance; COV_Subscriptions[index].monitoredObjectIdentifier.instance;
status = Device_Encode_Value_List( status =
object_type, Device_Encode_Value_List(object_type, object_instance,
object_instance,
&value_list[0]); &value_list[0]);
if (status) { if (status) {
COV_Subscriptions[index].send_requested = true; COV_Subscriptions[index].send_requested = true;
} }
if (COV_Subscriptions[index].send_requested) { if (COV_Subscriptions[index].send_requested) {
cov_send_request( cov_send_request(&COV_Subscriptions[index], &value_list[0]);
&COV_Subscriptions[index],
&value_list[0]);
COV_Subscriptions[index].send_requested = false; COV_Subscriptions[index].send_requested = false;
} }
if (status && ((index + 1) < MAX_COV_SUBCRIPTIONS)) { if (status && ((index + 1) < MAX_COV_SUBCRIPTIONS)) {
/* if more than one subscription for this object instance */ /* if more than one subscription for this object instance */
for (index2 = index+1; index2 < MAX_COV_SUBCRIPTIONS; index2++) { for (index2 = index + 1; index2 < MAX_COV_SUBCRIPTIONS;
index2++) {
object_type2 = object_type2 =
COV_Subscriptions[index2].monitoredObjectIdentifier.type; COV_Subscriptions[index2].monitoredObjectIdentifier.
type;
object_instance2 = object_instance2 =
COV_Subscriptions[index2].monitoredObjectIdentifier.instance; COV_Subscriptions[index2].monitoredObjectIdentifier.
instance;
if ((COV_Subscriptions[index].lifetime) && if ((COV_Subscriptions[index].lifetime) &&
(COV_Subscriptions[index].valid) && (COV_Subscriptions[index].valid) &&
(object_type == object_type2) && (object_type == object_type2) &&
(object_instance == object_instance2)) { (object_instance == object_instance2)) {
cov_send_request( cov_send_request(&COV_Subscriptions[index2],
&COV_Subscriptions[index2],
&value_list[0]); &value_list[0]);
COV_Subscriptions[index2].send_requested = false; COV_Subscriptions[index2].send_requested = false;
} }
@@ -470,11 +469,8 @@ static bool cov_subscribe(
if (status) { if (status) {
status = Device_Value_List_Supported(object_type); status = Device_Value_List_Supported(object_type);
if (status) { if (status) {
status = cov_list_subscribe( status =
src, cov_list_subscribe(src, cov_data, error_class, error_code);
cov_data,
error_class,
error_code);
} else { } else {
*error_class = ERROR_CLASS_OBJECT; *error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; *error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
+6 -6
View File
@@ -125,8 +125,10 @@ void handler_get_event_information(
if (valid_event > 0) { if (valid_event > 0) {
/* encode GetEvent_data only when type of object_id has max value */ /* encode GetEvent_data only when type of object_id has max value */
if (object_id.type != MAX_BACNET_OBJECT_TYPE) { if (object_id.type != MAX_BACNET_OBJECT_TYPE) {
if ((object_id.type == getevent_data.objectIdentifier.type) && if ((object_id.type ==
(object_id.instance == getevent_data.objectIdentifier.instance)) { getevent_data.objectIdentifier.type) &&
(object_id.instance ==
getevent_data.objectIdentifier.instance)) {
/* found 'Last Received Object Identifier' /* found 'Last Received Object Identifier'
so should set type of object_id to max value */ so should set type of object_id to max value */
object_id.type = MAX_BACNET_OBJECT_TYPE; object_id.type = MAX_BACNET_OBJECT_TYPE;
@@ -151,12 +153,10 @@ void handler_get_event_information(
len = BACNET_STATUS_ABORT; len = BACNET_STATUS_ABORT;
error = true; error = true;
goto GET_EVENT_ERROR; goto GET_EVENT_ERROR;
} } else
else
more_events = true; more_events = true;
break; break;
} } else
else
pdu_len += len; pdu_len += len;
} else if (valid_event < 0) { } else if (valid_event < 0) {
break; break;
+6 -9
View File
@@ -319,9 +319,8 @@ void handler_read_property_multiple(
if (property_count == 0) { if (property_count == 0) {
/* handle the error code - but use the special property */ /* handle the error code - but use the special property */
len = len =
RPM_Encode_Property( RPM_Encode_Property(&Handler_Transmit_Buffer
&Handler_Transmit_Buffer[npdu_len], [npdu_len], (uint16_t) apdu_len, MAX_APDU,
(uint16_t) apdu_len, MAX_APDU,
&rpmdata); &rpmdata);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
@@ -335,10 +334,9 @@ void handler_read_property_multiple(
RPM_Object_Property(&property_list, RPM_Object_Property(&property_list,
special_object_property, index); special_object_property, index);
len = len =
RPM_Encode_Property( RPM_Encode_Property(&Handler_Transmit_Buffer
&Handler_Transmit_Buffer[npdu_len], [npdu_len], (uint16_t) apdu_len, MAX_APDU,
(uint16_t) apdu_len, &rpmdata);
MAX_APDU, &rpmdata);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
@@ -352,8 +350,7 @@ void handler_read_property_multiple(
/* handle an individual property */ /* handle an individual property */
len = len =
RPM_Encode_Property(&Handler_Transmit_Buffer[npdu_len], RPM_Encode_Property(&Handler_Transmit_Buffer[npdu_len],
(uint16_t) apdu_len, (uint16_t) apdu_len, MAX_APDU, &rpmdata);
MAX_APDU, &rpmdata);
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
} else { } else {
+6 -6
View File
@@ -220,8 +220,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);
@@ -268,10 +268,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 -4
View File
@@ -64,10 +64,9 @@ static void match_name_or_object(
} }
} else { } else {
/* valid object_name copy in my device? */ /* valid object_name copy in my device? */
found = Device_Object_Name_Copy( found =
data->object.identifier.type, Device_Object_Name_Copy(data->object.identifier.type,
data->object.identifier.instance, data->object.identifier.instance, &object_name);
&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,
+2 -2
View File
@@ -181,8 +181,8 @@ bool WPValidateString(
(!characterstring_printable(&pValue->type.Character_String))) { (!characterstring_printable(&pValue->type.Character_String))) {
/* assumption: non-empty also means must be "printable" */ /* assumption: non-empty also means must be "printable" */
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE; *pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if (characterstring_length(&pValue->type. } else if (characterstring_length(&pValue->
Character_String) >= iMaxLen) { type.Character_String) >= iMaxLen) {
*pErrorClass = ERROR_CLASS_RESOURCES; *pErrorClass = ERROR_CLASS_RESOURCES;
*pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; *pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
} else } else
+32 -35
View File
@@ -84,9 +84,10 @@ void handler_write_property_multiple(
if (service_data->segmented_message) { if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], len =
service_data->invoke_id, abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Segmented message. Sending Abort!\n"); fprintf(stderr, "WPM: Segmented message. Sending Abort!\n");
#endif #endif
@@ -95,27 +96,25 @@ void handler_write_property_multiple(
/* decode service request */ /* decode service request */
decode_len = 0; decode_len = 0;
do do {
{
/* decode Object Identifier */ /* decode Object Identifier */
len = wpm_decode_object_id(&service_request[decode_len], len =
wpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &wp_data); service_len - decode_len, &wp_data);
if (len > 0) if (len > 0) {
{
uint8_t tag_number = 0; uint8_t tag_number = 0;
decode_len += len; decode_len += len;
/* Opening tag 1 - List of Properties */ /* Opening tag 1 - List of Properties */
if (decode_is_opening_tag_number(&service_request[decode_len++], 1)) if (decode_is_opening_tag_number(&service_request[decode_len++],
{ 1)) {
do do {
{
/* decode a 'Property Identifier'; (3) an optional 'Property Array Index' */ /* decode a 'Property Identifier'; (3) an optional 'Property Array Index' */
/* (4) a 'Property Value'; and (5) an optional 'Priority'. */ /* (4) a 'Property Value'; and (5) an optional 'Priority'. */
len = wpm_decode_object_property(&service_request[decode_len], len =
service_len - decode_len, &wp_data); wpm_decode_object_property(&service_request
if (len > 0) [decode_len], service_len - decode_len, &wp_data);
{ if (len > 0) {
decode_len += len; decode_len += len;
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
@@ -123,16 +122,14 @@ void handler_write_property_multiple(
(unsigned long) wp_data.object_type, (unsigned long) wp_data.object_type,
(unsigned long) wp_data.object_instance, (unsigned long) wp_data.object_instance,
(unsigned long) wp_data.object_property, (unsigned long) wp_data.object_property,
(unsigned long) wp_data.priority, (long) wp_data.array_index); (unsigned long) wp_data.priority,
(long) wp_data.array_index);
#endif #endif
if (Device_Write_Property(&wp_data) == false) if (Device_Write_Property(&wp_data) == false) {
{
error = true; error = true;
break; /* do while (decoding List of Properties) */ break; /* do while (decoding List of Properties) */
} }
} } else {
else
{
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Bad Encoding!\n"); fprintf(stderr, "WPM: Bad Encoding!\n");
#endif #endif
@@ -143,12 +140,11 @@ void handler_write_property_multiple(
} }
/* Closing tag 1 - List of Properties */ /* Closing tag 1 - List of Properties */
if (decode_is_closing_tag_number(&service_request[decode_len], 1)) if (decode_is_closing_tag_number(&service_request
{ [decode_len], 1)) {
tag_number = 1; tag_number = 1;
decode_len++; decode_len++;
} } else
else
tag_number = 0; /* it was not tag 1, decode next Property Identifier ... */ tag_number = 0; /* it was not tag 1, decode next Property Identifier ... */
} }
@@ -157,9 +153,7 @@ void handler_write_property_multiple(
if (error) if (error)
break; /*do while (decode service request) */ break; /*do while (decode service request) */
} }
} } else {
else
{
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Bad Encoding!\n"); fprintf(stderr, "WPM: Bad Encoding!\n");
#endif #endif
@@ -175,20 +169,22 @@ void handler_write_property_multiple(
/* encode the NPDU portion of the packet */ /* encode the NPDU portion of the packet */
datalink_get_my_address(&my_address); datalink_get_my_address(&my_address);
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, npdu_len =
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data); &npdu_data);
apdu_len = 0; apdu_len = 0;
if (error == false) { if (error == false) {
apdu_len = wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], apdu_len =
wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id); service_data->invoke_id);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Simple Ack!\n"); fprintf(stderr, "WPM: Sending Simple Ack!\n");
#endif #endif
} } else {
else { apdu_len =
apdu_len = wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len], wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, &wp_data); service_data->invoke_id, &wp_data);
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "WPM: Sending Error!\n"); fprintf(stderr, "WPM: Sending Error!\n");
@@ -198,6 +194,7 @@ void handler_write_property_multiple(
WPM_ABORT: WPM_ABORT:
pdu_len = npdu_len + apdu_len; pdu_len = npdu_len + apdu_len;
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
} }
+3 -2
View File
@@ -155,8 +155,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) {
+11 -12
View File
@@ -172,7 +172,8 @@ static void packet_statistics(
break; break;
case FRAME_TYPE_POLL_FOR_MASTER: case FRAME_TYPE_POLL_FOR_MASTER:
if (MSTP_Statistics[src].last_pfm_tokens) { if (MSTP_Statistics[src].last_pfm_tokens) {
npoll = MSTP_Statistics[src].token_received_count - npoll =
MSTP_Statistics[src].token_received_count -
MSTP_Statistics[src].last_pfm_tokens; MSTP_Statistics[src].last_pfm_tokens;
if (npoll > MSTP_Statistics[src].npoll) { if (npoll > MSTP_Statistics[src].npoll) {
MSTP_Statistics[src].npoll = npoll; MSTP_Statistics[src].npoll = npoll;
@@ -252,10 +253,8 @@ static void packet_statistics_print(
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
fprintf(stdout, "==== MS/TP Frame Counts ====\r\n"); fprintf(stdout, "==== MS/TP Frame Counts ====\r\n");
fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s", fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s", "MAC", "Tokens",
"MAC", "PFM", "RPFM", "DER", "Postpd", "DNER", "TestReq", "TestRsp");
"Tokens","PFM","RPFM","DER",
"Postpd","DNER","TestReq","TestRsp");
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
/* check for masters or slaves */ /* check for masters or slaves */
@@ -280,9 +279,9 @@ static void packet_statistics_print(
node_count = 0; node_count = 0;
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
fprintf(stdout, "==== MS/TP Usage and Timing Maximums ====\r\n"); fprintf(stdout, "==== MS/TP Usage and Timing Maximums ====\r\n");
fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", "MAC",
"MAC","MaxMstr","Retries","Npoll","Self", "MaxMstr", "Retries", "Npoll", "Self", "Treply", "Tusage", "Trpfm",
"Treply","Tusage","Trpfm","Tder","Tpostpd"); "Tder", "Tpostpd");
fprintf(stdout, "\r\n"); fprintf(stdout, "\r\n");
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
/* check for masters or slaves */ /* check for masters or slaves */
@@ -552,8 +551,8 @@ static void write_received_packet(
(void) data_write((char *) &mstp_port->DataCRCActualLSB, 1, 1); (void) data_write((char *) &mstp_port->DataCRCActualLSB, 1, 1);
} }
} else { } else {
fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n", Capture_Filename, fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n",
strerror(errno)); Capture_Filename, strerror(errno));
} }
} }
@@ -682,8 +681,8 @@ static bool read_received_packet(
mstp_port->HeaderCRCActual = header[7]; mstp_port->HeaderCRCActual = header[7];
if (orig_len > 8) { if (orig_len > 8) {
mstp_port->DataLength = orig_len - 8 - 2; mstp_port->DataLength = orig_len - 8 - 2;
count = fread(mstp_port->InputBuffer, count =
mstp_port->DataLength, 1, pFile); fread(mstp_port->InputBuffer, mstp_port->DataLength, 1, pFile);
if (count != 1) { if (count != 1) {
fclose(pFile); fclose(pFile);
pFile = NULL; pFile = NULL;
+183 -150
View File
@@ -127,8 +127,7 @@ void Analog_Input_Init(
handler_get_event_information_set(OBJECT_ANALOG_INPUT, handler_get_event_information_set(OBJECT_ANALOG_INPUT,
Analog_Input_Event_Information); Analog_Input_Event_Information);
/* Set handler for AcknowledgeAlarm function */ /* Set handler for AcknowledgeAlarm function */
handler_alarm_ack_set(OBJECT_ANALOG_INPUT, handler_alarm_ack_set(OBJECT_ANALOG_INPUT, Analog_Input_Alarm_Ack);
Analog_Input_Alarm_Ack);
#endif #endif
} }
} }
@@ -283,44 +282,55 @@ int Analog_Input_Read_Property(
#endif #endif
bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, CurrentAI->Out_Of_Service); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAI->Out_Of_Service);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_EVENT_STATE: case PROP_EVENT_STATE:
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAI->Event_State); CurrentAI->Event_State);
#else #else
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
EVENT_STATE_NORMAL); encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
#endif #endif
break; break;
case PROP_RELIABILITY: case PROP_RELIABILITY:
apdu_len = encode_application_enumerated(&apdu[0], CurrentAI->Reliability); apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAI->Reliability);
break; break;
case PROP_OUT_OF_SERVICE: case PROP_OUT_OF_SERVICE:
apdu_len = encode_application_boolean(&apdu[0], CurrentAI->Out_Of_Service); apdu_len =
encode_application_boolean(&apdu[0],
CurrentAI->Out_Of_Service);
break; break;
case PROP_UNITS: case PROP_UNITS:
apdu_len = encode_application_enumerated(&apdu[0], CurrentAI->Units); apdu_len =
encode_application_enumerated(&apdu[0], CurrentAI->Units);
break; break;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
case PROP_TIME_DELAY: case PROP_TIME_DELAY:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAI->Time_Delay); apdu_len =
encode_application_unsigned(&apdu[0], CurrentAI->Time_Delay);
break; break;
case PROP_NOTIFICATION_CLASS: case PROP_NOTIFICATION_CLASS:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAI->Notification_Class); apdu_len =
encode_application_unsigned(&apdu[0],
CurrentAI->Notification_Class);
break; break;
case PROP_HIGH_LIMIT: case PROP_HIGH_LIMIT:
apdu_len = encode_application_real(&apdu[0], CurrentAI->High_Limit); apdu_len =
encode_application_real(&apdu[0], CurrentAI->High_Limit);
break; break;
case PROP_LOW_LIMIT: case PROP_LOW_LIMIT:
@@ -334,9 +344,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 : false ); (CurrentAI->
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 : false ); (CurrentAI->
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;
@@ -344,11 +356,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 : false ); (CurrentAI->
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 : false ); (CurrentAI->
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 : false ); (CurrentAI->
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;
@@ -356,7 +371,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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
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,
@@ -366,26 +382,32 @@ int Analog_Input_Read_Property(
break; break;
case PROP_NOTIFY_TYPE: case PROP_NOTIFY_TYPE:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM);
break; break;
case PROP_EVENT_TIME_STAMPS: case PROP_EVENT_TIME_STAMPS:
/* Array element zero is the number of elements in the array */ /* Array element zero is the number of elements in the array */
if (rpdata->array_index == 0) if (rpdata->array_index == 0)
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
encode_application_unsigned(&apdu[0],
MAX_BACNET_EVENT_TRANSITION); MAX_BACNET_EVENT_TRANSITION);
/* 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. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) { else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {; for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {;
len = encode_opening_tag(&apdu[apdu_len], len =
encode_opening_tag(&apdu[apdu_len],
TIME_STAMP_DATETIME); TIME_STAMP_DATETIME);
len += encode_application_date(&apdu[apdu_len + len], len +=
encode_application_date(&apdu[apdu_len + len],
&CurrentAI->Event_Time_Stamps[i].date); &CurrentAI->Event_Time_Stamps[i].date);
len += encode_application_time(&apdu[apdu_len + len], len +=
encode_application_time(&apdu[apdu_len + len],
&CurrentAI->Event_Time_Stamps[i].time); &CurrentAI->Event_Time_Stamps[i].time);
len += encode_closing_tag(&apdu[apdu_len + len], len +=
encode_closing_tag(&apdu[apdu_len + len],
TIME_STAMP_DATETIME); TIME_STAMP_DATETIME);
/* add it if we have room */ /* add it if we have room */
@@ -398,18 +420,18 @@ int Analog_Input_Read_Property(
break; break;
} }
} }
} } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) {
else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { apdu_len =
apdu_len = encode_opening_tag(&apdu[apdu_len], encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
TIME_STAMP_DATETIME); apdu_len +=
apdu_len += encode_application_date(&apdu[apdu_len], encode_application_date(&apdu[apdu_len],
&CurrentAI->Event_Time_Stamps[rpdata->array_index].date); &CurrentAI->Event_Time_Stamps[rpdata->array_index].date);
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
encode_application_time(&apdu[apdu_len],
&CurrentAI->Event_Time_Stamps[rpdata->array_index].time); &CurrentAI->Event_Time_Stamps[rpdata->array_index].time);
apdu_len += encode_closing_tag(&apdu[apdu_len], apdu_len +=
TIME_STAMP_DATETIME); encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
} } else {
else {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
@@ -436,9 +458,8 @@ int Analog_Input_Read_Property(
break; break;
} }
/* only array properties can have array options */ /* only array properties can have array options */
if ((apdu_len >= 0) && if ((apdu_len >= 0) && (rpdata->object_property != PROP_EVENT_TIME_STAMPS)
(rpdata->object_property != PROP_EVENT_TIME_STAMPS) && && (rpdata->array_index != BACNET_ARRAY_ALL)) {
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
@@ -485,8 +506,7 @@ bool Analog_Input_Write_Property(
if (CurrentAI->Out_Of_Service == true) { if (CurrentAI->Out_Of_Service == true) {
Analog_Input_Present_Value_Set(wp_data->object_instance, Analog_Input_Present_Value_Set(wp_data->object_instance,
value.type.Real); value.type.Real);
} } 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;
status = false; status = false;
@@ -572,8 +592,7 @@ bool Analog_Input_Write_Property(
if (status) { if (status) {
if (value.type.Bit_String.bits_used == 2) { if (value.type.Bit_String.bits_used == 2) {
CurrentAI->Limit_Enable = value.type.Bit_String.value[0]; CurrentAI->Limit_Enable = value.type.Bit_String.value[0];
} } else {
else {
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;
status = false; status = false;
@@ -589,8 +608,7 @@ bool Analog_Input_Write_Property(
if (status) { if (status) {
if (value.type.Bit_String.bits_used == 3) { if (value.type.Bit_String.bits_used == 3) {
CurrentAI->Event_Enable = value.type.Bit_String.value[0]; CurrentAI->Event_Enable = value.type.Bit_String.value[0];
} } else {
else {
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;
status = false; status = false;
@@ -606,8 +624,7 @@ bool Analog_Input_Write_Property(
if (status) { if (status) {
if (value.type.Bit_String.bits_used > NOTIFY_EVENT) { if (value.type.Bit_String.bits_used > NOTIFY_EVENT) {
CurrentAI->Event_Enable = value.type.Enumerated; CurrentAI->Event_Enable = value.type.Enumerated;
} } else {
else {
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;
status = false; status = false;
@@ -626,7 +643,8 @@ bool Analog_Input_Write_Property(
} }
void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) void Analog_Input_Intrinsic_Reporting(
uint32_t object_instance)
{ {
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
BACNET_EVENT_NOTIFICATION_DATA event_data; BACNET_EVENT_NOTIFICATION_DATA event_data;
@@ -659,8 +677,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Send Acknotification for (%s,%d).\n", fprintf(stderr, "Send Acknotification for (%s,%d).\n",
bactext_object_type_name(OBJECT_ANALOG_INPUT), bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance);
object_instance);
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
characterstring_init_ansi(&msgText, "AckNotification"); characterstring_init_ansi(&msgText, "AckNotification");
@@ -670,14 +687,11 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Send EventNotification. */ /* Send EventNotification. */
SendNotify = true; SendNotify = true;
} } else {
else
{
/* actual Present_Value */ /* actual Present_Value */
PresentVal = Analog_Input_Present_Value(object_instance); PresentVal = Analog_Input_Present_Value(object_instance);
FromState = CurrentAI->Event_State; FromState = CurrentAI->Event_State;
switch (CurrentAI->Event_State) switch (CurrentAI->Event_State) {
{
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
/* A TO-OFFNORMAL event is generated under these conditions: /* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the High_Limit for a minimum (a) the Present_Value must exceed the High_Limit for a minimum
@@ -685,9 +699,10 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAI->High_Limit) && if ((PresentVal > CurrentAI->High_Limit) &&
((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAI->Remaining_Time_Delay) if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_HIGH_LIMIT; CurrentAI->Event_State = EVENT_STATE_HIGH_LIMIT;
else else
@@ -701,9 +716,10 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAI->Low_Limit) && if ((PresentVal < CurrentAI->Low_Limit) &&
((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAI->Remaining_Time_Delay) if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_LOW_LIMIT; CurrentAI->Event_State = EVENT_STATE_LOW_LIMIT;
else else
@@ -721,10 +737,11 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAI->High_Limit - CurrentAI->Deadband) && if ((PresentVal < CurrentAI->High_Limit - CurrentAI->Deadband)
((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && && ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAI->Remaining_Time_Delay) if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_NORMAL; CurrentAI->Event_State = EVENT_STATE_NORMAL;
else else
@@ -743,10 +760,11 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband) && if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband)
((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && && ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAI->Remaining_Time_Delay) if (!CurrentAI->Remaining_Time_Delay)
CurrentAI->Event_State = EVENT_STATE_NORMAL; CurrentAI->Event_State = EVENT_STATE_NORMAL;
else else
@@ -763,24 +781,20 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
ToState = CurrentAI->Event_State; ToState = CurrentAI->Event_State;
if (FromState != ToState) if (FromState != ToState) {
{
/* Event_State has changed. /* Event_State has changed.
Need to fill only the basic parameters of this type of event. Need to fill only the basic parameters of this type of event.
Other parameters will be filled in common function. */ Other parameters will be filled in common function. */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
ExceededLimit = CurrentAI->High_Limit; ExceededLimit = CurrentAI->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to high limit");
"Goes to high limit");
break; break;
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
ExceededLimit = CurrentAI->Low_Limit; ExceededLimit = CurrentAI->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to low limit");
"Goes to low limit");
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
@@ -788,8 +802,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
ExceededLimit = CurrentAI->High_Limit; ExceededLimit = CurrentAI->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from high limit"); "Back to normal state from high limit");
} } else {
else {
ExceededLimit = CurrentAI->Low_Limit; ExceededLimit = CurrentAI->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from low limit"); "Back to normal state from low limit");
@@ -803,8 +816,8 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n",
bactext_object_type_name(OBJECT_ANALOG_INPUT), bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance,
object_instance, bactext_event_state_name(FromState), bactext_event_state_name(FromState),
bactext_event_state_name(ToState)); bactext_event_state_name(ToState));
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
@@ -817,8 +830,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
} }
if (SendNotify) if (SendNotify) {
{
/* Event Object Identifier */ /* Event Object Identifier */
event_data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT; event_data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT;
event_data.eventObjectIdentifier.instance = object_instance; event_data.eventObjectIdentifier.instance = object_instance;
@@ -829,8 +841,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* fill Event_Time_Stamps */ /* fill Event_Time_Stamps */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAI->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] = CurrentAI->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] =
@@ -871,21 +882,27 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Event Values */ /* Event Values */
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* Value that exceeded a limit. */ /* Value that exceeded a limit. */
event_data.notificationParams.outOfRange.exceedingValue = PresentVal; event_data.notificationParams.outOfRange.exceedingValue =
PresentVal;
/* Status_Flags of the referenced object. */ /* Status_Flags of the referenced object. */
bitstring_init(&event_data.notificationParams.outOfRange.statusFlags); bitstring_init(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags);
STATUS_FLAG_IN_ALARM, CurrentAI->Event_State ? true : false); bitstring_set_bit(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags, STATUS_FLAG_IN_ALARM,
STATUS_FLAG_FAULT, false); CurrentAI->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OVERRIDDEN, false); statusFlags, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OUT_OF_SERVICE, CurrentAI->Out_Of_Service); statusFlags, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAI->Out_Of_Service);
/* Deadband used for limit checking. */ /* Deadband used for limit checking. */
event_data.notificationParams.outOfRange.deadband = CurrentAI->Deadband; event_data.notificationParams.outOfRange.deadband =
CurrentAI->Deadband;
/* Limit that was exceeded. */ /* Limit that was exceeded. */
event_data.notificationParams.outOfRange.exceededLimit = ExceededLimit; event_data.notificationParams.outOfRange.exceededLimit =
ExceededLimit;
} }
/* add data from notification class */ /* add data from notification class */
@@ -893,28 +910,29 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
/* Ack required */ /* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true)) (event_data.ackRequired == true)) {
{ switch (event_data.toState) {
switch (event_data.toState)
{
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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = false; CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = false; CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].
CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = false; CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].
CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -924,7 +942,8 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance)
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Input_Event_Information(unsigned index, int Analog_Input_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) BACNET_GET_EVENT_INFORMATION_DATA * getevent_data)
{ {
bool IsNotAckedTransitions; bool IsNotAckedTransitions;
@@ -939,26 +958,34 @@ int Analog_Input_Event_Information(unsigned index,
/* 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 = (AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) | IsNotAckedTransitions =
(AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
(AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); bIsAcked ==
} false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].
else bIsAcked ==
false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].
bIsAcked == false);
} else
return -1; /* end of list */ return -1; /* end of list */
if ((IsActiveEvent) || (IsNotAckedTransitions)) { if ((IsActiveEvent) || (IsNotAckedTransitions)) {
/* Object Identifier */ /* Object Identifier */
getevent_data->objectIdentifier.type = OBJECT_ANALOG_INPUT; getevent_data->objectIdentifier.type = OBJECT_ANALOG_INPUT;
getevent_data->objectIdentifier.instance = Analog_Input_Index_To_Instance(index); getevent_data->objectIdentifier.instance =
Analog_Input_Index_To_Instance(index);
/* Event State */ /* Event State */
getevent_data->eventState = AI_Descr[index].Event_State; getevent_data->eventState = AI_Descr[index].Event_State;
/* Acknowledged Transitions */ /* Acknowledged Transitions */
bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_init(&getevent_data->acknowledgedTransitions);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); TRANSITION_TO_OFFNORMAL,
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_FAULT,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_NORMAL,
AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
/* Event Time Stamps */ /* Event Time Stamps */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
@@ -971,31 +998,35 @@ int Analog_Input_Event_Information(unsigned index,
/* 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 : false ); (AI_Descr[index].
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 : false ); (AI_Descr[index].
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 : false ); (AI_Descr[index].
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);
return 1; /* active event */ return 1; /* active event */
} } else
else
return 0; /* no active event at this index */ return 0; /* no active event at this index */
} }
int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Input_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code) BACNET_ERROR_CODE * error_code)
{ {
ANALOG_INPUT_DESCR *CurrentAI; ANALOG_INPUT_DESCR *CurrentAI;
unsigned int object_index; unsigned int object_index;
object_index = Analog_Input_Instance_To_Index( object_index =
alarmack_data->eventObjectIdentifier.instance); Analog_Input_Instance_To_Index(alarmack_data->eventObjectIdentifier.
instance);
if (object_index < MAX_ANALOG_INPUTS) if (object_index < MAX_ANALOG_INPUTS)
CurrentAI = &AI_Descr[object_index]; CurrentAI = &AI_Descr[object_index];
@@ -1004,71 +1035,73 @@ int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data,
return -1; return -1;
} }
switch (alarmack_data->eventStateAcked) switch (alarmack_data->eventStateAcked) {
{
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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { if (CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
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[TRANSITION_TO_OFFNORMAL].Time_Stamp, if (datetime_compare(&CurrentAI->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
{ &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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
} bIsAcked = true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
if(CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false) { if (CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].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[TRANSITION_TO_NORMAL].Time_Stamp, if (datetime_compare(&CurrentAI->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
{ &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->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = true; CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
if(CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) { if (CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].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[TRANSITION_TO_FAULT].Time_Stamp, if (datetime_compare(&CurrentAI->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
{ &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->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true; CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
+6 -3
View File
@@ -113,13 +113,16 @@ extern "C" {
/* note: header of Intrinsic_Reporting function is required /* note: header of Intrinsic_Reporting function is required
even when INTRINSIC_REPORTING is not defined */ even when INTRINSIC_REPORTING is not defined */
void Analog_Input_Intrinsic_Reporting(uint32_t object_instance); void Analog_Input_Intrinsic_Reporting(
uint32_t object_instance);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Input_Event_Information(unsigned index, int Analog_Input_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data); BACNET_GET_EVENT_INFORMATION_DATA * getevent_data);
int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Input_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code); BACNET_ERROR_CODE * error_code);
#endif #endif
+4 -4
View File
@@ -447,11 +447,11 @@ bool Analog_Output_Write_Property(
if (status) { if (status) {
level = AO_LEVEL_NULL; level = AO_LEVEL_NULL;
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;
+178 -149
View File
@@ -133,8 +133,7 @@ void Analog_Value_Init(
handler_get_event_information_set(OBJECT_ANALOG_VALUE, handler_get_event_information_set(OBJECT_ANALOG_VALUE,
Analog_Value_Event_Information); Analog_Value_Event_Information);
/* Set handler for AcknowledgeAlarm function */ /* Set handler for AcknowledgeAlarm function */
handler_alarm_ack_set(OBJECT_ANALOG_VALUE, handler_alarm_ack_set(OBJECT_ANALOG_VALUE, Analog_Value_Alarm_Ack);
Analog_Value_Alarm_Ack);
#endif #endif
} }
} }
@@ -196,8 +195,7 @@ bool Analog_Value_Present_Value_Set(
CurrentAV = &AV_Descr[index]; CurrentAV = &AV_Descr[index];
if (priority && (priority <= BACNET_MAX_PRIORITY) && if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) && (priority != 6 /* reserved */ ) &&
(value >= 0.0) && (value <= 100.0)) (value >= 0.0) && (value <= 100.0)) {
{
CurrentAV->Priority_Array[priority - 1] = (uint8_t) value; CurrentAV->Priority_Array[priority - 1] = (uint8_t) value;
/* Note: you could set the physical output here to the next /* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no highest priority, or to the relinquish default if no
@@ -316,18 +314,20 @@ int Analog_Value_Read_Property(
#endif #endif
bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAV->Out_Of_Service);
apdu_len = encode_application_bitstring(&apdu[0], &bit_string); apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
break; break;
case PROP_EVENT_STATE: case PROP_EVENT_STATE:
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAV->Event_State); CurrentAV->Event_State);
#else #else
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
EVENT_STATE_NORMAL); encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
#endif #endif
break; break;
@@ -337,7 +337,8 @@ int Analog_Value_Read_Property(
break; break;
case PROP_UNITS: case PROP_UNITS:
apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Units); apdu_len =
encode_application_enumerated(&apdu[0], CurrentAV->Units);
break; break;
case PROP_PRIORITY_ARRAY: case PROP_PRIORITY_ARRAY:
@@ -374,8 +375,8 @@ int Analog_Value_Read_Property(
== ANALOG_LEVEL_NULL) == ANALOG_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]); apdu_len = encode_application_null(&apdu[0]);
else { else {
real_value = CurrentAV->Priority_Array real_value =
[rpdata->array_index - 1]; CurrentAV->Priority_Array[rpdata->array_index - 1];
apdu_len = apdu_len =
encode_application_real(&apdu[0], real_value); encode_application_real(&apdu[0], real_value);
} }
@@ -394,15 +395,19 @@ int Analog_Value_Read_Property(
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
case PROP_TIME_DELAY: case PROP_TIME_DELAY:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay); apdu_len =
encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay);
break; break;
case PROP_NOTIFICATION_CLASS: case PROP_NOTIFICATION_CLASS:
apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Notification_Class); apdu_len =
encode_application_unsigned(&apdu[0],
CurrentAV->Notification_Class);
break; break;
case PROP_HIGH_LIMIT: case PROP_HIGH_LIMIT:
apdu_len = encode_application_real(&apdu[0], CurrentAV->High_Limit); apdu_len =
encode_application_real(&apdu[0], CurrentAV->High_Limit);
break; break;
case PROP_LOW_LIMIT: case PROP_LOW_LIMIT:
@@ -416,9 +421,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 : false ); (CurrentAV->
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 : false ); (CurrentAV->
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;
@@ -426,11 +433,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 : false ); (CurrentAV->
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 : false ); (CurrentAV->
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 : false ); (CurrentAV->
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;
@@ -438,7 +448,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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
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,
@@ -448,26 +459,32 @@ int Analog_Value_Read_Property(
break; break;
case PROP_NOTIFY_TYPE: case PROP_NOTIFY_TYPE:
apdu_len = encode_application_enumerated(&apdu[0], apdu_len =
encode_application_enumerated(&apdu[0],
CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM);
break; break;
case PROP_EVENT_TIME_STAMPS: case PROP_EVENT_TIME_STAMPS:
/* Array element zero is the number of elements in the array */ /* Array element zero is the number of elements in the array */
if (rpdata->array_index == 0) if (rpdata->array_index == 0)
apdu_len = encode_application_unsigned(&apdu[0], apdu_len =
encode_application_unsigned(&apdu[0],
MAX_BACNET_EVENT_TRANSITION); MAX_BACNET_EVENT_TRANSITION);
/* 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. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) { else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {; for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {;
len = encode_opening_tag(&apdu[apdu_len], len =
encode_opening_tag(&apdu[apdu_len],
TIME_STAMP_DATETIME); TIME_STAMP_DATETIME);
len += encode_application_date(&apdu[apdu_len + len], len +=
encode_application_date(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].date); &CurrentAV->Event_Time_Stamps[i].date);
len += encode_application_time(&apdu[apdu_len + len], len +=
encode_application_time(&apdu[apdu_len + len],
&CurrentAV->Event_Time_Stamps[i].time); &CurrentAV->Event_Time_Stamps[i].time);
len += encode_closing_tag(&apdu[apdu_len + len], len +=
encode_closing_tag(&apdu[apdu_len + len],
TIME_STAMP_DATETIME); TIME_STAMP_DATETIME);
/* add it if we have room */ /* add it if we have room */
@@ -480,18 +497,18 @@ int Analog_Value_Read_Property(
break; break;
} }
} }
} } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) {
else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { apdu_len =
apdu_len = encode_opening_tag(&apdu[apdu_len], encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
TIME_STAMP_DATETIME); apdu_len +=
apdu_len += encode_application_date(&apdu[apdu_len], encode_application_date(&apdu[apdu_len],
&CurrentAV->Event_Time_Stamps[rpdata->array_index].date); &CurrentAV->Event_Time_Stamps[rpdata->array_index].date);
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
encode_application_time(&apdu[apdu_len],
&CurrentAV->Event_Time_Stamps[rpdata->array_index].time); &CurrentAV->Event_Time_Stamps[rpdata->array_index].time);
apdu_len += encode_closing_tag(&apdu[apdu_len], apdu_len +=
TIME_STAMP_DATETIME); encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME);
} } else {
else {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
@@ -506,8 +523,7 @@ int Analog_Value_Read_Property(
break; break;
} }
/* only array properties can have array options */ /* only array properties can have array options */
if ((apdu_len >= 0) && if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->object_property != PROP_EVENT_TIME_STAMPS) && (rpdata->object_property != PROP_EVENT_TIME_STAMPS) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) { (rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
@@ -679,8 +695,7 @@ bool Analog_Value_Write_Property(
if (status) { if (status) {
if (value.type.Bit_String.bits_used == 2) { if (value.type.Bit_String.bits_used == 2) {
CurrentAV->Limit_Enable = value.type.Bit_String.value[0]; CurrentAV->Limit_Enable = value.type.Bit_String.value[0];
} } else {
else {
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;
status = false; status = false;
@@ -696,8 +711,7 @@ bool Analog_Value_Write_Property(
if (status) { if (status) {
if (value.type.Bit_String.bits_used == 3) { if (value.type.Bit_String.bits_used == 3) {
CurrentAV->Event_Enable = value.type.Bit_String.value[0]; CurrentAV->Event_Enable = value.type.Bit_String.value[0];
} } else {
else {
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;
status = false; status = false;
@@ -713,8 +727,7 @@ bool Analog_Value_Write_Property(
if (status) { if (status) {
if (value.type.Bit_String.bits_used > NOTIFY_EVENT) { if (value.type.Bit_String.bits_used > NOTIFY_EVENT) {
CurrentAV->Event_Enable = value.type.Enumerated; CurrentAV->Event_Enable = value.type.Enumerated;
} } else {
else {
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;
status = false; status = false;
@@ -733,7 +746,8 @@ bool Analog_Value_Write_Property(
} }
void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) void Analog_Value_Intrinsic_Reporting(
uint32_t object_instance)
{ {
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
BACNET_EVENT_NOTIFICATION_DATA event_data; BACNET_EVENT_NOTIFICATION_DATA event_data;
@@ -766,8 +780,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Send Acknotification for (%s,%d).\n", fprintf(stderr, "Send Acknotification for (%s,%d).\n",
bactext_object_type_name(OBJECT_ANALOG_VALUE), bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance);
object_instance);
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
characterstring_init_ansi(&msgText, "AckNotification"); characterstring_init_ansi(&msgText, "AckNotification");
@@ -777,14 +790,11 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Send EventNotification. */ /* Send EventNotification. */
SendNotify = true; SendNotify = true;
} } else {
else
{
/* actual Present_Value */ /* actual Present_Value */
PresentVal = Analog_Value_Present_Value(object_instance); PresentVal = Analog_Value_Present_Value(object_instance);
FromState = CurrentAV->Event_State; FromState = CurrentAV->Event_State;
switch (CurrentAV->Event_State) switch (CurrentAV->Event_State) {
{
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
/* A TO-OFFNORMAL event is generated under these conditions: /* A TO-OFFNORMAL event is generated under these conditions:
(a) the Present_Value must exceed the High_Limit for a minimum (a) the Present_Value must exceed the High_Limit for a minimum
@@ -792,9 +802,10 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAV->High_Limit) && if ((PresentVal > CurrentAV->High_Limit) &&
((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAV->Remaining_Time_Delay) if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_HIGH_LIMIT; CurrentAV->Event_State = EVENT_STATE_HIGH_LIMIT;
else else
@@ -808,9 +819,10 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAV->Low_Limit) && if ((PresentVal < CurrentAV->Low_Limit) &&
((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ==
EVENT_ENABLE_TO_OFFNORMAL)) {
if (!CurrentAV->Remaining_Time_Delay) if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_LOW_LIMIT; CurrentAV->Event_State = EVENT_STATE_LOW_LIMIT;
else else
@@ -828,10 +840,11 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the HighLimitEnable flag must be set in the Limit_Enable property, and (b) the HighLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband) && if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband)
((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && && ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_HIGH_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAV->Remaining_Time_Delay) if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_NORMAL; CurrentAV->Event_State = EVENT_STATE_NORMAL;
else else
@@ -850,10 +863,11 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
for a minimum period of time, specified in the Time_Delay property, and for a minimum period of time, specified in the Time_Delay property, and
(b) the LowLimitEnable flag must be set in the Limit_Enable property, and (b) the LowLimitEnable flag must be set in the Limit_Enable property, and
(c) the TO-NORMAL flag must be set in the Event_Enable property. */ (c) the TO-NORMAL flag must be set in the Event_Enable property. */
if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) && if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband)
((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && && ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ==
((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) EVENT_LOW_LIMIT_ENABLE) &&
{ ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ==
EVENT_ENABLE_TO_NORMAL)) {
if (!CurrentAV->Remaining_Time_Delay) if (!CurrentAV->Remaining_Time_Delay)
CurrentAV->Event_State = EVENT_STATE_NORMAL; CurrentAV->Event_State = EVENT_STATE_NORMAL;
else else
@@ -870,24 +884,20 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
ToState = CurrentAV->Event_State; ToState = CurrentAV->Event_State;
if (FromState != ToState) if (FromState != ToState) {
{
/* Event_State has changed. /* Event_State has changed.
Need to fill only the basic parameters of this type of event. Need to fill only the basic parameters of this type of event.
Other parameters will be filled in common function. */ Other parameters will be filled in common function. */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
ExceededLimit = CurrentAV->High_Limit; ExceededLimit = CurrentAV->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to high limit");
"Goes to high limit");
break; break;
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
ExceededLimit = CurrentAV->Low_Limit; ExceededLimit = CurrentAV->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText, "Goes to low limit");
"Goes to low limit");
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
@@ -895,8 +905,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
ExceededLimit = CurrentAV->High_Limit; ExceededLimit = CurrentAV->High_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from high limit"); "Back to normal state from high limit");
} } else {
else {
ExceededLimit = CurrentAV->Low_Limit; ExceededLimit = CurrentAV->Low_Limit;
characterstring_init_ansi(&msgText, characterstring_init_ansi(&msgText,
"Back to normal state from low limit"); "Back to normal state from low limit");
@@ -910,8 +919,8 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n",
bactext_object_type_name(OBJECT_ANALOG_VALUE), bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance,
object_instance, bactext_event_state_name(FromState), bactext_event_state_name(FromState),
bactext_event_state_name(ToState)); bactext_event_state_name(ToState));
#endif /* PRINT_ENABLED */ #endif /* PRINT_ENABLED */
@@ -924,8 +933,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
} }
if (SendNotify) if (SendNotify) {
{
/* Event Object Identifier */ /* Event Object Identifier */
event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE; event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE;
event_data.eventObjectIdentifier.instance = object_instance; event_data.eventObjectIdentifier.instance = object_instance;
@@ -936,8 +944,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* fill Event_Time_Stamps */ /* fill Event_Time_Stamps */
switch (ToState) switch (ToState) {
{
case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_HIGH_LIMIT:
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
CurrentAV->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] = CurrentAV->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] =
@@ -978,21 +985,27 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Event Values */ /* Event Values */
if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) {
/* Value that exceeded a limit. */ /* Value that exceeded a limit. */
event_data.notificationParams.outOfRange.exceedingValue = PresentVal; event_data.notificationParams.outOfRange.exceedingValue =
PresentVal;
/* Status_Flags of the referenced object. */ /* Status_Flags of the referenced object. */
bitstring_init(&event_data.notificationParams.outOfRange.statusFlags); bitstring_init(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags);
STATUS_FLAG_IN_ALARM, CurrentAV->Event_State ? true : false); bitstring_set_bit(&event_data.notificationParams.outOfRange.
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, statusFlags, STATUS_FLAG_IN_ALARM,
STATUS_FLAG_FAULT, false); CurrentAV->Event_State ? true : false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OVERRIDDEN, false); statusFlags, STATUS_FLAG_FAULT, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.statusFlags, bitstring_set_bit(&event_data.notificationParams.outOfRange.
STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service); statusFlags, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&event_data.notificationParams.outOfRange.
statusFlags, STATUS_FLAG_OUT_OF_SERVICE,
CurrentAV->Out_Of_Service);
/* Deadband used for limit checking. */ /* Deadband used for limit checking. */
event_data.notificationParams.outOfRange.deadband = CurrentAV->Deadband; event_data.notificationParams.outOfRange.deadband =
CurrentAV->Deadband;
/* Limit that was exceeded. */ /* Limit that was exceeded. */
event_data.notificationParams.outOfRange.exceededLimit = ExceededLimit; event_data.notificationParams.outOfRange.exceededLimit =
ExceededLimit;
} }
/* add data from notification class */ /* add data from notification class */
@@ -1000,28 +1013,29 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
/* Ack required */ /* Ack required */
if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) &&
(event_data.ackRequired == true)) (event_data.ackRequired == true)) {
{ switch (event_data.toState) {
switch (event_data.toState)
{
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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = false; CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = false; CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = false; CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp = bIsAcked = false;
event_data.timeStamp.value.dateTime; CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].
Time_Stamp = event_data.timeStamp.value.dateTime;
break; break;
} }
} }
@@ -1031,7 +1045,8 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance)
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Value_Event_Information(unsigned index, int Analog_Value_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) BACNET_GET_EVENT_INFORMATION_DATA * getevent_data)
{ {
bool IsNotAckedTransitions; bool IsNotAckedTransitions;
@@ -1046,26 +1061,34 @@ int Analog_Value_Event_Information(unsigned index,
/* 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 = (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) | IsNotAckedTransitions =
(AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
(AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); bIsAcked ==
} false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].
else bIsAcked ==
false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].
bIsAcked == false);
} else
return -1; /* end of list */ return -1; /* end of list */
if ((IsActiveEvent) || (IsNotAckedTransitions)) { if ((IsActiveEvent) || (IsNotAckedTransitions)) {
/* Object Identifier */ /* Object Identifier */
getevent_data->objectIdentifier.type = OBJECT_ANALOG_VALUE; getevent_data->objectIdentifier.type = OBJECT_ANALOG_VALUE;
getevent_data->objectIdentifier.instance = Analog_Value_Index_To_Instance(index); getevent_data->objectIdentifier.instance =
Analog_Value_Index_To_Instance(index);
/* Event State */ /* Event State */
getevent_data->eventState = AV_Descr[index].Event_State; getevent_data->eventState = AV_Descr[index].Event_State;
/* Acknowledged Transitions */ /* Acknowledged Transitions */
bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_init(&getevent_data->acknowledgedTransitions);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); TRANSITION_TO_OFFNORMAL,
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL].
bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_FAULT,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked);
bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, bitstring_set_bit(&getevent_data->acknowledgedTransitions,
TRANSITION_TO_NORMAL,
AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked);
/* Event Time Stamps */ /* Event Time Stamps */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
@@ -1078,30 +1101,34 @@ int Analog_Value_Event_Information(unsigned index,
/* 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 : false ); (AV_Descr[index].
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 : false ); (AV_Descr[index].
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 : false ); (AV_Descr[index].
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);
return 1; /* active event */ return 1; /* active event */
} } else
else
return 0; /* no active event at this index */ return 0; /* no active event at this index */
} }
int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Value_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code) BACNET_ERROR_CODE * error_code)
{ {
ANALOG_VALUE_DESCR *CurrentAV; ANALOG_VALUE_DESCR *CurrentAV;
unsigned int object_index; unsigned int object_index;
object_index = Analog_Value_Instance_To_Index( object_index =
alarmack_data->eventObjectIdentifier.instance); Analog_Value_Instance_To_Index(alarmack_data->eventObjectIdentifier.
instance);
if (object_index < MAX_ANALOG_VALUES) if (object_index < MAX_ANALOG_VALUES)
CurrentAV = &AV_Descr[object_index]; CurrentAV = &AV_Descr[object_index];
@@ -1110,71 +1137,73 @@ int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data,
return -1; return -1;
} }
switch (alarmack_data->eventStateAcked) switch (alarmack_data->eventStateAcked) {
{
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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { if (CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
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[TRANSITION_TO_OFFNORMAL].Time_Stamp, if (datetime_compare(&CurrentAV->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp,
{ &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->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].
} bIsAcked = true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_FAULT: case EVENT_STATE_FAULT:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false) { if (CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].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[TRANSITION_TO_NORMAL].Time_Stamp, if (datetime_compare(&CurrentAV->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp,
{ &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->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = true; CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
break; break;
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
if(CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) { if (CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].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[TRANSITION_TO_FAULT].Time_Stamp, if (datetime_compare(&CurrentAV->
&alarmack_data->eventTimeStamp.value.dateTime) > 0) Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp,
{ &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->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true; CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked =
} true;
else { } else {
*error_code = ERROR_CODE_INVALID_EVENT_STATE; *error_code = ERROR_CODE_INVALID_EVENT_STATE;
return -1; return -1;
} }
+4 -2
View File
@@ -106,10 +106,12 @@ extern "C" {
uint32_t object_instance); uint32_t object_instance);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
int Analog_Value_Event_Information(unsigned index, int Analog_Value_Event_Information(
unsigned index,
BACNET_GET_EVENT_INFORMATION_DATA * getevent_data); BACNET_GET_EVENT_INFORMATION_DATA * getevent_data);
int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, int Analog_Value_Alarm_Ack(
BACNET_ALARM_ACK_DATA * alarmack_data,
BACNET_ERROR_CODE * error_code); BACNET_ERROR_CODE * error_code);
#endif #endif
+4 -6
View File
@@ -491,14 +491,12 @@ bool bacfile_read_ack_stream_data(
found = true; found = true;
pFile = fopen(pFilename, "rb"); pFile = fopen(pFilename, "rb");
if (pFile) { if (pFile) {
(void) fseek(pFile, data->type.stream.fileStartPosition, (void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET);
SEEK_SET);
if (fwrite(octetstring_value(&data->fileData), if (fwrite(octetstring_value(&data->fileData),
octetstring_length(&data->fileData), 1, octetstring_length(&data->fileData), 1, pFile) != 1) {
pFile) != 1) {
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stderr, "Failed to write to %s (%lu)!\n", fprintf(stderr, "Failed to write to %s (%lu)!\n", pFilename,
pFilename, (unsigned long) instance); (unsigned long) instance);
#endif #endif
} }
fclose(pFile); fclose(pFile);
+4 -4
View File
@@ -233,10 +233,10 @@ bool Binary_Input_Encode_Value_List(
value_list->value.context_specific = false; value_list->value.context_specific = false;
value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING; value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
bitstring_init(&value_list->value.type.Bit_String); bitstring_init(&value_list->value.type.Bit_String);
bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_IN_ALARM, bitstring_set_bit(&value_list->value.type.Bit_String,
false); STATUS_FLAG_IN_ALARM, false);
bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT, bitstring_set_bit(&value_list->value.type.Bit_String,
false); STATUS_FLAG_FAULT, false);
bitstring_set_bit(&value_list->value.type.Bit_String, bitstring_set_bit(&value_list->value.type.Bit_String,
STATUS_FLAG_OVERRIDDEN, false); STATUS_FLAG_OVERRIDDEN, false);
if (Binary_Input_Out_Of_Service(object_instance)) { if (Binary_Input_Out_Of_Service(object_instance)) {
+4 -4
View File
@@ -376,8 +376,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
@@ -403,8 +403,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
@@ -359,8 +359,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
@@ -386,8 +386,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--;
+40 -34
View File
@@ -112,14 +112,19 @@ static object_functions_t Object_Table[] = {
Binary_Value_Write_Property, Binary_Value_Property_Lists, Binary_Value_Write_Property, Binary_Value_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, OBJECT_NOTIFICATION_CLASS, Notification_Class_Init,
Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, Notification_Class_Count,
Notification_Class_Index_To_Instance,
Notification_Class_Valid_Instance,
Notification_Class_Object_Name, Notification_Class_Read_Property, Notification_Class_Object_Name, Notification_Class_Read_Property,
Notification_Class_Write_Property, Notification_Class_Property_Lists, Notification_Class_Write_Property,
Notification_Class_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
#endif #endif
OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init, Life_Safety_Point_Count, OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init,
Life_Safety_Point_Index_To_Instance, Life_Safety_Point_Valid_Instance, Life_Safety_Point_Count,
Life_Safety_Point_Index_To_Instance,
Life_Safety_Point_Valid_Instance,
Life_Safety_Point_Object_Name, Life_Safety_Point_Read_Property, Life_Safety_Point_Object_Name, Life_Safety_Point_Read_Property,
Life_Safety_Point_Write_Property, Life_Safety_Point_Property_Lists, Life_Safety_Point_Write_Property, Life_Safety_Point_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
@@ -128,13 +133,17 @@ static object_functions_t Object_Table[] = {
Load_Control_Object_Name, Load_Control_Read_Property, Load_Control_Object_Name, Load_Control_Read_Property,
Load_Control_Write_Property, Load_Control_Property_Lists, Load_Control_Write_Property, Load_Control_Property_Lists,
NULL, NULL, NULL}, { NULL, NULL, NULL}, {
OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init, Multistate_Output_Count, OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init,
Multistate_Output_Index_To_Instance, Multistate_Output_Valid_Instance, Multistate_Output_Count,
Multistate_Output_Index_To_Instance,
Multistate_Output_Valid_Instance,
Multistate_Output_Object_Name, Multistate_Output_Read_Property, Multistate_Output_Object_Name, Multistate_Output_Read_Property,
Multistate_Output_Write_Property, Multistate_Output_Property_Lists, Multistate_Output_Write_Property, Multistate_Output_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count, OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init,
Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance, Multistate_Input_Count,
Multistate_Input_Index_To_Instance,
Multistate_Input_Valid_Instance,
Multistate_Input_Object_Name, Multistate_Input_Read_Property, Multistate_Input_Object_Name, Multistate_Input_Read_Property,
Multistate_Input_Write_Property, Multistate_Input_Property_Lists, Multistate_Input_Write_Property, Multistate_Input_Property_Lists,
NULL, NULL, NULL, NULL}, { NULL, NULL, NULL, NULL}, {
@@ -960,7 +969,8 @@ int tm_isdst Daylight Savings flag.
} }
} }
void Device_getCurrentDateTime(BACNET_DATE_TIME * DateTime) void Device_getCurrentDateTime(
BACNET_DATE_TIME * DateTime)
{ {
Update_Current_Time(); Update_Current_Time();
@@ -1265,8 +1275,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;
@@ -1299,8 +1309,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:
@@ -1325,8 +1335,7 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
status = status =
WPValidateString(&value, WPValidateString(&value,
characterstring_capacity(&My_Object_Name), characterstring_capacity(&My_Object_Name), false,
false,
&wp_data->error_class, &wp_data->error_code); &wp_data->error_class, &wp_data->error_code);
if (status) { if (status) {
/* All the object names in a device must be unique. /* All the object names in a device must be unique.
@@ -1347,8 +1356,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;
@@ -1358,8 +1367,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;
@@ -1368,8 +1377,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;
@@ -1381,8 +1390,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;
@@ -1476,9 +1485,8 @@ bool Device_Encode_Value_List(
if (pObject->Object_Valid_Instance && if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(object_instance)) { pObject->Object_Valid_Instance(object_instance)) {
if (pObject->Object_Value_List) { if (pObject->Object_Value_List) {
status = pObject->Object_Value_List( status =
object_instance, pObject->Object_Value_List(object_instance, value_list);
value_list);
} }
} }
} }
@@ -1488,7 +1496,8 @@ bool Device_Encode_Value_List(
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
void Device_local_reporting(void) void Device_local_reporting(
void)
{ {
struct object_functions *pObject; struct object_functions *pObject;
uint32_t objects_count; uint32_t objects_count;
@@ -1499,18 +1508,15 @@ void Device_local_reporting(void)
objects_count = Device_Object_List_Count(); objects_count = Device_Object_List_Count();
/* loop for all objects */ /* loop for all objects */
for (idx = 1; idx < objects_count; idx++) for (idx = 1; idx < objects_count; idx++) {
{ Device_Object_List_Identifier(idx, &object_type, &object_instance);
Device_Object_List_Identifier(idx, &object_type,
&object_instance);
pObject = Device_Objects_Find_Functions(object_type); pObject = Device_Objects_Find_Functions(object_type);
if (pObject != NULL) { if (pObject != NULL) {
if (pObject->Object_Valid_Instance && if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(object_instance)) { pObject->Object_Valid_Instance(object_instance)) {
if (pObject->Object_Intrinsic_Reporting) { if (pObject->Object_Intrinsic_Reporting) {
pObject->Object_Intrinsic_Reporting( pObject->Object_Intrinsic_Reporting(object_instance);
object_instance);
} }
} }
} }
+4 -2
View File
@@ -213,7 +213,8 @@ extern "C" {
rr_info_function Device_Objects_RR_Info( rr_info_function Device_Objects_RR_Info(
BACNET_OBJECT_TYPE object_type); BACNET_OBJECT_TYPE object_type);
void Device_getCurrentDateTime(BACNET_DATE_TIME * DateTime); void Device_getCurrentDateTime(
BACNET_DATE_TIME * DateTime);
void Device_Property_Lists( void Device_Property_Lists(
const int **pRequired, const int **pRequired,
@@ -338,7 +339,8 @@ extern "C" {
BACNET_WRITE_PROPERTY_DATA * wp_data); BACNET_WRITE_PROPERTY_DATA * wp_data);
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
void Device_local_reporting(void); void Device_local_reporting(
void);
#endif #endif
/* Prototypes for Routing functionality in the Device Object. /* Prototypes for Routing functionality in the Device Object.
+7 -12
View File
@@ -127,14 +127,10 @@ uint16_t Add_Routed_Device(
pDev->bacObj.mObject_Type = OBJECT_DEVICE; pDev->bacObj.mObject_Type = OBJECT_DEVICE;
pDev->bacObj.Object_Instance_Number = Object_Instance; pDev->bacObj.Object_Instance_Number = Object_Instance;
if (sObject_Name != NULL) if (sObject_Name != NULL)
Routed_Device_Set_Object_Name( Routed_Device_Set_Object_Name(CHARACTER_UTF8, sObject_Name,
CHARACTER_UTF8,
sObject_Name,
strlen(sObject_Name)); strlen(sObject_Name));
else else
Routed_Device_Set_Object_Name( Routed_Device_Set_Object_Name(CHARACTER_UTF8, "No Name",
CHARACTER_UTF8,
"No Name",
strlen("No Name")); strlen("No Name"));
if (sDescription != NULL) if (sDescription != NULL)
Routed_Device_Set_Description(sDescription, strlen(sDescription)); Routed_Device_Set_Description(sDescription, strlen(sDescription));
@@ -488,8 +484,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;
@@ -503,8 +499,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( Routed_Device_Set_Object_Name(characterstring_encoding(&value.
characterstring_encoding(&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));
} }
@@ -559,8 +555,7 @@ bool Routed_Device_Set_Object_Name(
bool status = false; /*return value */ bool status = false; /*return value */
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
if ((encoding == CHARACTER_UTF8) && if ((encoding == CHARACTER_UTF8) && (length < MAX_DEV_NAME_LEN)) {
(length < MAX_DEV_NAME_LEN)) {
/* Make the change and update the database revision */ /* Make the change and update the database revision */
memmove(pDev->bacObj.Object_Name, value, length); memmove(pDev->bacObj.Object_Name, value, length);
pDev->bacObj.Object_Name[length] = 0; pDev->bacObj.Object_Name[length] = 0;
+8 -8
View File
@@ -469,8 +469,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]
@@ -554,11 +554,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
@@ -585,8 +585,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;
} }
+6 -5
View File
@@ -218,7 +218,8 @@ int Life_Safety_Point_Read_Property(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
Life_Safety_Point_Object_Name(rpdata->object_instance, &char_string); Life_Safety_Point_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
@@ -324,8 +325,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 {
@@ -341,8 +342,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;
} }
+10 -9
View File
@@ -348,7 +348,8 @@ int Multistate_Input_Read_Property(
/* note: Name and Description don't have to be the same. /* note: Name and Description don't have to be the same.
You could make Description writable and different */ You could make Description writable and different */
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
Multistate_Input_Object_Name(rpdata->object_instance, &char_string); Multistate_Input_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
@@ -403,8 +404,8 @@ int Multistate_Input_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_Input_Instance_To_Index(rpdata-> Multistate_Input_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_Input_State_Text(rpdata->object_instance, Multistate_Input_State_Text(rpdata->object_instance,
@@ -425,8 +426,8 @@ int Multistate_Input_Read_Property(
} }
} else { } else {
object_index = object_index =
Multistate_Input_Instance_To_Index(rpdata-> Multistate_Input_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_Input_State_Text(rpdata->object_instance, Multistate_Input_State_Text(rpdata->object_instance,
@@ -486,8 +487,8 @@ bool Multistate_Input_Write_Property(
if (status) { if (status) {
if (Out_Of_Service[object_index]) { if (Out_Of_Service[object_index]) {
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;
@@ -505,8 +506,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) {
object_index = object_index =
Multistate_Input_Instance_To_Index(wp_data-> Multistate_Input_Instance_To_Index
object_instance); (wp_data->object_instance);
Out_Of_Service[object_index] = value.type.Boolean; Out_Of_Service[object_index] = value.type.Boolean;
} }
break; break;
+12 -11
View File
@@ -224,7 +224,8 @@ int Multistate_Output_Read_Property(
You could make Description writable and different */ You could make Description writable and different */
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
Multistate_Output_Object_Name(rpdata->object_instance, &char_string); Multistate_Output_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
@@ -267,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] ==
@@ -293,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)
@@ -376,8 +377,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;
@@ -404,8 +405,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--;
@@ -431,8 +432,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;
} }
+220 -180
View File
@@ -51,8 +51,7 @@
static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES]; static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES];
/* These three arrays are used by the ReadPropertyMultiple handler */ /* These three arrays are used by the ReadPropertyMultiple handler */
static const int Notification_Properties_Required[] = static const int Notification_Properties_Required[] = {
{
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME, PROP_OBJECT_NAME,
PROP_OBJECT_TYPE, PROP_OBJECT_TYPE,
@@ -63,14 +62,12 @@ static const int Notification_Properties_Required[] =
-1 -1
}; };
static const int Notification_Properties_Optional[] = static const int Notification_Properties_Optional[] = {
{
PROP_DESCRIPTION, PROP_DESCRIPTION,
-1 -1
}; };
static const int Notification_Properties_Proprietary[] = static const int Notification_Properties_Proprietary[] = {
{
-1 -1
}; };
@@ -88,12 +85,12 @@ void Notification_Class_Property_Lists(
return; return;
} }
void Notification_Class_Init(void) void Notification_Class_Init(
void)
{ {
uint8_t NotifyIdx = 0; uint8_t NotifyIdx = 0;
for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) {
{
/* init with zeros */ /* init with zeros */
memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO)); memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO));
/* set the basic parameters */ /* set the basic parameters */
@@ -124,7 +121,8 @@ bool Notification_Class_Valid_Instance(
/* we simply have 0-n object instances. Yours might be */ /* we simply have 0-n object instances. Yours might be */
/* more complex, and then count how many you have */ /* more complex, and then count how many you have */
unsigned Notification_Class_Count(void) unsigned Notification_Class_Count(
void)
{ {
return MAX_NOTIFICATION_CLASSES; return MAX_NOTIFICATION_CLASSES;
} }
@@ -132,7 +130,8 @@ unsigned Notification_Class_Count(void)
/* we simply have 0-n object instances. Yours might be */ /* we simply have 0-n object instances. Yours might be */
/* more complex, and then you need to return the instance */ /* more complex, and then you need to return the instance */
/* that correlates to the correct index */ /* that correlates to the correct index */
uint32_t Notification_Class_Index_To_Instance(unsigned index) uint32_t Notification_Class_Index_To_Instance(
unsigned index)
{ {
return index; return index;
} }
@@ -189,56 +188,58 @@ int Notification_Class_Read_Property(
} }
apdu = rpdata->application_data; apdu = rpdata->application_data;
CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(rpdata->object_instance)]; CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index(rpdata->
object_instance)];
switch (rpdata->object_property) switch (rpdata->object_property) {
{
case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_IDENTIFIER:
apdu_len = apdu_len =
encode_application_object_id(&apdu[0], OBJECT_NOTIFICATION_CLASS, encode_application_object_id(&apdu[0],
rpdata->object_instance); OBJECT_NOTIFICATION_CLASS, rpdata->object_instance);
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
Notification_Class_Object_Name(rpdata->object_instance, &char_string); Notification_Class_Object_Name(rpdata->object_instance,
&char_string);
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
apdu_len = apdu_len =
encode_application_enumerated(&apdu[0], OBJECT_NOTIFICATION_CLASS); encode_application_enumerated(&apdu[0],
OBJECT_NOTIFICATION_CLASS);
break; break;
case PROP_NOTIFICATION_CLASS: case PROP_NOTIFICATION_CLASS:
apdu_len += encode_application_unsigned(&apdu[0], rpdata->object_instance); apdu_len +=
encode_application_unsigned(&apdu[0], rpdata->object_instance);
break; break;
case PROP_PRIORITY: case PROP_PRIORITY:
if (rpdata->array_index == 0) if (rpdata->array_index == 0)
apdu_len += encode_application_unsigned(&apdu[0], 3); apdu_len += encode_application_unsigned(&apdu[0], 3);
else else {
{ if (rpdata->array_index == BACNET_ARRAY_ALL) {
if (rpdata->array_index == BACNET_ARRAY_ALL)
{
/* TO-OFFNORMAL */ /* TO-OFFNORMAL */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
CurrentNotify->Priority[0]); CurrentNotify->Priority[0]);
/* TO-FAULT */ /* TO-FAULT */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
CurrentNotify->Priority[1]); CurrentNotify->Priority[1]);
/* TO-NORMAL */ /* TO-NORMAL */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
CurrentNotify->Priority[2]); CurrentNotify->Priority[2]);
} } else if (rpdata->array_index <= 3) {
else if (rpdata->array_index <= 3) apdu_len +=
{ encode_application_unsigned(&apdu[apdu_len],
apdu_len += encode_application_unsigned(&apdu[apdu_len],
CurrentNotify->Priority[rpdata->array_index - 1]); CurrentNotify->Priority[rpdata->array_index - 1]);
} } else {
else
{
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = -1; apdu_len = -1;
@@ -257,40 +258,43 @@ int Notification_Class_Read_Property(
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false); (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false);
/* encode bitstring */ /* encode bitstring */
apdu_len += encode_application_bitstring(&apdu[apdu_len], &bit_string); apdu_len +=
encode_application_bitstring(&apdu[apdu_len], &bit_string);
break; break;
case PROP_RECIPIENT_LIST: case PROP_RECIPIENT_LIST:
/* encode all entry of Recipient_List */ /* encode all entry of Recipient_List */
for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) {
{
BACNET_DESTINATION *RecipientEntry; BACNET_DESTINATION *RecipientEntry;
int i = 0; int i = 0;
/* get pointer of current element for Recipient_List - easier for use */ /* get pointer of current element for Recipient_List - easier for use */
RecipientEntry = &CurrentNotify->Recipient_List[idx]; RecipientEntry = &CurrentNotify->Recipient_List[idx];
if (RecipientEntry->Recipient.RecipientType != RECIPIENT_TYPE_NOTINITIALIZED) if (RecipientEntry->Recipient.RecipientType !=
{ RECIPIENT_TYPE_NOTINITIALIZED) {
/* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday */ /* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday */
u8Val = 0x01; u8Val = 0x01;
bitstring_init(&bit_string); bitstring_init(&bit_string);
for (i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) for (i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) {
{
if (RecipientEntry->ValidDays & u8Val) if (RecipientEntry->ValidDays & u8Val)
bitstring_set_bit(&bit_string, i, true); bitstring_set_bit(&bit_string, i, true);
else else
bitstring_set_bit(&bit_string, i, false); bitstring_set_bit(&bit_string, i, false);
u8Val <<= 1; /* next day */ u8Val <<= 1; /* next day */
} }
apdu_len += encode_application_bitstring(&apdu[apdu_len],&bit_string); apdu_len +=
encode_application_bitstring(&apdu[apdu_len],
&bit_string);
/* From Time */ /* From Time */
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
encode_application_time(&apdu[apdu_len],
&RecipientEntry->FromTime); &RecipientEntry->FromTime);
/* To Time */ /* To Time */
apdu_len += encode_application_time(&apdu[apdu_len], apdu_len +=
encode_application_time(&apdu[apdu_len],
&RecipientEntry->ToTime); &RecipientEntry->ToTime);
/* /*
@@ -300,47 +304,51 @@ int Notification_Class_Read_Property(
} */ } */
/* CHOICE - device [0] BACnetObjectIdentifier */ /* CHOICE - device [0] BACnetObjectIdentifier */
if (RecipientEntry->Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) if (RecipientEntry->Recipient.RecipientType ==
{ RECIPIENT_TYPE_DEVICE) {
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, OBJECT_DEVICE, apdu_len +=
encode_context_object_id(&apdu[apdu_len], 0,
OBJECT_DEVICE,
RecipientEntry->Recipient._.DeviceIdentifier); RecipientEntry->Recipient._.DeviceIdentifier);
} }
/* CHOICE - address [1] BACnetAddress */ /* CHOICE - address [1] BACnetAddress */
else if (RecipientEntry->Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) else if (RecipientEntry->Recipient.RecipientType ==
{ RECIPIENT_TYPE_ADDRESS) {
/* opening tag 1 */ /* opening tag 1 */
apdu_len += encode_opening_tag(&apdu[apdu_len], 1); apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
/* network-number Unsigned16, */ /* network-number Unsigned16, */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
RecipientEntry->Recipient._.Address.net); RecipientEntry->Recipient._.Address.net);
/* mac-address OCTET STRING */ /* mac-address OCTET STRING */
if (RecipientEntry->Recipient._.Address.net) if (RecipientEntry->Recipient._.Address.net) {
{
octetstring_init(&octet_string, octetstring_init(&octet_string,
RecipientEntry->Recipient._.Address.adr, RecipientEntry->Recipient._.Address.adr,
RecipientEntry->Recipient._.Address.len); RecipientEntry->Recipient._.Address.len);
} } else {
else
{
octetstring_init(&octet_string, octetstring_init(&octet_string,
RecipientEntry->Recipient._.Address.mac, RecipientEntry->Recipient._.Address.mac,
RecipientEntry->Recipient._.Address.mac_len); RecipientEntry->Recipient._.Address.mac_len);
} }
apdu_len += encode_application_octet_string(&apdu[apdu_len], &octet_string); apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&octet_string);
/* closing tag 1 */ /* closing tag 1 */
apdu_len += encode_closing_tag(&apdu[apdu_len], 1); apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
} } else {;
else {;} /* shouldn't happen */ } /* shouldn't happen */
/* Process Identifier - Unsigned32 */ /* Process Identifier - Unsigned32 */
apdu_len += encode_application_unsigned(&apdu[apdu_len], apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
RecipientEntry->ProcessIdentifier); RecipientEntry->ProcessIdentifier);
/* Issue Confirmed Notifications - boolean */ /* Issue Confirmed Notifications - boolean */
apdu_len += encode_application_boolean(&apdu[apdu_len], apdu_len +=
encode_application_boolean(&apdu[apdu_len],
RecipientEntry->ConfirmedNotify); RecipientEntry->ConfirmedNotify);
/* Transitions - BACnet Event Transition Bits [bitstring] */ /* Transitions - BACnet Event Transition Bits [bitstring] */
@@ -348,13 +356,16 @@ int Notification_Class_Read_Property(
bitstring_init(&bit_string); bitstring_init(&bit_string);
bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL,
(u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false ); (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true :
false);
bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT,
(u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false); (u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false);
bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL,
(u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false); (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false);
apdu_len += encode_application_bitstring(&apdu[apdu_len], &bit_string); apdu_len +=
encode_application_bitstring(&apdu[apdu_len],
&bit_string);
} }
} }
break; break;
@@ -368,8 +379,7 @@ int Notification_Class_Read_Property(
/* only array properties can have array options */ /* only array properties can have array options */
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY) && if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) (rpdata->array_index != BACNET_ARRAY_ALL)) {
{
rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = BACNET_STATUS_ERROR; apdu_len = BACNET_STATUS_ERROR;
@@ -392,15 +402,17 @@ bool Notification_Class_Write_Property(
CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(wp_data->object_instance)]; CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index(wp_data->
object_instance)];
/* decode the some of the request /* decode the some of the request
*/ */
len = bacapp_decode_application_data(wp_data->application_data, len =
bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value); wp_data->application_data_len, &value);
switch (wp_data->object_property) switch (wp_data->object_property) {
{
case PROP_PRIORITY: case PROP_PRIORITY:
status = status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
@@ -410,15 +422,12 @@ bool Notification_Class_Write_Property(
if (wp_data->array_index == 0) { if (wp_data->array_index == 0) {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
} } else if (wp_data->array_index == BACNET_ARRAY_ALL) {
else if (wp_data->array_index == BACNET_ARRAY_ALL) {
/* FIXME: wite all array */ /* FIXME: wite all array */
} } else if (wp_data->array_index <= 3) {
else if (wp_data->array_index <= 3) {
CurrentNotify->Priority[wp_data->array_index - 1] = CurrentNotify->Priority[wp_data->array_index - 1] =
value.type.Unsigned_Int; value.type.Unsigned_Int;
} } else {
else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
} }
@@ -434,8 +443,7 @@ bool Notification_Class_Write_Property(
if (value.type.Bit_String.bits_used == 3) { if (value.type.Bit_String.bits_used == 3) {
CurrentNotify->Ack_Required = CurrentNotify->Ack_Required =
value.type.Bit_String.value[0]; value.type.Bit_String.value[0];
} } else {
else {
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;
} }
@@ -447,14 +455,15 @@ bool Notification_Class_Write_Property(
memset(&TmpNotify, 0x00, sizeof(NOTIFICATION_CLASS_INFO)); memset(&TmpNotify, 0x00, sizeof(NOTIFICATION_CLASS_INFO));
/* decode all packed */ /* decode all packed */
while (iOffset < wp_data->application_data_len) while (iOffset < wp_data->application_data_len) {
{
/* Decode Valid Days */ /* Decode Valid Days */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
@@ -463,7 +472,8 @@ bool Notification_Class_Write_Property(
if (value.type.Bit_String.bits_used == MAX_BACNET_DAYS_OF_WEEK) if (value.type.Bit_String.bits_used == MAX_BACNET_DAYS_OF_WEEK)
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].ValidDays = value.type.Bit_String.value[0]; TmpNotify.Recipient_List[idx].ValidDays =
value.type.Bit_String.value[0];
else { else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_OTHER; wp_data->error_code = ERROR_CODE_OTHER;
@@ -472,9 +482,10 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Decode From Time */ /* Decode From Time */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
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 */
@@ -487,9 +498,10 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* Decode To Time */ /* Decode To Time */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
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 */
@@ -502,69 +514,78 @@ bool Notification_Class_Write_Property(
iOffset += len; iOffset += len;
/* context tag [0] - Device */ /* context tag [0] - Device */
if (decode_is_context_tag(&wp_data->application_data[iOffset], 0)) if (decode_is_context_tag(&wp_data->application_data[iOffset],
{ 0)) {
TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_DEVICE; TmpNotify.Recipient_List[idx].Recipient.RecipientType =
RECIPIENT_TYPE_DEVICE;
/* Decode Network Number */ /* Decode Network Number */
len = bacapp_decode_context_data( len =
&wp_data->application_data[iOffset], bacapp_decode_context_data(&wp_data->
application_data[iOffset],
wp_data->application_data_len, &value, wp_data->application_data_len, &value,
PROP_RECIPIENT_LIST); PROP_RECIPIENT_LIST);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OBJECT_ID)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_OBJECT_ID)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].Recipient._.DeviceIdentifier = TmpNotify.Recipient_List[idx].Recipient._.
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(&wp_data->application_data[iOffset], 1)) else if (decode_is_opening_tag_number(&wp_data->
{ application_data[iOffset], 1)) {
iOffset++; iOffset++;
TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_ADDRESS; TmpNotify.Recipient_List[idx].Recipient.RecipientType =
RECIPIENT_TYPE_ADDRESS;
/* Decode Network Number */ /* Decode Network Number */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
application_data[iOffset],
wp_data->application_data_len, &value); wp_data->application_data_len, &value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].Recipient._.Address.net = value.type.Unsigned_Int; TmpNotify.Recipient_List[idx].Recipient._.Address.net =
value.type.Unsigned_Int;
iOffset += len; iOffset += len;
/* Decode Address */ /* Decode Address */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
application_data[iOffset],
wp_data->application_data_len, &value); wp_data->application_data_len, &value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OCTET_STRING)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_OCTET_STRING)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
return false; return false;
} }
/* store value */ /* store value */
if (TmpNotify.Recipient_List[idx].Recipient._.Address.net == 0) { if (TmpNotify.Recipient_List[idx].Recipient._.Address.
memcpy(TmpNotify.Recipient_List[idx].Recipient._.Address.mac, net == 0) {
value.type.Octet_String.value, memcpy(TmpNotify.Recipient_List[idx].Recipient._.
Address.mac, value.type.Octet_String.value,
value.type.Octet_String.length); value.type.Octet_String.length);
TmpNotify.Recipient_List[idx].Recipient._.Address.mac_len = TmpNotify.Recipient_List[idx].Recipient._.Address.
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, Address.adr, value.type.Octet_String.value,
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;
@@ -572,7 +593,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[iOffset], 1)) if (decode_is_closing_tag_number(&wp_data->
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 */
@@ -580,8 +602,7 @@ bool Notification_Class_Write_Property(
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
return false; return false;
} }
} } else {
else {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
@@ -589,50 +610,60 @@ bool Notification_Class_Write_Property(
} }
/* Process Identifier */ /* Process Identifier */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].ProcessIdentifier = value.type.Unsigned_Int; TmpNotify.Recipient_List[idx].ProcessIdentifier =
value.type.Unsigned_Int;
iOffset += len; iOffset += len;
/* Issue Confirmed Notifications */ /* Issue Confirmed Notifications */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
return false; return false;
} }
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].ConfirmedNotify = value.type.Boolean; TmpNotify.Recipient_List[idx].ConfirmedNotify =
value.type.Boolean;
iOffset += len; iOffset += len;
/* Transitions */ /* Transitions */
len = bacapp_decode_application_data( len =
&wp_data->application_data[iOffset], bacapp_decode_application_data(&wp_data->
wp_data->application_data_len, &value); application_data[iOffset], wp_data->application_data_len,
&value);
if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { if ((len == 0) ||
(value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) {
/* Bad decode, wrong tag or following required parameter missing */ /* Bad decode, wrong tag or following required parameter missing */
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;
return false; return false;
} }
if (value.type.Bit_String.bits_used == MAX_BACNET_EVENT_TRANSITION) if (value.type.Bit_String.bits_used ==
MAX_BACNET_EVENT_TRANSITION)
/* store value */ /* store value */
TmpNotify.Recipient_List[idx].Transitions = value.type.Bit_String.value[0]; TmpNotify.Recipient_List[idx].Transitions =
value.type.Bit_String.value[0];
else { else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_OTHER; wp_data->error_code = ERROR_CODE_OTHER;
@@ -643,28 +674,32 @@ bool Notification_Class_Write_Property(
/* Increasing element of list */ /* Increasing element of list */
if (++idx >= NC_MAX_RECIPIENTS) { if (++idx >= NC_MAX_RECIPIENTS) {
wp_data->error_class = ERROR_CLASS_RESOURCES; wp_data->error_class = ERROR_CLASS_RESOURCES;
wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; wp_data->error_code =
ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
return false; return false;
} }
} }
/* Decoded all recipient list */ /* Decoded all recipient list */
/* copy elements from temporary object */ /* copy elements from temporary object */
for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) {
{
BACNET_ADDRESS src = { 0 }; BACNET_ADDRESS src = { 0 };
unsigned max_apdu = 0; unsigned max_apdu = 0;
int32_t DeviceID; int32_t DeviceID;
CurrentNotify->Recipient_List[idx] = TmpNotify.Recipient_List[idx]; CurrentNotify->Recipient_List[idx] =
TmpNotify.Recipient_List[idx];
if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { if (CurrentNotify->Recipient_List[idx].Recipient.
RecipientType == RECIPIENT_TYPE_DEVICE) {
/* copy Device_ID */ /* copy Device_ID */
DeviceID = CurrentNotify->Recipient_List[idx].Recipient._.DeviceIdentifier; DeviceID =
CurrentNotify->Recipient_List[idx].Recipient._.
DeviceIdentifier;
address_bind_request(DeviceID, &max_apdu, &src); address_bind_request(DeviceID, &max_apdu, &src);
} } else if (CurrentNotify->Recipient_List[idx].Recipient.
else if (CurrentNotify->Recipient_List[idx].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); */
@@ -686,7 +721,8 @@ bool Notification_Class_Write_Property(
void Notification_Class_Get_Priorities( void Notification_Class_Get_Priorities(
uint32_t Object_Instance, uint32_t *pPriorityArray) uint32_t Object_Instance,
uint32_t * pPriorityArray)
{ {
NOTIFICATION_CLASS_INFO *CurrentNotify; NOTIFICATION_CLASS_INFO *CurrentNotify;
uint32_t object_index; uint32_t object_index;
@@ -707,13 +743,14 @@ void Notification_Class_Get_Priorities(
} }
static bool IsRecipientActive(BACNET_DESTINATION * pBacDest, uint8_t EventToState) static bool IsRecipientActive(
BACNET_DESTINATION * pBacDest,
uint8_t EventToState)
{ {
BACNET_DATE_TIME DateTime; BACNET_DATE_TIME DateTime;
/* valid Transitions */ /* valid Transitions */
switch (EventToState) switch (EventToState) {
{
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:
@@ -765,8 +802,8 @@ void Notification_Class_common_reporting_function(
uint8_t index; uint8_t index;
notify_index = Notification_Class_Instance_To_Index( notify_index =
event_data->notificationClass); Notification_Class_Instance_To_Index(event_data->notificationClass);
if (notify_index < MAX_NOTIFICATION_CLASSES) if (notify_index < MAX_NOTIFICATION_CLASSES)
CurrentNotify = &NC_Info[notify_index]; CurrentNotify = &NC_Info[notify_index];
@@ -780,20 +817,19 @@ void Notification_Class_common_reporting_function(
Device_Object_Instance_Number(); Device_Object_Instance_Number();
/* Priority and AckRequired */ /* Priority and AckRequired */
switch (event_data->toState) switch (event_data->toState) {
{
case EVENT_STATE_NORMAL: case EVENT_STATE_NORMAL:
event_data->priority = event_data->priority = CurrentNotify->Priority[EVENT_STATE_NORMAL];
CurrentNotify->Priority[EVENT_STATE_NORMAL]; event_data->ackRequired =
event_data->ackRequired = (CurrentNotify->Ack_Required & (CurrentNotify->
TRANSITION_TO_NORMAL_MASKED) ? 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[EVENT_STATE_FAULT];
CurrentNotify->Priority[EVENT_STATE_FAULT]; event_data->ackRequired =
event_data->ackRequired = (CurrentNotify->Ack_Required & (CurrentNotify->
TRANSITION_TO_FAULT_MASKED) ? true : false; Ack_Required & TRANSITION_TO_FAULT_MASKED) ? true : false;
break; break;
case EVENT_STATE_OFFNORMAL: case EVENT_STATE_OFFNORMAL:
@@ -801,8 +837,9 @@ void Notification_Class_common_reporting_function(
case EVENT_STATE_LOW_LIMIT: case EVENT_STATE_LOW_LIMIT:
event_data->priority = event_data->priority =
CurrentNotify->Priority[EVENT_STATE_OFFNORMAL]; CurrentNotify->Priority[EVENT_STATE_OFFNORMAL];
event_data->ackRequired = (CurrentNotify->Ack_Required & event_data->ackRequired =
TRANSITION_TO_OFFNORMAL_MASKED) ? true : false; (CurrentNotify->
Ack_Required & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false;
break; break;
default: /* shouldn't happen */ default: /* shouldn't happen */
@@ -812,14 +849,12 @@ void Notification_Class_common_reporting_function(
/* send notifications for active recipients */ /* send notifications for active recipients */
/* pointer to first recipient */ /* pointer to first recipient */
pBacDest = &CurrentNotify->Recipient_List[0]; pBacDest = &CurrentNotify->Recipient_List[0];
for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) {
{
/* check if recipient is defined */ /* check if recipient is defined */
if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_NOTINITIALIZED) if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_NOTINITIALIZED)
break; /* recipient doesn't defined - end of list */ break; /* recipient doesn't defined - end of list */
if (IsRecipientActive(pBacDest, event_data->toState) == true) if (IsRecipientActive(pBacDest, event_data->toState) == true) {
{
BACNET_ADDRESS dest; BACNET_ADDRESS dest;
uint32_t device_id; uint32_t device_id;
unsigned max_apdu; unsigned max_apdu;
@@ -835,17 +870,18 @@ void Notification_Class_common_reporting_function(
if (pBacDest->ConfirmedNotify == true) if (pBacDest->ConfirmedNotify == true)
Send_CEvent_Notify(device_id, event_data); Send_CEvent_Notify(device_id, event_data);
else if (address_get_by_device(device_id, &max_apdu, &dest)) else if (address_get_by_device(device_id, &max_apdu, &dest))
Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, &dest); Send_UEvent_Notify(Handler_Transmit_Buffer, event_data,
} &dest);
else if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { } else if (pBacDest->Recipient.RecipientType ==
RECIPIENT_TYPE_ADDRESS) {
/* send notification to the address indicated */ /* send notification to the address indicated */
if (pBacDest->ConfirmedNotify == true) { if (pBacDest->ConfirmedNotify == true) {
if (address_get_device_id(&dest, &device_id)) if (address_get_device_id(&dest, &device_id))
Send_CEvent_Notify(device_id, event_data); Send_CEvent_Notify(device_id, event_data);
} } else {
else {
dest = pBacDest->Recipient._.Address; dest = pBacDest->Recipient._.Address;
Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, &dest); Send_UEvent_Notify(Handler_Transmit_Buffer, event_data,
&dest);
} }
} }
} }
@@ -854,7 +890,8 @@ void Notification_Class_common_reporting_function(
/* This function tries to find the addresses of the defined devices. */ /* This function tries to find the addresses of the defined devices. */
/* It should be called periodically (example once per minute). */ /* It should be called periodically (example once per minute). */
void Notification_Class_find_recipient(void) void Notification_Class_find_recipient(
void)
{ {
NOTIFICATION_CLASS_INFO *CurrentNotify; NOTIFICATION_CLASS_INFO *CurrentNotify;
BACNET_DESTINATION *pBacDest; BACNET_DESTINATION *pBacDest;
@@ -865,22 +902,25 @@ void Notification_Class_find_recipient(void)
uint8_t idx; uint8_t idx;
for (notify_index = 0; notify_index < MAX_NOTIFICATION_CLASSES; notify_index++) for (notify_index = 0; notify_index < MAX_NOTIFICATION_CLASSES;
{ notify_index++) {
/* pointer to current notification */ /* pointer to current notification */
CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(notify_index)]; CurrentNotify =
&NC_Info[Notification_Class_Instance_To_Index(notify_index)];
/* pointer to first recipient */ /* pointer to first recipient */
pBacDest = &CurrentNotify->Recipient_List[0]; pBacDest = &CurrentNotify->Recipient_List[0];
for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++, pBacDest++) for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++, pBacDest++) {
{ if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType ==
if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { RECIPIENT_TYPE_DEVICE) {
/* Device ID */ /* Device ID */
DeviceID = CurrentNotify->Recipient_List[idx].Recipient._.DeviceIdentifier; DeviceID =
CurrentNotify->Recipient_List[idx].Recipient._.
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].Recipient.
else if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { RecipientType == RECIPIENT_TYPE_ADDRESS) {
} }
} }
+10 -7
View File
@@ -102,12 +102,15 @@ typedef struct Ack_Notification {
const int **pOptional, const int **pOptional,
const int **pProprietary); const int **pProprietary);
void Notification_Class_Init(void); void Notification_Class_Init(
void);
bool Notification_Class_Valid_Instance( bool Notification_Class_Valid_Instance(
uint32_t object_instance); uint32_t object_instance);
unsigned Notification_Class_Count(void); unsigned Notification_Class_Count(
uint32_t Notification_Class_Index_To_Instance(unsigned index); void);
uint32_t Notification_Class_Index_To_Instance(
unsigned index);
unsigned Notification_Class_Instance_To_Index( unsigned Notification_Class_Instance_To_Index(
uint32_t object_instance); uint32_t object_instance);
bool Notification_Class_Object_Name( bool Notification_Class_Object_Name(
@@ -121,24 +124,24 @@ typedef struct Ack_Notification {
BACNET_WRITE_PROPERTY_DATA * wp_data); BACNET_WRITE_PROPERTY_DATA * wp_data);
void Notification_Class_Get_Priorities( void Notification_Class_Get_Priorities(
uint32_t Object_Instance, uint32_t *pPriorityArray); uint32_t Object_Instance,
uint32_t * pPriorityArray);
void Notification_Class_common_reporting_function( void Notification_Class_common_reporting_function(
BACNET_EVENT_NOTIFICATION_DATA * event_data); BACNET_EVENT_NOTIFICATION_DATA * event_data);
void Notification_Class_find_recipient(void); void Notification_Class_find_recipient(
void);
#endif /* defined(INTRINSIC_REPORTING) */ #endif /* defined(INTRINSIC_REPORTING) */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#define NOTIFICATION_CLASS_OBJ_FUNCTIONS \ #define NOTIFICATION_CLASS_OBJ_FUNCTIONS \
OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, \ OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, \
Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, \ Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, \
Notification_Class_Object_Name, Notification_Class_Read_Property, \ Notification_Class_Object_Name, Notification_Class_Read_Property, \
Notification_Class_Write_Property, Notification_Class_Property_Lists, \ Notification_Class_Write_Property, Notification_Class_Property_Lists, \
NULL, NULL, NULL NULL, NULL, NULL
#endif /* NC_H */ #endif /* NC_H */
+7 -7
View File
@@ -736,9 +736,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 */
@@ -755,8 +755,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)) {
@@ -1098,8 +1098,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) ||
+11 -4
View File
@@ -38,18 +38,25 @@ extern "C" {
/* decode the service request only */ /* decode the service request only */
int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len, int wpm_decode_object_id(
uint8_t * apdu,
uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * data); BACNET_WRITE_PROPERTY_DATA * data);
int wpm_decode_object_property(uint8_t * apdu, int wpm_decode_object_property(
uint8_t * apdu,
uint16_t apdu_len, uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * wpm_data); BACNET_WRITE_PROPERTY_DATA * wpm_data);
/* encode service */ /* encode service */
int wpm_ack_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id); int wpm_ack_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id);
int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, int wpm_error_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_WRITE_PROPERTY_DATA * wp_data); BACNET_WRITE_PROPERTY_DATA * wp_data);
+2 -2
View File
@@ -360,8 +360,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
@@ -271,8 +271,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;
+10 -13
View File
@@ -179,8 +179,7 @@ static int Read_Property_Common(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
if (pObject->Object_Name) { if (pObject->Object_Name) {
(void)pObject->Object_Name( (void) pObject->Object_Name(rpdata->object_instance,
rpdata->object_instance,
&char_string); &char_string);
} else { } else {
characterstring_init_ansi(&char_string, ""); characterstring_init_ansi(&char_string, "");
@@ -851,8 +850,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 {
@@ -895,22 +894,20 @@ bool Device_Write_Property_Local(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
length = characterstring_length( length = characterstring_length(&value.type.Character_String);
&value.type.Character_String);
if (length < characterstring_capacity(&My_Object_Name)) { if (length < characterstring_capacity(&My_Object_Name)) {
encoding = characterstring_encoding( 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( if (Device_Valid_Object_Name(&value.type.
&value.type.Character_String, Character_String, NULL, NULL)) {
NULL, NULL)) {
status = false; status = false;
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( Device_Set_Object_Name(&value.type.
&value.type.Character_String); Character_String);
} }
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
+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 -2
View File
@@ -380,8 +380,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;
@@ -72,8 +72,8 @@ void adc_enable(
* Notes: none * Notes: none
**************************************************/ **************************************************/
uint8_t adc_result_8bit( uint8_t adc_result_8bit(
uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */ uint8_t channel)
{ { /* 0..7 = ADC0..ADC7, respectively */
uint8_t value = 0; /* return value */ uint8_t value = 0; /* return value */
while (ADCSRA & (1 << ADSC)); while (ADCSRA & (1 << ADSC));
@@ -95,8 +95,8 @@ uint8_t adc_result_8bit(
* Notes: none * Notes: none
**************************************************/ **************************************************/
uint16_t adc_result_10bit( uint16_t adc_result_10bit(
uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */ uint8_t channel)
{ { /* 0..7 = ADC0..ADC7, respectively */
uint16_t value = 0; /* return value */ uint16_t value = 0; /* return value */
while (ADCSRA & (1 << ADSC)); while (ADCSRA & (1 << ADSC));
@@ -118,7 +118,8 @@ uint16_t adc_result_10bit(
* Returns: none * Returns: none
* Notes: none * Notes: none
**************************************************/ **************************************************/
void adc_init(void) void adc_init(
void)
{ {
/* configure ADC for Free Running Mode - ADTS = 000 */ /* configure ADC for Free Running Mode - ADTS = 000 */
/* AIN1 is applied to the negative input of the Analog Comparator - ACME */ /* AIN1 is applied to the negative input of the Analog Comparator - ACME */
+34 -25
View File
@@ -39,20 +39,30 @@
by Jeff Bezanson by Jeff Bezanson
placed in the public domain Fall 2005 */ placed in the public domain Fall 2005 */
static const char trailingBytesForUTF8[256] = { static const char trailingBytesForUTF8[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4,
4, 4, 4, 5, 5, 5, 5
}; };
/* based on the valid_utf8 routine from the PCRE library by Philip Hazel /* based on the valid_utf8 routine from the PCRE library by Philip Hazel
length is in bytes, since without knowing whether the string is valid length is in bytes, since without knowing whether the string is valid
it's hard to know how many characters there are! */ it's hard to know how many characters there are! */
static int utf8_isvalid(const char *str, int length) static int utf8_isvalid(
const char *str,
int length)
{ {
const unsigned char *p, *pend = (unsigned char *) str + length; const unsigned char *p, *pend = (unsigned char *) str + length;
unsigned char c; unsigned char c;
@@ -86,35 +96,40 @@ static int utf8_isvalid(const char *str, int length)
switch (ab) { switch (ab) {
/* Check for xx00 000x */ /* Check for xx00 000x */
case 1: case 1:
if ((c & 0x3e) == 0) return 0; if ((c & 0x3e) == 0)
return 0;
continue; /* We know there aren't any more bytes to check */ continue; /* We know there aren't any more bytes to check */
/* Check for 1110 0000, xx0x xxxx */ /* Check for 1110 0000, xx0x xxxx */
case 2: case 2:
if (c == 0xe0 && (*p & 0x20) == 0) return 0; if (c == 0xe0 && (*p & 0x20) == 0)
return 0;
break; break;
/* Check for 1111 0000, xx00 xxxx */ /* Check for 1111 0000, xx00 xxxx */
case 3: case 3:
if (c == 0xf0 && (*p & 0x30) == 0) return 0; if (c == 0xf0 && (*p & 0x30) == 0)
return 0;
break; break;
/* Check for 1111 1000, xx00 0xxx */ /* Check for 1111 1000, xx00 0xxx */
case 4: case 4:
if (c == 0xf8 && (*p & 0x38) == 0) return 0; if (c == 0xf8 && (*p & 0x38) == 0)
return 0;
break; break;
/* Check for leading 0xfe or 0xff, /* Check for leading 0xfe or 0xff,
and then for 1111 1100, xx00 00xx */ and then for 1111 1100, xx00 00xx */
case 5: case 5:
if (c == 0xfe || c == 0xff || if (c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0))
(c == 0xfc && (*p & 0x3c) == 0)) return 0; return 0;
break; break;
} }
/* Check for valid bytes after the 2nd, if any; all must start 10 */ /* Check for valid bytes after the 2nd, if any; all must start 10 */
while (--ab > 0) { while (--ab > 0) {
if ((*(++p) & 0xc0) != 0x80) return 0; if ((*(++p) & 0xc0) != 0x80)
return 0;
} }
} }
@@ -154,15 +169,9 @@ bool bacnet_name_set(
encoding = characterstring_encoding(char_string); encoding = characterstring_encoding(char_string);
str = characterstring_value(char_string); str = characterstring_value(char_string);
if (bacnet_name_isvalid(encoding, length, str)) { if (bacnet_name_isvalid(encoding, length, str)) {
seeprom_bytes_write( seeprom_bytes_write(NV_EEPROM_NAME_LENGTH(offset), &length, 1);
NV_EEPROM_NAME_LENGTH(offset), seeprom_bytes_write(NV_EEPROM_NAME_ENCODING(offset), &encoding, 1);
&length, 1); seeprom_bytes_write(NV_EEPROM_NAME_STRING(offset), (uint8_t *) str,
seeprom_bytes_write(
NV_EEPROM_NAME_ENCODING(offset),
&encoding, 1);
seeprom_bytes_write(
NV_EEPROM_NAME_STRING(offset),
(uint8_t *)str,
length); length);
return true; return true;
} }
+2 -2
View File
@@ -439,8 +439,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
+19 -28
View File
@@ -195,12 +195,12 @@ static int Read_Property_Common(
} else { } else {
characterstring_init_ansi(&char_string, ""); characterstring_init_ansi(&char_string, "");
if (pObject->Object_Name) { if (pObject->Object_Name) {
(void)pObject->Object_Name( (void) pObject->Object_Name(rpdata->object_instance,
rpdata->object_instance,
&char_string); &char_string);
} }
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0],
&char_string);
} }
break; break;
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
@@ -361,7 +361,8 @@ uint32_t Device_Index_To_Instance(
return Object_Instance_Number; return Object_Instance_Number;
} }
static char *Device_Name_Default(void) static char *Device_Name_Default(
void)
{ {
static char text_string[32]; /* okay for single thread */ static char text_string[32]; /* okay for single thread */
@@ -377,10 +378,7 @@ bool Device_Object_Name(
bool status = false; bool status = false;
if (object_instance == Object_Instance_Number) { if (object_instance == Object_Instance_Number) {
bacnet_name( bacnet_name(NV_EEPROM_DEVICE_NAME, object_name, Device_Name_Default());
NV_EEPROM_DEVICE_NAME,
object_name,
Device_Name_Default());
status = true; status = true;
} }
@@ -673,17 +671,13 @@ int Device_Read_Property_Local(
apdu = rpdata->application_data; apdu = rpdata->application_data;
switch (rpdata->object_property) { switch (rpdata->object_property) {
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
bacnet_name( bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string,
NV_EEPROM_DEVICE_DESCRIPTION,
&char_string,
"BACnet Development Kit"); "BACnet Development Kit");
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
break; break;
case PROP_LOCATION: case PROP_LOCATION:
bacnet_name( bacnet_name(NV_EEPROM_DEVICE_LOCATION, &char_string,
NV_EEPROM_DEVICE_LOCATION,
&char_string,
"default location"); "default location");
apdu_len = apdu_len =
encode_application_character_string(&apdu[0], &char_string); encode_application_character_string(&apdu[0], &char_string);
@@ -881,8 +875,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 {
@@ -925,10 +919,9 @@ bool Device_Write_Property_Local(
break; break;
case PROP_OBJECT_NAME: case PROP_OBJECT_NAME:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write( status =
NV_EEPROM_DEVICE_NAME, bacnet_name_write(NV_EEPROM_DEVICE_NAME,
&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;
@@ -937,10 +930,9 @@ bool Device_Write_Property_Local(
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 = bacnet_name_write_other( status =
NV_EEPROM_DEVICE_DESCRIPTION, bacnet_name_write_other(NV_EEPROM_DEVICE_DESCRIPTION,
&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;
@@ -949,10 +941,9 @@ bool Device_Write_Property_Local(
break; break;
case PROP_LOCATION: case PROP_LOCATION:
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
status = bacnet_name_write_other( status =
NV_EEPROM_DEVICE_LOCATION, bacnet_name_write_other(NV_EEPROM_DEVICE_LOCATION,
&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;
+50 -33
View File
@@ -91,7 +91,8 @@ static uint8_t Tusage_timeout = 60;
static struct timeval start; static struct timeval start;
static uint32_t Timer_Silence(void) static uint32_t Timer_Silence(
void)
{ {
struct timeval now, tmp_diff; struct timeval now, tmp_diff;
int32_t res; int32_t res;
@@ -105,14 +106,16 @@ static uint32_t Timer_Silence(void)
return (res >= 0 ? res : -res); return (res >= 0 ? res : -res);
} }
static void Timer_Silence_Reset(void) static void Timer_Silence_Reset(
void)
{ {
pthread_mutex_lock(&Timer_Mutex); pthread_mutex_lock(&Timer_Mutex);
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
pthread_mutex_unlock(&Timer_Mutex); pthread_mutex_unlock(&Timer_Mutex);
} }
static void get_abstime(struct timespec *abstime, static void get_abstime(
struct timespec *abstime,
unsigned long milliseconds) unsigned long milliseconds)
{ {
struct timeval now, offset, result; struct timeval now, offset, result;
@@ -125,7 +128,8 @@ static void get_abstime(struct timespec *abstime,
abstime->tv_nsec = result.tv_usec * 1000; abstime->tv_nsec = result.tv_usec * 1000;
} }
void dlmstp_cleanup(void) void dlmstp_cleanup(
void)
{ {
pthread_cond_destroy(&Received_Frame_Flag); pthread_cond_destroy(&Received_Frame_Flag);
pthread_cond_destroy(&Receive_Packet_Flag); pthread_cond_destroy(&Receive_Packet_Flag);
@@ -137,12 +141,10 @@ void dlmstp_cleanup(void)
} }
/* returns number of bytes sent on success, zero on failure */ /* returns number of bytes sent on success, zero on failure */
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int dlmstp_send_pdu(
BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
int bytes_sent = 0; int bytes_sent = 0;
@@ -168,12 +170,10 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
return bytes_sent; return bytes_sent;
} }
uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ uint16_t dlmstp_receive(
BACNET_ADDRESS * src, /* source address */
uint8_t * pdu, /* PDU data */ uint8_t * pdu, /* PDU data */
uint16_t max_pdu, /* amount of space available in the PDU */ uint16_t max_pdu, /* amount of space available in the PDU */
unsigned timeout) unsigned timeout)
{ /* milliseconds to wait for a packet */ { /* milliseconds to wait for a packet */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
@@ -207,7 +207,8 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
return pdu_len; return pdu_len;
} }
static void *dlmstp_master_fsm_task(void *pArg) static void *dlmstp_master_fsm_task(
void *pArg)
{ {
uint32_t silence = 0; uint32_t silence = 0;
bool run_master = false; bool run_master = false;
@@ -252,7 +253,8 @@ static void *dlmstp_master_fsm_task(void *pArg)
return NULL; return NULL;
} }
void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, void dlmstp_fill_bacnet_address(
BACNET_ADDRESS * src,
uint8_t mstp_address) uint8_t mstp_address)
{ {
int i = 0; int i = 0;
@@ -277,7 +279,8 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src,
} }
/* for the MS/TP state machine to use for putting received data */ /* for the MS/TP state machine to use for putting received data */
uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port) uint16_t MSTP_Put_Receive(
volatile struct mstp_port_struct_t *mstp_port)
{ {
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
@@ -300,7 +303,8 @@ uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port)
/* for the MS/TP state machine to use for getting data to send */ /* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */ /* Return: amount of PDU data */
uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port, uint16_t MSTP_Get_Send(
volatile struct mstp_port_struct_t * mstp_port,
unsigned timeout) unsigned timeout)
{ /* milliseconds to wait for a packet */ { /* milliseconds to wait for a packet */
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
@@ -329,7 +333,8 @@ uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port,
return pdu_len; return pdu_len;
} }
static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu, static bool dlmstp_compare_data_expecting_reply(
uint8_t * request_pdu,
uint16_t request_pdu_len, uint16_t request_pdu_len,
uint8_t src_address, uint8_t src_address,
uint8_t * reply_pdu, uint8_t * reply_pdu,
@@ -445,7 +450,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu,
} }
/* Get the reply to a DATA_EXPECTING_REPLY frame, or nothing */ /* Get the reply to a DATA_EXPECTING_REPLY frame, or nothing */
uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port, uint16_t MSTP_Get_Reply(
volatile struct mstp_port_struct_t * mstp_port,
unsigned timeout) unsigned timeout)
{ /* milliseconds to wait for a packet */ { /* milliseconds to wait for a packet */
uint16_t pdu_len = 0; /* return value */ uint16_t pdu_len = 0; /* return value */
@@ -484,7 +490,8 @@ uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port,
return pdu_len; return pdu_len;
} }
void dlmstp_set_mac_address(uint8_t mac_address) void dlmstp_set_mac_address(
uint8_t mac_address)
{ {
/* Master Nodes can only have address 0-127 */ /* Master Nodes can only have address 0-127 */
if (mac_address <= 127) { if (mac_address <= 127) {
@@ -501,7 +508,8 @@ void dlmstp_set_mac_address(uint8_t mac_address)
return; return;
} }
uint8_t dlmstp_mac_address(void) uint8_t dlmstp_mac_address(
void)
{ {
return MSTP_Port.This_Station; return MSTP_Port.This_Station;
} }
@@ -513,7 +521,8 @@ uint8_t dlmstp_mac_address(void)
/* nodes. This may be used to allocate more or less of the available link */ /* nodes. This may be used to allocate more or less of the available link */
/* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */ /* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */
/* node, its value shall be 1. */ /* node, its value shall be 1. */
void dlmstp_set_max_info_frames(uint8_t max_info_frames) void dlmstp_set_max_info_frames(
uint8_t max_info_frames)
{ {
if (max_info_frames >= 1) { if (max_info_frames >= 1) {
MSTP_Port.Nmax_info_frames = max_info_frames; MSTP_Port.Nmax_info_frames = max_info_frames;
@@ -527,7 +536,8 @@ void dlmstp_set_max_info_frames(uint8_t max_info_frames)
return; return;
} }
uint8_t dlmstp_max_info_frames(void) uint8_t dlmstp_max_info_frames(
void)
{ {
return MSTP_Port.Nmax_info_frames; return MSTP_Port.Nmax_info_frames;
} }
@@ -537,7 +547,8 @@ uint8_t dlmstp_max_info_frames(void)
/* allowable address for master nodes. The value of Max_Master shall be */ /* allowable address for master nodes. The value of Max_Master shall be */
/* less than or equal to 127. If Max_Master is not writable in a node, */ /* less than or equal to 127. If Max_Master is not writable in a node, */
/* its value shall be 127. */ /* its value shall be 127. */
void dlmstp_set_max_master(uint8_t max_master) void dlmstp_set_max_master(
uint8_t max_master)
{ {
if (max_master <= 127) { if (max_master <= 127) {
if (MSTP_Port.This_Station <= max_master) { if (MSTP_Port.This_Station <= max_master) {
@@ -553,23 +564,27 @@ void dlmstp_set_max_master(uint8_t max_master)
return; return;
} }
uint8_t dlmstp_max_master(void) uint8_t dlmstp_max_master(
void)
{ {
return MSTP_Port.Nmax_master; return MSTP_Port.Nmax_master;
} }
/* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */ /* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */
void dlmstp_set_baud_rate(uint32_t baud) void dlmstp_set_baud_rate(
uint32_t baud)
{ {
RS485_Set_Baud_Rate(baud); RS485_Set_Baud_Rate(baud);
} }
uint32_t dlmstp_baud_rate(void) uint32_t dlmstp_baud_rate(
void)
{ {
return RS485_Get_Baud_Rate(); return RS485_Get_Baud_Rate();
} }
void dlmstp_get_my_address(BACNET_ADDRESS * my_address) void dlmstp_get_my_address(
BACNET_ADDRESS * my_address)
{ {
int i = 0; /* counter */ int i = 0; /* counter */
@@ -584,7 +599,8 @@ void dlmstp_get_my_address(BACNET_ADDRESS * my_address)
return; return;
} }
void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) void dlmstp_get_broadcast_address(
BACNET_ADDRESS * dest)
{ /* destination address */ { /* destination address */
int i = 0; /* counter */ int i = 0; /* counter */
@@ -601,7 +617,8 @@ void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest)
return; return;
} }
bool dlmstp_init(char *ifname) bool dlmstp_init(
char *ifname)
{ {
unsigned long hThread = 0; unsigned long hThread = 0;
int rv = 0; int rv = 0;
@@ -665,10 +682,9 @@ bool dlmstp_init(char *ifname)
#ifdef TEST_DLMSTP #ifdef TEST_DLMSTP
#include <stdio.h> #include <stdio.h>
void apdu_handler(BACNET_ADDRESS * src, /* source address */ void apdu_handler(
BACNET_ADDRESS * src, /* source address */
uint8_t * apdu, /* APDU data */ uint8_t * apdu, /* APDU data */
uint16_t pdu_len) uint16_t pdu_len)
{ /* for confirmed messages */ { /* for confirmed messages */
(void) src; (void) src;
@@ -678,7 +694,8 @@ void apdu_handler(BACNET_ADDRESS * src, /* source address */
static char *Network_Interface = NULL; static char *Network_Interface = NULL;
int main(int argc, int main(
int argc,
char *argv[]) char *argv[])
{ {
uint16_t pdu_len = 0; uint16_t pdu_len = 0;
+20 -12
View File
@@ -95,7 +95,8 @@ static pthread_mutex_t Reader_Mutex, IOMutex;
#define _POSIX_SOURCE 1 /* POSIX compliant source */ #define _POSIX_SOURCE 1 /* POSIX compliant source */
static void *rs485_read_task(void *arg) static void *rs485_read_task(
void *arg)
{ {
uint8_t buf[1 << 11]; uint8_t buf[1 << 11];
int count, n; int count, n;
@@ -134,7 +135,8 @@ static void *rs485_read_task(void *arg)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*********************************************************************/ *********************************************************************/
void RS485_Set_Interface(char *ifname) void RS485_Set_Interface(
char *ifname)
{ {
/* note: expects a constant char, or char from the heap */ /* note: expects a constant char, or char from the heap */
if (ifname) { if (ifname) {
@@ -148,7 +150,8 @@ void RS485_Set_Interface(char *ifname)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*********************************************************************/ *********************************************************************/
const char *RS485_Interface(void) const char *RS485_Interface(
void)
{ {
return RS485_Port_Name; return RS485_Port_Name;
} }
@@ -159,7 +162,8 @@ const char *RS485_Interface(void)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint32_t RS485_Get_Baud_Rate(void) uint32_t RS485_Get_Baud_Rate(
void)
{ {
switch (RS485_Baud) { switch (RS485_Baud) {
case B19200: case B19200:
@@ -182,7 +186,8 @@ uint32_t RS485_Get_Baud_Rate(void)
* ALGORITHM: none * ALGORITHM: none
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool RS485_Set_Baud_Rate(uint32_t baud) bool RS485_Set_Baud_Rate(
uint32_t baud)
{ {
bool valid = true; bool valid = true;
@@ -215,10 +220,9 @@ bool RS485_Set_Baud_Rate(uint32_t baud)
} }
/* Transmits a Frame on the wire */ /* Transmits a Frame on the wire */
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ void RS485_Send_Frame(
volatile struct mstp_port_struct_t *mstp_port, /* port specific data */
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes) uint16_t nbytes)
{ /* number of bytes of data (up to 501) */ { /* number of bytes of data (up to 501) */
ssize_t written = 0; ssize_t written = 0;
@@ -246,7 +250,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
} }
/* called by timer, interrupt(?) or other thread */ /* called by timer, interrupt(?) or other thread */
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) void RS485_Check_UART_Data(
volatile struct mstp_port_struct_t *mstp_port)
{ {
if (mstp_port->ReceiveError == true) { if (mstp_port->ReceiveError == true) {
/* wait for state machine to clear this */ /* wait for state machine to clear this */
@@ -266,7 +271,8 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port)
} }
} }
void RS485_Cleanup(void) void RS485_Cleanup(
void)
{ {
/* restore the old port settings */ /* restore the old port settings */
tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio); tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio);
@@ -276,7 +282,8 @@ void RS485_Cleanup(void)
} }
void RS485_Initialize(void) void RS485_Initialize(
void)
{ {
struct termios newtio; struct termios newtio;
unsigned long hThread = 0; unsigned long hThread = 0;
@@ -333,7 +340,8 @@ void RS485_Initialize(void)
#ifdef TEST_RS485 #ifdef TEST_RS485
#include <string.h> #include <string.h>
int main(int argc, int main(
int argc,
char *argv[]) char *argv[])
{ {
uint8_t buf[8]; uint8_t buf[8];
+2 -2
View File
@@ -325,8 +325,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
@@ -237,8 +237,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;
+2 -2
View File
@@ -510,8 +510,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 -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
@@ -429,8 +429,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
@@ -833,8 +833,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 {
@@ -868,8 +868,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;
@@ -878,8 +878,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;
@@ -889,8 +889,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 -1
View File
@@ -30,7 +30,8 @@
#include "led.h" #include "led.h"
/** Main function of BACnet demo for RX62N evaluation board */ /** Main function of BACnet demo for RX62N evaluation board */
int main(void) int main(
void)
{ {
InitialiseLCD(); InitialiseLCD();
ClearLCD(); ClearLCD();
+5 -9
View File
@@ -30,7 +30,8 @@
static volatile uint32_t Millisecond_Counter; static volatile uint32_t Millisecond_Counter;
static volatile uint8_t Millisecond_Counter_Byte; static volatile uint8_t Millisecond_Counter_Byte;
/* forward prototype for interrupt service routine */ /* forward prototype for interrupt service routine */
void int_cmt0_isr(void); void int_cmt0_isr(
void);
/************************************************************************* /*************************************************************************
* Description: Timer Interrupt Handler * Description: Timer Interrupt Handler
@@ -49,7 +50,8 @@ static void timer_interrupt_handler(
* Returns: nothing * Returns: nothing
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
void int_cmt0_isr(void) void int_cmt0_isr(
void)
{ {
timer_interrupt_handler(); timer_interrupt_handler();
} }
@@ -93,13 +95,7 @@ void timer_init(
/* CMT is configured for a 1ms interval, and executes the callback /* CMT is configured for a 1ms interval, and executes the callback
function CB_CompareMatch on every compare match */ function CB_CompareMatch on every compare match */
err &= R_CMT_Create( err &= R_CMT_Create(3, PDL_CMT_PERIOD, 1E-3, int_cmt0_isr, 3);
3,
PDL_CMT_PERIOD,
1E-3,
int_cmt0_isr,
3
);
/* Halt in while loop when RPDL errors detected */ /* Halt in while loop when RPDL errors detected */
while (!err); while (!err);
+41 -29
View File
@@ -65,7 +65,8 @@ static bool Auto_Mode_Enabled;
* RETURN: true if automode enabled * RETURN: true if automode enabled
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool automac_enabled(void) bool automac_enabled(
void)
{ {
return Auto_Mode_Enabled; return Auto_Mode_Enabled;
} }
@@ -75,7 +76,8 @@ bool automac_enabled(void)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_enabled_set(bool status) void automac_enabled_set(
bool status)
{ {
Auto_Mode_Enabled = status; Auto_Mode_Enabled = status;
} }
@@ -85,7 +87,8 @@ void automac_enabled_set(bool status)
* RETURN: true if full * RETURN: true if full
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool automac_pfm_cycle_complete(void) bool automac_pfm_cycle_complete(
void)
{ {
return PFM_Cycle_Complete; return PFM_Cycle_Complete;
} }
@@ -95,13 +98,13 @@ bool automac_pfm_cycle_complete(void)
* RETURN: true if used * RETURN: true if used
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
static bool automac_address_used(uint8_t mac) static bool automac_address_used(
uint8_t mac)
{ {
bool status = false; bool status = false;
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
if ((Auto_MAC_Data[mac].emitter) || if ((Auto_MAC_Data[mac].emitter) || (Auto_MAC_Data[mac].reserved) ||
(Auto_MAC_Data[mac].reserved) ||
(Auto_MAC_Data[mac].token)) { (Auto_MAC_Data[mac].token)) {
status = true; status = true;
} }
@@ -115,13 +118,13 @@ static bool automac_address_used(uint8_t mac)
* RETURN: true if valid * RETURN: true if valid
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
bool automac_free_address_valid(uint8_t mac) bool automac_free_address_valid(
uint8_t mac)
{ {
bool status = false; bool status = false;
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
if ((Auto_MAC_Data[mac].pfm) && if ((Auto_MAC_Data[mac].pfm) && (!automac_address_used(mac))) {
(!automac_address_used(mac))) {
status = true; status = true;
} }
} }
@@ -134,7 +137,8 @@ bool automac_free_address_valid(uint8_t mac)
* RETURN: Next_Station, or 255 if there are no next stations * RETURN: Next_Station, or 255 if there are no next stations
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_next_station(uint8_t mac) uint8_t automac_next_station(
uint8_t mac)
{ {
uint8_t i = 0; /* loop counter */ uint8_t i = 0; /* loop counter */
uint8_t next_station = 255; /* return value */ uint8_t next_station = 255; /* return value */
@@ -157,7 +161,8 @@ uint8_t automac_next_station(uint8_t mac)
* RETURN: Number of free MAC addresses * RETURN: Number of free MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_free_address_count(void) uint8_t automac_free_address_count(
void)
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t slots = 0; uint8_t slots = 0;
@@ -176,7 +181,8 @@ uint8_t automac_free_address_count(void)
* RETURN: Number of free MAC addresses * RETURN: Number of free MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_free_address_mac(uint8_t count) uint8_t automac_free_address_mac(
uint8_t count)
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t slots = 0; uint8_t slots = 0;
@@ -200,7 +206,8 @@ uint8_t automac_free_address_mac(uint8_t count)
* RETURN: free MAC addresses * RETURN: free MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_free_address_random(void) uint8_t automac_free_address_random(
void)
{ {
uint8_t count = 0; uint8_t count = 0;
uint8_t random_count = 0; uint8_t random_count = 0;
@@ -220,7 +227,8 @@ uint8_t automac_free_address_random(void)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint8_t automac_address(void) uint8_t automac_address(
void)
{ {
return My_MAC_Address; return My_MAC_Address;
} }
@@ -230,7 +238,8 @@ uint8_t automac_address(void)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_address_set(uint8_t mac) void automac_address_set(
uint8_t mac)
{ {
My_MAC_Address = mac; My_MAC_Address = mac;
} }
@@ -240,7 +249,8 @@ void automac_address_set(uint8_t mac)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
uint16_t automac_time_slot(void) uint16_t automac_time_slot(
void)
{ {
return My_Time_Slot; return My_Time_Slot;
} }
@@ -250,9 +260,11 @@ uint16_t automac_time_slot(void)
* RETURN: MAC addresses * RETURN: MAC addresses
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_address_init(void) void automac_address_init(
void)
{ {
My_MAC_Address = MAC_SLOTS_OFFSET + rand()%(MAC_SLOTS_MAX-MAC_SLOTS_OFFSET); My_MAC_Address =
MAC_SLOTS_OFFSET + rand() % (MAC_SLOTS_MAX - MAC_SLOTS_OFFSET);
/* at least as long as a dropped token - worst case */ /* at least as long as a dropped token - worst case */
My_Time_Slot = Tno_token + (MAC_SLOTS_MAX * Tslot); My_Time_Slot = Tno_token + (MAC_SLOTS_MAX * Tslot);
My_Time_Slot += (uint16_t) My_MAC_Address *Tslot; My_Time_Slot += (uint16_t) My_MAC_Address *Tslot;
@@ -263,7 +275,8 @@ void automac_address_init(void)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_pfm_set(uint8_t mac) void automac_pfm_set(
uint8_t mac)
{ {
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
if (Auto_MAC_Data[mac].pfm) { if (Auto_MAC_Data[mac].pfm) {
@@ -281,7 +294,8 @@ void automac_pfm_set(uint8_t mac)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_token_set(uint8_t mac) void automac_token_set(
uint8_t mac)
{ {
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
Auto_MAC_Data[mac].token = true; Auto_MAC_Data[mac].token = true;
@@ -293,7 +307,8 @@ void automac_token_set(uint8_t mac)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_emitter_set(uint8_t mac) void automac_emitter_set(
uint8_t mac)
{ {
if (mac < MAC_SLOTS_MAX) { if (mac < MAC_SLOTS_MAX) {
Auto_MAC_Data[mac].emitter = true; Auto_MAC_Data[mac].emitter = true;
@@ -305,7 +320,8 @@ void automac_emitter_set(uint8_t mac)
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
*****************************************************************************/ *****************************************************************************/
void automac_init(void) void automac_init(
void)
{ {
uint8_t i = 0; uint8_t i = 0;
@@ -371,8 +387,7 @@ void test_Auto_MAC(
mac = automac_free_address_mac(1); mac = automac_free_address_mac(1);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2)); ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2));
mac = automac_free_address_random(); mac = automac_free_address_random();
ct_test(pTest, ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
(mac == (MAC_SLOTS_OFFSET+1)) ||
(mac == (MAC_SLOTS_OFFSET + 2))); (mac == (MAC_SLOTS_OFFSET + 2)));
/* test 3 free addresses */ /* test 3 free addresses */
automac_pfm_set(126); automac_pfm_set(126);
@@ -383,10 +398,8 @@ void test_Auto_MAC(
mac = automac_free_address_mac(2); mac = automac_free_address_mac(2);
ct_test(pTest, mac == 126); ct_test(pTest, mac == 126);
mac = automac_free_address_random(); mac = automac_free_address_random();
ct_test(pTest, ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
(mac == (MAC_SLOTS_OFFSET+1))|| (mac == (MAC_SLOTS_OFFSET + 2)) || (mac == 126));
(mac == (MAC_SLOTS_OFFSET+2))||
(mac == 126));
/* test the stored address */ /* test the stored address */
mac = automac_address(); mac = automac_address();
ct_test(pTest, mac < MAC_SLOTS_MAX); ct_test(pTest, mac < MAC_SLOTS_MAX);
@@ -423,4 +436,3 @@ int main(
} }
#endif #endif
#endif #endif
+32 -17
View File
@@ -34,26 +34,41 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
void automac_init(void); void automac_init(
void);
bool automac_free_address_valid(uint8_t mac); bool automac_free_address_valid(
uint8_t automac_free_address_count(void); uint8_t mac);
uint8_t automac_free_address_mac(uint8_t count); uint8_t automac_free_address_count(
uint8_t automac_free_address_random(void); void);
void automac_pfm_set(uint8_t mac); uint8_t automac_free_address_mac(
void automac_token_set(uint8_t mac); uint8_t count);
void automac_emitter_set(uint8_t mac); uint8_t automac_free_address_random(
uint8_t automac_next_station(uint8_t mac); void);
uint8_t automac_address(void); void automac_pfm_set(
void automac_address_set(uint8_t mac); uint8_t mac);
void automac_address_init(void); void automac_token_set(
uint16_t automac_time_slot(void); uint8_t mac);
bool automac_pfm_cycle_complete(void); void automac_emitter_set(
bool automac_enabled(void); uint8_t mac);
void automac_enabled_set(bool status); uint8_t automac_next_station(
uint8_t mac);
uint8_t automac_address(
void);
void automac_address_set(
uint8_t mac);
void automac_address_init(
void);
uint16_t automac_time_slot(
void);
bool automac_pfm_cycle_complete(
void);
bool automac_enabled(
void);
void automac_enabled_set(
bool status);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif
+2 -2
View File
@@ -430,8 +430,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
+5 -6
View File
@@ -175,8 +175,7 @@ static int Read_Property_Common(
} else { } else {
characterstring_init_ansi(&char_string, ""); characterstring_init_ansi(&char_string, "");
if (pObject->Object_Name) { if (pObject->Object_Name) {
(void)pObject->Object_Name( (void) pObject->Object_Name(rpdata->object_instance,
rpdata->object_instance,
&char_string); &char_string);
} }
} }
@@ -816,8 +815,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 {
@@ -869,8 +868,8 @@ bool Device_Write_Property_Local(
uint8_t encoding = uint8_t encoding =
characterstring_encoding(&value.type.Character_String); characterstring_encoding(&value.type.Character_String);
if (encoding < MAX_CHARACTER_STRING_ENCODING) { if (encoding < MAX_CHARACTER_STRING_ENCODING) {
characterstring_copy(&My_Object_Name, &value.type. characterstring_copy(&My_Object_Name,
Character_String); &value.type.Character_String);
status = true; status = true;
} else { } else {
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
+37 -49
View File
@@ -206,22 +206,17 @@ static RING_BUFFER PDU_Queue;
/* node, its value shall be 1. */ /* node, its value shall be 1. */
static uint8_t Nmax_info_frames = MSTP_PDU_PACKET_COUNT; static uint8_t Nmax_info_frames = MSTP_PDU_PACKET_COUNT;
void dlmstp_automac_hander(void); void dlmstp_automac_hander(
void);
bool dlmstp_init( bool dlmstp_init(
char *ifname) char *ifname)
{ {
ifname = ifname; ifname = ifname;
Ringbuf_Init( Ringbuf_Init(&Transmit_Queue, (uint8_t *) & Transmit_Buffer,
&Transmit_Queue, sizeof(struct mstp_tx_packet), MSTP_TRANSMIT_PACKET_COUNT);
(uint8_t *)&Transmit_Buffer, Ringbuf_Init(&PDU_Queue, (uint8_t *) & PDU_Buffer,
sizeof(struct mstp_tx_packet), sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT);
MSTP_TRANSMIT_PACKET_COUNT);
Ringbuf_Init(
&PDU_Queue,
(uint8_t *)&PDU_Buffer,
sizeof(struct mstp_pdu_packet),
MSTP_PDU_PACKET_COUNT);
rs485_init(); rs485_init();
automac_init(); automac_init();
@@ -366,14 +361,14 @@ static bool dlmstp_compare_data_expecting_reply(
return true; return true;
} }
typedef enum typedef enum {
{
MSTP_TX_STATE_IDLE, MSTP_TX_STATE_IDLE,
MSTP_TX_STATE_SILENCE_WAIT, MSTP_TX_STATE_SILENCE_WAIT,
MSTP_TX_STATE_SEND_WAIT, MSTP_TX_STATE_SEND_WAIT,
MSTP_TX_STATE_STOP MSTP_TX_STATE_STOP
} MSTP_TX_STATE; } MSTP_TX_STATE;
static bool MSTP_Transmit_FSM(void) static bool MSTP_Transmit_FSM(
void)
{ {
static MSTP_TX_STATE state = MSTP_TX_STATE_IDLE; static MSTP_TX_STATE state = MSTP_TX_STATE_IDLE;
static struct mstp_tx_packet *pkt; static struct mstp_tx_packet *pkt;
@@ -383,8 +378,9 @@ static bool MSTP_Transmit_FSM(void)
case MSTP_TX_STATE_IDLE: case MSTP_TX_STATE_IDLE:
if (!Ringbuf_Empty(&Transmit_Queue)) { if (!Ringbuf_Empty(&Transmit_Queue)) {
/* get the packet - but don't remove it from queue */ /* get the packet - but don't remove it from queue */
pkt = (struct mstp_tx_packet *)Ringbuf_Get_Front( pkt =
&Transmit_Queue); (struct mstp_tx_packet *)
Ringbuf_Get_Front(&Transmit_Queue);
state = MSTP_TX_STATE_SILENCE_WAIT; state = MSTP_TX_STATE_SILENCE_WAIT;
} }
break; break;
@@ -452,8 +448,7 @@ static void MSTP_Send_Frame(
static struct mstp_tx_packet *pkt; static struct mstp_tx_packet *pkt;
uint16_t i = 0; /* used to calculate CRC for data */ uint16_t i = 0; /* used to calculate CRC for data */
pkt = (struct mstp_tx_packet *)Ringbuf_Alloc( pkt = (struct mstp_tx_packet *) Ringbuf_Alloc(&Transmit_Queue);
&Transmit_Queue);
if (pkt) { if (pkt) {
/* create the MS/TP header */ /* create the MS/TP header */
pkt->buffer[0] = 0x55; pkt->buffer[0] = 0x55;
@@ -630,13 +625,15 @@ static void MSTP_Receive_Frame_FSM(
} else { } else {
/* receive the data portion of the frame. */ /* receive the data portion of the frame. */
if ((DestinationAddress == This_Station) || if ((DestinationAddress == This_Station) ||
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) { (DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
if (DataLength <= InputBufferSize) { if (DataLength <= InputBufferSize) {
/* Data */ /* Data */
Receive_State = MSTP_RECEIVE_STATE_DATA; Receive_State = MSTP_RECEIVE_STATE_DATA;
} else { } else {
/* FrameTooLong */ /* FrameTooLong */
Receive_State = MSTP_RECEIVE_STATE_SKIP_DATA; Receive_State =
MSTP_RECEIVE_STATE_SKIP_DATA;
} }
} else { } else {
/* NotForUs */ /* NotForUs */
@@ -877,8 +874,7 @@ static bool MSTP_Master_Node_FSM(
transition_now = true; transition_now = true;
} else { } else {
uint8_t frame_type; uint8_t frame_type;
pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front( pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
&PDU_Queue);
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 {
@@ -987,8 +983,7 @@ static bool MSTP_Master_Node_FSM(
/* then the next station to which the token /* then the next station to which the token
should be sent is unknown - so PollForMaster */ should be sent is unknown - so PollForMaster */
Poll_Station = next_this_station; Poll_Station = next_this_station;
MSTP_Send_Frame( MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0); This_Station, NULL, 0);
RetryCount = 0; RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER; Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
@@ -1214,12 +1209,11 @@ static bool MSTP_Master_Node_FSM(
/* Note: we could wait for up to Treply_delay */ /* Note: we could wait for up to Treply_delay */
matched = false; matched = false;
if (!Ringbuf_Empty(&PDU_Queue)) { if (!Ringbuf_Empty(&PDU_Queue)) {
pkt = (struct mstp_pdu_packet *)Ringbuf_Get_Front( pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&PDU_Queue);
&PDU_Queue);
matched = matched =
dlmstp_compare_data_expecting_reply(&InputBuffer[0], dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength, SourceAddress, &pkt->buffer[0], DataLength, SourceAddress, &pkt->buffer[0], pkt->length,
pkt->length, pkt->destination_mac); pkt->destination_mac);
} }
if (matched) { if (matched) {
/* Reply */ /* Reply */
@@ -1230,8 +1224,7 @@ static bool MSTP_Master_Node_FSM(
/* then call MSTP_Send_Frame to transmit the reply frame */ /* then call MSTP_Send_Frame to transmit the reply frame */
/* and enter the IDLE state to wait for the next frame. */ /* and enter the IDLE state to wait for the next frame. */
uint8_t frame_type; uint8_t frame_type;
pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front( pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
&PDU_Queue);
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 {
@@ -1300,7 +1293,8 @@ typedef enum {
} AUTOMAC_STATE; } AUTOMAC_STATE;
/* buffer used to send and validate a response - size is min APDU size */ /* buffer used to send and validate a response - size is min APDU size */
static uint8_t AutoMAC_Test_Buffer[50]; static uint8_t AutoMAC_Test_Buffer[50];
void dlmstp_automac_hander(void) void dlmstp_automac_hander(
void)
{ {
static AUTOMAC_STATE state = AUTOMAC_STATE_IDLE; static AUTOMAC_STATE state = AUTOMAC_STATE_IDLE;
uint8_t mac = 0; uint8_t mac = 0;
@@ -1360,7 +1354,8 @@ void dlmstp_automac_hander(void)
automac_init(); automac_init();
state = AUTOMAC_STATE_IDLE; state = AUTOMAC_STATE_IDLE;
} else if (mac == DestinationAddress) { } else if (mac == DestinationAddress) {
MSTP_Send_Frame(FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER, MSTP_Send_Frame
(FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER,
SourceAddress, mac, NULL, 0); SourceAddress, mac, NULL, 0);
state = AUTOMAC_STATE_TOKEN; state = AUTOMAC_STATE_TOKEN;
} }
@@ -1433,9 +1428,8 @@ void dlmstp_automac_hander(void)
encode_unsigned16(&AutoMAC_Test_Buffer[0], vendor_id); encode_unsigned16(&AutoMAC_Test_Buffer[0], vendor_id);
serial_number = Device_Object_Instance_Number(); serial_number = Device_Object_Instance_Number();
encode_unsigned32(&AutoMAC_Test_Buffer[2], serial_number); encode_unsigned32(&AutoMAC_Test_Buffer[2], serial_number);
MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST, MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST, SourceAddress, mac,
SourceAddress, mac, &AutoMAC_Test_Buffer[0], &AutoMAC_Test_Buffer[0], 6);
6);
state = AUTOMAC_STATE_CONFIRM; state = AUTOMAC_STATE_CONFIRM;
break; break;
case AUTOMAC_STATE_CONFIRM: case AUTOMAC_STATE_CONFIRM:
@@ -1448,8 +1442,7 @@ void dlmstp_automac_hander(void)
MSTP_Flag.ReceivedValidFrame = false; MSTP_Flag.ReceivedValidFrame = false;
MSTP_Flag.ReceivedValidFrameNotForUs = false; MSTP_Flag.ReceivedValidFrameNotForUs = false;
mac = automac_address(); mac = automac_address();
if ((mac == DestinationAddress) && if ((mac == DestinationAddress) && (DataLength >= 6)) {
(DataLength >= 6)) {
decode_unsigned16(&InputBuffer[0], &vendor_id); decode_unsigned16(&InputBuffer[0], &vendor_id);
decode_unsigned32(&InputBuffer[2], &serial_number); decode_unsigned32(&InputBuffer[2], &serial_number);
if ((vendor_id == Device_Vendor_Identifier()) && if ((vendor_id == Device_Vendor_Identifier()) &&
@@ -1511,18 +1504,14 @@ uint16_t dlmstp_receive(
/* only do receive state machine while we don't have a frame */ /* only do receive state machine while we don't have a frame */
if ((MSTP_Flag.ReceivedValidFrame == false) && if ((MSTP_Flag.ReceivedValidFrame == false) &&
(MSTP_Flag.ReceivedValidFrameNotForUs == false) && (MSTP_Flag.ReceivedValidFrameNotForUs == false) &&
(MSTP_Flag.ReceivedInvalidFrame == false) && (MSTP_Flag.ReceivedInvalidFrame == false) && (transmitting == false)) {
(transmitting == false)) {
MSTP_Receive_Frame_FSM(); MSTP_Receive_Frame_FSM();
} }
/* only do master state machine while rx is idle */ /* only do master state machine while rx is idle */
if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) && if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) && (transmitting == false)) {
(transmitting == false)) { if ((This_Station != 255) && (MSTP_Flag.ReceivedValidFrameNotForUs)) {
if ((This_Station != 255) &&
(MSTP_Flag.ReceivedValidFrameNotForUs)) {
MSTP_Flag.ReceivedValidFrameNotForUs = false; MSTP_Flag.ReceivedValidFrameNotForUs = false;
if ((SourceAddress == This_Station) && if ((SourceAddress == This_Station) && automac_enabled()) {
automac_enabled()) {
/* duplicate MAC on the wire */ /* duplicate MAC on the wire */
automac_init(); automac_init();
This_Station = 255; This_Station = 255;
@@ -1602,8 +1591,7 @@ void dlmstp_set_max_master(
uint8_t max_master) uint8_t max_master)
{ {
if (max_master <= 127) { if (max_master <= 127) {
if ((This_Station == 255) || if ((This_Station == 255) || (This_Station <= max_master)) {
(This_Station <= max_master)) {
Nmax_master = max_master; Nmax_master = max_master;
} }
} }
@@ -1651,7 +1639,8 @@ void dlmstp_get_broadcast_address(
return; return;
} }
bool dlmstp_sole_master(void) bool dlmstp_sole_master(
void)
{ {
if (MSTP_Flag.SoleMaster) { if (MSTP_Flag.SoleMaster) {
return true; return true;
@@ -1659,4 +1648,3 @@ bool dlmstp_sole_master(void)
return false; return false;
} }
+12 -6
View File
@@ -89,7 +89,8 @@ void led_rx_off(
* Returns: true if on, false if off. * Returns: true if on, false if off.
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
bool led_rx_state(void) bool led_rx_state(
void)
{ {
return Rx_State; return Rx_State;
} }
@@ -99,7 +100,8 @@ bool led_rx_state(void)
* Returns: true if on, false if off. * Returns: true if on, false if off.
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
bool led_tx_state(void) bool led_tx_state(
void)
{ {
return Tx_State; return Tx_State;
} }
@@ -109,7 +111,8 @@ bool led_tx_state(void)
* Returns: none * Returns: none
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
void led_tx_toggle(void) void led_tx_toggle(
void)
{ {
if (led_tx_state()) { if (led_tx_state()) {
led_tx_off(); led_tx_off();
@@ -123,7 +126,8 @@ void led_tx_toggle(void)
* Returns: none * Returns: none
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
void led_rx_toggle(void) void led_rx_toggle(
void)
{ {
if (led_rx_state()) { if (led_rx_state()) {
led_rx_off(); led_rx_off();
@@ -247,7 +251,8 @@ void led_ld3_off(
* Returns: true if on, false if off. * Returns: true if on, false if off.
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
bool led_ld3_state(void) bool led_ld3_state(
void)
{ {
return LD3_State; return LD3_State;
} }
@@ -257,7 +262,8 @@ bool led_ld3_state(void)
* Returns: none * Returns: none
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
void led_ld3_toggle(void) void led_ld3_toggle(
void)
{ {
if (led_ld3_state()) { if (led_ld3_state()) {
led_ld3_off(); led_ld3_off();
+20 -10
View File
@@ -39,30 +39,40 @@ extern "C" {
void); void);
void led_ld4_off( void led_ld4_off(
void); void);
bool led_ld3_state(void); bool led_ld3_state(
void led_ld3_toggle(void); void);
void led_ld3_toggle(
void);
void led_tx_on(void); void led_tx_on(
void led_rx_on(void); void);
void led_rx_on(
void);
void led_tx_on_interval( void led_tx_on_interval(
uint16_t interval_ms); uint16_t interval_ms);
void led_rx_on_interval( void led_rx_on_interval(
uint16_t interval_ms); uint16_t interval_ms);
void led_tx_off(void); void led_tx_off(
void led_rx_off(void); void);
void led_rx_off(
void);
void led_tx_off_delay( void led_tx_off_delay(
uint32_t delay_ms); uint32_t delay_ms);
void led_rx_off_delay( void led_rx_off_delay(
uint32_t delay_ms); uint32_t delay_ms);
void led_tx_toggle(void); void led_tx_toggle(
void led_rx_toggle(void); void);
void led_rx_toggle(
void);
bool led_tx_state(void); bool led_tx_state(
bool led_rx_state(void); void);
bool led_rx_state(
void);
void led_task( void led_task(
void); void);
+14 -18
View File
@@ -44,14 +44,15 @@ char *BACnet_Version = "1.0";
* @param line: assert_param error line source number * @param line: assert_param error line source number
* @retval None * @retval None
*/ */
void assert_failed(uint8_t* file, uint32_t line) void assert_failed(
uint8_t * file,
uint32_t line)
{ {
/* User can add his own implementation to report the file name and line number, /* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */ /* Infinite loop */
while (1) while (1) {
{
} }
} }
#endif #endif
@@ -60,7 +61,8 @@ void assert_failed(uint8_t* file, uint32_t line)
#define LSE_FAIL_FLAG 0x80 #define LSE_FAIL_FLAG 0x80
#define LSE_PASS_FLAG 0x100 #define LSE_PASS_FLAG 0x100
void lse_init(void) void lse_init(
void)
{ {
uint32_t LSE_Delay = 0; uint32_t LSE_Delay = 0;
struct etimer Delay_Timer; struct etimer Delay_Timer;
@@ -71,18 +73,15 @@ void lse_init(void)
RCC_LSEConfig(RCC_LSE_ON); RCC_LSEConfig(RCC_LSE_ON);
/* Check the LSE Status */ /* Check the LSE Status */
while(1) while (1) {
{ if (LSE_Delay < LSE_FAIL_FLAG) {
if(LSE_Delay < LSE_FAIL_FLAG)
{
timer_elapsed_start(&Delay_Timer); timer_elapsed_start(&Delay_Timer);
while (!timer_elapsed_milliseconds(&Delay_Timer, 500)) { while (!timer_elapsed_milliseconds(&Delay_Timer, 500)) {
/* do nothing */ /* do nothing */
} }
/* check whether LSE is ready, with 4 seconds timeout */ /* check whether LSE is ready, with 4 seconds timeout */
LSE_Delay += 0x10; LSE_Delay += 0x10;
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) {
{
/* Set flag: LSE PASS */ /* Set flag: LSE PASS */
LSE_Delay |= LSE_PASS_FLAG; LSE_Delay |= LSE_PASS_FLAG;
led_ld4_off(); led_ld4_off();
@@ -93,10 +92,8 @@ void lse_init(void)
} }
/* LSE_FAIL_FLAG = 0x80 */ /* LSE_FAIL_FLAG = 0x80 */
else if(LSE_Delay >= LSE_FAIL_FLAG) else if (LSE_Delay >= LSE_FAIL_FLAG) {
{ if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
/* Set flag: LSE FAIL */ /* Set flag: LSE FAIL */
LSE_Delay |= LSE_FAIL_FLAG; LSE_Delay |= LSE_FAIL_FLAG;
led_ld4_on(); led_ld4_on();
@@ -121,10 +118,9 @@ int main(
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
led_init(); led_init();
RCC_APB2PeriphClockCmd( RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | ENABLE);
RCC_APB2Periph_GPIOE, ENABLE);
timer_init(); timer_init();
lse_init(); lse_init();
led_init(); led_init();
+17 -12
View File
@@ -58,7 +58,8 @@ static uint32_t Baud_Rate = 38400;
* Returns: nothing * Returns: nothing
* Notes: none * Notes: none
**************************************************************************/ **************************************************************************/
void rs485_silence_reset(void) void rs485_silence_reset(
void)
{ {
timer_elapsed_start(&Silence_Timer); timer_elapsed_start(&Silence_Timer);
} }
@@ -68,7 +69,8 @@ void rs485_silence_reset(void)
* Returns: true if the amount of time has elapsed * Returns: true if the amount of time has elapsed
* Notes: none * Notes: none
**************************************************************************/ **************************************************************************/
bool rs485_silence_elapsed(uint32_t interval) bool rs485_silence_elapsed(
uint32_t interval)
{ {
return timer_elapsed_milliseconds(&Silence_Timer, interval); return timer_elapsed_milliseconds(&Silence_Timer, interval);
} }
@@ -95,9 +97,7 @@ static uint16_t rs485_turnaround_time(
bool rs485_turnaround_elapsed( bool rs485_turnaround_elapsed(
void) void)
{ {
return timer_elapsed_milliseconds( return timer_elapsed_milliseconds(&Silence_Timer, rs485_turnaround_time());
&Silence_Timer,
rs485_turnaround_time());
} }
@@ -117,7 +117,8 @@ bool rs485_receive_error(
* @param[in] None * @param[in] None
* @return None * @return None
**********************************************************************/ **********************************************************************/
void USART2_IRQHandler(void) void USART2_IRQHandler(
void)
{ {
uint8_t data_byte; uint8_t data_byte;
@@ -154,7 +155,8 @@ bool rs485_byte_available(
* RETURN: nothing * RETURN: nothing
* NOTES: none * NOTES: none
**************************************************************************/ **************************************************************************/
void rs485_byte_send(uint8_t tx_byte) void rs485_byte_send(
uint8_t tx_byte)
{ {
led_tx_on_interval(10); led_tx_on_interval(10);
USART_SendData(USART2, tx_byte); USART_SendData(USART2, tx_byte);
@@ -167,7 +169,8 @@ void rs485_byte_send(uint8_t tx_byte)
* Returns: true if the USART register is empty * Returns: true if the USART register is empty
* Notes: none * Notes: none
**************************************************************************/ **************************************************************************/
bool rs485_byte_sent(void) bool rs485_byte_sent(
void)
{ {
return USART_GetFlagStatus(USART2, USART_FLAG_TXE); return USART_GetFlagStatus(USART2, USART_FLAG_TXE);
} }
@@ -177,7 +180,8 @@ bool rs485_byte_sent(void)
* Returns: true if the USART FIFO is empty * Returns: true if the USART FIFO is empty
* Notes: none * Notes: none
**************************************************************************/ **************************************************************************/
bool rs485_frame_sent(void) bool rs485_frame_sent(
void)
{ {
return USART_GetFlagStatus(USART2, USART_FLAG_TC); return USART_GetFlagStatus(USART2, USART_FLAG_TC);
} }
@@ -189,8 +193,8 @@ bool rs485_frame_sent(void)
**************************************************************************/ **************************************************************************/
void rs485_bytes_send( void rs485_bytes_send(
uint8_t * buffer, /* data to send */ uint8_t * buffer, /* data to send */
uint16_t nbytes) /* number of bytes of data */ uint16_t nbytes)
{ { /* number of bytes of data */
uint8_t tx_byte; uint8_t tx_byte;
while (nbytes) { while (nbytes) {
@@ -295,7 +299,8 @@ void rs485_rts_enable(
* Returns: nothing * Returns: nothing
* Notes: none * Notes: none
**************************************************************************/ **************************************************************************/
void rs485_init(void) void rs485_init(
void)
{ {
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure;
+8 -4
View File
@@ -52,13 +52,17 @@ extern "C" {
/* a granular approach */ /* a granular approach */
void rs485_byte_send( void rs485_byte_send(
uint8_t data_register); uint8_t data_register);
bool rs485_byte_sent(void); bool rs485_byte_sent(
bool rs485_frame_sent(void); void);
bool rs485_frame_sent(
void);
bool rs485_turnaround_elapsed( bool rs485_turnaround_elapsed(
void); void);
void rs485_silence_reset(void); void rs485_silence_reset(
bool rs485_silence_elapsed(uint32_t interval); void);
bool rs485_silence_elapsed(
uint32_t interval);
#ifdef __cplusplus #ifdef __cplusplus
} }
@@ -64,7 +64,9 @@
*/ */
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line); void assert_failed(
uint8_t * file,
uint32_t line);
#else #else
#define assert_param(expr) ((void)0) #define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */ #endif /* USE_FULL_ASSERT */
+20 -16
View File
@@ -47,7 +47,8 @@
* @param None * @param None
* @retval None * @retval None
*/ */
void NMI_Handler(void) void NMI_Handler(
void)
{ {
} }
@@ -56,11 +57,11 @@ void NMI_Handler(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void HardFault_Handler(void) void HardFault_Handler(
void)
{ {
/* Go to infinite loop when Hard Fault exception occurs */ /* Go to infinite loop when Hard Fault exception occurs */
while (1) while (1) {
{
} }
} }
@@ -69,11 +70,11 @@ void HardFault_Handler(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void MemManage_Handler(void) void MemManage_Handler(
void)
{ {
/* Go to infinite loop when Memory Manage exception occurs */ /* Go to infinite loop when Memory Manage exception occurs */
while (1) while (1) {
{
} }
} }
@@ -82,11 +83,11 @@ void MemManage_Handler(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void BusFault_Handler(void) void BusFault_Handler(
void)
{ {
/* Go to infinite loop when Bus Fault exception occurs */ /* Go to infinite loop when Bus Fault exception occurs */
while (1) while (1) {
{
} }
} }
@@ -95,11 +96,11 @@ void BusFault_Handler(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void UsageFault_Handler(void) void UsageFault_Handler(
void)
{ {
/* Go to infinite loop when Usage Fault exception occurs */ /* Go to infinite loop when Usage Fault exception occurs */
while (1) while (1) {
{
} }
} }
@@ -108,7 +109,8 @@ void UsageFault_Handler(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void SVC_Handler(void) void SVC_Handler(
void)
{ {
} }
@@ -117,7 +119,8 @@ void SVC_Handler(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void DebugMon_Handler(void) void DebugMon_Handler(
void)
{ {
} }
@@ -126,7 +129,8 @@ void DebugMon_Handler(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void PendSV_Handler(void) void PendSV_Handler(
void)
{ {
} }
+16 -8
View File
@@ -30,14 +30,22 @@
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */
void NMI_Handler(void); void NMI_Handler(
void HardFault_Handler(void); void);
void MemManage_Handler(void); void HardFault_Handler(
void BusFault_Handler(void); void);
void UsageFault_Handler(void); void MemManage_Handler(
void SVC_Handler(void); void);
void DebugMon_Handler(void); void BusFault_Handler(
void PendSV_Handler(void); void);
void UsageFault_Handler(
void);
void SVC_Handler(
void);
void DebugMon_Handler(
void);
void PendSV_Handler(
void);
#endif /* __STM32F10x_IT_H */ #endif /* __STM32F10x_IT_H */
+175 -187
View File
@@ -132,7 +132,8 @@
uint32_t SystemCoreClock = HSI_VALUE; /*!< System Clock Frequency (Core Clock) */ uint32_t SystemCoreClock = HSI_VALUE; /*!< System Clock Frequency (Core Clock) */
#endif #endif
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; __I uint8_t AHBPrescTable[16] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9 };
/** /**
* @} * @}
*/ */
@@ -141,24 +142,32 @@ __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}
* @{ * @{
*/ */
static void SetSysClock(void); static void SetSysClock(
void);
#ifdef SYSCLK_FREQ_HSE #ifdef SYSCLK_FREQ_HSE
static void SetSysClockToHSE(void); static void SetSysClockToHSE(
void);
#elif defined SYSCLK_FREQ_24MHz #elif defined SYSCLK_FREQ_24MHz
static void SetSysClockTo24(void); static void SetSysClockTo24(
void);
#elif defined SYSCLK_FREQ_36MHz #elif defined SYSCLK_FREQ_36MHz
static void SetSysClockTo36(void); static void SetSysClockTo36(
void);
#elif defined SYSCLK_FREQ_48MHz #elif defined SYSCLK_FREQ_48MHz
static void SetSysClockTo48(void); static void SetSysClockTo48(
void);
#elif defined SYSCLK_FREQ_56MHz #elif defined SYSCLK_FREQ_56MHz
static void SetSysClockTo56(void); static void SetSysClockTo56(
void);
#elif defined SYSCLK_FREQ_72MHz #elif defined SYSCLK_FREQ_72MHz
static void SetSysClockTo72(void); static void SetSysClockTo72(
void);
#endif #endif
#ifdef DATA_IN_ExtSRAM #ifdef DATA_IN_ExtSRAM
static void SystemInit_ExtMemCtl(void); static void SystemInit_ExtMemCtl(
void);
#endif /* DATA_IN_ExtSRAM */ #endif /* DATA_IN_ExtSRAM */
/** /**
@@ -177,7 +186,8 @@ static void SetSysClock(void);
* @param None * @param None
* @retval None * @retval None
*/ */
void SystemInit (void) void SystemInit(
void)
{ {
/* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
/* Set HSION bit */ /* Set HSION bit */
@@ -242,12 +252,14 @@ void SystemInit (void)
* @param None * @param None
* @retval None * @retval None
*/ */
void SystemCoreClockUpdate (void) void SystemCoreClockUpdate(
void)
{ {
uint32_t tmp = 0, pllmull = 0, pllsource = 0; uint32_t tmp = 0, pllmull = 0, pllsource = 0;
#ifdef STM32F10X_CL #ifdef STM32F10X_CL
uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0; uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor =
0, pll2mull = 0;
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
@@ -257,8 +269,7 @@ void SystemCoreClockUpdate (void)
/* Get SYSCLK source ------------------------------------------------------- */ /* Get SYSCLK source ------------------------------------------------------- */
tmp = RCC->CFGR & RCC_CFGR_SWS; tmp = RCC->CFGR & RCC_CFGR_SWS;
switch (tmp) switch (tmp) {
{
case 0x00: /* HSI used as system clock */ case 0x00: /* HSI used as system clock */
SystemCoreClock = HSI_VALUE; SystemCoreClock = HSI_VALUE;
break; break;
@@ -274,25 +285,19 @@ void SystemCoreClockUpdate (void)
#ifndef STM32F10X_CL #ifndef STM32F10X_CL
pllmull = (pllmull >> 18) + 2; pllmull = (pllmull >> 18) + 2;
if (pllsource == 0x00) if (pllsource == 0x00) {
{
/* HSI oscillator clock divided by 2 selected as PLL clock entry */ /* HSI oscillator clock divided by 2 selected as PLL clock entry */
SystemCoreClock = (HSI_VALUE >> 1) * pllmull; SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
} } else {
else
{
#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
/* HSE oscillator clock selected as PREDIV1 clock entry */ /* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
#else #else
/* HSE selected as PLL clock entry */ /* HSE selected as PLL clock entry */
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t) RESET) { /* HSE oscillator clock divided by 2 */
{/* HSE oscillator clock divided by 2 */
SystemCoreClock = (HSE_VALUE >> 1) * pllmull; SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
} } else {
else
{
SystemCoreClock = HSE_VALUE * pllmull; SystemCoreClock = HSE_VALUE * pllmull;
} }
#endif #endif
@@ -300,39 +305,33 @@ void SystemCoreClockUpdate (void)
#else #else
pllmull = pllmull >> 18; pllmull = pllmull >> 18;
if (pllmull != 0x0D) if (pllmull != 0x0D) {
{
pllmull += 2; pllmull += 2;
} } else { /* PLL multiplication factor = PLL input clock * 6.5 */
else
{ /* PLL multiplication factor = PLL input clock * 6.5 */
pllmull = 13 / 2; pllmull = 13 / 2;
} }
if (pllsource == 0x00) if (pllsource == 0x00) {
{
/* HSI oscillator clock divided by 2 selected as PLL clock entry */ /* HSI oscillator clock divided by 2 selected as PLL clock entry */
SystemCoreClock = (HSI_VALUE >> 1) * pllmull; SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
} } else { /* PREDIV1 selected as PLL clock entry */
else
{/* PREDIV1 selected as PLL clock entry */
/* Get PREDIV1 clock source and division factor */ /* Get PREDIV1 clock source and division factor */
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
if (prediv1source == 0) if (prediv1source == 0) {
{
/* HSE oscillator clock selected as PREDIV1 clock entry */ /* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
} } else { /* PLL2 clock selected as PREDIV1 clock entry */
else
{/* PLL2 clock selected as PREDIV1 clock entry */
/* Get PREDIV2 division factor and PLL2 multiplication factor */ /* Get PREDIV2 division factor and PLL2 multiplication factor */
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1; prediv2factor =
((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1;
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8) + 2; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8) + 2;
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; SystemCoreClock =
(((HSE_VALUE / prediv2factor) * pll2mull) /
prediv1factor) * pllmull;
} }
} }
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
@@ -355,7 +354,8 @@ void SystemCoreClockUpdate (void)
* @param None * @param None
* @retval None * @retval None
*/ */
static void SetSysClock(void) static void SetSysClock(
void)
{ {
#ifdef SYSCLK_FREQ_HSE #ifdef SYSCLK_FREQ_HSE
SetSysClockToHSE(); SetSysClockToHSE();
@@ -391,7 +391,8 @@ static void SetSysClock(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void SystemInit_ExtMemCtl(void) void SystemInit_ExtMemCtl(
void)
{ {
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
required, then adjust the Register Addresses */ required, then adjust the Register Addresses */
@@ -436,7 +437,8 @@ void SystemInit_ExtMemCtl(void)
* @param None * @param None
* @retval None * @retval None
*/ */
static void SetSysClockToHSE(void) static void SetSysClockToHSE(
void)
{ {
__IO uint32_t StartUpCounter = 0, HSEStatus = 0; __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
@@ -445,23 +447,18 @@ static void SetSysClockToHSE(void)
RCC->CR |= ((uint32_t) RCC_CR_HSEON); RCC->CR |= ((uint32_t) RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */ /* Wait till HSE is ready and if Time out is reached exit */
do do {
{
HSEStatus = RCC->CR & RCC_CR_HSERDY; HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++; StartUpCounter++;
} while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET) if ((RCC->CR & RCC_CR_HSERDY) != RESET) {
{
HSEStatus = (uint32_t) 0x01; HSEStatus = (uint32_t) 0x01;
} } else {
else
{
HSEStatus = (uint32_t) 0x00; HSEStatus = (uint32_t) 0x00;
} }
if (HSEStatus == (uint32_t)0x01) if (HSEStatus == (uint32_t) 0x01) {
{
#if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
/* Enable Prefetch Buffer */ /* Enable Prefetch Buffer */
@@ -473,12 +470,9 @@ static void SetSysClockToHSE(void)
#ifndef STM32F10X_CL #ifndef STM32F10X_CL
FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_0; FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_0;
#else #else
if (HSE_VALUE <= 24000000) if (HSE_VALUE <= 24000000) {
{
FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_0; FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_0;
} } else {
else
{
FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_1; FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_1;
} }
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
@@ -498,12 +492,9 @@ static void SetSysClockToHSE(void)
RCC->CFGR |= (uint32_t) RCC_CFGR_SW_HSE; RCC->CFGR |= (uint32_t) RCC_CFGR_SW_HSE;
/* Wait till HSE is used as system clock source */ /* Wait till HSE is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x04) while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x04) {
{
} }
} } else { /* If HSE fails to start-up, the application will have wrong clock
else
{ /* If HSE fails to start-up, the application will have wrong clock
configuration. User can add here some code to deal with this error */ configuration. User can add here some code to deal with this error */
} }
} }
@@ -515,7 +506,8 @@ static void SetSysClockToHSE(void)
* @param None * @param None
* @retval None * @retval None
*/ */
static void SetSysClockTo24(void) static void SetSysClockTo24(
void)
{ {
__IO uint32_t StartUpCounter = 0, HSEStatus = 0; __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
@@ -524,23 +516,18 @@ static void SetSysClockTo24(void)
RCC->CR |= ((uint32_t) RCC_CR_HSEON); RCC->CR |= ((uint32_t) RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */ /* Wait till HSE is ready and if Time out is reached exit */
do do {
{
HSEStatus = RCC->CR & RCC_CR_HSERDY; HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++; StartUpCounter++;
} while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET) if ((RCC->CR & RCC_CR_HSERDY) != RESET) {
{
HSEStatus = (uint32_t) 0x01; HSEStatus = (uint32_t) 0x01;
} } else {
else
{
HSEStatus = (uint32_t) 0x00; HSEStatus = (uint32_t) 0x00;
} }
if (HSEStatus == (uint32_t)0x01) if (HSEStatus == (uint32_t) 0x01) {
{
#if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
/* Enable Prefetch Buffer */ /* Enable Prefetch Buffer */
FLASH->ACR |= FLASH_ACR_PRFTBE; FLASH->ACR |= FLASH_ACR_PRFTBE;
@@ -562,39 +549,50 @@ static void SetSysClockTo24(void)
#ifdef STM32F10X_CL #ifdef STM32F10X_CL
/* Configure PLLs ------------------------------------------------------ */ /* Configure PLLs ------------------------------------------------------ */
/* PLL configuration: PLLCLK = PREDIV1 * 6 = 24 MHz */ /* PLL configuration: PLLCLK = PREDIV1 * 6 = 24 MHz */
RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC |
RCC_CFGR_PLLMULL);
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
RCC_CFGR_PLLMULL6); RCC_CFGR_PLLMULL6);
/* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
/* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */ /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */
RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | RCC->CFGR2 &=
(uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | RCC->CFGR2 |=
(uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10); RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
/* Enable PLL2 */ /* Enable PLL2 */
RCC->CR |= RCC_CR_PLL2ON; RCC->CR |= RCC_CR_PLL2ON;
/* Wait till PLL2 is ready */ /* Wait till PLL2 is ready */
while((RCC->CR & RCC_CR_PLL2RDY) == 0) while ((RCC->CR & RCC_CR_PLL2RDY) == 0) {
{
} }
#elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
/* PLL configuration: = (HSE / 2) * 6 = 24 MHz */ /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL6); (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
RCC_CFGR_PLLMULL));
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLSRC_PREDIV1 |
RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL6);
#else #else
/* PLL configuration: = (HSE / 2) * 6 = 24 MHz */ /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL6); (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
RCC_CFGR_PLLMULL));
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 |
RCC_CFGR_PLLMULL6);
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
/* Enable PLL */ /* Enable PLL */
RCC->CR |= RCC_CR_PLLON; RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */ /* Wait till PLL is ready */
while((RCC->CR & RCC_CR_PLLRDY) == 0) while ((RCC->CR & RCC_CR_PLLRDY) == 0) {
{
} }
/* Select PLL as system clock source */ /* Select PLL as system clock source */
@@ -602,12 +600,9 @@ static void SetSysClockTo24(void)
RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */ /* Wait till PLL is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) {
{
} }
} } else { /* If HSE fails to start-up, the application will have wrong clock
else
{ /* If HSE fails to start-up, the application will have wrong clock
configuration. User can add here some code to deal with this error */ configuration. User can add here some code to deal with this error */
} }
} }
@@ -619,7 +614,8 @@ static void SetSysClockTo24(void)
* @param None * @param None
* @retval None * @retval None
*/ */
static void SetSysClockTo36(void) static void SetSysClockTo36(
void)
{ {
__IO uint32_t StartUpCounter = 0, HSEStatus = 0; __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
@@ -628,23 +624,18 @@ static void SetSysClockTo36(void)
RCC->CR |= ((uint32_t) RCC_CR_HSEON); RCC->CR |= ((uint32_t) RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */ /* Wait till HSE is ready and if Time out is reached exit */
do do {
{
HSEStatus = RCC->CR & RCC_CR_HSERDY; HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++; StartUpCounter++;
} while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET) if ((RCC->CR & RCC_CR_HSERDY) != RESET) {
{
HSEStatus = (uint32_t) 0x01; HSEStatus = (uint32_t) 0x01;
} } else {
else
{
HSEStatus = (uint32_t) 0x00; HSEStatus = (uint32_t) 0x00;
} }
if (HSEStatus == (uint32_t)0x01) if (HSEStatus == (uint32_t) 0x01) {
{
/* Enable Prefetch Buffer */ /* Enable Prefetch Buffer */
FLASH->ACR |= FLASH_ACR_PRFTBE; FLASH->ACR |= FLASH_ACR_PRFTBE;
@@ -665,37 +656,44 @@ static void SetSysClockTo36(void)
/* Configure PLLs ------------------------------------------------------ */ /* Configure PLLs ------------------------------------------------------ */
/* PLL configuration: PLLCLK = PREDIV1 * 9 = 36 MHz */ /* PLL configuration: PLLCLK = PREDIV1 * 9 = 36 MHz */
RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC |
RCC_CFGR_PLLMULL);
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
RCC_CFGR_PLLMULL9); RCC_CFGR_PLLMULL9);
/*!< PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ /*!< PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
/* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */ /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */
RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | RCC->CFGR2 &=
(uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | RCC->CFGR2 |=
(uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10); RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
/* Enable PLL2 */ /* Enable PLL2 */
RCC->CR |= RCC_CR_PLL2ON; RCC->CR |= RCC_CR_PLL2ON;
/* Wait till PLL2 is ready */ /* Wait till PLL2 is ready */
while((RCC->CR & RCC_CR_PLL2RDY) == 0) while ((RCC->CR & RCC_CR_PLL2RDY) == 0) {
{
} }
#else #else
/* PLL configuration: PLLCLK = (HSE / 2) * 9 = 36 MHz */ /* PLL configuration: PLLCLK = (HSE / 2) * 9 = 36 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL9); (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
RCC_CFGR_PLLMULL));
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 |
RCC_CFGR_PLLMULL9);
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
/* Enable PLL */ /* Enable PLL */
RCC->CR |= RCC_CR_PLLON; RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */ /* Wait till PLL is ready */
while((RCC->CR & RCC_CR_PLLRDY) == 0) while ((RCC->CR & RCC_CR_PLLRDY) == 0) {
{
} }
/* Select PLL as system clock source */ /* Select PLL as system clock source */
@@ -703,12 +701,9 @@ static void SetSysClockTo36(void)
RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */ /* Wait till PLL is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) {
{
} }
} } else { /* If HSE fails to start-up, the application will have wrong clock
else
{ /* If HSE fails to start-up, the application will have wrong clock
configuration. User can add here some code to deal with this error */ configuration. User can add here some code to deal with this error */
} }
} }
@@ -720,7 +715,8 @@ static void SetSysClockTo36(void)
* @param None * @param None
* @retval None * @retval None
*/ */
static void SetSysClockTo48(void) static void SetSysClockTo48(
void)
{ {
__IO uint32_t StartUpCounter = 0, HSEStatus = 0; __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
@@ -729,23 +725,18 @@ static void SetSysClockTo48(void)
RCC->CR |= ((uint32_t) RCC_CR_HSEON); RCC->CR |= ((uint32_t) RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */ /* Wait till HSE is ready and if Time out is reached exit */
do do {
{
HSEStatus = RCC->CR & RCC_CR_HSERDY; HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++; StartUpCounter++;
} while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET) if ((RCC->CR & RCC_CR_HSERDY) != RESET) {
{
HSEStatus = (uint32_t) 0x01; HSEStatus = (uint32_t) 0x01;
} } else {
else
{
HSEStatus = (uint32_t) 0x00; HSEStatus = (uint32_t) 0x00;
} }
if (HSEStatus == (uint32_t)0x01) if (HSEStatus == (uint32_t) 0x01) {
{
/* Enable Prefetch Buffer */ /* Enable Prefetch Buffer */
FLASH->ACR |= FLASH_ACR_PRFTBE; FLASH->ACR |= FLASH_ACR_PRFTBE;
@@ -767,26 +758,32 @@ static void SetSysClockTo48(void)
/* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
/* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */
RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | RCC->CFGR2 &=
(uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | RCC->CFGR2 |=
(uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
/* Enable PLL2 */ /* Enable PLL2 */
RCC->CR |= RCC_CR_PLL2ON; RCC->CR |= RCC_CR_PLL2ON;
/* Wait till PLL2 is ready */ /* Wait till PLL2 is ready */
while((RCC->CR & RCC_CR_PLL2RDY) == 0) while ((RCC->CR & RCC_CR_PLL2RDY) == 0) {
{
} }
/* PLL configuration: PLLCLK = PREDIV1 * 6 = 48 MHz */ /* PLL configuration: PLLCLK = PREDIV1 * 6 = 48 MHz */
RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC |
RCC_CFGR_PLLMULL);
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
RCC_CFGR_PLLMULL6); RCC_CFGR_PLLMULL6);
#else #else
/* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */ /* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); RCC->CFGR &=
(uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
RCC_CFGR_PLLMULL));
RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6); RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6);
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
@@ -794,8 +791,7 @@ static void SetSysClockTo48(void)
RCC->CR |= RCC_CR_PLLON; RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */ /* Wait till PLL is ready */
while((RCC->CR & RCC_CR_PLLRDY) == 0) while ((RCC->CR & RCC_CR_PLLRDY) == 0) {
{
} }
/* Select PLL as system clock source */ /* Select PLL as system clock source */
@@ -803,12 +799,9 @@ static void SetSysClockTo48(void)
RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */ /* Wait till PLL is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) {
{
} }
} } else { /* If HSE fails to start-up, the application will have wrong clock
else
{ /* If HSE fails to start-up, the application will have wrong clock
configuration. User can add here some code to deal with this error */ configuration. User can add here some code to deal with this error */
} }
} }
@@ -821,7 +814,8 @@ static void SetSysClockTo48(void)
* @param None * @param None
* @retval None * @retval None
*/ */
static void SetSysClockTo56(void) static void SetSysClockTo56(
void)
{ {
__IO uint32_t StartUpCounter = 0, HSEStatus = 0; __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
@@ -830,23 +824,18 @@ static void SetSysClockTo56(void)
RCC->CR |= ((uint32_t) RCC_CR_HSEON); RCC->CR |= ((uint32_t) RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */ /* Wait till HSE is ready and if Time out is reached exit */
do do {
{
HSEStatus = RCC->CR & RCC_CR_HSERDY; HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++; StartUpCounter++;
} while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET) if ((RCC->CR & RCC_CR_HSERDY) != RESET) {
{
HSEStatus = (uint32_t) 0x01; HSEStatus = (uint32_t) 0x01;
} } else {
else
{
HSEStatus = (uint32_t) 0x00; HSEStatus = (uint32_t) 0x00;
} }
if (HSEStatus == (uint32_t)0x01) if (HSEStatus == (uint32_t) 0x01) {
{
/* Enable Prefetch Buffer */ /* Enable Prefetch Buffer */
FLASH->ACR |= FLASH_ACR_PRFTBE; FLASH->ACR |= FLASH_ACR_PRFTBE;
@@ -868,26 +857,32 @@ static void SetSysClockTo56(void)
/* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
/* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */
RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | RCC->CFGR2 &=
(uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | RCC->CFGR2 |=
(uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
/* Enable PLL2 */ /* Enable PLL2 */
RCC->CR |= RCC_CR_PLL2ON; RCC->CR |= RCC_CR_PLL2ON;
/* Wait till PLL2 is ready */ /* Wait till PLL2 is ready */
while((RCC->CR & RCC_CR_PLL2RDY) == 0) while ((RCC->CR & RCC_CR_PLL2RDY) == 0) {
{
} }
/* PLL configuration: PLLCLK = PREDIV1 * 7 = 56 MHz */ /* PLL configuration: PLLCLK = PREDIV1 * 7 = 56 MHz */
RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC |
RCC_CFGR_PLLMULL);
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
RCC_CFGR_PLLMULL7); RCC_CFGR_PLLMULL7);
#else #else
/* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */ /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); RCC->CFGR &=
(uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
RCC_CFGR_PLLMULL));
RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7); RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7);
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
@@ -896,8 +891,7 @@ static void SetSysClockTo56(void)
RCC->CR |= RCC_CR_PLLON; RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */ /* Wait till PLL is ready */
while((RCC->CR & RCC_CR_PLLRDY) == 0) while ((RCC->CR & RCC_CR_PLLRDY) == 0) {
{
} }
/* Select PLL as system clock source */ /* Select PLL as system clock source */
@@ -905,12 +899,9 @@ static void SetSysClockTo56(void)
RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */ /* Wait till PLL is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) {
{
} }
} } else { /* If HSE fails to start-up, the application will have wrong clock
else
{ /* If HSE fails to start-up, the application will have wrong clock
configuration. User can add here some code to deal with this error */ configuration. User can add here some code to deal with this error */
} }
} }
@@ -923,7 +914,8 @@ static void SetSysClockTo56(void)
* @param None * @param None
* @retval None * @retval None
*/ */
static void SetSysClockTo72(void) static void SetSysClockTo72(
void)
{ {
__IO uint32_t StartUpCounter = 0, HSEStatus = 0; __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
@@ -932,23 +924,18 @@ static void SetSysClockTo72(void)
RCC->CR |= ((uint32_t) RCC_CR_HSEON); RCC->CR |= ((uint32_t) RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */ /* Wait till HSE is ready and if Time out is reached exit */
do do {
{
HSEStatus = RCC->CR & RCC_CR_HSERDY; HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++; StartUpCounter++;
} while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET) if ((RCC->CR & RCC_CR_HSERDY) != RESET) {
{
HSEStatus = (uint32_t) 0x01; HSEStatus = (uint32_t) 0x01;
} } else {
else
{
HSEStatus = (uint32_t) 0x00; HSEStatus = (uint32_t) 0x00;
} }
if (HSEStatus == (uint32_t)0x01) if (HSEStatus == (uint32_t) 0x01) {
{
/* Enable Prefetch Buffer */ /* Enable Prefetch Buffer */
FLASH->ACR |= FLASH_ACR_PRFTBE; FLASH->ACR |= FLASH_ACR_PRFTBE;
@@ -971,26 +958,31 @@ static void SetSysClockTo72(void)
/* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
/* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */
RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | RCC->CFGR2 &=
(uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | RCC->CFGR2 |=
(uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
/* Enable PLL2 */ /* Enable PLL2 */
RCC->CR |= RCC_CR_PLL2ON; RCC->CR |= RCC_CR_PLL2ON;
/* Wait till PLL2 is ready */ /* Wait till PLL2 is ready */
while((RCC->CR & RCC_CR_PLL2RDY) == 0) while ((RCC->CR & RCC_CR_PLL2RDY) == 0) {
{
} }
/* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */ /* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */
RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); RCC->CFGR &=
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC |
RCC_CFGR_PLLMULL);
RCC->CFGR |=
(uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
RCC_CFGR_PLLMULL9); RCC_CFGR_PLLMULL9);
#else #else
/* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */ /* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC->CFGR &=
(uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
RCC_CFGR_PLLMULL)); RCC_CFGR_PLLMULL));
RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9); RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);
#endif /* STM32F10X_CL */ #endif /* STM32F10X_CL */
@@ -999,8 +991,7 @@ static void SetSysClockTo72(void)
RCC->CR |= RCC_CR_PLLON; RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */ /* Wait till PLL is ready */
while((RCC->CR & RCC_CR_PLLRDY) == 0) while ((RCC->CR & RCC_CR_PLLRDY) == 0) {
{
} }
/* Select PLL as system clock source */ /* Select PLL as system clock source */
@@ -1008,12 +999,9 @@ static void SetSysClockTo72(void)
RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */ /* Wait till PLL is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) {
{
} }
} } else { /* If HSE fails to start-up, the application will have wrong clock
else
{ /* If HSE fails to start-up, the application will have wrong clock
configuration. User can add here some code to deal with this error */ configuration. User can add here some code to deal with this error */
} }
} }
+8 -4
View File
@@ -61,7 +61,8 @@ static void timer_debug_off(
* Returns: none * Returns: none
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
void timer_debug_toggle(void) void timer_debug_toggle(
void)
{ {
static bool state = false; static bool state = false;
@@ -79,7 +80,8 @@ void timer_debug_toggle(void)
* Returns: nothing * Returns: nothing
* Notes: reserved name for ISR handlers * Notes: reserved name for ISR handlers
*************************************************************************/ *************************************************************************/
void SysTick_Handler(void) void SysTick_Handler(
void)
{ {
/* increment the tick count */ /* increment the tick count */
Millisecond_Counter++; Millisecond_Counter++;
@@ -91,7 +93,8 @@ void SysTick_Handler(void)
* Returns: none * Returns: none
* Notes: none * Notes: none
*************************************************************************/ *************************************************************************/
uint32_t timer_milliseconds(void) uint32_t timer_milliseconds(
void)
{ {
return Millisecond_Counter; return Millisecond_Counter;
} }
@@ -101,7 +104,8 @@ uint32_t timer_milliseconds(void)
* Returns: none * Returns: none
* Notes: peripheral frequency defined in hardware.h * Notes: peripheral frequency defined in hardware.h
*************************************************************************/ *************************************************************************/
void timer_init(void) void timer_init(
void)
{ {
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
+3 -2
View File
@@ -207,8 +207,9 @@ void timer_init(
/* configure for 1ms resolution - if possible */ /* configure for 1ms resolution - if possible */
Timer_Period = min(max(tc.wPeriodMin, 1L), tc.wPeriodMax); Timer_Period = min(max(tc.wPeriodMin, 1L), tc.wPeriodMax);
if (Timer_Period != 1L) { if (Timer_Period != 1L) {
fprintf(stderr, "Failed to set timer to 1ms. " fprintf(stderr,
"Time period set to %ums\n", (unsigned)Timer_Period); "Failed to set timer to 1ms. " "Time period set to %ums\n",
(unsigned) Timer_Period);
} }
timeBeginPeriod(Timer_Period); timeBeginPeriod(Timer_Period);
atexit(timer_cleanup); atexit(timer_cleanup);
+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 */
+12 -12
View File
@@ -1008,8 +1008,8 @@ bool bacapp_print_value(
case PROP_OBJECT_TYPE: case PROP_OBJECT_TYPE:
if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) { if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) {
fprintf(stream, "%s", fprintf(stream, "%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) {
fprintf(stream, "reserved %lu", fprintf(stream, "reserved %lu",
(unsigned long) value->type.Enumerated); (unsigned long) value->type.Enumerated);
@@ -1025,8 +1025,8 @@ bool bacapp_print_value(
case PROP_UNITS: case PROP_UNITS:
if (value->type.Enumerated < 256) { if (value->type.Enumerated < 256) {
fprintf(stream, "%s", fprintf(stream, "%s",
bactext_engineering_unit_name(value->type. bactext_engineering_unit_name(value->
Enumerated)); type.Enumerated));
} else { } else {
fprintf(stream, "proprietary %lu", fprintf(stream, "proprietary %lu",
(unsigned long) value->type.Enumerated); (unsigned long) value->type.Enumerated);
@@ -1034,14 +1034,14 @@ bool bacapp_print_value(
break; break;
case PROP_POLARITY: case PROP_POLARITY:
fprintf(stream, "%s", fprintf(stream, "%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:
if (object_type < PROPRIETARY_BACNET_OBJECT_TYPE) { if (object_type < PROPRIETARY_BACNET_OBJECT_TYPE) {
fprintf(stream, "%s", fprintf(stream, "%s",
bactext_binary_present_value_name(value-> bactext_binary_present_value_name(value->type.
type.Enumerated)); Enumerated));
} else { } else {
fprintf(stream, "%lu", fprintf(stream, "%lu",
(unsigned long) value->type.Enumerated); (unsigned long) value->type.Enumerated);
@@ -1053,8 +1053,8 @@ bool bacapp_print_value(
break; break;
case PROP_SYSTEM_STATUS: case PROP_SYSTEM_STATUS:
fprintf(stream, "%s", fprintf(stream, "%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:
fprintf(stream, "%s", fprintf(stream, "%s",
@@ -1425,8 +1425,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 -2
View File
@@ -2277,8 +2277,7 @@ void testBACDCodeObject(
uint32_t decoded_instance = 0; uint32_t decoded_instance = 0;
encode_bacnet_object_id(&encoded_array[0], type, instance); encode_bacnet_object_id(&encoded_array[0], type, instance);
decode_object_id(&encoded_array[0], &decoded_type, decode_object_id(&encoded_array[0], &decoded_type, &decoded_instance);
&decoded_instance);
ct_test(pTest, decoded_type == type); ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance); ct_test(pTest, decoded_instance == instance);
encode_bacnet_object_id(&object_array[0], type, instance); encode_bacnet_object_id(&object_array[0], type, instance);
+1 -2
View File
@@ -51,8 +51,7 @@ int bacapp_decode_property_state(
uint8_t tagnum; uint8_t tagnum;
section_length = section_length =
decode_tag_number_and_value(&apdu[len], &tagnum, decode_tag_number_and_value(&apdu[len], &tagnum, &len_value_type);
&len_value_type);
if (-1 == section_length) { if (-1 == section_length) {
return -1; return -1;
+31 -16
View File
@@ -496,20 +496,30 @@ bool characterstring_printable(
by Jeff Bezanson by Jeff Bezanson
placed in the public domain Fall 2005 */ placed in the public domain Fall 2005 */
static const char trailingBytesForUTF8[256] = { static const char trailingBytesForUTF8[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4,
4, 4, 4, 5, 5, 5, 5
}; };
/* based on the valid_utf8 routine from the PCRE library by Philip Hazel /* based on the valid_utf8 routine from the PCRE library by Philip Hazel
length is in bytes, since without knowing whether the string is valid length is in bytes, since without knowing whether the string is valid
it's hard to know how many characters there are! */ it's hard to know how many characters there are! */
static int utf8_isvalid(const char *str, int length) static int utf8_isvalid(
const char *str,
int length)
{ {
const unsigned char *p, *pend = (unsigned char *) str + length; const unsigned char *p, *pend = (unsigned char *) str + length;
unsigned char c; unsigned char c;
@@ -543,35 +553,40 @@ static int utf8_isvalid(const char *str, int length)
switch (ab) { switch (ab) {
/* Check for xx00 000x */ /* Check for xx00 000x */
case 1: case 1:
if ((c & 0x3e) == 0) return 0; if ((c & 0x3e) == 0)
return 0;
continue; /* We know there aren't any more bytes to check */ continue; /* We know there aren't any more bytes to check */
/* Check for 1110 0000, xx0x xxxx */ /* Check for 1110 0000, xx0x xxxx */
case 2: case 2:
if (c == 0xe0 && (*p & 0x20) == 0) return 0; if (c == 0xe0 && (*p & 0x20) == 0)
return 0;
break; break;
/* Check for 1111 0000, xx00 xxxx */ /* Check for 1111 0000, xx00 xxxx */
case 3: case 3:
if (c == 0xf0 && (*p & 0x30) == 0) return 0; if (c == 0xf0 && (*p & 0x30) == 0)
return 0;
break; break;
/* Check for 1111 1000, xx00 0xxx */ /* Check for 1111 1000, xx00 0xxx */
case 4: case 4:
if (c == 0xf8 && (*p & 0x38) == 0) return 0; if (c == 0xf8 && (*p & 0x38) == 0)
return 0;
break; break;
/* Check for leading 0xfe or 0xff, /* Check for leading 0xfe or 0xff,
and then for 1111 1100, xx00 00xx */ and then for 1111 1100, xx00 00xx */
case 5: case 5:
if (c == 0xfe || c == 0xff || if (c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0))
(c == 0xfc && (*p & 0x3c) == 0)) return 0; return 0;
break; break;
} }
/* Check for valid bytes after the 2nd, if any; all must start 10 */ /* Check for valid bytes after the 2nd, if any; all must start 10 */
while (--ab > 0) { while (--ab > 0) {
if ((*(++p) & 0xc0) != 0x80) return 0; if ((*(++p) & 0xc0) != 0x80)
return 0;
} }
} }
+2 -2
View File
@@ -656,8 +656,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())
+161 -154
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;
@@ -1020,8 +1025,8 @@ void testEventEventState(
data.notificationParams.changeOfState.newState.state.units == data.notificationParams.changeOfState.newState.state.units ==
data2.notificationParams.changeOfState.newState.state.units); data2.notificationParams.changeOfState.newState.state.units);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.changeOfState.statusFlags, bitstring_same(&data.notificationParams.changeOfState.statusFlags,
&data2.notificationParams.changeOfState.statusFlags)); &data2.notificationParams.changeOfState.statusFlags));
/**********************************************************************************/ /**********************************************************************************/
@@ -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);
@@ -1110,12 +1115,13 @@ void testEventEventState(
ct_test(pTest, inLen == outLen); ct_test(pTest, inLen == outLen);
testBaseEventState(pTest); testBaseEventState(pTest);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.changeOfBitstring.referencedBitString, bitstring_same(&data.notificationParams.changeOfBitstring.
referencedBitString,
&data2.notificationParams.changeOfBitstring.referencedBitString)); &data2.notificationParams.changeOfBitstring.referencedBitString));
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.changeOfBitstring.statusFlags, bitstring_same(&data.notificationParams.changeOfBitstring.statusFlags,
&data2.notificationParams.changeOfBitstring.statusFlags)); &data2.notificationParams.changeOfBitstring.statusFlags));
/**********************************************************************************/ /**********************************************************************************/
@@ -1154,8 +1160,8 @@ void testEventEventState(
ct_test(pTest, inLen == outLen); ct_test(pTest, inLen == outLen);
testBaseEventState(pTest); testBaseEventState(pTest);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.changeOfValue.statusFlags, bitstring_same(&data.notificationParams.changeOfValue.statusFlags,
&data2.notificationParams.changeOfValue.statusFlags)); &data2.notificationParams.changeOfValue.statusFlags));
ct_test(pTest, ct_test(pTest,
@@ -1174,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);
@@ -1195,16 +1201,17 @@ void testEventEventState(
ct_test(pTest, inLen == outLen); ct_test(pTest, inLen == outLen);
testBaseEventState(pTest); testBaseEventState(pTest);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.changeOfValue.statusFlags, bitstring_same(&data.notificationParams.changeOfValue.statusFlags,
&data2.notificationParams.changeOfValue.statusFlags)); &data2.notificationParams.changeOfValue.statusFlags));
ct_test(pTest, ct_test(pTest,
data.notificationParams.changeOfValue.tag == data.notificationParams.changeOfValue.tag ==
data2.notificationParams.changeOfValue.tag); data2.notificationParams.changeOfValue.tag);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.changeOfValue.newValue.changedBits, bitstring_same(&data.notificationParams.changeOfValue.newValue.
changedBits,
&data2.notificationParams.changeOfValue.newValue.changedBits)); &data2.notificationParams.changeOfValue.newValue.changedBits));
/**********************************************************************************/ /**********************************************************************************/
@@ -1254,8 +1261,8 @@ void testEventEventState(
ct_test(pTest, ct_test(pTest,
data.notificationParams.floatingLimit.errorLimit == data.notificationParams.floatingLimit.errorLimit ==
data2.notificationParams.floatingLimit.errorLimit); data2.notificationParams.floatingLimit.errorLimit);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.floatingLimit.statusFlags, bitstring_same(&data.notificationParams.floatingLimit.statusFlags,
&data2.notificationParams.floatingLimit.statusFlags)); &data2.notificationParams.floatingLimit.statusFlags));
@@ -1306,8 +1313,8 @@ void testEventEventState(
ct_test(pTest, ct_test(pTest,
data.notificationParams.outOfRange.exceedingValue == data.notificationParams.outOfRange.exceedingValue ==
data2.notificationParams.outOfRange.exceedingValue); data2.notificationParams.outOfRange.exceedingValue);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.outOfRange.statusFlags, bitstring_same(&data.notificationParams.outOfRange.statusFlags,
&data2.notificationParams.outOfRange.statusFlags)); &data2.notificationParams.outOfRange.statusFlags));
/**********************************************************************************/ /**********************************************************************************/
@@ -1361,8 +1368,8 @@ void testEventEventState(
data.notificationParams.changeOfLifeSafety.operationExpected == data.notificationParams.changeOfLifeSafety.operationExpected ==
data2.notificationParams.changeOfLifeSafety.operationExpected); data2.notificationParams.changeOfLifeSafety.operationExpected);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.changeOfLifeSafety.statusFlags, bitstring_same(&data.notificationParams.changeOfLifeSafety.statusFlags,
&data2.notificationParams.changeOfLifeSafety.statusFlags)); &data2.notificationParams.changeOfLifeSafety.statusFlags));
/**********************************************************************************/ /**********************************************************************************/
@@ -1408,8 +1415,8 @@ void testEventEventState(
data.notificationParams.unsignedRange.exceededLimit == data.notificationParams.unsignedRange.exceededLimit ==
data2.notificationParams.unsignedRange.exceededLimit); data2.notificationParams.unsignedRange.exceededLimit);
ct_test(pTest, bitstring_same( ct_test(pTest,
&data.notificationParams.unsignedRange.statusFlags, bitstring_same(&data.notificationParams.unsignedRange.statusFlags,
&data2.notificationParams.unsignedRange.statusFlags)); &data2.notificationParams.unsignedRange.statusFlags));
/**********************************************************************************/ /**********************************************************************************/
@@ -1427,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;
@@ -1457,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 ==
+1 -2
View File
@@ -642,8 +642,7 @@ void test_Unconfirmed_Private_Transfer_Request(
len = uptransfer_encode_apdu(&apdu[0], &private_data); len = uptransfer_encode_apdu(&apdu[0], &private_data);
ct_test(pTest, len != 0); ct_test(pTest, len != 0);
apdu_len = len; apdu_len = len;
len = len = uptransfer_decode_apdu(&apdu[0], apdu_len, &test_data);
uptransfer_decode_apdu(&apdu[0], apdu_len, &test_data);
ct_test(pTest, len != -1); ct_test(pTest, len != -1);
ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.vendorID == private_data.vendorID);
ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber);
+2 -10
View File
@@ -319,22 +319,14 @@ void testRingBuf(
} }
ct_test(pTest, Ringbuf_Empty(&test_buffer)); ct_test(pTest, Ringbuf_Empty(&test_buffer));
testRingAroundBuffer( testRingAroundBuffer(pTest, &test_buffer, data_element, element_size,
pTest,
&test_buffer,
data_element,
element_size,
element_count); element_count);
/* adjust the internal index of Ringbuf to test unsigned wrapping */ /* adjust the internal index of Ringbuf to test unsigned wrapping */
test_buffer.head = UINT_MAX - 1; test_buffer.head = UINT_MAX - 1;
test_buffer.tail = UINT_MAX - 1; test_buffer.tail = UINT_MAX - 1;
testRingAroundBuffer( testRingAroundBuffer(pTest, &test_buffer, data_element, element_size,
pTest,
&test_buffer,
data_element,
element_size,
element_count); element_count);
return; return;
+50 -45
View File
@@ -33,7 +33,9 @@
/** @file wpm.c Encode/Decode BACnet Write Property Multiple APDUs */ /** @file wpm.c Encode/Decode BACnet Write Property Multiple APDUs */
/* decode service */ /* decode service */
int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len, int wpm_decode_object_id(
uint8_t * apdu,
uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * data) BACNET_WRITE_PROPERTY_DATA * data)
{ {
uint8_t tag_number = 0; uint8_t tag_number = 0;
@@ -42,27 +44,26 @@ int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len,
uint16_t object_type = 0; uint16_t object_type = 0;
uint16_t len = 0; uint16_t len = 0;
if((apdu )&& (apdu_len)) if ((apdu) && (apdu_len)) {
{
/* Context tag 0 - Object ID */ /* Context tag 0 - Object ID */
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len +=
if(tag_number == 0) decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
{ if (tag_number == 0) {
len += decode_object_id(&apdu[len], &object_type, &object_instance); len +=
decode_object_id(&apdu[len], &object_type, &object_instance);
data->object_type = object_type; data->object_type = object_type;
data->object_instance = object_instance; data->object_instance = object_instance;
} } else
else
return -1; return -1;
} } else
else
return -1; return -1;
return len; return len;
} }
int wpm_decode_object_property(uint8_t * apdu, int wpm_decode_object_property(
uint8_t * apdu,
uint16_t apdu_len, uint16_t apdu_len,
BACNET_WRITE_PROPERTY_DATA * wp_data) BACNET_WRITE_PROPERTY_DATA * wp_data)
{ {
@@ -72,37 +73,37 @@ int wpm_decode_object_property(uint8_t * apdu,
int len = 0, i = 0; int len = 0, i = 0;
if((apdu) && (apdu_len) && (wp_data)) if ((apdu) && (apdu_len) && (wp_data)) {
{
wp_data->array_index = BACNET_ARRAY_ALL; wp_data->array_index = BACNET_ARRAY_ALL;
wp_data->priority = BACNET_MAX_PRIORITY; wp_data->priority = BACNET_MAX_PRIORITY;
wp_data->application_data_len = 0; wp_data->application_data_len = 0;
/* tag 0 - Property Identifier */ /* tag 0 - Property Identifier */
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len +=
if(tag_number == 0) decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
{ if (tag_number == 0) {
len += decode_enumerated(&apdu[len], len_value, &ulVal); len += decode_enumerated(&apdu[len], len_value, &ulVal);
wp_data->object_property = ulVal; wp_data->object_property = ulVal;
} } else
else
return -1; return -1;
/* tag 1 - Property Array Index - optional */ /* tag 1 - Property Array Index - optional */
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len +=
if(tag_number == 1) decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
{ if (tag_number == 1) {
len += decode_unsigned(&apdu[len], len_value, &ulVal); len += decode_unsigned(&apdu[len], len_value, &ulVal);
wp_data->array_index = ulVal; wp_data->array_index = ulVal;
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value);
} }
/* tag 2 - Property Value */ /* tag 2 - Property Value */
if((tag_number == 2) && (decode_is_opening_tag(&apdu[len-1]))) if ((tag_number == 2) && (decode_is_opening_tag(&apdu[len - 1]))) {
{
len--; len--;
wp_data->application_data_len = bacapp_data_len(&apdu[len], wp_data->application_data_len =
apdu_len - len, wp_data->object_property); bacapp_data_len(&apdu[len], apdu_len - len,
wp_data->object_property);
len++; len++;
/* copy application data */ /* copy application data */
@@ -110,30 +111,32 @@ int wpm_decode_object_property(uint8_t * apdu,
wp_data->application_data[i] = apdu[len + i]; wp_data->application_data[i] = apdu[len + i];
len += wp_data->application_data_len; len += wp_data->application_data_len;
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value);
/* closing tag 2 */ /* closing tag 2 */
if ((tag_number != 2) && (decode_is_closing_tag(&apdu[len - 1]))) if ((tag_number != 2) && (decode_is_closing_tag(&apdu[len - 1])))
return -1; return -1;
} } else
else
return -1; return -1;
/* tag 3 - Priority - optional */ /* tag 3 - Priority - optional */
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len +=
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
if (tag_number == 3) { if (tag_number == 3) {
len += decode_unsigned(&apdu[len], len_value, &ulVal); len += decode_unsigned(&apdu[len], len_value, &ulVal);
wp_data->priority = ulVal; wp_data->priority = ulVal;
} } else
else
len--; len--;
} } else
else
return -1; return -1;
return len; return len;
} }
int wpm_ack_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id) int wpm_ack_encode_apdu_init(
uint8_t * apdu,
uint8_t invoke_id)
{ {
int len = 0; int len = 0;
@@ -146,13 +149,14 @@ int wpm_ack_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id)
return len; return len;
} }
int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, int wpm_error_ack_encode_apdu(
uint8_t * apdu,
uint8_t invoke_id,
BACNET_WRITE_PROPERTY_DATA * wp_data) BACNET_WRITE_PROPERTY_DATA * wp_data)
{ {
int len = 0; int len = 0;
if (apdu) if (apdu) {
{
apdu[len++] = PDU_TYPE_ERROR; apdu[len++] = PDU_TYPE_ERROR;
apdu[len++] = invoke_id; apdu[len++] = invoke_id;
apdu[len++] = SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE; apdu[len++] = SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE;
@@ -163,15 +167,16 @@ int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id,
len += encode_closing_tag(&apdu[len], 0); len += encode_closing_tag(&apdu[len], 0);
len += encode_opening_tag(&apdu[len], 1); len += encode_opening_tag(&apdu[len], 1);
len += encode_context_object_id(&apdu[len], 0, len +=
wp_data->object_type, wp_data->object_instance); encode_context_object_id(&apdu[len], 0, wp_data->object_type,
len += encode_context_enumerated(&apdu[len], 1, wp_data->object_instance);
wp_data->object_property); len +=
encode_context_enumerated(&apdu[len], 1, wp_data->object_property);
if (wp_data->array_index != BACNET_ARRAY_ALL) if (wp_data->array_index != BACNET_ARRAY_ALL)
len += encode_context_unsigned(&apdu[len], 2, wp_data->array_index); len +=
encode_context_unsigned(&apdu[len], 2, wp_data->array_index);
len += encode_closing_tag(&apdu[len], 1); len += encode_closing_tag(&apdu[len], 1);
} }
return len; return len;
} }