Schedule sets the correct value but only in the schedule object. References are not set yet. (#1236)

Add device_moc.c to tests cmake. Thanks Steve
This commit is contained in:
GauiStori
2026-02-19 22:03:52 +01:00
committed by GitHub
parent 2874dcea5e
commit f9a0386614
4 changed files with 49 additions and 15 deletions
+1 -1
View File
@@ -406,7 +406,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */,
NULL /* Intrinsic Reporting */, NULL /* Add_List_Element */,
NULL /* Remove_List_Element */, NULL /* Create */, NULL /* Delete */,
NULL /* Timer */, Schedule_Writable_Property_List },
Schedule_Timer /* Timer */, Schedule_Writable_Property_List },
{ OBJECT_STRUCTURED_VIEW, Structured_View_Init, Structured_View_Count,
Structured_View_Index_To_Instance, Structured_View_Valid_Instance,
Structured_View_Object_Name, Structured_View_Read_Property,
+44 -14
View File
@@ -16,9 +16,11 @@
#include "bacnet/timestamp.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/device.h" /* me */
#include "bacnet/basic/object/schedule.h"
#define UNUSED(v) (void)(v)
#ifndef MAX_SCHEDULES
#define MAX_SCHEDULES 4
#endif
@@ -1027,30 +1029,58 @@ bool Schedule_In_Effective_Period(
void Schedule_Recalculate_PV(
SCHEDULE_DESCR *desc, BACNET_WEEKDAY wday, const BACNET_TIME *time)
{
int i;
int i, current, diff;
BACNET_TIME *tmptime;
desc->Present_Value.tag = BACNET_APPLICATION_TAG_NULL;
/* for future development, here should be the loop for Exception Schedule */
/* Note to developers: please ping Edward at info@connect-ex.com
for a more complete schedule object implementation. */
for (i = 0; i < desc->Weekly_Schedule[wday - 1].TV_Count &&
desc->Present_Value.tag == BACNET_APPLICATION_TAG_NULL;
i++) {
int diff = datetime_wildcard_compare_time(
current = -1;
tmptime = NULL;
for (i = 0; i < desc->Weekly_Schedule[wday - 1].TV_Count; i++) {
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) {
bacnet_primitive_to_application_data_value(
&desc->Present_Value,
&desc->Weekly_Schedule[wday - 1].Time_Values[i].Value);
if (diff >= 0) {
if (tmptime == NULL) {
tmptime = &desc->Weekly_Schedule[wday - 1].Time_Values[i].Time;
current = i;
} else {
diff = datetime_wildcard_compare_time(
&desc->Weekly_Schedule[wday - 1].Time_Values[i].Time,
tmptime);
if (diff >= 0) {
tmptime =
&desc->Weekly_Schedule[wday - 1].Time_Values[i].Time;
current = i;
}
}
}
}
if (desc->Present_Value.tag == BACNET_APPLICATION_TAG_NULL) {
if (current >= 0) {
bacnet_primitive_to_application_data_value(
&desc->Present_Value,
&desc->Weekly_Schedule[wday - 1].Time_Values[current].Value);
} else {
memcpy(
&desc->Present_Value, &desc->Schedule_Default,
sizeof(desc->Present_Value));
}
}
/**
* @brief Updates the Present Value of the Schedule object
* @param object_instance - object-instance number of the object
* @param milliseconds - Unused parameter
*/
void Schedule_Timer(uint32_t object_instance, uint16_t milliseconds)
{
BACNET_DATE_TIME bdatetime;
UNUSED(milliseconds);
Device_getCurrentDateTime(&bdatetime);
Schedule_Recalculate_PV(
Schedule_Object(object_instance), bdatetime.date.wday, &bdatetime.time);
}
+3
View File
@@ -147,6 +147,9 @@ BACNET_STACK_EXPORT
void Schedule_Recalculate_PV(
SCHEDULE_DESCR *desc, BACNET_WEEKDAY wday, const BACNET_TIME *time);
BACNET_STACK_EXPORT
void Schedule_Timer(uint32_t object_instance, uint16_t milliseconds);
#ifdef __cplusplus
}
#endif /* __cplusplus */
@@ -69,6 +69,7 @@ add_executable(${PROJECT_NAME}
# Test and test library files
./src/main.c
${TST_DIR}/bacnet/basic/object/test/property_test.c
${TST_DIR}/bacnet/basic/object/test/device_mock.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)