3232PointValueType = Union [opendnp3 .Analog , opendnp3 .Binary , opendnp3 .AnalogOutputStatus , opendnp3 .BinaryOutputStatus ]
3333
3434
35- class MyOutStationNew (opendnp3 .IOutstationApplication ):
35+ class MyOutStation (opendnp3 .IOutstationApplication ):
3636 """
3737 Interface for all outstation callback info except for control requests.
3838
@@ -62,7 +62,7 @@ class MyOutStationNew(opendnp3.IOutstationApplication):
6262 # db_handler = None
6363 outstation_application = None
6464 # outstation_pool = {} # a pool of outstations
65- outstation_application_pool : Dict [str , MyOutStationNew ] = {} # a pool of outstation applications
65+ outstation_application_pool : Dict [str , MyOutStation ] = {} # a pool of outstation applications
6666
6767 def __init__ (self ,
6868 outstation_ip : str = "0.0.0.0" ,
@@ -73,6 +73,9 @@ def __init__(self,
7373
7474 channel_log_level = opendnp3 .levels .NORMAL ,
7575 outstation_log_level = opendnp3 .levels .NORMAL ,
76+
77+ db_sizes : opendnp3 .DatabaseSizes = None ,
78+ event_buffer_config : opendnp3 .EventBufferConfig = None
7679 ):
7780 super ().__init__ ()
7881
@@ -91,15 +94,25 @@ def __init__(self,
9194 self .master_id : int = master_id
9295 self .outstation_id : int = outstation_id
9396
97+ # Set to default
98+ if db_sizes is None :
99+ db_sizes = opendnp3 .DatabaseSizes .AllTypes (count = 5 )
100+ if event_buffer_config is None :
101+ event_buffer_config = opendnp3 .EventBufferConfig ().AllTypes (sizes = 10 )
102+ self .db_sizes = db_sizes
103+ self .event_buffer_config = event_buffer_config
104+
94105 _log .debug ('Configuring the DNP3 stack.' )
95106 _log .debug ('Configuring the outstation database.' )
96- self .stack_config = self .configure_stack () # TODO: refactor it to outside of the class
107+ self .stack_config = self .configure_stack (db_sizes = db_sizes ,
108+ event_buffer_config = event_buffer_config )
97109
98110 # TODO: Justify if this is is really working? (Not sure if it really takes effect yet.)
99111 # but needs to add docstring. Search for "intriguing" in "data_retrieval_demo.py"
100112 # Note: dbconfig signature at cpp/libs/include/asiodnp3/DatabaseConfig.h
101113 # which has sizes parameter
102- self .configure_database (self .stack_config .dbConfig ) # TODO: refactor it to outside of the class.
114+ # Note: stack_config is far-reaching, keep this method within the class
115+ self .configure_database (self .stack_config .dbConfig )
103116
104117 # self.log_handler = MyLogger()
105118 self .log_handler = asiodnp3 .ConsoleLogger ().Create () # (or use this during regression testing)
@@ -132,16 +145,16 @@ def __init__(self,
132145 self .command_handler .post_init (outstation_id = self .outstation_app_id )
133146 # self.command_handler = opendnp3.SuccessCommandHandler().Create() # (or use this during regression testing)
134147 # init outstation applicatioin, # Note: singleton for AddOutstation()
135- MyOutStationNew .set_outstation_application (outstation_application = self )
148+ MyOutStation .set_outstation_application (outstation_application = self )
136149
137150 # finally, init outstation
138151 self .outstation = self .channel .AddOutstation (id = "outstation-" + self .outstation_app_id ,
139152 commandHandler = self .command_handler ,
140- application = MyOutStationNew .outstation_application ,
153+ application = MyOutStation .outstation_application ,
141154 config = self .stack_config )
142155
143- MyOutStationNew .add_outstation_app (outstation_id = self .outstation_app_id ,
144- outstation_app = self .outstation_application )
156+ MyOutStation .add_outstation_app (outstation_id = self .outstation_app_id ,
157+ outstation_app = self .outstation_application )
145158
146159 # Configure log level for channel(tcpclient) and outstation
147160 # note: one of the following
@@ -209,13 +222,13 @@ def get_config(self):
209222 return self ._comm_conifg
210223
211224 @classmethod
212- def add_outstation_app (cls , outstation_id : str , outstation_app : MyOutStationNew ):
225+ def add_outstation_app (cls , outstation_id : str , outstation_app : MyOutStation ):
213226 """add outstation instance to outstation pool,
214227 the id is in the format of `ip-port`, e.g., `0.0.0.0-20000`."""
215228 cls .outstation_application_pool [outstation_id ] = outstation_app
216229
217230 @classmethod
218- def get_outstation_app (cls , outstation_id : str ) -> MyOutStationNew :
231+ def get_outstation_app (cls , outstation_id : str ) -> MyOutStation :
219232 """get outstation instance from the outstation pool using outstation id,
220233 the id is in the format of `ip-port`, e.g., `0.0.0.0-20000`."""
221234 return cls .outstation_application_pool .get (outstation_id )
@@ -231,22 +244,14 @@ def set_outstation_application(cls, outstation_application):
231244 else :
232245 cls .outstation_application = outstation_application
233246
234- def configure_stack (self ):
247+ def configure_stack (self , db_sizes : opendnp3 .DatabaseSizes = None ,
248+ event_buffer_config : opendnp3 .EventBufferConfig = None ,
249+ ** kwargs ) -> asiodnp3 .OutstationStackConfig :
235250 """Set up the OpenDNP3 configuration."""
236- stack_config = asiodnp3 .OutstationStackConfig (opendnp3 .DatabaseSizes .AllTypes (10 ))
237- # stack_config = asiodnp3.OutstationStackConfig(opendnp3.DatabaseSizes.Empty())
238- # stack_config = asiodnp3.OutstationStackConfig(dbSizes=opendnp3.DatabaseSizes.AnalogOnly(8))
239- # TODO: expose DatabaseSizes to public interface
240- # stack_config = asiodnp3.OutstationStackConfig(dbSizes=opendnp3.DatabaseSizes(numBinary=10,
241- # numDoubleBinary=0,
242- # numAnalog=10,
243- # numCounter=0,
244- # numFrozenCounter=0,
245- # numBinaryOutputStatus=10,
246- # numAnalogOutputStatus=10,
247- # numTimeAndInterval=0))
248-
249- stack_config .outstation .eventBufferConfig = opendnp3 .EventBufferConfig ().AllTypes (10 )
251+
252+ stack_config = asiodnp3 .OutstationStackConfig (dbSizes = db_sizes )
253+
254+ stack_config .outstation .eventBufferConfig = event_buffer_config
250255 stack_config .outstation .params .allowUnsolicited = True # TODO: create interface for this
251256 stack_config .link .LocalAddr = self .outstation_id # meaning for outstation, use 1 to follow simulator's default
252257 stack_config .link .RemoteAddr = self .master_id # meaning for master station, use 2 to follow simulator's default
@@ -262,7 +267,6 @@ def configure_database(db_config):
262267 Configure two Analog points (group/variation 30.1) at indexes 0, 1.
263268 Configure two Binary points (group/variation 1.2) at indexes 1 and 2.
264269 """
265- # TODO: figure out the right way to configure
266270
267271 # AnalogInput
268272 db_config .analog [0 ].clazz = opendnp3 .PointClass .Class2
@@ -414,7 +418,7 @@ def Select(self, command, index):
414418 :param index: int
415419 :return: CommandStatus
416420 """
417- outstation_application_pool = MyOutStationNew .outstation_application_pool
421+ outstation_application_pool = MyOutStation .outstation_application_pool
418422 outstation_app = outstation_application_pool .get (self .outstation_id )
419423
420424 try :
@@ -437,7 +441,7 @@ def Operate(self, command, index, op_type):
437441 :return: CommandStatus
438442 """
439443
440- outstation_application_pool = MyOutStationNew .outstation_application_pool
444+ outstation_application_pool = MyOutStation .outstation_application_pool
441445 outstation_app = outstation_application_pool .get (self .outstation_id )
442446 try :
443447 # self.outstation_application.process_point_value('Operate', command, index, op_type)
0 commit comments