Project

General

Profile

The logic » History » Version 13

David Božjak, 21.12.2010 10:32

1 1 Aleksander Bešir
h1. The logic
2
3 2 Aleksander Bešir
{{toc}}
4
5 1 Aleksander Bešir
h2. Basic concept
6 3 David Božjak
7
System Eneratptor is designed to take predefined actions in response to events in the surrounding world. The logic system is designed to be easily calibrated and managed. In addition to its predefined logic it allows the human administrator (through HMI) to reverse any automated or scripted decision and to execute any of the predefined actions, thus allowing the operator to tweak the system according to her best judgement.
8
9
!Logika.jpg!
10
11
The logic of the system consists of the following concepts:
12 11 David Božjak
* Device maneger
13 4 David Božjak
* Mailbox
14
* Decision making software
15
* Predefined action list
16
* Action
17 7 Aleksander Bešir
* [[Human Machine Interface]]
18 1 Aleksander Bešir
19 11 David Božjak
The basic idea behind this design is modularity. Eneraptor supports any device and can execute any action as long as the driver follows our standard. In this scenario we [the eneraptor designers] expect the device manufacturer (ie air conditioning unit) at least two supply two _programs_ : the device manager and the action program. If there are several actions supported by the device, we expect each to be a standalone program or all actions to be in a single program targeted by different command line arguments.
20 6 David Božjak
21 3 David Božjak
h2. Concepts described in detail
22 1 Aleksander Bešir
23 11 David Božjak
h3. Device manager
24 4 David Božjak
25 11 David Božjak
Device manager is basically a program. The eneratptor system doesn't know anything about it, the only crucial part is the driver-mailbox communication through witch data is supplied. More about date in the _message specification_. The device manager has to know how to reach the mailbox and how to correctly format the message. The device manager does not receive any confirmation from the message recipient.
26 6 David Božjak
27
This driver is not necessarily the same software which is supplied by the manufacturer, it is only a program that communicates with the eneratpr Mailbox.
28
29 3 David Božjak
h3. Mailbox
30 6 David Božjak
31 11 David Božjak
Mailbox is a bridge between the device managers and the decision making software. It is a buffer of messages that the decision making software can read at its own pace.
32 1 Aleksander Bešir
33 12 David Božjak
*The design of the mailbox and message structure is still open to debate; all input is welcome!*
34 1 Aleksander Bešir
35 12 David Božjak
The mailbox should be event driven, meaning no periodic checking is necessary. The device manager will signal the control program which will in turn read the shared variable for data.
36
37 3 David Božjak
h3. Decision making software
38 1 Aleksander Bešir
39 8 David Božjak
Decision making software is the key mechanism of the eneraptor project. It brings all other components together to ensure all conditions set by (human) operators are met.
40
41
The decision making software continuously checks the mailbox for new messages. If any new info is read the software compares it with all the predefined conditions (see _predefined action list_). If a condition is met, the action is executed. If several conditions are met, all co-responding actions are executed.
42
43
This (very elegant) main loop is always executing, however it can be halted by the [[Human Machine Interface]]. When this happens the loop still executes, however all but the messages originating from HMI are ignored.
44
45 1 Aleksander Bešir
h3. Predefined action list
46 8 David Božjak
47
Predefined action list is a list of all the conditions and co-responding actions entered to the system. It is implemented as a non-ordered list of structures containing the information: 
48 1 Aleksander Bešir
49 9 David Božjak
# Input device ID
50
# Corner value
51
# Comparison operator
52
# Action to be executed
53
54 10 David Božjak
The list is saved in a csv/xml file. It is initialized with on the Decision Making Software program startup and then periodically refreshed, insuring no restart is required when additional rules are entered.
55
56 1 Aleksander Bešir
h3. Action
57 9 David Božjak
58
Action is a program path and program argument pair, thus allowing the _Decision making software_ to execute it.
59
60
There are several rules for the Action developers:
61
62 1 Aleksander Bešir
* The Action program must be executable through command line,
63
* The Action program must *not* expect human interaction,
64
* The Action program must terminate in a deterministic time,
65
66
Outside of this very general rules the Action developers have no limitations in writing the Action programs.
67 11 David Božjak
68
h2. Communication and message formats
69
70
The logic component uses three types of messages to connect to other parts of the Eneraptor system. They are the following:
71
72
* The message for communication with device manager -> XML
73
* The message for communication with HMI -> XML
74
* The message for logging (via syslog) -> formatted plain text
75
76 1 Aleksander Bešir
These messages are then transported over the network to their destination.
77 11 David Božjak
78 12 David Božjak
* The Logic -> device manager communication uses *IP sockets* to relay messages.
79 11 David Božjak
* The Logic <--> HMI communication uses *UDP* communication to relay messages.
80
* The Logic <--> Logging service uses syslog's built in mechanism for relaying the messages to their destination.
81
82 1 Aleksander Bešir
h3. The logic <--> device manager message
83
84 13 David Božjak
The device manager logic is twofold: when the device manager signals new available data, it is read from a shared variable (encapsulated within a monitor). The IP socket is used for the reverse connection, when the HMI request a certain value which has to be read. When that happens a +request message+ is sent. The messaging thread blocks until an answer is received. The response is then transformed to Logic -> HMI message and sent to HMI.
85 12 David Božjak
86
The syntax of the request message is irrelevant since the there aren't several data points to choose from. The response however should be a single double value (defined with IEEE 754).
87
88
*Questions:*
89
*Will there ever be a device manager with several data points available for reading?
90
91
*Notes:*
92
* The named pipe option was considered however I prefer the IP socket protocol. The main reason behind this decision is that a named pipe can only be open for reading *or* writing thus complicating the programming somewhat.
93
94 11 David Božjak
h3. The logic <--> HMI message
95
96
h3. The logic -> logging
97 1 Aleksander Bešir
98 13 David Božjak
The logic uses syslog to save a plain text message to the database. However the message has to be formatted, so the information can be extracted by the Statistical Data Analysis Software ([[Archive and statistics]]. 
99
100
The archiving can be initiated for the following reasons:
101
* Type1: New data was sent by the device manager,
102
* Type2: Action was taken due to the read changes in the observed world,
103
* Type3: Action was initiated by the system administrator via HMI.
104
105
The reason for the archiving has to be visible in the message. Thus the first byte of the message is reserved for the type of the message. The rest of the message is conditioned by the type.
106
107
h4. Type1
108
109
h4. Type2
110
111
h4. Type3
112
113
114
115 1 Aleksander Bešir
h2. Configuration
116 12 David Božjak
117 13 David Božjak
The configuration consists of a XML file, which is read on startup. The XML file should look like this:
118 1 Aleksander Bešir
119 13 David Božjak
<todo>
120
121
The configuration can also be modified by the HMI. When that happens the XML configuration file has to be modified to reflect the new changes.
122
123 1 Aleksander Bešir
h2. The interfaces
124 13 David Božjak
125
The following interfaces have to be defined by the extern components for them to be seen as a valid Eneraptor component:
126
127
<todo>