78 import ptolemy.kernel.util.IllegalActionException;
80 import java.io.FileNotFoundException;
81 import java.io.IOException;
82 import java.util.ArrayList;
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;
127 private final static String
bcvtbhome = System.getenv(
"BCVTB_HOME");
130 private final static String
LS = System.getProperty(
"line.separator");
133 private final static String
FS = System.getProperty(
"file.separator");
136 private final static String
osName= System.getProperty(
"os.name");
370 BINARY_INACTIVE_VALUE}
393 MAX_BACNET_APPLICATION_TAG
405 String s =
new String();
406 if(
osName.startsWith(
"Windows"))
408 +
"bin-windows" +
FS +
"bacrp.exe";
409 if(
osName.startsWith(
"Linux"))
411 FS +
"bin-linux" +
FS +
"bacrp";
425 String s =
new String();
426 if(
osName.startsWith(
"Windows"))
428 +
"bin-windows" +
FS +
"bacwp.exe";
429 if(
osName.startsWith(
"Linux"))
431 FS +
"bin-linux" +
FS +
"bacwp";
444 String s =
new String();
445 if(
osName.startsWith(
"Windows"))
447 +
"bin-windows" +
FS +
"globalwi.exe";
448 if(
osName.startsWith(
"Linux"))
450 FS +
"bin-linux" +
FS +
"globalwi";
462 public ArrayList<Integer>
findDevice() throws IllegalActionException
465 ArrayList<Integer> dev_array =
new ArrayList<Integer>();
468 ProcessBuilder pb =
new ProcessBuilder(s);
474 String em =
"Error while executing bacnet stack binary: '" + s +
"'."
475 +
LS + e.getMessage();
476 throw new IllegalActionException(em);
478 catch(NullPointerException e)
480 String em =
"Some of the command lists passed to globalwi are null.";
481 throw new IllegalActionException(em +
LS + e.getMessage());
483 catch(IndexOutOfBoundsException e)
485 String em =
"The command list passed to glabalwi is empty.";
486 throw new IllegalActionException(em +
LS + e.getMessage());
488 catch(SecurityException e)
490 String em =
"Creation of the '" + s +
"' subprocess is not allowed.";
491 throw new IllegalActionException(em +
LS + e.getMessage());
495 BufferedReader br =
new BufferedReader(
new InputStreamReader(p.getInputStream()));
498 while ((line=br.readLine())!=null)
500 if(line.startsWith(
"Received")==
false)
503 final int val = Integer.parseInt(line);
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);
514 catch(IOException e){
515 String em =
"IOException when reading output of '" + s +
"'.";
516 throw new IllegalActionException(em +
LS + e.getMessage());
520 exiVal = p.waitFor();
522 catch(InterruptedException e){
523 String em =
"The process of running bacnet stack" +
LS
524 +
"command has been interrupted" +
LS +
526 throw new IllegalActionException(em);
529 String em =
"BACnet-stack process quit abnormally with error signal '" + exiVal +
"'.";
530 throw new IllegalActionException(em);
547 ParserConfigurationException, SAXException, IOException
549 ArrayList<BACnetObjectType> bot_arr =
new ArrayList<BACnetObjectType>();
552 bot_arr = bot.parseObjectType(s);
554 catch (SAXException e) {
555 String em =
"Parser error occurs while parsing xml configuration file '"
557 throw new SAXException(em +
LS + e.getMessage());
559 catch(ParserConfigurationException e)
561 String em =
"SAX Parser configuration error in parsing configuration file '"
563 throw new ParserConfigurationException(em +
LS + e.getMessage());
567 final String em =
"IOException when parsing configuration file '" + s +
"'." +
569 throw new IOException(em);
585 throws NumberFormatException
587 final ArrayList<Integer> dev_array =
new ArrayList<Integer>();
588 for(
int i=0;
i<bot_arr.size();
i++)
591 if(bot.
getBOTName().equals(
"DeviceObjectType"))
593 final String inst = bot.getBOTInst();
595 final int inst_int = Integer.parseInt(inst);
596 dev_array.add(inst_int);
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);
605 dev_array.trimToSize();
621 public ArrayList<BACnetObject>
readObjectList(
final ArrayList<BACnetObjectType> bot_arr,
623 throws NumberFormatException
625 final ArrayList<BACnetObject> object_array =
new ArrayList<BACnetObject>();
626 for(
int i=0;
i<bot_arr.size();
i++)
631 bot_inst = Integer.parseInt(bot.getBOTInst());
633 catch(NumberFormatException e)
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);
640 if(bot.
getBOTName().equals(
"DeviceObjectType") &&
644 HashMap mapOTname = bot.getBACnetObjectTypeNameMap();
645 HashMap mapOTinst = bot.getBACnetObjectTypeInstanceMap();
646 for(
int j=0; j<mapOTname.size(); j++)
648 String instkey = Integer.toString(j);
649 String type = mapOTname.get(instkey).
toString();
650 String inst = mapOTinst.get(instkey).
toString();
654 instint = Integer.parseInt(inst);
656 catch(NumberFormatException e)
659 "NumberFormatException when trying to parse '"
660 + inst +
"'" +
LS +
"to an integer. "
661 +
LS + e.getMessage();
662 throw new NumberFormatException(em);
666 object_array.add(bacobj);
685 (
final ArrayList<BACnetObjectType> bot_arr,
final int dev_inst)
throws NumberFormatException
687 ArrayList<BACnetCompleteProperty> proparr =
new ArrayList<BACnetCompleteProperty>();
688 for(
int i=0;
i<bot_arr.size();
i++)
693 bot_inst = Integer.parseInt(bot.getBOTInst());
695 catch(NumberFormatException e)
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);
702 if(bot.
getBOTName().equals(
"DeviceObjectType")
703 && Integer.parseInt(bot.
getBOTInst())==dev_inst)
705 ArrayList<BACnetPropertyValue> mapPI = bot.getBOTPI();
706 ArrayList<BACnetObject> objarr =
new ArrayList<BACnetObject>();
709 for(
int j=0; j<mapPI.size(); 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);
726 for(
int k=0; k<objarr.size(); k++)
730 ArrayList<BACnetCompleteProperty> objproparr =
733 obj.getObjectInstance());
734 for(
int l=0; l<objproparr.size();l++)
757 final String obj_type,
761 final ArrayList<BACnetCompleteProperty> opl =
new ArrayList<BACnetCompleteProperty>();
762 for(
int i=0;
i<bot_arr.size();
i++)
767 HashMap mapOTinst = bot.getBACnetObjectTypeInstanceMap();
768 ArrayList<BACnetPropertyValue> mapPI = bot.getBOTPI();
769 if(mapOTinst.get(Integer.toString(obj_inst)).equals(Integer.toString(dev_inst)))
771 for(
int j=0; j<mapPI.size(); 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);
796 public ArrayList<ProcessBuilder>
getProcesses(ArrayList<BACnetCompleteProperty> prop_arr)
800 final String pro_app = prop_arr.get(0).getApplicationTag();
801 final boolean isReader = pro_app.equals(
"null");
803 ArrayList<ProcessBuilder> pro =
new ArrayList<ProcessBuilder>();
806 final String binPat = isReader ?
808 for(
int i=0;
i<prop_arr.size();
i++)
811 int dev_inst = bcp.getDeviceInstance();
812 int obj_inst = bcp.getObjectInstance();
813 String obj_type = bcp.getObjectType();
815 String prop_name = bcp.getPropertyName();
816 int prop_id = BacProperty.valueOf(prop_name).ordinal();
817 int obj_id = obj.ordinal();
821 String pro_prio = bcp.getPropertyPriority();
822 String pro_index = bcp.getPropertyIndex();
823 String pro_value = bcp.getPropertyValue();
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);
833 ProcessBuilder procBui =
new ProcessBuilder
834 (binPat,Integer.toString(dev_inst),Integer.toString(obj_id),
835 Integer.toString(obj_inst),Integer.toString(prop_id));
849 throws IllegalArgumentException{
850 ArrayList<String> s =
new ArrayList<String>();
853 if(arg.equals(
"BacnetApplicationTag"))
855 else if(arg.equals(
"BacProperty"))
857 else if(arg.equals(
"BacObjectType"))
861 throw new IllegalArgumentException(
"Program error. Argument '" + arg +
"' is not known.");
884 for(
int i=0;
i<s.size();
i++){
885 final String ele = s.get(
i);
886 strLen += ele.length() + 2;
911 catch(IllegalArgumentException e)
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());
933 catch(IllegalArgumentException e)
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());
954 catch(IllegalArgumentException e)
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());
975 throws SAXException, FileNotFoundException,IOException
978 Validator validator = schema.newValidator();
979 SAXSource
source =
new SAXSource(
980 new InputSource(
new java.io.FileInputStream(xmlfile)));
981 validator.validate(
source);
983 catch(SAXParseException e)
985 String em = xmlfile +
": Line " + e.getLineNumber() +
", column "
986 + e.getColumnNumber() +
": " + e.getMessage();
987 throw new SAXException(em);
989 catch(FileNotFoundException e)
991 String em =
"XML file configuration file '" + xmlfile +
"' cannot be found.";
992 throw new FileNotFoundException(em +
LS + e.getMessage());
996 String em =
"Error while validating XML configuration file '" + xmlfile +
".";
997 throw new IOException(em +
LS + e.getMessage());
1011 Schema schema = null;
1013 String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
1014 SchemaFactory factory = SchemaFactory.newInstance(language);
1015 schema = factory.newSchema(
new File(name));
1017 catch (SAXException e) {
1018 throw new SAXException(
"Error while loading schema: " + name +
LS +
ArrayList< Integer > findDevice()
Find BACnet devices in the network and return an integer list with their instance number...
RECORDS_SINCE_NOTIFICATION
MANIPULATED_VARIABLE_REFERENCE
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.
REQUESTED_UPDATE_INTERVAL
String getGlobalwiBinaryPath()
Returns the globalwi binary file path.
void validatePropertyName(final String s)
Property name validation.
UTC_TIME_SYNCHRONIZATION_RECIPIENTS
LIMIT_MONITORING_INTERVAL
LAST_CREDENTIAL_ADDED_TIME
ArrayList< BACnetObjectType > parseBACnetObjectType(final String s)
Parse the configuration file and generate an ArrayList that contains the xml content as specified in ...
AccessCredentialObjectType
RESTART_NOTIFICATION_RECIPIENTS
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.
CONTROLLED_VARIABLE_VALUE
ACTIVE_AUTHENTICATION_POLICY
AuthenticationFactorInputObjectType
static String toString(String arg)
Gets a string representation of the enumeration.
PROTOCOL_CONFORMANCE_CLASS
static final String FS
System-dependent file separator.
ACCESS_TRANSACTION_EVENTS
AUTHENTICATION_POLICY_LIST
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...
ACCESS_EVENT_AUTHENTICATION_FACTOR
BACnet property enumeration object, contains major properties specified in BACnet Standard...
ArrayList< ProcessBuilder > getProcesses(ArrayList< BACnetCompleteProperty > prop_arr)
Prepare the process to be executed.
TIME_SYNCHRONIZATION_RECIPIENTS
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.
NUMBER_OF_AUTHENTICATION_POLICIES
CONTROLLED_VARIABLE_REFERENCE
PROTOCOL_OBJECT_TYPES_SUPPORTED
This is the driver class in BACnet.
MultiStateInputObjectType
LAST_CREDENTIAL_REMOVED_TIME
const int * strLen
the length of string parsed to this function
TIME_OF_STATE_COUNT_RESET
void validateObjectType(final String s)
object type validation.
String getObjectType()
Get the object type.
EventEnrollmentObjectType
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...
LIGHTING_COMMAND_PRIORITY
MultiStateValueObjectType
LIST_OF_OBJECT_PROPERTY_REFERENCES
PROPORTIONAL_CONSTANT_UNITS
OCCUPANCY_UPPER_LIMIT_ENFORCED
NotificationClassObjectType
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.
LifeSafetyPointObjectType
TRANSACTION_NOTIFICATION_CLASS
PROTOCOL_SERVICES_SUPPORTED
AUTHENTICATION_FACTOR_INPUT_LIST
void validateXMLFile(final String xmlfile, final Schema schema)
XMLfile validation.
TrendLogMultipleObjectType
OCCUPANCY_LOWER_THRESHOLD
static final String bcvtbhome
String that points to root directory of the BCVTB.
int source
flag for function /c getepvariables 0=EnergyPlus, 1=Ptolemy
OCCUPANCY_COUNT_EXEMPTION
APPLICATION_SOFTWARE_VERSION
static final String osName
Name of the operating system.
ArrayList< Integer > readDeviceArray(final ArrayList< BACnetObjectType > bot_arr)
Read device instance from parsed ArrayList.
MultiStateOutputObjectType