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