|
Often it is desirable to access some Attributes from a simulator with external programs. This way, the simulator can be stimulated (e.g. by external control programs) or simulated values ccan be monitored. Most of the functionality that is required for external acesses is already implemented in the simulator's kernel-library. This library handles socket connections and interprets a simple command languege. Basically, there are 3 commands:
Commands are terminated by the control-sequence ctrl-a and a carriage-return. Ctrl-b means "quit". The commands may be entered using a normal telnet connection to the host the simulator is running on. The default port is 32418. For details see http://hauspc1.informatik.uni-kl.de/doku.html .
All what is needed to access an attribute externally is a mapping between the sensuator's name and the actual attribute. This can be done using this pattern.
Assume the following situation: The temperature of a building should be simulated and the temperature of some selected rooms has to be monitored by an external program. The following things are required to install an accessible temperature sensor for a room:

This pattern should be bound to a sensor object with its name and an attribute to be accessed. In simple cases (e.g. every room has only one temperature) it can be directly bound to the simulation objects.

The attribute of a Sensuator ccan be read and written by external processes. Additionally it can be set into eventMode where every change is automatically propagated. To restrict this flexibility, use one of the patterns SensorServer , ActuatorServer , or BinarySensorServer .
The socet connection is automatically handled in the simulator-kernel library. All this pattern does is to register a sensuator object in the kernel.
{init} |aSet anArray | self {name} notNil ifTrue: [ aSet := Set new. anArray := Array withSize: 6. anArray at: 1 put: self. anArray at: 2 put: #{attribute}. anArray at: 3 put: #{attribute}:. anArray at: 4 put: #setEventMode. anArray at: 5 put: #resetEventMode. anArray at: 6 put: aSet. Scheduler simSched remoteAccessibleObjects at: (self {name} asSymbol) put: anArray. ]
ActuatorServer , SensorServer , and BinarySensorServer are special, restricted versions of this pattern.
Pattern SensuatorServer Category sockets ObjectType use target Attribute use name Attribute use attribute SingleMethod implement preset init End