Building Controls Virtual Test Bed
BACnetDeviceManager.java
Go to the documentation of this file.
1 /*
2 ********************************************************************
3 Copyright Notice
4 ----------------
5 
6 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
7 Regents of the University of California, through Lawrence Berkeley
8 National Laboratory (subject to receipt of any required approvals from
9 the U.S. Dept. of Energy). All rights reserved.
10 
11 If you have questions about your rights to use or distribute this
12 software, please contact Berkeley Lab's Technology Transfer Department
13 at TTD@lbl.gov
14 
15 NOTICE. This software was developed under partial funding from the U.S.
16 Department of Energy. As such, the U.S. Government has been granted for
17 itself and others acting on its behalf a paid-up, nonexclusive,
18 irrevocable, worldwide license in the Software to reproduce, prepare
19 derivative works, and perform publicly and display publicly. Beginning
20 five (5) years after the date permission to assert copyright is obtained
21 from the U.S. Department of Energy, and subject to any subsequent five
22 (5) year renewals, the U.S. Government is granted for itself and others
23 acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide
24 license in the Software to reproduce, prepare derivative works,
25 distribute copies to the public, perform publicly and display publicly,
26 and to permit others to do so.
27 
28 
29 Modified BSD License agreement
30 ------------------------------
31 
32 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
33 Regents of the University of California, through Lawrence Berkeley
34 National Laboratory (subject to receipt of any required approvals from
35 the U.S. Dept. of Energy). All rights reserved.
36 
37 Redistribution and use in source and binary forms, with or without
38 modification, are permitted provided that the following conditions are met:
39 
40  1. Redistributions of source code must retain the above copyright
41  notice, this list of conditions and the following disclaimer.
42  2. Redistributions in binary form must reproduce the above copyright
43  notice, this list of conditions and the following disclaimer in
44  the documentation and/or other materials provided with the
45  distribution.
46  3. Neither the name of the University of California, Lawrence
47  Berkeley National Laboratory, U.S. Dept. of Energy nor the names
48  of its contributors may be used to endorse or promote products
49  derived from this software without specific prior written permission.
50 
51 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
52 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
53 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
54 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
55 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
58 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
59 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
60 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 
63 You are under no obligation whatsoever to provide any bug fixes,
64 patches, or upgrades to the features, functionality or performance of
65 the source code ("Enhancements") to anyone; however, if you choose to
66 make your Enhancements available either publicly, or directly to
67 Lawrence Berkeley National Laboratory, without imposing a separate
68 written license agreement for such Enhancements, then you hereby grant
69 the following license: a non-exclusive, royalty-free perpetual license
70 to install, use, modify, prepare derivative works, incorporate into
71 other computer software, distribute, and sublicense such enhancements or
72 derivative works thereof, in binary and source code form.
73 
74 ********************************************************************
75 */
76 package bacnet.util;
77 
78 import ptolemy.kernel.util.IllegalActionException;
79 
80 import java.io.FileNotFoundException;
81 import java.io.IOException;
82 import java.util.ArrayList;
83 import java.io.File;
84 import java.io.InputStreamReader;
85 import java.io.Writer;
86 import java.io.InputStream;
87 import java.io.BufferedReader;
88 import java.io.ByteArrayInputStream;
89 import java.lang.IllegalThreadStateException;
90 import java.util.HashMap;
91 import java.util.Iterator;
92 import org.xml.sax.SAXParseException;
93 import javax.xml.parsers.ParserConfigurationException;
94 import javax.xml.parsers.SAXParser;
95 import javax.xml.parsers.SAXParserFactory;
96 import javax.xml.validation.Schema;
97 import javax.xml.validation.SchemaFactory;
98 import javax.xml.validation.Validator;
99 import javax.xml.transform.sax.SAXSource;
100 import javax.xml.XMLConstants;
101 import org.xml.sax.SAXException;
102 import org.xml.sax.Attributes;
103 import org.xml.sax.helpers.DefaultHandler;
104 import org.xml.sax.InputSource;
105 import javax.naming.OperationNotSupportedException;
106 
124 {
125 
127  private final static String bcvtbhome = System.getenv("BCVTB_HOME");
128 
130  private final static String LS = System.getProperty("line.separator");
131 
133  private final static String FS = System.getProperty("file.separator");
134 
136  private final static String osName= System.getProperty("os.name");
137 
142  public enum BacObjectType {
181  MaxASHRAEObjectType}
182 
187  public enum BacProperty {
188  ACKED_TRANSITIONS, ACK_REQUIRED, ACTION,
189  ACTION_TEXT, ACTIVE_TEXT, ACTIVE_VT_SESSIONS,
190  ALARM_VALUE, ALARM_VALUES,
192  APDU_SEGMENT_TIMEOUT, APDU_TIMEOUT,
194  ARCHIVE, BIAS, CHANGE_OF_STATE_COUNT,
198  CONTROLLED_VARIABLE_UNITS, CONTROLLED_VARIABLE_VALUE,
202  DERIVATIVE_CONSTANT_UNITS , DESCRIPTION ,
204  DEVICE_ADDRESS_BINDING, DEVICE_TYPE,
206  ELAPSED_ACTIVE_TIME, ERROR_LIMIT,
208  EVENT_STATE, EVENT_TYPE,
209  EXCEPTION_SCHEDULE, FAULT_VALUES,
210  FEEDBACK_VALUE, FILE_ACCESS_METHOD,
211  FILE_SIZE, FILE_TYPE,
212  FIRMWARE_REVISION, HIGH_LIMIT,
213  INACTIVE_TEXT, IN_PROCESS,
214  INSTANCE_OF, INTEGRAL_CONSTANT,
216  ISSUE_CONFIRMED_NOTIFICATIONS, LIMIT_ENABLE,
219  LIST_OF_SESSION_KEYS, LOCAL_DATE,
220  LOCAL_TIME, LOCATION, LOW_LIMIT,
222  MAXIMUM_OUTPUT, MAX_APDU_LENGTH_ACCEPTED,
224  MAX_MASTER, MAX_PRES_VALUE,
225  MINIMUM_OFF_TIME, MINIMUM_ON_TIME,
226  MINIMUM_OUTPUT, MIN_PRES_VALUE,
227  MODEL_NAME, MODIFICATION_DATE,
230  OBJECT_IDENTIFIER, OBJECT_LIST,
232  OBJECT_PROPERTY_REFERENCE, OBJECT_TYPE,
233  OPTIONAL, OUT_OF_SERVICE,
234  OUTPUT_UNITS, EVENT_PARAMETERS,
236  PRESENT_VALUE, PRIORITY,
238  PRIORITY_FOR_WRITING, PROCESS_IDENTIFIER,
240  PROGRAM_LOCATION, PROGRAM_STATE,
246  PROTOCOL_VERSION, READ_ONLY, REASON_FOR_HALT,
247  RECIPIENT, RECIPIENT_LIST, RELIABILITY,
248  RELINQUISH_DEFAULT, REQUIRED, RESOLUTION,
249  SEGMENTATION_SUPPORTED, SETPOINT,
250  SETPOINT_REFERENCE, STATE_TEXT, STATUS_FLAGS,
251  SYSTEM_STATUS, TIME_DELAY,
252  TIME_OF_ACTIVE_TIME_RESET, TIME_OF_STATE_COUNT_RESET ,
254  UNITS , UPDATE_INTERVAL ,
255  UTC_OFFSET , VENDOR_IDENTIFIER ,
256  VENDOR_NAME , VT_CLASSES_SUPPORTED ,
258  ATTEMPTED_SAMPLES , AVERAGE_VALUE ,
259  BUFFER_SIZE , CLIENT_COV_INCREMENT ,
260  COV_RESUBSCRIPTION_INTERVAL , CURRENT_NOTIFY_TIME ,
261  EVENT_TIME_STAMPS , LOG_BUFFER ,
263  ENABLE , LOG_INTERVAL ,
264  MAXIMUM_VALUE , MINIMUM_VALUE ,
265  NOTIFICATION_THRESHOLD , PREVIOUS_NOTIFY_TIME ,
266  PROTOCOL_REVISION , RECORDS_SINCE_NOTIFICATION ,
267  RECORD_COUNT , START_TIME ,
268  STOP_TIME , STOP_WHEN_FULL ,
270  VALID_SAMPLES , WINDOW_INTERVAL ,
271  WINDOW_SAMPLES , MAXIMUM_VALUE_TIMESTAMP ,
272  MINIMUM_VALUE_TIMESTAMP , VARIANCE_VALUE ,
273  ACTIVE_COV_SUBSCRIPTIONS , BACKUP_FAILURE_TIMEOUT ,
274  CONFIGURATION_FILES , DATABASE_REVISION ,
275  DIRECT_READING , LAST_RESTORE_TIME ,
277  MEMBER_OF , MODE ,
278  OPERATION_EXPECTED , SETTING , SILENCED ,
279  TRACKING_VALUE , ZONE_MEMBERS ,
280  LIFE_SAFETY_ALARM_VALUES , MAX_SEGMENTS_ACCEPTED ,
281  PROFILE_NAME , AUTO_SLAVE_DISCOVERY ,
282  MANUAL_SLAVE_ADDRESS_BINDING , SLAVE_ADDRESS_BINDING ,
283  SLAVE_PROXY_ENABLE , LAST_NOTIFY_TIME ,
284  SCHEDULE_DEFAULT , ACCEPTED_MODES ,
287  COUNT_CHANGE_TIME , COV_PERIOD ,
288  INPUT_REFERENCE , LIMIT_MONITORING_INTERVAL ,
289  LGGING_DEVICE , LOGGING_RECORD , PRESCALE ,
290  PULSE_RATE , SCALE , SCALE_FACTOR ,
291  UPDATE_TIME , VALUE_BEFORE_CHANGE , VALUE_SET ,
292  VALUE_CHANGE_TIME , ALIGN_INTERVALS ,
293  GROUP_MEMBER_NAMES , INTERVAL_OFFSET ,
294  LAST_RESTART_REASON , LOGGING_TYPE ,
295  MEMBER_STATUS_FLAGS , NOTIFICATION_PERIOD ,
296  PREVIOUS_NOTIFY_RECORD , REQUESTED_UPDATE_INTERVAL ,
299  TIME_SYNCHRONIZATION_INTERVAL , TRIGGER ,
301  NODE_TYPE , STRUCTURED_OBJECT_LIST ,
302  SUBORDINATE_ANNOTATIONS , SUBORDINATE_LIST ,
303  ACTUAL_SHED_LEVEL , DUTY_WINDOW ,
304  EXPECTED_SHED_LEVEL , FULL_DUTY_BASELINE ,
305  BLINK_PRIORITY_THRESHOLD , BLINK_TIME ,
306  REQUESTED_SHED_LEVEL , SHED_DURATION ,
307  SHED_LEVEL_DESCRIPTIONS , SHED_LEVELS ,
309  FADE_TIME , LIGHTING_COMMAND ,
311  DOOR_ALARM_STATE , DOOR_EXTENDED_PULSE_TIME ,
312  DOOR_MEMBERS , DOOR_OPEN_TOO_LONG_TIME ,
314  DOOR_STATUS , DOOR_UNLOCK_DELAY_TIME ,
315  LOCK_STATUS , MASKED_ALARM_VALUES ,
317  OFF_DELAY , ON_DELAY , POWER ,
318  POWER_ON_VALUE , PROGRESS_VALUE , RAMP_RATE ,
319  STEP_INCREMENT , SYSTEM_FAILURE_VALUE ,
320  ABSENTEE_LIMIT , ACCESS_ALARM_EVENTS ,
323  ACCESS_EVENT_CREDENTIAL , ACCESS_EVENT_TIME ,
325  ACCESS_RULES_ENABLE , ACCESS_TRANSACTION_EVENTS ,
326  ACCOMPANIED , ACTIVATION_TIME ,
332  AUTHENTICATION_POLICY_NAMES , AUTHORIZATION_MODE ,
333  BELONGS_TO , CREDENTIAL_DISABLE ,
334  CREDENTIAL_STATUS , CREDENTIALS ,
336  DAYS_REMAINING , ENTRY_POINTS ,
337  EXIT_POINTS , EXPIRY_TIME ,
339  FAILED_ATTEMPT_EVENTS , FAILED_ATTEMPTS ,
340  FAILED_ATTEMPTS_TIME , FORMAT_CLASS_SUPPORTED ,
342  LAST_ACCESS_EVENT , LAST_ACCESS_POINT ,
343  LAST_CREDENTIAL_ADDED , LAST_CREDENTIAL_ADDED_TIME ,
344  LAST_CREDENTIAL_REMOVED , LAST_CREDENTIAL_REMOVED_TIME ,
345  LAST_USE_TIME , LOCKDOWN ,
347  MASTER_EXEMPTION , MAX_FAILED_ATTEMPTS ,
348  MEMBERS , MASTER_POINT ,
350  NoProperty_292 , OCCUPANCY_COUNT ,
354  OCCUPANCY_LOWER_THRESHOLD_ENFORCED , OCCUPANCY_STATE ,
357  PASSBACK_EXEMPTION , PASSBACK_MODE ,
358  PASSBACK_TIMEOUT , POSITIVE_ACCESS_RULES ,
360  REASON_FOR_DISABLE , THREAT_AUTHORITY ,
361  THREAT_LEVEL , TRACE_FLAG,
363  USER_EXTERNAL_IDENTIFIER, CHARACTER_SET,
364  STRICT_CHARACTER_MODE, BACKUP_AND_RESTORE_STATE,
365  BACKUP_PREPARATION_TIME, RESTORE_PREPARATION_TIME,
366  USER_INFORMATION_REFERENCE, USER_NAME,
368  USES_REMAINING, VENDOR_FORMAT_IDENTIFIER,
369  ZONE_FROM, ZONE_TO, BINARY_ACTIVE_VALUE,
370  BINARY_INACTIVE_VALUE}
371 
376  public enum BacnetApplicationTag {
393  MAX_BACNET_APPLICATION_TAG
394  }
395 
404  {
405  String s = new String();
406  if(osName.startsWith("Windows"))
407  s = bcvtbhome + FS + "lib" + FS + "bacnet-stack" + FS
408  + "bin-windows" + FS + "bacrp.exe";
409  if(osName.startsWith("Linux"))
410  s = bcvtbhome + FS + "lib" + FS + "bacnet-stack" +
411  FS + "bin-linux" + FS + "bacrp";
412  return s;
413  }
414 
424  {
425  String s = new String();
426  if(osName.startsWith("Windows"))
427  s = bcvtbhome + FS + "lib" + FS + "bacnet-stack" + FS
428  + "bin-windows" + FS + "bacwp.exe";
429  if(osName.startsWith("Linux"))
430  s = bcvtbhome + FS + "lib" + FS + "bacnet-stack" +
431  FS + "bin-linux" + FS + "bacwp";
432  return s;
433  }
434 
442  public String getGlobalwiBinaryPath()
443  {
444  String s = new String();
445  if(osName.startsWith("Windows"))
446  s = bcvtbhome + FS + "lib" + FS + "bacnet-stack" + FS
447  + "bin-windows" + FS + "globalwi.exe";
448  if(osName.startsWith("Linux"))
449  s = bcvtbhome + FS + "lib" + FS + "bacnet-stack" +
450  FS + "bin-linux" + FS + "globalwi";
451  return s;
452  }
453 
462  public ArrayList<Integer> findDevice() throws IllegalActionException
463  {
464  Process p=null;
465  ArrayList<Integer> dev_array = new ArrayList<Integer>();
466  String s = getGlobalwiBinaryPath();
467  // Broadcast the globalwi
468  ProcessBuilder pb = new ProcessBuilder(s);
469  try{
470  p=pb.start();
471  }
472  catch(IOException e)
473  {
474  String em = "Error while executing bacnet stack binary: '" + s + "'."
475  + LS + e.getMessage();
476  throw new IllegalActionException(em);
477  }
478  catch(NullPointerException e)
479  {
480  String em = "Some of the command lists passed to globalwi are null.";
481  throw new IllegalActionException(em + LS + e.getMessage());
482  }
483  catch(IndexOutOfBoundsException e)
484  {
485  String em = "The command list passed to glabalwi is empty.";
486  throw new IllegalActionException(em + LS + e.getMessage());
487  }
488  catch(SecurityException e)
489  {
490  String em = "Creation of the '" + s + "' subprocess is not allowed.";
491  throw new IllegalActionException(em + LS + e.getMessage());
492  }
493 
494  // Parse the stream from globalwi
495  BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
496  String line = "";
497  try{
498  while ((line=br.readLine())!=null)
499  {
500  if(line.startsWith("Received")==false)
501  try
502  {
503  final int val = Integer.parseInt(line);
504  dev_array.add(val);
505  }
506  catch(NumberFormatException e){
507  final String em = "NumberFormatException when trying to parse '"
508  + line + "'" + LS + "to an integer. " + LS + e.getMessage();
509  throw new IllegalActionException(em);
510  }
511 
512  }
513  }
514  catch(IOException e){
515  String em = "IOException when reading output of '" + s + "'.";
516  throw new IllegalActionException(em + LS + e.getMessage());
517  }
518  int exiVal = -99;
519  try{
520  exiVal = p.waitFor();
521  }
522  catch(InterruptedException e){
523  String em = "The process of running bacnet stack" + LS
524  + "command has been interrupted" + LS +
525  e.getMessage();
526  throw new IllegalActionException(em);
527  }
528  if(exiVal != 0){
529  String em = "BACnet-stack process quit abnormally with error signal '" + exiVal + "'.";
530  throw new IllegalActionException(em);
531  }
532 
533  return dev_array;
534  }
535 
546  public ArrayList<BACnetObjectType> parseBACnetObjectType(final String s) throws
547  ParserConfigurationException, SAXException, IOException
548  {
549  ArrayList<BACnetObjectType> bot_arr = new ArrayList<BACnetObjectType>();
551  try{
552  bot_arr = bot.parseObjectType(s);
553  }
554  catch (SAXException e) {
555  String em = "Parser error occurs while parsing xml configuration file '"
556  + s + "'.";
557  throw new SAXException(em + LS + e.getMessage());
558  }
559  catch(ParserConfigurationException e)
560  {
561  String em = "SAX Parser configuration error in parsing configuration file '"
562  + s + "'.";
563  throw new ParserConfigurationException(em + LS + e.getMessage());
564  }
565  catch(IOException e)
566  {
567  final String em = "IOException when parsing configuration file '" + s + "'." +
568  LS + e.getMessage();
569  throw new IOException(em);
570  }
571  return bot_arr;
572  }
573 
584  public ArrayList<Integer> readDeviceArray(final ArrayList<BACnetObjectType> bot_arr)
585  throws NumberFormatException
586  {
587  final ArrayList<Integer> dev_array = new ArrayList<Integer>();
588  for(int i=0;i<bot_arr.size();i++)
589  {
590  BACnetObjectType bot = bot_arr.get(i);
591  if(bot.getBOTName().equals("DeviceObjectType"))
592  {
593  final String inst = bot.getBOTInst();
594  try{
595  final int inst_int = Integer.parseInt(inst);
596  dev_array.add(inst_int);
597  }
598  catch(NumberFormatException e){
599  final String em = "NumberFormatException when trying to parse '"
600  + inst + "'" + LS + "to an integer." + LS + e.getMessage();
601  throw new NumberFormatException(em);
602  }
603  }
604  }
605  dev_array.trimToSize();
606  return dev_array;
607  }
608 
609 
621  public ArrayList<BACnetObject> readObjectList(final ArrayList<BACnetObjectType> bot_arr,
622  final int dev_inst)
623  throws NumberFormatException
624  {
625  final ArrayList<BACnetObject> object_array = new ArrayList<BACnetObject>();
626  for(int i=0; i<bot_arr.size(); i++)
627  {
628  BACnetObjectType bot = bot_arr.get(i);
629  int bot_inst;
630  try{
631  bot_inst = Integer.parseInt(bot.getBOTInst());
632  }
633  catch(NumberFormatException e)
634  {
635  final String em = "NumberFormatException when trying to parse '"
636  + bot.getBOTInst() + "'" + LS + "to an integer. "
637  + LS + e.getMessage();
638  throw new NumberFormatException(em);
639  }
640  if(bot.getBOTName().equals("DeviceObjectType") &&
641  Integer.parseInt(bot.getBOTInst())==dev_inst)
642  {
643 
644  HashMap mapOTname = bot.getBACnetObjectTypeNameMap();
645  HashMap mapOTinst = bot.getBACnetObjectTypeInstanceMap();
646  for(int j=0; j<mapOTname.size(); j++)
647  {
648  String instkey = Integer.toString(j);
649  String type = mapOTname.get(instkey).toString();
650  String inst = mapOTinst.get(instkey).toString();
651  int instint;
652  try
653  {
654  instint = Integer.parseInt(inst);
655  }
656  catch(NumberFormatException e)
657  {
658  final String em =
659  "NumberFormatException when trying to parse '"
660  + inst + "'" + LS + "to an integer. "
661  + LS + e.getMessage();
662  throw new NumberFormatException(em);
663  }
664  BACnetObject bacobj = new BACnetObject(dev_inst, type,
665  instint);
666  object_array.add(bacobj);
667  }
668  }
669  }
670  return object_array;
671  }
672 
673 
684  public ArrayList<BACnetCompleteProperty> readDevicePropertyList
685  (final ArrayList<BACnetObjectType> bot_arr, final int dev_inst) throws NumberFormatException
686  {
687  ArrayList<BACnetCompleteProperty> proparr = new ArrayList<BACnetCompleteProperty>();
688  for(int i=0; i<bot_arr.size();i++)
689  {
690  BACnetObjectType bot = bot_arr.get(i);
691  int bot_inst;
692  try{
693  bot_inst = Integer.parseInt(bot.getBOTInst());
694  }
695  catch(NumberFormatException e)
696  {
697  final String em = "NumberFormatException when trying to parse '"
698  + bot.getBOTInst() + "'" + LS +
699  "to an integer. " + LS + e.getMessage();
700  throw new NumberFormatException(em);
701  }
702  if(bot.getBOTName().equals("DeviceObjectType")
703  && Integer.parseInt(bot.getBOTInst())==dev_inst)
704  {
705  ArrayList<BACnetPropertyValue> mapPI = bot.getBOTPI();
706  ArrayList<BACnetObject> objarr = new ArrayList<BACnetObject>();
707 
708  //add device property list to proparr
709  for(int j=0; j<mapPI.size(); j++)
710  {
711  BACnetPropertyValue bpv = mapPI.get(j);
712  String instkey = bpv.getName();
713  String[] prop_val = bpv.getValue();
714  String value = prop_val[0];
715  String apptag = prop_val[1];
716  String priority = prop_val[2];
717  String index = prop_val[3];
718  String botname = bot.getBOTName();
720  (dev_inst,botname,dev_inst,instkey,value,apptag,priority,index);
721  proparr.add(bcp);
722 
723  }
724  //add object property list to proparr
725  objarr = readObjectList(bot_arr,dev_inst);
726  for(int k=0; k<objarr.size(); k++)
727  {
728  BACnetObject obj = objarr.get(k);
729 
730  ArrayList<BACnetCompleteProperty> objproparr =
731  readCompleteObjectPropertyList(bot_arr,dev_inst,
732  obj.getObjectType(),
733  obj.getObjectInstance());
734  for(int l=0; l<objproparr.size();l++)
735  {
736  BACnetCompleteProperty objbcp = objproparr.get(l);
737  proparr.add(objbcp);
738  }
739  }
740  }
741  }
742  return proparr;
743  }
744 
755  public ArrayList<BACnetCompleteProperty> readCompleteObjectPropertyList(final ArrayList<BACnetObjectType> bot_arr,
756  final int dev_inst,
757  final String obj_type,
758  final int obj_inst)
759  {
760  // Object property list that will be returned
761  final ArrayList<BACnetCompleteProperty> opl = new ArrayList<BACnetCompleteProperty>();
762  for(int i=0;i<bot_arr.size();i++)
763  {
764  BACnetObjectType bot = bot_arr.get(i);
765  if(bot.getBOTName().equals(obj_type) && bot.getBOTInst().equals(Integer.toString(obj_inst)))
766  {
767  HashMap mapOTinst = bot.getBACnetObjectTypeInstanceMap();
768  ArrayList<BACnetPropertyValue> mapPI = bot.getBOTPI();
769  if(mapOTinst.get(Integer.toString(obj_inst)).equals(Integer.toString(dev_inst)))
770  {
771  for(int j=0; j<mapPI.size(); j++)
772  {
773  final BACnetPropertyValue bpv = mapPI.get(j);
774  final String instkey = bpv.getName();
775  final String[] prop_val = bpv.getValue();
776  final String value = prop_val[0];
777  final String apptag = prop_val[1];
778  final String priority = prop_val[2];
779  final String index = prop_val[3];
780  final String botname = bot.getBOTName();
782  (dev_inst, botname,obj_inst,instkey,value,apptag,priority,index);
783  opl.add(bcp);
784  }
785  }
786  }
787  }
788  return opl;
789  }
790 
796  public ArrayList<ProcessBuilder> getProcesses(ArrayList<BACnetCompleteProperty> prop_arr)
797  {
798  // All elements in prop_arr are either for the writer or for the reader.
799  // Determine if we are called by the reader or the writer
800  final String pro_app = prop_arr.get(0).getApplicationTag();
801  final boolean isReader = pro_app.equals("null");
802 
803  ArrayList<ProcessBuilder> pro = new ArrayList<ProcessBuilder>();
804 
805  // Path of binary
806  final String binPat = isReader ?
808  for(int i=0; i<prop_arr.size(); i++)
809  {
810  BACnetCompleteProperty bcp = prop_arr.get(i);
811  int dev_inst = bcp.getDeviceInstance();
812  int obj_inst = bcp.getObjectInstance();
813  String obj_type = bcp.getObjectType();
814  BacObjectType obj = BacObjectType.valueOf(obj_type);
815  String prop_name = bcp.getPropertyName();
816  int prop_id = BacProperty.valueOf(prop_name).ordinal();
817  int obj_id = obj.ordinal();
818 
819  if( !isReader ){
820  BacnetApplicationTag appt = BacnetApplicationTag.valueOf(pro_app);
821  String pro_prio = bcp.getPropertyPriority();
822  String pro_index = bcp.getPropertyIndex();
823  String pro_value = bcp.getPropertyValue();
824 
825  ProcessBuilder procBui = new ProcessBuilder
826  (binPat, Integer.toString(dev_inst), Integer.toString(obj_id),
827  Integer.toString(obj_inst), Integer.toString(prop_id),pro_prio,
828  pro_index,Integer.toString(appt.ordinal()),pro_value);
829  pro.add(procBui);
830  }
831  else
832  {
833  ProcessBuilder procBui = new ProcessBuilder
834  (binPat,Integer.toString(dev_inst),Integer.toString(obj_id),
835  Integer.toString(obj_inst),Integer.toString(prop_id));
836  pro.add(procBui);
837  }
838  }
839  return pro;
840  }
841 
848  static protected String toString(String arg)
849  throws IllegalArgumentException{
850  ArrayList<String> s = new ArrayList<String>();
851  int nLen = 50;
852  int num;
853  if(arg.equals("BacnetApplicationTag"))
854  num = 1;
855  else if(arg.equals("BacProperty"))
856  num = 2;
857  else if(arg.equals("BacObjectType"))
858  num = 3;
859  else{
860  num = -1;
861  throw new IllegalArgumentException("Program error. Argument '" + arg + "' is not known.");
862  }
863  switch (num)
864  {
865  case 1:
866  for (BacnetApplicationTag p : BacnetApplicationTag.values()) {
867  s.add(p.toString());
868  }
869  break;
870  case 2:
871  for (BacProperty p : BacProperty.values()) {
872  s.add(p.toString());
873  }
874  break;
875  case 3:
876  for (BacObjectType p : BacObjectType.values()) {
877  s.add(p.toString());
878  }
879  break;
880  }
881  // Assemble string that will be reported in the error message
882  String r ="";
883  int strLen = 0;
884  for(int i=0; i<s.size(); i++){
885  final String ele = s.get(i);
886  strLen += ele.length() + 2;
887  if (strLen > nLen){
888  r += LS;
889  strLen = 0;
890  }
891  r += ele;
892  if (i < s.size()-1)
893  r += ", ";
894  }
895  return r;
896  }
897 
898 
906  public void validateApplicationTag(final String s) throws IllegalArgumentException
907  {
908  try{
909  BacnetApplicationTag bat = BacnetApplicationTag.valueOf(s);
910  }
911  catch(IllegalArgumentException e)
912  {
913  String em = "'" + s +
914  "' is not allowed as the value for 'ApplicationTag.'" +
915  LS + "Possible values are:" + LS + toString("BacnetApplicationTag") + ".";
916  throw new IllegalArgumentException(em + LS + e.getMessage());
917  }
918  }
919 
928  public void validatePropertyName(final String s) throws IllegalArgumentException
929  {
930  try{
931  BacProperty bacprop1 = BacProperty.valueOf(s);
932  }
933  catch(IllegalArgumentException e)
934  {
935  String em = "'" + s +
936  "' is not allowed as the value for 'PropertyIdentifier.'" +
937  LS + "Possible values are:" + LS + toString("BacProperty") + ".";
938  throw new IllegalArgumentException(em + LS + e.getMessage());
939  }
940  }
941 
949  public void validateObjectType(final String s) throws IllegalArgumentException
950  {
951  try{
952  BacObjectType bacprop1 = BacObjectType.valueOf(s);
953  }
954  catch(IllegalArgumentException e)
955  {
956  String em = "'" + s +
957  "' is not allowed as the value for 'Object Type.'" +
958  LS + "Possible values are:" + LS + toString("BacObjectType") + ".";
959  throw new IllegalArgumentException(em + LS + e.getMessage());
960  }
961  }
962 
974  public void validateXMLFile(final String xmlfile, final Schema schema)
975  throws SAXException, FileNotFoundException,IOException
976  {
977  try{
978  Validator validator = schema.newValidator(); //construct a validator
979  SAXSource source = new SAXSource(
980  new InputSource(new java.io.FileInputStream(xmlfile)));
981  validator.validate(source);
982  }
983  catch(SAXParseException e)
984  {
985  String em = xmlfile + ": Line " + e.getLineNumber() + ", column "
986  + e.getColumnNumber() + ": " + e.getMessage();
987  throw new SAXException(em);
988  }
989  catch(FileNotFoundException e)
990  {
991  String em = "XML file configuration file '" + xmlfile + "' cannot be found.";
992  throw new FileNotFoundException(em + LS + e.getMessage());
993  }
994  catch(IOException e)
995  {
996  String em = "Error while validating XML configuration file '" + xmlfile +".";
997  throw new IOException(em + LS + e.getMessage());
998  }
999  }
1000 
1009  public Schema loadSchema(final String name)throws SAXException
1010  {
1011  Schema schema = null;
1012  try {
1013  String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
1014  SchemaFactory factory = SchemaFactory.newInstance(language);
1015  schema = factory.newSchema(new File(name));
1016  }
1017  catch (SAXException e) {
1018  throw new SAXException("Error while loading schema: " + name + LS +
1019  e.getMessage());
1020  }
1021  return schema;
1022  }
1023 }
ArrayList< Integer > findDevice()
Find BACnet devices in the network and return an integer list with their instance number...
for i
Definition: compile.m:69
ArrayList< BACnetCompleteProperty > readCompleteObjectPropertyList(final ArrayList< BACnetObjectType > bot_arr, final int dev_inst, final String obj_type, final int obj_inst)
Read complete object property list from BACnetObjectype.
function r
String getGlobalwiBinaryPath()
Returns the globalwi binary file path.
void validatePropertyName(final String s)
Property name validation.
ArrayList< BACnetObjectType > parseBACnetObjectType(final String s)
Parse the configuration file and generate an ArrayList that contains the xml content as specified in ...
This class reads the XML configuration file and stores the data in the BACnetObjectType data type...
String getBOTInst()
Get the instance of the bacnet object type.
static String toString(String arg)
Gets a string representation of the enumeration.
static final String FS
System-dependent file separator.
String getReadPropertyBinaryPath()
Returns the bacrp binary file path.
This object stores information of BACnet objects.
This class is used to create objects that have the information from the xml configuration file...
BACnet property enumeration object, contains major properties specified in BACnet Standard...
ArrayList< ProcessBuilder > getProcesses(ArrayList< BACnetCompleteProperty > prop_arr)
Prepare the process to be executed.
String getBOTName()
Get the bacnet object type name.
ArrayList< BACnetObject > readObjectList(final ArrayList< BACnetObjectType > bot_arr, final int dev_inst)
Read a subset of all objects associated with a device from ArrayList.
static final String LS
System-dependent line separator.
This class stores the BACnet property name and property value array pair.
This is the driver class in BACnet.
const int * strLen
the length of string parsed to this function
Definition: util/utilXml.h:159
void validateObjectType(final String s)
object type validation.
String getObjectType()
Get the object type.
ArrayList< BACnetCompleteProperty > readDevicePropertyList(final ArrayList< BACnetObjectType > bot_arr, final int dev_inst)
Get an arraylist with elements of BACnetCompleteProerty, one for each property of BACnet device and B...
enumeration object, contains all the BACnet application tags specified in BACnet Standard used in wri...
Enumeration object, contains all the object names specified in BACnet Standard, including BACnet Devi...
void validateApplicationTag(final String s)
Application tag validaton.
String getWritePropertyBinaryPath()
Returns the bacwp binary file path.
Schema loadSchema(final String name)
Load schema.
void validateXMLFile(final String xmlfile, final Schema schema)
XMLfile validation.
static final String bcvtbhome
String that points to root directory of the BCVTB.
int source
flag for function /c getepvariables 0=EnergyPlus, 1=Ptolemy
Definition: util/utilXml.h:158
static final String osName
Name of the operating system.
ArrayList< Integer > readDeviceArray(final ArrayList< BACnetObjectType > bot_arr)
Read device instance from parsed ArrayList.