Schedule encoding/decoding (#319)
* schedule: add decode_daily_schedule() and encode_daily_schedule() * schedule: encode/decode implemented + add to bacapp * add safe encode/decode functions for timevalue, schedule function renaming * fix unit tests build failing * add IDEA and test temporary files to .gitignore * try to make "deprecated" work in MSVC * add WeeklySchedule compare function * add bacnet_weeklyschedule_context_decode() * Add basic test for WeeklySchedule * Fix WeeklySchedule parsing and snprintf, decoder verified with real hardware * try to fix windows build * improve boolean parsing in 'bacapp_parse_application_data' * add parse function for weekly schedule * allow types > 16 in bacwp, show the decoded value before sending * add bacapp binaries to gitignore * remove bacwp logging * Add error checking to bacapp_parse_application_data * try to fix windows build * fix avr build * Fix error handling in RP Ack * add singleDay flag * show day name in single day weeklyschedule snprintf * show weeklyschedule inner tag in snprintf * improve weeklyschedule parsing and printing, supports type names now * add weekly schedule to bacapp_decode_data * move bacnet/bacnet_plat_compat.h to bacnet/basic/sys/platform.h * disable tag limit also in bacwpm * add ifdef's around strtoX helper functions in bacapp * move strtox to BACAPP_PRINT_ENABLED ifdef in bacapp * fix stm32 makefiles * fix at91sam7s build * use BACNET_UNSIGNED_INTEGER in BACnet_Short_Application_Data_Value * fix capitalization in BACnet_Daily_Schedule * add name to BACNET_TIME_VALUE struct * change bacwp bacwpm to use bacapp_known_property_tag() * fix some macros in bacdcode missing parentheses * Remove dummy fields from BACNET_SHORT_APPLICATION_DATA_VALUE, replace remaining uses of upcasting (adds extra overhead but is maybe safer), rename short DV to Primitive * fix new ci warnings * more fixes for ancient C * fix tests no longer building * primitive value renamed to shorter name
This commit is contained in:
@@ -86,10 +86,10 @@ void Schedule_Init(void)
|
||||
for (j = 0; j < 7; j++) {
|
||||
psched->Weekly_Schedule[j].TV_Count = 0;
|
||||
}
|
||||
psched->Present_Value = &psched->Schedule_Default;
|
||||
memcpy(&psched->Present_Value, &psched->Schedule_Default, sizeof(psched->Present_Value));
|
||||
psched->Schedule_Default.context_specific = false;
|
||||
psched->Schedule_Default.tag = BACNET_APPLICATION_TAG_REAL;
|
||||
psched->Schedule_Default.type.Real = 21.0; /* 21 C, room temperature */
|
||||
psched->Schedule_Default.type.Real = 21.0f; /* 21 C, room temperature */
|
||||
psched->obj_prop_ref_cnt = 0; /* no references, add as needed */
|
||||
psched->Priority_For_Writing = 16; /* lowest priority */
|
||||
psched->Out_Of_Service = false;
|
||||
@@ -197,7 +197,7 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
apdu_len = encode_application_enumerated(&apdu[0], OBJECT_SCHEDULE);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
apdu_len = bacapp_encode_data(&apdu[0], CurrentSC->Present_Value);
|
||||
apdu_len = bacapp_encode_data(&apdu[0], &CurrentSC->Present_Value);
|
||||
break;
|
||||
case PROP_EFFECTIVE_PERIOD:
|
||||
/* BACnet Testing Observed Incident oi00110
|
||||
@@ -224,7 +224,7 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
for (i = 0; i < CurrentSC->Weekly_Schedule[day].TV_Count;
|
||||
i++) {
|
||||
apdu_len += bacapp_encode_time_value(&apdu[apdu_len],
|
||||
apdu_len += bacnet_time_value_encode(&apdu[apdu_len],
|
||||
&CurrentSC->Weekly_Schedule[day].Time_Values[i]);
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
@@ -233,7 +233,7 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
int day = rpdata->array_index - 1;
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
for (i = 0; i < CurrentSC->Weekly_Schedule[day].TV_Count; i++) {
|
||||
apdu_len += bacapp_encode_time_value(&apdu[apdu_len],
|
||||
apdu_len += bacnet_time_value_encode(&apdu[apdu_len],
|
||||
&CurrentSC->Weekly_Schedule[day].Time_Values[i]);
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
|
||||
@@ -396,7 +396,7 @@ void Schedule_Recalculate_PV(
|
||||
SCHEDULE_DESCR *desc, BACNET_WEEKDAY wday, BACNET_TIME *time)
|
||||
{
|
||||
int i;
|
||||
desc->Present_Value = NULL;
|
||||
desc->Present_Value.tag = BACNET_APPLICATION_TAG_NULL;
|
||||
|
||||
/* for future development, here should be the loop for Exception Schedule */
|
||||
|
||||
@@ -408,19 +408,19 @@ void Schedule_Recalculate_PV(
|
||||
broker an early release on a case-by-case basis. */
|
||||
|
||||
for (i = 0; i < desc->Weekly_Schedule[wday - 1].TV_Count &&
|
||||
desc->Present_Value == NULL;
|
||||
desc->Present_Value.tag == BACNET_APPLICATION_TAG_NULL;
|
||||
i++) {
|
||||
int diff = datetime_wildcard_compare_time(
|
||||
time, &desc->Weekly_Schedule[wday - 1].Time_Values[i].Time);
|
||||
if (diff >= 0 &&
|
||||
desc->Weekly_Schedule[wday - 1].Time_Values[i].Value.tag !=
|
||||
BACNET_APPLICATION_TAG_NULL) {
|
||||
desc->Present_Value =
|
||||
&desc->Weekly_Schedule[wday - 1].Time_Values[i].Value;
|
||||
bacnet_primitive_to_application_data_value(&desc->Present_Value,
|
||||
&desc->Weekly_Schedule[wday - 1].Time_Values[i].Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (desc->Present_Value == NULL) {
|
||||
desc->Present_Value = &desc->Schedule_Default;
|
||||
if (desc->Present_Value.tag == BACNET_APPLICATION_TAG_NULL) {
|
||||
memcpy(&desc->Present_Value, &desc->Schedule_Default, sizeof(desc->Present_Value));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user