Commit 69739f0a authored by Alessio Netti's avatar Alessio Netti
Browse files

Documentation and fixes

- Added documentation to the new SensorID implementation
- NOTE: virtual sensors will likely require some modifications due to
how topics are handled now ('/' separator clashing with divide symbol)
parent b45ce395
......@@ -67,6 +67,16 @@ public:
* @param hierarchy String containing a sensor hierarchy
*/
void setSensorHierarchy(const string& hierarchy) { _sensorHierarchy = hierarchy; }
/**
* @brief Set the current sensor filter
*
* This method sets the internal filter string used to discard sensors when building a
* SensorNavigator object.
*
* @param filter String containing the new filter
*/
void setFilter(const string& filter) { _filter = filter; }
/**
* @brief Sets the internal callback to retrieve sensor data
......@@ -105,6 +115,13 @@ public:
*/
const string& getSensorHierarchy() { return _sensorHierarchy; }
/**
* @brief Returns the current sensor filter
*
* @return String containing the current sensor filter
*/
const string& getFilter() { return _filter; }
/**
* @brief Perform a sensor query
*
......@@ -208,6 +225,8 @@ private:
QueryEngineJobCallback _jCallback;
// String storing the current sensor hierarchy, used for convenience
string _sensorHierarchy;
// String storing the filter to be used when building a sensor navigator
string _filter;
};
#endif //PROJECT_QUERYENGINE_H
......@@ -43,7 +43,7 @@ bool AnalyticsController::initialize(Configuration& settings, const string& conf
_dcdbCfg->getPublicSensorsVerbose(publicSensors);
for (const auto &s : publicSensors)
if (!s.is_virtual) {
topics.push_back(s.pattern);
topics.push_back(s.name);
}
publicSensors.clear();
......
......@@ -658,6 +658,8 @@ int main(int argc, char* const argv[]) {
analyticsController->setCache(&mySensorCache);
if(!analyticsController->initialize(settings, argv[argc - 1]))
return EXIT_FAILURE;
queryEngine.setFilter(analyticsSettings.filter);
queryEngine.setSensorHierarchy(analyticsSettings.hierarchy);
queryEngine.setQueryCallback(sensorQueryCallback);
queryEngine.setJobQueryCallback(jobQueryCallback);
......
......@@ -405,7 +405,7 @@ void HttpsServer::requestHandler::operator()(server::request const &request, ser
for (const auto &s : g->getSensors()) {
topics.push_back(s->getMqtt());
}
//TODO: add filter here
navigator->setFilter(qEngine.getFilter());
navigator->buildTree(qEngine.getSensorHierarchy(), &topics);
topics.clear();
qEngine.setNavigator(navigator);
......
......@@ -284,7 +284,9 @@ int main(int argc, char** argv) {
return 1;
}
}
_queryEngine.setFilter(analyticsSettings.filter);
_queryEngine.setSensorHierarchy(analyticsSettings.hierarchy);
_queryEngine.setQueryCallback(sensorQueryCallback);
if(!_analyticsManager->load(argv[argc-1], "dcdbpusher.conf", pluginSettings)) {
LOG(fatal) << "Failed to load data analytics manager!";
......
......@@ -17,27 +17,51 @@ namespace DCDB {
#pragma pack(push,1)
/**
* @brief The SensorId class packs the DeviceLocation and DeviceSensorId
* types into a single object.
* @brief The SensorId class uniquely identifies sensors that can be queried
*
* In DCDB, a sensor is described by it's location, a sensor number at
* this location, and a unique part number identifier. This information
* is packed into a 128 bit wide bitfield.
* In DCDB, a sensor is described by an ID in the form of a string, which
* usually corresponds to its MQTT topic. An additional field of 16 bits
* allows to set secondary identification info (such as the week-stamp).
*
* Access to this bitfield can be done through the raw member of through
* the two variables dl and dsid of the helper types DeviceLocation and
* DeviceSensorId.
*/
class SensorId {
protected:
// The string object used to store the sensor's ID
std::string data;
// 16-bits reserved field
uint16_t rsvd;
public:
/**
* @brief Sets the internal data field
*
* The input string is assumed to be an MQTT topic, which is sanitized and then stored
* in the data field.
*
* @param d The string to be used as sensor ID
*/
void setId(std::string &d) { if (!mqttTopicConvert(d)) data = ""; }
/**
* @brief Sets the value of the internal reserved bit field
*
* This field usually contains the week-stamp associated to the row of a certain sensor.
*
* @param rs The short integer value encoding the bit field
*/
void setRsvd(uint16_t rs) { rsvd = rs; }
/**
* @param Get the current sensor ID
* @return The string encoding the current sensor ID
*/
std::string getId() const { return data; }
/**
* @param Get the reserved bit field
* @return A short integer encoding the bit field
*/
uint16_t getRsvd() const { return rsvd; }
/**
......@@ -54,6 +78,7 @@ class SensorId {
*/
bool patternMatch(std::string pattern);
// Overloaded operators for comparisons
inline bool operator == (const SensorId& rhs) const {
return (data == rhs.data) && (rsvd == rhs.rsvd);
}
......
......@@ -40,12 +40,9 @@ using namespace DCDB;
/**
* @details
* The conversion of a MQTT message topic to a SensorId
* object is performed by byte-wise scanning of the string,
* and skipping of all characters except for those in the
* range [0-9,a-f,A-F]. Each character is then turned from
* hex string into its binary representation an OR'ed into
* the 128-bit raw fields of the SensorId object.
* This method includes all necessary logic to convert a MQTT topic to its internal sensor ID structure.
* No particular checks are performed at the moment; changing this implementation will affect the storage
* of sensor IDs at all levels in DCDB.
*/
bool SensorId::mqttTopicConvert(std::string mqttTopic)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment