33 import wx |
33 import wx |
34 |
34 |
35 from bacnet.BacnetSlaveEditor import * |
35 from bacnet.BacnetSlaveEditor import * |
36 from bacnet.BacnetSlaveEditor import ObjectProperties |
36 from bacnet.BacnetSlaveEditor import ObjectProperties |
37 from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_MEMORY |
37 from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_MEMORY |
38 |
38 from ConfigTreeNode import ConfigTreeNode |
39 base_folder = os.path.split( |
39 |
40 os.path.dirname(os.path.realpath(__file__)))[0] |
40 base_folder = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0] |
41 base_folder = os.path.join(base_folder, "..") |
41 base_folder = os.path.join(base_folder, "..") |
42 BacnetPath = os.path.join(base_folder, "BACnet") |
42 BacnetPath = os.path.join(base_folder, "BACnet") |
43 BacnetLibraryPath = os.path.join(BacnetPath, "lib") |
43 BacnetLibraryPath = os.path.join(BacnetPath, "lib") |
44 BacnetIncludePath = os.path.join(BacnetPath, "include") |
44 BacnetIncludePath = os.path.join(BacnetPath, "include") |
45 BacnetIncludePortPath = os.path.join(BacnetPath, "ports") |
45 BacnetIncludePortPath = os.path.join(BacnetPath, "ports") |
46 BacnetIncludePortPath = os.path.join(BacnetIncludePortPath, "linux") |
46 BacnetIncludePortPath = os.path.join(BacnetIncludePortPath, "linux") |
47 |
47 |
48 # Parameters to be monkey patched in beremiz customizations |
48 # Parameters to be monkey patched in beremiz customizations |
49 BACNET_VENDOR_ID = 9999 |
49 BACNET_VENDOR_ID = 9999 |
50 BACNET_VENDOR_NAME = "Beremiz.org" |
50 BACNET_VENDOR_NAME = "Beremiz.org" |
51 BACNET_DEVICE_MODEL_NAME = "Beremiz PLC" |
51 BACNET_DEVICE_MODEL_NAME = "Beremiz PLC" |
|
52 |
|
53 |
|
54 # Max String Size of BACnet Paramaters |
|
55 BACNET_PARAM_STRING_SIZE = 64 |
52 |
56 |
53 # |
57 # |
54 # |
58 # |
55 # |
59 # |
56 # S L A V E D E V I C E # |
60 # S L A V E D E V I C E # |
95 <xsd:attribute name="BACnet_Device_Application_Software_Version" type="xsd:string" use="optional" default="1.0"/> |
99 <xsd:attribute name="BACnet_Device_Application_Software_Version" type="xsd:string" use="optional" default="1.0"/> |
96 </xsd:complexType> |
100 </xsd:complexType> |
97 </xsd:element> |
101 </xsd:element> |
98 </xsd:schema> |
102 </xsd:schema> |
99 """ |
103 """ |
|
104 # NOTE; Add the following code/declaration to the aboce XSD in order to activate the |
|
105 # Override_Parameters_Saved_on_PLC flag (currenty not in use as it requires further |
|
106 # analysis how the user would interpret this user interface option. |
|
107 # <--- snip ---> |
|
108 # <xsd:attribute name="Override_Parameters_Saved_on_PLC" |
|
109 # type="xsd:boolean" use="optional" default="true"/> |
|
110 # <--- snip ---> |
|
111 # |
100 # NOTE: BACnet device (object) IDs are 22 bits long (not counting the 10 bits for the type ID) |
112 # NOTE: BACnet device (object) IDs are 22 bits long (not counting the 10 bits for the type ID) |
101 # so the Device instance ID is limited from 0 to 22^2-1 = 4194303 |
113 # so the Device instance ID is limited from 0 to 22^2-1 = 4194303 |
102 # However, 4194303 is reserved for special use (similar to NULL pointer), so last |
114 # However, 4194303 is reserved for special use (similar to NULL pointer), so last |
103 # valid ID becomes 4194302 |
115 # valid ID becomes 4194302 |
104 |
116 |
550 generate_file_content = open(template_file_name).read() |
562 generate_file_content = open(template_file_name).read() |
551 generate_file_handle = open(generate_file_name, 'w') |
563 generate_file_handle = open(generate_file_name, 'w') |
552 generate_file_handle .write(generate_file_content) |
564 generate_file_handle .write(generate_file_content) |
553 generate_file_handle .close() |
565 generate_file_handle .close() |
554 |
566 |
555 # |
567 |
556 # Generate the source files # |
568 |
|
569 # |
|
570 # Generate the C source code files |
557 # |
571 # |
558 def CTNGenerate_C(self, buildpath, locations): |
572 def CTNGenerate_C(self, buildpath, locations): |
559 # Determine the current location in Beremiz's project configuration |
573 # Determine the current location in Beremiz's project configuration |
560 # tree |
574 # tree |
561 current_location = self.GetCurrentLocation() |
575 current_location = self.GetCurrentLocation() |
594 loc_dict["locstr"] = locstr |
608 loc_dict["locstr"] = locstr |
595 |
609 |
596 # The BACnetServerNode attribute is added dynamically by ConfigTreeNode._AddParamsMembers() |
610 # The BACnetServerNode attribute is added dynamically by ConfigTreeNode._AddParamsMembers() |
597 # It will be an XML parser object created by |
611 # It will be an XML parser object created by |
598 # GenerateParserFromXSDstring(self.XSD).CreateRoot() |
612 # GenerateParserFromXSDstring(self.XSD).CreateRoot() |
|
613 # |
|
614 # Note: Override_Parameters_Saved_on_PLC is converted to an integer by int() |
|
615 # The above flag is not currently in use. It requires further thinking on how the |
|
616 # user will interpret and interact with this user interface... |
|
617 #loc_dict["Override_Parameters_Saved_on_PLC"] = int(self.BACnetServerNode.getOverride_Parameters_Saved_on_PLC()) |
599 loc_dict["network_interface"] = self.BACnetServerNode.getNetwork_Interface() |
618 loc_dict["network_interface"] = self.BACnetServerNode.getNetwork_Interface() |
600 loc_dict["port_number"] = self.BACnetServerNode.getUDP_Port_Number() |
619 loc_dict["port_number"] = self.BACnetServerNode.getUDP_Port_Number() |
601 loc_dict["BACnet_Device_ID"] = self.BACnetServerNode.getBACnet_Device_ID() |
620 loc_dict["BACnet_Device_ID"] = self.BACnetServerNode.getBACnet_Device_ID() |
602 loc_dict["BACnet_Device_Name"] = self.BACnetServerNode.getBACnet_Device_Name() |
621 loc_dict["BACnet_Device_Name"] = self.BACnetServerNode.getBACnet_Device_Name() |
603 loc_dict["BACnet_Comm_Control_Password"] = self.BACnetServerNode.getBACnet_Communication_Control_Password() |
622 loc_dict["BACnet_Comm_Control_Password"] = self.BACnetServerNode.getBACnet_Communication_Control_Password() |
605 loc_dict["BACnet_Device_Description"] = self.BACnetServerNode.getBACnet_Device_Description() |
624 loc_dict["BACnet_Device_Description"] = self.BACnetServerNode.getBACnet_Device_Description() |
606 loc_dict["BACnet_Device_AppSoft_Version"] = self.BACnetServerNode.getBACnet_Device_Application_Software_Version() |
625 loc_dict["BACnet_Device_AppSoft_Version"] = self.BACnetServerNode.getBACnet_Device_Application_Software_Version() |
607 loc_dict["BACnet_Vendor_ID"] = BACNET_VENDOR_ID |
626 loc_dict["BACnet_Vendor_ID"] = BACNET_VENDOR_ID |
608 loc_dict["BACnet_Vendor_Name"] = BACNET_VENDOR_NAME |
627 loc_dict["BACnet_Vendor_Name"] = BACNET_VENDOR_NAME |
609 loc_dict["BACnet_Model_Name"] = BACNET_DEVICE_MODEL_NAME |
628 loc_dict["BACnet_Model_Name"] = BACNET_DEVICE_MODEL_NAME |
|
629 loc_dict["BACnet_Param_String_Size"] = BACNET_PARAM_STRING_SIZE |
|
630 |
610 |
631 |
611 # 2) Add the data specific to each BACnet object type |
632 # 2) Add the data specific to each BACnet object type |
612 # For each BACnet object type, start off by creating some intermediate helpful lists |
633 # For each BACnet object type, start off by creating some intermediate helpful lists |
613 # a) parameters_list containing the strings that will |
634 # a) parameters_list containing the strings that will |
614 # be included in the C source code, and which will initialize the struct with the |
635 # be included in the C source code, and which will initialize the struct with the |
724 ' "' + os.path.join(BacnetLibraryPath, "libbacnet.a") + '"') |
745 ' "' + os.path.join(BacnetLibraryPath, "libbacnet.a") + '"') |
725 |
746 |
726 CFLAGS = ' -I"' + BacnetIncludePath + '"' |
747 CFLAGS = ' -I"' + BacnetIncludePath + '"' |
727 CFLAGS += ' -I"' + BacnetIncludePortPath + '"' |
748 CFLAGS += ' -I"' + BacnetIncludePortPath + '"' |
728 |
749 |
|
750 # ---------------------------------------------------------------------- |
|
751 # Create a file containing the default configuration paramters. |
|
752 # Beremiz will then transfer this file to the PLC, where the web server |
|
753 # will read it to obtain the default configuration parameters. |
|
754 # ---------------------------------------------------------------------- |
|
755 # NOTE: This is no loner needed! The web interface will read these |
|
756 # parameters directly from the compiled C code (.so file) |
|
757 # |
|
758 ### extra_file_name = os.path.join(buildpath, "%s_%s.%s" % ('bacnet_extrafile', postfix, 'txt')) |
|
759 ### extra_file_handle = open(extra_file_name, 'w') |
|
760 ### |
|
761 ### proplist = ["network_interface", "port_number", "BACnet_Device_ID", "BACnet_Device_Name", |
|
762 ### "BACnet_Comm_Control_Password", "BACnet_Device_Location", |
|
763 ### "BACnet_Device_Description", "BACnet_Device_AppSoft_Version"] |
|
764 ### for propname in proplist: |
|
765 ### extra_file_handle.write("%s:%s\n" % (propname, loc_dict[propname])) |
|
766 ### |
|
767 ### extra_file_handle.close() |
|
768 ### extra_file_handle = open(extra_file_name, 'r') |
|
769 |
|
770 # Format of data to return: |
|
771 # [(Cfiles, CFLAGS), ...], LDFLAGS, DoCalls, extra_files |
|
772 # LDFLAGS = ['flag1', 'flag2', ...] |
|
773 # DoCalls = true or false |
|
774 # extra_files = (fname,fobject), ... |
|
775 # fobject = file object, already open'ed for read() !! |
|
776 # |
|
777 # extra_files -> files that will be downloaded to the PLC! |
729 return [(Generated_BACnet_c_mainfile_name, CFLAGS)], LDFLAGS, True |
778 return [(Generated_BACnet_c_mainfile_name, CFLAGS)], LDFLAGS, True |
|
779 #return [(Generated_BACnet_c_mainfile_name, CFLAGS)], LDFLAGS, True, ('extrafile1.txt', extra_file_handle) |