|
1 /************************************************************************** |
|
2 * |
|
3 * Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net> |
|
4 * Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com> |
|
5 * Copyright (C) 2017 Mario de Sousa <msousa@fe.up.pt> |
|
6 * |
|
7 * Permission is hereby granted, free of charge, to any person obtaining |
|
8 * a copy of this software and associated documentation files (the |
|
9 * "Software"), to deal in the Software without restriction, including |
|
10 * without limitation the rights to use, copy, modify, merge, publish, |
|
11 * distribute, sublicense, and/or sell copies of the Software, and to |
|
12 * permit persons to whom the Software is furnished to do so, subject to |
|
13 * the following conditions: |
|
14 * |
|
15 * The above copyright notice and this permission notice shall be included |
|
16 * in all copies or substantial portions of the Software. |
|
17 * |
|
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
25 * |
|
26 *********************************************************************/ |
|
27 |
|
28 /* Analog Output Objects - customize for your use */ |
|
29 |
|
30 #include <stdbool.h> |
|
31 #include <stdint.h> |
|
32 #include <stdio.h> |
|
33 #include <string.h> |
|
34 #include <math.h> /* NAN maro */ |
|
35 |
|
36 #include "config_bacnet_for_beremiz_%(locstr)s.h" /* the custom configuration for beremiz plugin */ |
|
37 #include "bacdef.h" |
|
38 #include "bacdcode.h" |
|
39 #include "bacenum.h" |
|
40 #include "bacapp.h" |
|
41 #include "bactext.h" |
|
42 #include "device_%(locstr)s.h" |
|
43 #include "handlers.h" |
|
44 #include "ao_%(locstr)s.h" |
|
45 |
|
46 /* we choose to have a NULL level in our system represented by */ |
|
47 /* a particular value. When the priorities are not in use, they */ |
|
48 /* will be relinquished (i.e. set to the NULL level). */ |
|
49 /* Since the values are floats, we use NAN (Not A Number) as our NULL value. */ |
|
50 /* WARNING: Never use comparisons like 'if (value == AO_LEVEL_NULL)' |
|
51 * as it will always return false, even if both values are NAN. |
|
52 * Use instead the negated version 'if (value != AO_LEVEL_NULL)' |
|
53 * and add an 'else' to the 'if' condition if necessary. |
|
54 * However, some compilers may screw this up if they do not |
|
55 * implement IEEE 754 properly. It is probably best to stick with |
|
56 * the isnan() macro if available. |
|
57 */ |
|
58 #define AO_VALUE_NULL NAN |
|
59 #define AO_VALUE_IS_NULL(x) (isnan(x)) |
|
60 /* When all the priorities are level null, the present value returns */ |
|
61 /* the Relinquish Default value */ |
|
62 #define AO_VALUE_RELINQUISH_DEFAULT (0.0) |
|
63 |
|
64 |
|
65 /* The IEC 61131-3 located variables mapped onto the Analog Output objects of BACnet protocol */ |
|
66 %(AO_lvars)s |
|
67 |
|
68 |
|
69 /* The array where we keep all the state related to the Analog Output Objects */ |
|
70 #define MAX_ANALOG_OUTPUTS %(AO_count)s |
|
71 static ANALOG_OUTPUT_DESCR AO_Descr[MAX_ANALOG_OUTPUTS] = { |
|
72 %(AO_param)s |
|
73 }; |
|
74 |
|
75 |
|
76 /* These three arrays are used by the ReadPropertyMultiple handler, |
|
77 * as well as to initialize the XXX_Property_List used by the |
|
78 * Property List (PROP_PROPERTY_LIST) property. |
|
79 */ |
|
80 static const int Analog_Output_Properties_Required[] = { |
|
81 /* (1) Currently Supported */ |
|
82 /* (2) Required by standard ASHRAE 135-2016 */ |
|
83 /*(1)(2) */ |
|
84 PROP_OBJECT_IDENTIFIER, /* R R ( 75) */ |
|
85 PROP_OBJECT_NAME, /* R R ( 77) */ |
|
86 PROP_OBJECT_TYPE, /* R R ( 79) */ |
|
87 PROP_PRESENT_VALUE, /* W W ( 85) */ |
|
88 PROP_STATUS_FLAGS, /* R R (111) */ |
|
89 PROP_EVENT_STATE, /* R R ( 36) */ |
|
90 PROP_OUT_OF_SERVICE, /* W R ( 81) */ |
|
91 PROP_UNITS, /* W R (117) */ |
|
92 PROP_PRIORITY_ARRAY, /* R R ( 87) */ |
|
93 PROP_RELINQUISH_DEFAULT, /* R R (104) */ |
|
94 // PROP_PROPERTY_LIST, /* R R (371) */ |
|
95 // PROP_CURRENT_COMMAND_PRIORITY,/* R R (431) */ |
|
96 -1 |
|
97 }; |
|
98 |
|
99 static const int Analog_Output_Properties_Optional[] = { |
|
100 /* (1) Currently Supported */ |
|
101 /* (2) Required by standard ASHRAE 135-2016 */ |
|
102 /*(1)(2) */ |
|
103 PROP_DESCRIPTION, /* R O ( 28) */ |
|
104 -1 |
|
105 }; |
|
106 |
|
107 static const int Analog_Output_Properties_Proprietary[] = { |
|
108 -1 |
|
109 }; |
|
110 |
|
111 /* This array stores the PROPERTY_LIST which may be read by clients. |
|
112 * End of list is marked by following the last element with the value '-1' |
|
113 * |
|
114 * It is initialized by Analog_Outputs_Init() based off the values |
|
115 * stored in Analog_Output_Properties_Required |
|
116 * Analog_Output_Properties_Optional |
|
117 * Analog_Output_Properties_Proprietary |
|
118 */ |
|
119 /* TODO: Allocate memory for this array with malloc() at startup */ |
|
120 static int Analog_Output_Properties_List[64]; |
|
121 |
|
122 |
|
123 |
|
124 /********************************************************/ |
|
125 /** Callback functions. **/ |
|
126 /** Functions required by BACnet devie implementation. **/ |
|
127 /********************************************************/ |
|
128 |
|
129 |
|
130 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
131 void Analog_Output_Property_Lists( |
|
132 const int **pRequired, |
|
133 const int **pOptional, |
|
134 const int **pProprietary) |
|
135 { |
|
136 if (pRequired) |
|
137 *pRequired = Analog_Output_Properties_Required; |
|
138 if (pOptional) |
|
139 *pOptional = Analog_Output_Properties_Optional; |
|
140 if (pProprietary) |
|
141 *pProprietary = Analog_Output_Properties_Proprietary; |
|
142 |
|
143 return; |
|
144 } |
|
145 |
|
146 |
|
147 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
148 void Analog_Output_Init( |
|
149 void) |
|
150 { |
|
151 unsigned i, j; |
|
152 static bool initialized = false; |
|
153 |
|
154 if (!initialized) { |
|
155 initialized = true; |
|
156 |
|
157 /* initialize the Analog_Output_Properties_List array */ |
|
158 int len = 0; |
|
159 len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len, |
|
160 Analog_Output_Properties_Required); |
|
161 len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len, |
|
162 Analog_Output_Properties_Optional); |
|
163 len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len, |
|
164 Analog_Output_Properties_Proprietary); |
|
165 |
|
166 for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) { |
|
167 // MJS: the following line in th original demo code was commented out so we do not |
|
168 // overwrite the initial values configured by the user in beremiz IDE |
|
169 // memset(&AO_Descr[i], 0x00, sizeof(ANALOG_OUTPUT_DESCR)); |
|
170 for (j = 0; j < BACNET_MAX_PRIORITY; j++) { |
|
171 AO_Descr[i].Present_Value[j] = AO_VALUE_NULL; |
|
172 } |
|
173 AO_Descr[i].Out_Of_Service = 0; |
|
174 AO_Descr[i].Event_State = 0; |
|
175 // AO_Descr[i].Units = UNITS_NO_UNITS; |
|
176 } |
|
177 } |
|
178 } |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 /* validate that the given instance exists */ |
|
184 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
185 bool Analog_Output_Valid_Instance( |
|
186 uint32_t object_instance) |
|
187 { |
|
188 return (Analog_Output_Instance_To_Index(object_instance) < MAX_ANALOG_OUTPUTS); |
|
189 } |
|
190 |
|
191 /* the number of Analog Output Objects */ |
|
192 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
193 unsigned Analog_Output_Count(void) {return MAX_ANALOG_OUTPUTS;} |
|
194 |
|
195 |
|
196 /* returns the instance (i.e. Object Identifier) that correlates to the correct index */ |
|
197 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
198 uint32_t Analog_Output_Index_To_Instance(unsigned index) {return AO_Descr[index].Object_Identifier;} |
|
199 |
|
200 |
|
201 |
|
202 /* returns the index that correlates to the correct instance number (Object Identifier) */ |
|
203 unsigned Analog_Output_Instance_To_Index( |
|
204 uint32_t object_instance) |
|
205 { |
|
206 unsigned index = 0; |
|
207 |
|
208 for (index = 0; index < MAX_ANALOG_OUTPUTS; index++) |
|
209 if (object_instance == AO_Descr[index].Object_Identifier) |
|
210 return index; |
|
211 |
|
212 /* error, this object ID is not in our list! */ |
|
213 return MAX_ANALOG_OUTPUTS; |
|
214 } |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 float Analog_Output_Present_Value( |
|
220 uint32_t object_instance) |
|
221 { |
|
222 float value = AO_VALUE_RELINQUISH_DEFAULT; |
|
223 unsigned index = 0; |
|
224 unsigned i = 0; |
|
225 |
|
226 index = Analog_Output_Instance_To_Index(object_instance); |
|
227 if (index < MAX_ANALOG_OUTPUTS) { |
|
228 for (i = 0; i < BACNET_MAX_PRIORITY; i++) { |
|
229 if (!AO_VALUE_IS_NULL(AO_Descr[index].Present_Value[i])) { |
|
230 value = AO_Descr[index].Present_Value[i]; |
|
231 break; |
|
232 } |
|
233 } |
|
234 } |
|
235 |
|
236 return value; |
|
237 } |
|
238 |
|
239 |
|
240 |
|
241 /* returns command priority (1..16), or 0 if all priority values are at NULL */ |
|
242 int Analog_Output_Current_Command_Priority( |
|
243 uint32_t object_instance) |
|
244 { |
|
245 unsigned index = 0; |
|
246 unsigned i = 0; |
|
247 |
|
248 index = Analog_Output_Instance_To_Index(object_instance); |
|
249 if (index < MAX_ANALOG_OUTPUTS) { |
|
250 for (i = 0; i < BACNET_MAX_PRIORITY; i++) { |
|
251 if (!AO_VALUE_IS_NULL(AO_Descr[index].Present_Value[i])) { |
|
252 return i+1; // +1 since priority is 1..16, and not 0..15 |
|
253 } |
|
254 } |
|
255 } |
|
256 // command values in all priorities are set to NULL |
|
257 return 0; |
|
258 } |
|
259 |
|
260 |
|
261 |
|
262 /* For a given object instance-number, sets the present-value at a given |
|
263 * priority 1..16 (except 6, see ASHRAE 135-2016, section 19.2.2) |
|
264 */ |
|
265 bool Analog_Output_Present_Value_Set( |
|
266 uint32_t object_instance, |
|
267 float value, |
|
268 uint8_t priority) |
|
269 { |
|
270 unsigned index = 0; |
|
271 |
|
272 index = Analog_Output_Instance_To_Index(object_instance); |
|
273 if (index >= MAX_ANALOG_OUTPUTS) |
|
274 return false; |
|
275 if ((priority == 0) || (priority > BACNET_MAX_PRIORITY) || |
|
276 (priority == 6 /* reserved, ASHRAE 135-2016, section 19.2.2 */)) |
|
277 return false; |
|
278 |
|
279 priority--; |
|
280 AO_Descr[index].Present_Value[priority] = value; |
|
281 return true; |
|
282 } |
|
283 |
|
284 |
|
285 |
|
286 bool Analog_Output_Present_Value_Relinquish( |
|
287 uint32_t object_instance, |
|
288 unsigned priority) |
|
289 { |
|
290 unsigned index = 0; |
|
291 |
|
292 index = Analog_Output_Instance_To_Index(object_instance); |
|
293 if (index >= MAX_ANALOG_OUTPUTS) |
|
294 return false; |
|
295 |
|
296 if ((priority == 0) || (priority > BACNET_MAX_PRIORITY) || |
|
297 (priority == 6 /* reserved, ASHRAE 135-2016, section 19.2.2 */)) |
|
298 return false; |
|
299 |
|
300 priority--; |
|
301 AO_Descr[index].Present_Value[priority] = AO_VALUE_NULL; |
|
302 return true; |
|
303 } |
|
304 |
|
305 |
|
306 |
|
307 /* note: the object name must be unique within this device */ |
|
308 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
309 bool Analog_Output_Object_Name( |
|
310 uint32_t object_instance, |
|
311 BACNET_CHARACTER_STRING * object_name) |
|
312 { |
|
313 bool status = false; |
|
314 unsigned index = Analog_Output_Instance_To_Index(object_instance); |
|
315 |
|
316 if (index < MAX_ANALOG_OUTPUTS) |
|
317 status = characterstring_init_ansi(object_name, AO_Descr[index].Object_Name); |
|
318 |
|
319 return status; |
|
320 } |
|
321 |
|
322 |
|
323 |
|
324 bool Analog_Output_Object_Description( |
|
325 uint32_t object_instance, |
|
326 BACNET_CHARACTER_STRING * object_name) |
|
327 { |
|
328 bool status = false; |
|
329 unsigned index = Analog_Output_Instance_To_Index(object_instance); |
|
330 |
|
331 if (index < MAX_ANALOG_OUTPUTS) |
|
332 status = characterstring_init_ansi(object_name, AO_Descr[index].Description); |
|
333 |
|
334 return status; |
|
335 } |
|
336 |
|
337 |
|
338 |
|
339 /* return apdu len, or BACNET_STATUS_ERROR on error */ |
|
340 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
341 int Analog_Output_Read_Property( |
|
342 BACNET_READ_PROPERTY_DATA * rpdata) |
|
343 { |
|
344 int apdu_len = 0; /* return value */ |
|
345 BACNET_BIT_STRING bit_string; |
|
346 BACNET_CHARACTER_STRING char_string; |
|
347 float real_value = (float) 1.414; |
|
348 unsigned object_index = 0; |
|
349 bool state = false; |
|
350 uint8_t *apdu = NULL; |
|
351 |
|
352 if ((rpdata == NULL) || (rpdata->application_data == NULL) || |
|
353 (rpdata->application_data_len == 0)) { |
|
354 return 0; |
|
355 } |
|
356 |
|
357 apdu = rpdata->application_data; |
|
358 |
|
359 object_index = Analog_Output_Instance_To_Index(rpdata->object_instance); |
|
360 if (object_index >= MAX_ANALOG_OUTPUTS) { |
|
361 rpdata->error_class = ERROR_CLASS_OBJECT; |
|
362 rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; |
|
363 return BACNET_STATUS_ERROR; |
|
364 } |
|
365 |
|
366 switch (rpdata->object_property) { |
|
367 case PROP_OBJECT_IDENTIFIER: |
|
368 apdu_len = |
|
369 encode_application_object_id(&apdu[0], OBJECT_ANALOG_OUTPUT, |
|
370 rpdata->object_instance); |
|
371 break; |
|
372 |
|
373 case PROP_OBJECT_NAME: |
|
374 Analog_Output_Object_Name(rpdata->object_instance, &char_string); |
|
375 apdu_len = |
|
376 encode_application_character_string(&apdu[0], &char_string); |
|
377 break; |
|
378 |
|
379 case PROP_DESCRIPTION: |
|
380 Analog_Output_Object_Description(rpdata->object_instance, &char_string); |
|
381 apdu_len = |
|
382 encode_application_character_string(&apdu[0], &char_string); |
|
383 break; |
|
384 |
|
385 case PROP_OBJECT_TYPE: |
|
386 apdu_len = |
|
387 encode_application_enumerated(&apdu[0], OBJECT_ANALOG_OUTPUT); |
|
388 break; |
|
389 |
|
390 case PROP_PRESENT_VALUE: |
|
391 real_value = Analog_Output_Present_Value(rpdata->object_instance); |
|
392 apdu_len = encode_application_real(&apdu[0], real_value); |
|
393 break; |
|
394 |
|
395 case PROP_STATUS_FLAGS: |
|
396 bitstring_init(&bit_string); |
|
397 bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); |
|
398 bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); |
|
399 bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); |
|
400 bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, |
|
401 AO_Descr[object_index].Out_Of_Service); |
|
402 |
|
403 apdu_len = encode_application_bitstring(&apdu[0], &bit_string); |
|
404 break; |
|
405 |
|
406 case PROP_EVENT_STATE: |
|
407 apdu_len = |
|
408 encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); |
|
409 break; |
|
410 |
|
411 case PROP_OUT_OF_SERVICE: |
|
412 state = AO_Descr[object_index].Out_Of_Service; |
|
413 apdu_len = encode_application_boolean(&apdu[0], state); |
|
414 break; |
|
415 |
|
416 case PROP_PRIORITY_ARRAY: |
|
417 BACnet_encode_array(AO_Descr[object_index].Present_Value, |
|
418 BACNET_MAX_PRIORITY, |
|
419 AO_VALUE_IS_NULL, |
|
420 encode_application_real) |
|
421 break; |
|
422 |
|
423 // case PROP_CURRENT_COMMAND_PRIORITY: { |
|
424 // unsigned i = Analog_Output_Current_Command_Priority(rpdata->object_instance); |
|
425 // if (i == 0) apdu_len = encode_application_null (&apdu[0]); |
|
426 // else apdu_len = encode_application_unsigned(&apdu[0], i); |
|
427 // break; |
|
428 // } |
|
429 |
|
430 case PROP_RELINQUISH_DEFAULT: |
|
431 real_value = AO_VALUE_RELINQUISH_DEFAULT; |
|
432 apdu_len = encode_application_real(&apdu[0], real_value); |
|
433 break; |
|
434 |
|
435 case PROP_UNITS: |
|
436 apdu_len = |
|
437 encode_application_enumerated(&apdu[0], AO_Descr[object_index].Units); |
|
438 break; |
|
439 |
|
440 // case PROP_PROPERTY_LIST: |
|
441 // BACnet_encode_array(Analog_Output_Properties_List, |
|
442 // property_list_count(Analog_Output_Properties_List), |
|
443 // retfalse, encode_application_enumerated); |
|
444 // break; |
|
445 default: |
|
446 rpdata->error_class = ERROR_CLASS_PROPERTY; |
|
447 rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; |
|
448 apdu_len = BACNET_STATUS_ERROR; |
|
449 break; |
|
450 } |
|
451 /* only array properties can have array options */ |
|
452 if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) && |
|
453 (rpdata->object_property != PROP_EVENT_TIME_STAMPS) && |
|
454 // (rpdata->object_property != PROP_PROPERTY_LIST) && |
|
455 (rpdata->array_index != BACNET_ARRAY_ALL)) { |
|
456 rpdata->error_class = ERROR_CLASS_PROPERTY; |
|
457 rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; |
|
458 apdu_len = BACNET_STATUS_ERROR; |
|
459 } |
|
460 |
|
461 return apdu_len; |
|
462 } |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 /* returns true if successful */ |
|
468 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ |
|
469 bool Analog_Output_Write_Property( |
|
470 BACNET_WRITE_PROPERTY_DATA * wp_data) |
|
471 { |
|
472 bool status = false; /* return value */ |
|
473 unsigned int object_index = 0; |
|
474 int len = 0; |
|
475 BACNET_APPLICATION_DATA_VALUE value; |
|
476 ANALOG_OUTPUT_DESCR *CurrentAO; |
|
477 |
|
478 /* decode the some of the request */ |
|
479 len = |
|
480 bacapp_decode_application_data(wp_data->application_data, |
|
481 wp_data->application_data_len, &value); |
|
482 /* FIXME: len < application_data_len: more data? */ |
|
483 if (len < 0) { |
|
484 /* error while decoding - a value larger than we can handle */ |
|
485 wp_data->error_class = ERROR_CLASS_PROPERTY; |
|
486 wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; |
|
487 return false; |
|
488 } |
|
489 if ((wp_data->object_property != PROP_PRIORITY_ARRAY) && |
|
490 (wp_data->object_property != PROP_EVENT_TIME_STAMPS) && |
|
491 (wp_data->array_index != BACNET_ARRAY_ALL)) { |
|
492 /* only array properties can have array options */ |
|
493 wp_data->error_class = ERROR_CLASS_PROPERTY; |
|
494 wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; |
|
495 return false; |
|
496 } |
|
497 object_index = Analog_Output_Instance_To_Index(wp_data->object_instance); |
|
498 if (object_index < MAX_ANALOG_OUTPUTS) |
|
499 CurrentAO = &AO_Descr[object_index]; |
|
500 else |
|
501 return false; |
|
502 |
|
503 switch (wp_data->object_property) { |
|
504 case PROP_PRESENT_VALUE: |
|
505 if (value.tag == BACNET_APPLICATION_TAG_REAL) { |
|
506 if (Analog_Output_Present_Value_Set(wp_data->object_instance, |
|
507 value.type.Real, wp_data->priority)) { |
|
508 status = true; |
|
509 } else if (wp_data->priority == 6) { |
|
510 /* Command priority 6 is reserved for use by Minimum On/Off |
|
511 algorithm and may not be used for other purposes in any |
|
512 object. */ |
|
513 wp_data->error_class = ERROR_CLASS_PROPERTY; |
|
514 wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; |
|
515 } else { |
|
516 wp_data->error_class = ERROR_CLASS_PROPERTY; |
|
517 wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; |
|
518 } |
|
519 } else { |
|
520 status = |
|
521 WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, |
|
522 &wp_data->error_class, &wp_data->error_code); |
|
523 if (status) { |
|
524 status = |
|
525 Analog_Output_Present_Value_Relinquish |
|
526 (wp_data->object_instance, wp_data->priority); |
|
527 } |
|
528 if (!status) { |
|
529 wp_data->error_class = ERROR_CLASS_PROPERTY; |
|
530 wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; |
|
531 } |
|
532 } |
|
533 break; |
|
534 |
|
535 case PROP_OUT_OF_SERVICE: |
|
536 { |
|
537 bool Previous_Out_Of_Service = CurrentAO->Out_Of_Service; |
|
538 status = |
|
539 WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, |
|
540 &wp_data->error_class, &wp_data->error_code); |
|
541 if (status) { |
|
542 CurrentAO->Out_Of_Service = value.type.Boolean; |
|
543 if (Previous_Out_Of_Service && !CurrentAO->Out_Of_Service) |
|
544 /* We have just changed from Out_of_Service -> In Service */ |
|
545 /* We need to update the Present_Value to the value |
|
546 * currently in the PLC... |
|
547 */ |
|
548 CurrentAO->Present_Value[BACNET_MAX_PRIORITY-1] = |
|
549 *(CurrentAO->Located_Var_ptr); |
|
550 } |
|
551 break; |
|
552 } |
|
553 |
|
554 case PROP_UNITS: |
|
555 status = |
|
556 WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, |
|
557 &wp_data->error_class, &wp_data->error_code); |
|
558 if (status) { |
|
559 CurrentAO->Units = value.type.Enumerated; |
|
560 } |
|
561 break; |
|
562 |
|
563 case PROP_OBJECT_IDENTIFIER: |
|
564 case PROP_OBJECT_NAME: |
|
565 case PROP_OBJECT_TYPE: |
|
566 case PROP_STATUS_FLAGS: |
|
567 case PROP_EVENT_STATE: |
|
568 case PROP_DESCRIPTION: |
|
569 case PROP_RELINQUISH_DEFAULT: |
|
570 case PROP_PRIORITY_ARRAY: |
|
571 // case PROP_PROPERTY_LIST: |
|
572 // case PROP_CURRENT_COMMAND_PRIORITY: |
|
573 wp_data->error_class = ERROR_CLASS_PROPERTY; |
|
574 wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; |
|
575 break; |
|
576 default: |
|
577 wp_data->error_class = ERROR_CLASS_PROPERTY; |
|
578 wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; |
|
579 break; |
|
580 } |
|
581 |
|
582 return status; |
|
583 } |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 /********************************************/ |
|
592 /** Functions required for Beremiz plugin **/ |
|
593 /********************************************/ |
|
594 |
|
595 void Analog_Output_Copy_Present_Value_to_Located_Var(void) { |
|
596 unsigned i; |
|
597 for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) { |
|
598 // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true |
|
599 if (AO_Descr[i].Out_Of_Service) |
|
600 continue; |
|
601 |
|
602 // copy the value |
|
603 *(AO_Descr[i].Located_Var_ptr) = Analog_Output_Present_Value(AO_Descr[i].Object_Identifier); |
|
604 } |
|
605 } |
|
606 |
|
607 |
|
608 |
|
609 void Analog_Output_Copy_Located_Var_to_Present_Value(void) { |
|
610 unsigned i; |
|
611 for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) { |
|
612 // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true |
|
613 if (AO_Descr[i].Out_Of_Service) |
|
614 continue; |
|
615 |
|
616 // copy the value |
|
617 AO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] = *(AO_Descr[i].Located_Var_ptr); |
|
618 } |
|
619 } |
|
620 |