
Chapter 4. Implementation 53
other thread is ready to exchange data. As a result, they are only suitable for large data transfers,
such as the device list exchange within the “get device list” service. Small data exchange is best
done via signals and slots, as signals are buffered and the thread has not to wait. Buffering large
amounts of data would be slower than waiting for the other thread to finish its current operations,
consequently both functions were used. The rosnode object acts as mediator between ROS and
the device manger class; it translates ROS messages into the format of the device manager class
and vice versa. The major work is done by the device manager class, therefore it is described in
more detail in the next section.
4.4.1. Device manager class
The device manager class is an enhanced database for saving HA devices as data structures and
translating protocol messages to database entries. It is composed of two parts, the database and
a set of functions for managing it.
The database is a custom programmed database, which was specially developed for this work.
Other databases, such as SQLite [33] and mongoDB
3
could have been used, but a custom, light
weighted database is beneficial for the speed and size of the node. It offers very fast access to its
data and can be easily integrated into the program, due to use of signal and slots. Figure 4.15
shows its internal structure.
QHash <int, receiverStruct>
receiver list
receiver name to id
on-code to id
off-code to id
QHash <string, int>
QMultiHash <string, int>
key1: value1
key2: value2
keyN: valueN
QMultiHash <string, int>
QHash <int, transmitterStruct>
transmitter list
transmitter name to id
t on-code to id
t off-code to id
QHash <string, int>
QHash <string, int>
key1: value1
key2: value2
keyN: valueN
QHash <string, int>
receiver transmitter
Figure 4.15.: The internal structure of the device manager class.
The database consists of two separate sets of QHash containers, each one for receivers and trans-
mitters respectively. QHash lists are one of Qt’s generic container classes for storing (key, value)-
pairs. They provide very fast lookup of the value associated with a key and linear insertion time,
which makes the database very fast for both normal lookup functions and direct manipulations.
Each set includes four QHash lists, of which only one list contains the actual device information.
The other lists link commonly used information, such as the on/off-codes and device names to the
3
http://www.mongodb.org/
Comentarios a estos manuales