wip refactor
This commit is contained in:
@@ -83,6 +83,18 @@
|
|||||||
./usr/bin/ubus call domo.lights read "{\"id\":2}"
|
./usr/bin/ubus call domo.lights read "{\"id\":2}"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Salon",
|
||||||
|
"speach_name": "salon",
|
||||||
|
"state": false,
|
||||||
|
"zone": "",
|
||||||
|
"sender": 12797322,
|
||||||
|
"interruptor": 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### update
|
### update
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -18,13 +18,16 @@ file(
|
|||||||
${workspaceRoot}/src/prog/domod/src/main.cpp
|
${workspaceRoot}/src/prog/domod/src/main.cpp
|
||||||
# devices
|
# devices
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/devices-manager.cpp
|
${workspaceRoot}/src/prog/domod/src/devices/devices-manager.cpp
|
||||||
|
${workspaceRoot}/src/prog/domod/src/devices/devices-collection.cpp
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/device.cpp
|
${workspaceRoot}/src/prog/domod/src/devices/device.cpp
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/light-device.cpp
|
${workspaceRoot}/src/prog/domod/src/devices/generic-dio.cpp
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/shutter-device.cpp
|
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/sprinkler-device.cpp
|
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/light.cpp
|
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/shutter.cpp
|
|
||||||
${workspaceRoot}/src/prog/domod/src/devices/sprinkler.cpp
|
${workspaceRoot}/src/prog/domod/src/devices/sprinkler.cpp
|
||||||
|
${workspaceRoot}/src/prog/domod/src/devices/shutter.cpp
|
||||||
|
|
||||||
|
# ${workspaceRoot}/src/prog/domod/src/devices/light-device.cpp
|
||||||
|
# ${workspaceRoot}/src/prog/domod/src/devices/shutter-device.cpp
|
||||||
|
# ${workspaceRoot}/src/prog/domod/src/devices/sprinkler-device.cpp
|
||||||
|
|
||||||
# ubus models
|
# ubus models
|
||||||
${workspaceRoot}/src/prog/domod/src/ubus/capabilities-controller.cpp
|
${workspaceRoot}/src/prog/domod/src/ubus/capabilities-controller.cpp
|
||||||
${workspaceRoot}/src/prog/domod/src/ubus/lights-controller.cpp
|
${workspaceRoot}/src/prog/domod/src/ubus/lights-controller.cpp
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
|
|
||||||
#include "domo.h"
|
#include "domo.h"
|
||||||
@@ -51,6 +49,17 @@ Device::~Device(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn get_id
|
||||||
|
*
|
||||||
|
* @brief Return the ID of the device.
|
||||||
|
*/
|
||||||
|
uint16_t Device::get_id(void)
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn from_json
|
* @fn from_json
|
||||||
*
|
*
|
||||||
@@ -59,13 +68,27 @@ Device::~Device(void)
|
|||||||
int Device::from_json(struct json_object *a_node)
|
int Device::from_json(struct json_object *a_node)
|
||||||
{
|
{
|
||||||
struct json_object *the_value_node;
|
struct json_object *the_value_node;
|
||||||
fprintf(stderr, "Device::load_from_json...\n");
|
// TODO: Should shared with Light.
|
||||||
|
// id
|
||||||
// speach name
|
if (json_object_object_get_ex(a_node, k_entry_id, &the_value_node))
|
||||||
|
{
|
||||||
|
m_id = json_object_get_int(the_value_node);
|
||||||
|
}
|
||||||
|
// name
|
||||||
|
if (json_object_object_get_ex(a_node, k_entry_name, &the_value_node))
|
||||||
|
{
|
||||||
|
m_name = json_object_get_string(the_value_node);
|
||||||
|
}
|
||||||
|
// speech_name
|
||||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node))
|
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node))
|
||||||
{
|
{
|
||||||
m_speach_name = json_object_get_string(the_value_node);
|
m_speach_name = json_object_get_string(the_value_node);
|
||||||
}
|
}
|
||||||
|
// state
|
||||||
|
if (json_object_object_get_ex(a_node, k_entry_state, &the_value_node))
|
||||||
|
{
|
||||||
|
m_state = json_object_get_boolean(the_value_node);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -77,5 +100,30 @@ int Device::from_json(struct json_object *a_node)
|
|||||||
*/
|
*/
|
||||||
struct json_object *Device::to_json(void) const
|
struct json_object *Device::to_json(void) const
|
||||||
{
|
{
|
||||||
return NULL;
|
struct json_object *the_root_node;
|
||||||
|
|
||||||
|
the_root_node = json_object_new_object();
|
||||||
|
|
||||||
|
to_json(the_root_node);
|
||||||
|
|
||||||
|
return the_root_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn to_json
|
||||||
|
*
|
||||||
|
* @brief Export Device Object as JSON Object without creating a node.
|
||||||
|
*/
|
||||||
|
int Device::to_json(struct json_object *a_node) const
|
||||||
|
{
|
||||||
|
// id
|
||||||
|
json_object_object_add(a_node, k_entry_id, json_object_new_int(m_id));
|
||||||
|
// name
|
||||||
|
json_object_object_add(a_node, k_entry_name, json_object_new_string(m_name.c_str()));
|
||||||
|
// speach_name
|
||||||
|
json_object_object_add(a_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
||||||
|
// state
|
||||||
|
json_object_object_add(a_node, k_entry_state, json_object_new_boolean(m_state));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Device.h
|
* device.h
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
struct json_object;
|
struct json_object;
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class Device
|
class Device
|
||||||
@@ -43,11 +42,19 @@ class Device
|
|||||||
Device(void);
|
Device(void);
|
||||||
virtual ~Device(void);
|
virtual ~Device(void);
|
||||||
|
|
||||||
|
uint16_t get_id(void);
|
||||||
|
|
||||||
virtual int from_json(struct json_object *a_node);
|
virtual int from_json(struct json_object *a_node);
|
||||||
virtual struct json_object *to_json(void) const;
|
virtual struct json_object *to_json(void) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual int to_json(struct json_object *a_node) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
uint16_t m_id;
|
||||||
|
std::string m_name;
|
||||||
std::string m_speach_name;
|
std::string m_speach_name;
|
||||||
|
bool m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _DEVICE_H */
|
#endif /* _DEVICE_H */
|
||||||
|
|||||||
115
src/prog/domod/src/devices/devices-collection.cpp
Normal file
115
src/prog/domod/src/devices/devices-collection.cpp
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*!
|
||||||
|
* device-collection.cpp
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @Author: NADAL Jean-Baptiste
|
||||||
|
* @Date: 04/05/2018
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <json-c/json.h>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
#include "devices-collection.h"
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn DeviceCollection
|
||||||
|
*
|
||||||
|
* @brief Constructor of the Device Collection.
|
||||||
|
*/
|
||||||
|
DeviceCollection::DeviceCollection(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn DeviceCollection
|
||||||
|
*
|
||||||
|
* @brief Destructor of the Device Collection.
|
||||||
|
*/
|
||||||
|
DeviceCollection::~DeviceCollection(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn operator[]
|
||||||
|
*
|
||||||
|
* @brief to access to a specific light object.
|
||||||
|
*/
|
||||||
|
Device *DeviceCollection::operator[](int a_pos)
|
||||||
|
{
|
||||||
|
return m_devices[a_pos].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn add
|
||||||
|
*
|
||||||
|
* @brief add a device to the collection.
|
||||||
|
*/
|
||||||
|
int DeviceCollection::add(Device *a_device)
|
||||||
|
{
|
||||||
|
m_devices.push_back(std::unique_ptr<Device>(a_device));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn find
|
||||||
|
*
|
||||||
|
* @brief find a device in the collection.
|
||||||
|
*/
|
||||||
|
int DeviceCollection::find(int a_pos)
|
||||||
|
{
|
||||||
|
std::vector <std::unique_ptr<Device>>::iterator the_it;
|
||||||
|
int the_status = -1;
|
||||||
|
int the_pos = 0;
|
||||||
|
|
||||||
|
for (the_it = m_devices.begin(); the_it != m_devices.end(); the_it++)
|
||||||
|
{
|
||||||
|
if ((*the_it).get()->get_id() == a_pos)
|
||||||
|
{
|
||||||
|
return the_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
the_pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return the_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn to_json
|
||||||
|
*
|
||||||
|
* @brief Export the device collection as JSON Object.
|
||||||
|
*/
|
||||||
|
struct json_object *DeviceCollection::to_json(void)
|
||||||
|
{
|
||||||
|
struct json_object *the_root_node;
|
||||||
|
std::vector <std::unique_ptr<Device>>::iterator the_it;
|
||||||
|
|
||||||
|
the_root_node = json_object_new_array();
|
||||||
|
|
||||||
|
for (the_it = m_devices.begin(); the_it != m_devices.end(); the_it++)
|
||||||
|
{
|
||||||
|
json_object_array_add(the_root_node, (*the_it).get()->to_json());
|
||||||
|
}
|
||||||
|
|
||||||
|
return the_root_node;
|
||||||
|
}
|
||||||
58
src/prog/domod/src/devices/devices-collection.h
Normal file
58
src/prog/domod/src/devices/devices-collection.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*!
|
||||||
|
* device-collection.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @Author: NADAL Jean-Baptiste
|
||||||
|
* @Date: 04/05/2018
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DEVICE_COLLECTION_H
|
||||||
|
#define _DEVICE_COLLECTION_H
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/*------------------------------ DEPENDENCIES -------------------------------*/
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
|
||||||
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
|
class DeviceCollection
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeviceCollection(void);
|
||||||
|
~DeviceCollection(void);
|
||||||
|
|
||||||
|
Device *operator[](int a_pos);
|
||||||
|
|
||||||
|
int add(Device *a_device);
|
||||||
|
|
||||||
|
int find(int a_pos);
|
||||||
|
|
||||||
|
struct json_object *to_json(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector <std::unique_ptr<Device>> m_devices;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _DEVICE_COLLECTION_H */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Devices.cpp
|
* devices-manager.cpp
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -32,12 +32,17 @@
|
|||||||
|
|
||||||
#include "domo.h"
|
#include "domo.h"
|
||||||
|
|
||||||
|
#include "generic-dio.h"
|
||||||
|
#include "shutter.h"
|
||||||
|
#include "sprinkler.h"
|
||||||
|
|
||||||
|
|
||||||
#include "devices/devices-manager.h"
|
#include "devices/devices-manager.h"
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn DevicesManager
|
* @fn DevicesManager
|
||||||
*
|
*
|
||||||
* @brief Constructor of the Devices Managagers.
|
* @brief Constructor of the Devices Managers.
|
||||||
*/
|
*/
|
||||||
DevicesManager::DevicesManager(const std::string &a_path) : m_file_path(a_path)
|
DevicesManager::DevicesManager(const std::string &a_path) : m_file_path(a_path)
|
||||||
{
|
{
|
||||||
@@ -46,7 +51,7 @@ DevicesManager::DevicesManager(const std::string &a_path) : m_file_path(a_path)
|
|||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ~DevicesManager
|
* @fn ~DevicesManager
|
||||||
*
|
*
|
||||||
* @brief Destructor of the Devices Managagers.
|
* @brief Destructor of the Devices Managers.
|
||||||
*/
|
*/
|
||||||
DevicesManager::~DevicesManager(void)
|
DevicesManager::~DevicesManager(void)
|
||||||
{
|
{
|
||||||
@@ -72,19 +77,19 @@ int DevicesManager::load(void)
|
|||||||
if (json_object_object_get_ex(the_root_node, kLightEntry, &the_value_node))
|
if (json_object_object_get_ex(the_root_node, kLightEntry, &the_value_node))
|
||||||
{
|
{
|
||||||
printf(" On a des Lights.\n");
|
printf(" On a des Lights.\n");
|
||||||
m_lights.from_json(the_value_node);
|
load_lights(the_value_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
|
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
|
||||||
{
|
{
|
||||||
printf(" On a des shutters.\n");
|
printf(" On a des shutters.\n");
|
||||||
m_shutters.from_json(the_value_node);
|
load_shutters(the_value_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json_object_object_get_ex(the_root_node, kSprinklerEntry, &the_value_node))
|
if (json_object_object_get_ex(the_root_node, kSprinklerEntry, &the_value_node))
|
||||||
{
|
{
|
||||||
printf(" On a des sprintkler.\n");
|
printf(" On a des sprintkler.\n");
|
||||||
m_sprinklers.from_json(the_value_node);
|
load_sprinklers(the_value_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean the json object. */
|
/* Clean the json object. */
|
||||||
@@ -106,11 +111,11 @@ int DevicesManager::save(void)
|
|||||||
the_root_node = json_object_new_object();
|
the_root_node = json_object_new_object();
|
||||||
|
|
||||||
// Lights
|
// Lights
|
||||||
json_object_object_add(the_root_node, kLightEntry, m_lights.to_json());
|
//json_object_object_add(the_root_node, kLightEntry, m_lights.to_json());
|
||||||
// Shutters
|
// Shutters
|
||||||
json_object_object_add(the_root_node, kShutterEntry, m_shutters.to_json());
|
//json_object_object_add(the_root_node, kShutterEntry, m_shutters.to_json());
|
||||||
// Sprinklers
|
// Sprinklers
|
||||||
json_object_object_add(the_root_node, kSprinklerEntry, m_sprinklers.to_json());
|
//json_object_object_add(the_root_node, kSprinklerEntry, m_sprinklers.to_json());
|
||||||
|
|
||||||
the_result = json_object_to_file(m_file_path.c_str(), the_root_node);
|
the_result = json_object_to_file(m_file_path.c_str(), the_root_node);
|
||||||
|
|
||||||
@@ -167,7 +172,7 @@ std::string DevicesManager::get(const std::string &a_capability, uint32_t an_id)
|
|||||||
the_pos = m_lights.find(an_id);
|
the_pos = m_lights.find(an_id);
|
||||||
if (the_pos != -1)
|
if (the_pos != -1)
|
||||||
{
|
{
|
||||||
the_output = json_object_to_json_string(m_lights[the_pos].to_json());
|
the_output = json_object_to_json_string(m_lights[the_pos]->to_json());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +187,7 @@ std::string DevicesManager::get(const std::string &a_capability, uint32_t an_id)
|
|||||||
int DevicesManager::set(const std::string &a_capability, struct json_object *a_node)
|
int DevicesManager::set(const std::string &a_capability, struct json_object *a_node)
|
||||||
{
|
{
|
||||||
int the_result = -1;
|
int the_result = -1;
|
||||||
|
#if 0
|
||||||
if (a_capability == kLightEntry)
|
if (a_capability == kLightEntry)
|
||||||
{
|
{
|
||||||
the_result = m_lights.set(a_node);
|
the_result = m_lights.set(a_node);
|
||||||
@@ -198,7 +203,7 @@ int DevicesManager::set(const std::string &a_capability, struct json_object *a_n
|
|||||||
|
|
||||||
if (the_result == 0)
|
if (the_result == 0)
|
||||||
save();
|
save();
|
||||||
|
#endif
|
||||||
return the_result;
|
return the_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +215,7 @@ int DevicesManager::set(const std::string &a_capability, struct json_object *a_n
|
|||||||
int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a_state)
|
int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a_state)
|
||||||
{
|
{
|
||||||
int the_result = -1;
|
int the_result = -1;
|
||||||
|
#if 0
|
||||||
if (a_capability == kLightEntry)
|
if (a_capability == kLightEntry)
|
||||||
{
|
{
|
||||||
the_result = m_lights.set(an_id, a_state);
|
the_result = m_lights.set(an_id, a_state);
|
||||||
@@ -223,7 +228,7 @@ int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a
|
|||||||
{
|
{
|
||||||
the_result = m_sprinklers.set(an_id, a_state);
|
the_result = m_sprinklers.set(an_id, a_state);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (the_result == 0)
|
if (the_result == 0)
|
||||||
{
|
{
|
||||||
save();
|
save();
|
||||||
@@ -231,3 +236,91 @@ int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a
|
|||||||
|
|
||||||
return the_result;
|
return the_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn load_lights
|
||||||
|
*
|
||||||
|
* @brief Load Lights Object From a Json Node.
|
||||||
|
*/
|
||||||
|
int DevicesManager::load_lights(struct json_object *a_node)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "DevicesManager::load_lights\n");
|
||||||
|
|
||||||
|
// Get Lights
|
||||||
|
if (json_object_get_type(a_node) == json_type_array)
|
||||||
|
{
|
||||||
|
int the_len;
|
||||||
|
struct json_object *the_light_node;
|
||||||
|
|
||||||
|
the_len = json_object_array_length(a_node);
|
||||||
|
for (int i = 0; i < the_len; i++)
|
||||||
|
{
|
||||||
|
GenericDio* the_light = new GenericDio;
|
||||||
|
the_light_node = json_object_array_get_idx(a_node, i);
|
||||||
|
the_light->from_json(the_light_node);
|
||||||
|
|
||||||
|
m_lights.add(the_light);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn load_lights
|
||||||
|
*
|
||||||
|
* @brief Load Lights Object From a Json Node.
|
||||||
|
*/
|
||||||
|
int DevicesManager::load_shutters(struct json_object *a_node)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "DevicesManager::load_shutters\n");
|
||||||
|
|
||||||
|
// Get Shutter
|
||||||
|
if (json_object_get_type(a_node) == json_type_array)
|
||||||
|
{
|
||||||
|
int the_len;
|
||||||
|
struct json_object *the_shutter_node;
|
||||||
|
|
||||||
|
the_len = json_object_array_length(a_node);
|
||||||
|
for (int i = 0; i < the_len; i++)
|
||||||
|
{
|
||||||
|
Shutter* the_shutter = new Shutter;
|
||||||
|
the_shutter_node = json_object_array_get_idx(a_node, i);
|
||||||
|
the_shutter->from_json(the_shutter_node);
|
||||||
|
|
||||||
|
m_shutters.add(the_shutter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn load_lights
|
||||||
|
*
|
||||||
|
* @brief Load Lights Object From a Json Node.
|
||||||
|
*/
|
||||||
|
int DevicesManager::load_sprinklers(struct json_object *a_node)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "DevicesManager::load_sprinklers\n");
|
||||||
|
|
||||||
|
// Get Sprinklers
|
||||||
|
if (json_object_get_type(a_node) == json_type_array)
|
||||||
|
{
|
||||||
|
int the_len;
|
||||||
|
struct json_object *the_sprinkler_node;
|
||||||
|
|
||||||
|
the_len = json_object_array_length(a_node);
|
||||||
|
for (int i = 0; i < the_len; i++)
|
||||||
|
{
|
||||||
|
Sprinkler* the_sprinkler = new Sprinkler;
|
||||||
|
the_sprinkler_node = json_object_array_get_idx(a_node, i);
|
||||||
|
the_sprinkler->from_json(the_sprinkler_node);
|
||||||
|
|
||||||
|
m_sprinklers.add(the_sprinkler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Devices.h
|
* devices-manager.h
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -30,14 +30,16 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "devices/light-device.h"
|
//#include "devices/light-device.h"
|
||||||
#include "devices/shutter-device.h"
|
//#include "devices/shutter-device.h"
|
||||||
#include "devices/sprinkler-device.h"
|
//#include "devices/sprinkler-device.h"
|
||||||
|
|
||||||
#include "devices/device.h"
|
#include "devices/devices-collection.h"
|
||||||
|
|
||||||
/*---------------------------------- Deps -----------------------------------*/
|
/*---------------------------------- Deps -----------------------------------*/
|
||||||
|
|
||||||
|
struct json_object;
|
||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class DevicesManager
|
class DevicesManager
|
||||||
@@ -54,12 +56,17 @@ class DevicesManager
|
|||||||
int set(const std::string &a_capability, struct json_object *a_node);
|
int set(const std::string &a_capability, struct json_object *a_node);
|
||||||
int set_state(const std::string &a_capability, int an_id, bool a_state);
|
int set_state(const std::string &a_capability, int an_id, bool a_state);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int load_lights(struct json_object *a_node);
|
||||||
|
int load_shutters(struct json_object *a_node);
|
||||||
|
int load_sprinklers(struct json_object *a_node);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_file_path;
|
std::string m_file_path;
|
||||||
|
|
||||||
LightDevice m_lights;
|
DeviceCollection m_lights;
|
||||||
ShutterDevice m_shutters;
|
DeviceCollection m_shutters;
|
||||||
SprinklerDevice m_sprinklers;
|
DeviceCollection m_sprinklers;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _DEVICES_MANAGER_H */
|
#endif /* _DEVICES_MANAGER_H */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Light.cpp
|
* generic-dio.cpp
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -33,15 +33,15 @@
|
|||||||
|
|
||||||
#include "domo.h"
|
#include "domo.h"
|
||||||
|
|
||||||
#include "devices/light.h"
|
#include "generic-dio.h"
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn Light
|
* @fn GenericDio
|
||||||
*
|
*
|
||||||
* @brief Constructor of the Light Object.
|
* @brief Constructor of the Light Object.
|
||||||
*/
|
*/
|
||||||
Light::Light(void)
|
GenericDio::GenericDio(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ Light::Light(void)
|
|||||||
*
|
*
|
||||||
* @brief Destructor of the Light Object.
|
* @brief Destructor of the Light Object.
|
||||||
*/
|
*/
|
||||||
Light::~Light(void)
|
GenericDio::~GenericDio(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,35 +59,20 @@ Light::~Light(void)
|
|||||||
*
|
*
|
||||||
* @brief Load a Light Element from a Json Entry.
|
* @brief Load a Light Element from a Json Entry.
|
||||||
*/
|
*/
|
||||||
int Light::from_json(struct json_object *a_node)
|
int GenericDio::from_json(struct json_object *a_node)
|
||||||
{
|
{
|
||||||
|
int the_result;
|
||||||
struct json_object *the_value_node;
|
struct json_object *the_value_node;
|
||||||
|
|
||||||
// id
|
the_result = Device::from_json(a_node);
|
||||||
if (json_object_object_get_ex(a_node, k_entry_id, &the_value_node))
|
if (the_result < 0)
|
||||||
{
|
return the_result;
|
||||||
m_id = json_object_get_int(the_value_node);
|
|
||||||
}
|
|
||||||
// name
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_name, &the_value_node))
|
|
||||||
{
|
|
||||||
m_name = json_object_get_string(the_value_node);
|
|
||||||
}
|
|
||||||
// speach_name
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node))
|
|
||||||
{
|
|
||||||
m_speach_name = json_object_get_string(the_value_node);
|
|
||||||
}
|
|
||||||
// zone
|
// zone
|
||||||
if (json_object_object_get_ex(a_node, k_entry_zone, &the_value_node))
|
if (json_object_object_get_ex(a_node, k_entry_zone, &the_value_node))
|
||||||
{
|
{
|
||||||
m_zone = json_object_get_string(the_value_node);
|
m_zone = json_object_get_string(the_value_node);
|
||||||
}
|
}
|
||||||
// state
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_state, &the_value_node))
|
|
||||||
{
|
|
||||||
m_state = json_object_get_boolean(the_value_node);
|
|
||||||
}
|
|
||||||
// sender
|
// sender
|
||||||
if (json_object_object_get_ex(a_node, k_entry_sender, &the_value_node))
|
if (json_object_object_get_ex(a_node, k_entry_sender, &the_value_node))
|
||||||
{
|
{
|
||||||
@@ -107,30 +92,39 @@ int Light::from_json(struct json_object *a_node)
|
|||||||
*
|
*
|
||||||
* @brief Return Light Object as a Json Object.
|
* @brief Return Light Object as a Json Object.
|
||||||
*/
|
*/
|
||||||
struct json_object *Light::to_json(void) const
|
struct json_object *GenericDio::to_json(void) const
|
||||||
{
|
{
|
||||||
struct json_object *the_root_node;
|
struct json_object *the_root_node;
|
||||||
|
|
||||||
the_root_node = json_object_new_object();
|
the_root_node = json_object_new_object();
|
||||||
|
|
||||||
// id
|
to_json(the_root_node);
|
||||||
json_object_object_add(the_root_node, k_entry_id, json_object_new_int(m_id));
|
|
||||||
// name
|
|
||||||
json_object_object_add(the_root_node, k_entry_name, json_object_new_string(m_name.c_str()));
|
|
||||||
// speach_name
|
|
||||||
json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
|
||||||
// zone
|
|
||||||
json_object_object_add(the_root_node, k_entry_zone, json_object_new_string(m_zone.c_str()));
|
|
||||||
// state
|
|
||||||
json_object_object_add(the_root_node, k_entry_state, json_object_new_boolean(m_state));
|
|
||||||
// sender
|
|
||||||
json_object_object_add(the_root_node, k_entry_sender, json_object_new_int(m_sender));
|
|
||||||
// interruptor
|
|
||||||
json_object_object_add(the_root_node, k_entry_interruptor, json_object_new_int(m_interruptor));
|
|
||||||
|
|
||||||
return the_root_node;
|
return the_root_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn to_json
|
||||||
|
*
|
||||||
|
* @brief Export Device Object as JSON Object without creating a node.
|
||||||
|
*/
|
||||||
|
int GenericDio::to_json(struct json_object *a_node) const
|
||||||
|
{
|
||||||
|
// Get DEvices fields
|
||||||
|
Device::to_json(a_node);
|
||||||
|
|
||||||
|
// zone
|
||||||
|
json_object_object_add(a_node, k_entry_zone, json_object_new_string(m_zone.c_str()));
|
||||||
|
// sender
|
||||||
|
json_object_object_add(a_node, k_entry_sender, json_object_new_int(m_sender));
|
||||||
|
// interruptor
|
||||||
|
json_object_object_add(a_node, k_entry_interruptor, json_object_new_int(m_interruptor));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn update
|
* @fn update
|
||||||
*
|
*
|
||||||
@@ -179,3 +173,4 @@ int Light::send_state(void)
|
|||||||
|
|
||||||
return the_result;
|
return the_result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Light.h
|
* generic-dio.h
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -28,9 +28,7 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "device.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/*---------------------------------- Deps -----------------------------------*/
|
/*---------------------------------- Deps -----------------------------------*/
|
||||||
|
|
||||||
@@ -38,28 +36,25 @@ struct json_object;
|
|||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class Light
|
class GenericDio : public Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Light(void);
|
GenericDio(void);
|
||||||
~Light(void);
|
~GenericDio(void);
|
||||||
|
|
||||||
int from_json(struct json_object *a_node);
|
virtual int from_json(struct json_object *a_node);
|
||||||
struct json_object *to_json(void) const;
|
virtual struct json_object *to_json(void) const;
|
||||||
|
|
||||||
int update(bool a_state);
|
protected:
|
||||||
|
virtual int to_json(struct json_object *a_node) const;
|
||||||
|
|
||||||
uint16_t get_id(void);
|
// int update(bool a_state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int send_state(void);
|
// int send_state(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t m_id;
|
|
||||||
std::string m_name;
|
|
||||||
std::string m_speach_name;
|
|
||||||
std::string m_zone;
|
std::string m_zone;
|
||||||
bool m_state;
|
|
||||||
uint32_t m_sender;
|
uint32_t m_sender;
|
||||||
uint8_t m_interruptor;
|
uint8_t m_interruptor;
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Shutter.cpp
|
* shutter.cpp
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -61,43 +61,13 @@ Shutter::~Shutter(void)
|
|||||||
*/
|
*/
|
||||||
int Shutter::from_json(struct json_object *a_node)
|
int Shutter::from_json(struct json_object *a_node)
|
||||||
{
|
{
|
||||||
|
int the_result;
|
||||||
struct json_object *the_value_node;
|
struct json_object *the_value_node;
|
||||||
// TODO: Should shared with Light.
|
|
||||||
// id
|
the_result = GenericDio::from_json(a_node);
|
||||||
if (json_object_object_get_ex(a_node, k_entry_id, &the_value_node))
|
if (the_result < 0)
|
||||||
{
|
return the_result;
|
||||||
m_id = json_object_get_int(the_value_node);
|
|
||||||
}
|
|
||||||
// name
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_name, &the_value_node))
|
|
||||||
{
|
|
||||||
m_name = json_object_get_string(the_value_node);
|
|
||||||
}
|
|
||||||
// speach_name
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node))
|
|
||||||
{
|
|
||||||
m_speach_name = json_object_get_string(the_value_node);
|
|
||||||
}
|
|
||||||
// zone
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_zone, &the_value_node))
|
|
||||||
{
|
|
||||||
m_zone = json_object_get_string(the_value_node);
|
|
||||||
}
|
|
||||||
// state
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_state, &the_value_node))
|
|
||||||
{
|
|
||||||
m_state = json_object_get_boolean(the_value_node);
|
|
||||||
}
|
|
||||||
// sender
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_sender, &the_value_node))
|
|
||||||
{
|
|
||||||
m_sender = json_object_get_int(the_value_node);
|
|
||||||
}
|
|
||||||
// interruptor
|
|
||||||
if (json_object_object_get_ex(a_node, k_entry_interruptor, &the_value_node))
|
|
||||||
{
|
|
||||||
m_interruptor = json_object_get_int(the_value_node);
|
|
||||||
}
|
|
||||||
// speed up
|
// speed up
|
||||||
if (json_object_object_get_ex(a_node, k_entry_speed_up, &the_value_node))
|
if (json_object_object_get_ex(a_node, k_entry_speed_up, &the_value_node))
|
||||||
{
|
{
|
||||||
@@ -123,28 +93,30 @@ struct json_object *Shutter::to_json(void) const
|
|||||||
|
|
||||||
the_root_node = json_object_new_object();
|
the_root_node = json_object_new_object();
|
||||||
|
|
||||||
// id
|
to_json(the_root_node);
|
||||||
json_object_object_add(the_root_node, k_entry_id, json_object_new_int(m_id));
|
|
||||||
// name
|
|
||||||
json_object_object_add(the_root_node, k_entry_name, json_object_new_string(m_name.c_str()));
|
|
||||||
// speach_name
|
|
||||||
json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
|
||||||
// zone
|
|
||||||
json_object_object_add(the_root_node, k_entry_zone, json_object_new_string(m_zone.c_str()));
|
|
||||||
// state
|
|
||||||
json_object_object_add(the_root_node, k_entry_state, json_object_new_boolean(m_state));
|
|
||||||
// sender
|
|
||||||
json_object_object_add(the_root_node, k_entry_sender, json_object_new_int(m_sender));
|
|
||||||
// interruptor
|
|
||||||
json_object_object_add(the_root_node, k_entry_interruptor, json_object_new_int(m_interruptor));
|
|
||||||
// speed up
|
|
||||||
json_object_object_add(the_root_node, k_entry_speed_up, json_object_new_int(m_speed_up));
|
|
||||||
// speed down
|
|
||||||
json_object_object_add(the_root_node, k_entry_speed_down, json_object_new_int(m_speed_down));
|
|
||||||
|
|
||||||
return the_root_node;
|
return the_root_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn to_json
|
||||||
|
*
|
||||||
|
* @brief Export Device Object as JSON Object without creating a node.
|
||||||
|
*/
|
||||||
|
int Shutter::to_json(struct json_object *a_node) const
|
||||||
|
{
|
||||||
|
// Get Generic Dio fields
|
||||||
|
GenericDio::to_json(a_node);
|
||||||
|
|
||||||
|
// speed up
|
||||||
|
json_object_object_add(a_node, k_entry_speed_up, json_object_new_int(m_speed_up));
|
||||||
|
// speed down
|
||||||
|
json_object_object_add(a_node, k_entry_speed_down, json_object_new_int(m_speed_down));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn update
|
* @fn update
|
||||||
*
|
*
|
||||||
@@ -179,3 +151,4 @@ int Shutter::send_state(void)
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Shutter.h
|
* shutter.h
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "generic-dio.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ struct json_object;
|
|||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class Shutter
|
class Shutter : public GenericDio
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Shutter(void);
|
Shutter(void);
|
||||||
@@ -47,21 +47,18 @@ class Shutter
|
|||||||
int from_json(struct json_object *a_node);
|
int from_json(struct json_object *a_node);
|
||||||
struct json_object *to_json(void) const;
|
struct json_object *to_json(void) const;
|
||||||
|
|
||||||
int update(bool a_state);
|
protected:
|
||||||
|
int to_json(struct json_object *a_node) const;
|
||||||
|
|
||||||
uint16_t get_id(void);
|
|
||||||
|
// int update(bool a_state);
|
||||||
|
|
||||||
|
// uint16_t get_id(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int send_state(void);
|
// int send_state(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t m_id;
|
|
||||||
std::string m_name;
|
|
||||||
std::string m_speach_name;
|
|
||||||
std::string m_zone;
|
|
||||||
bool m_state;
|
|
||||||
uint32_t m_sender;
|
|
||||||
uint8_t m_interruptor;
|
|
||||||
uint8_t m_speed_up;
|
uint8_t m_speed_up;
|
||||||
uint8_t m_speed_down;
|
uint8_t m_speed_down;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Sprinkler.cpp
|
* sprinkler.cpp
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -57,6 +57,7 @@ Sprinkler::~Sprinkler(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn from_json
|
* @fn from_json
|
||||||
*
|
*
|
||||||
@@ -160,3 +161,4 @@ int Sprinkler::send_state(void)
|
|||||||
|
|
||||||
return the_result;
|
return the_result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Sprinkler.h
|
* sprinkler.h
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -28,9 +28,7 @@
|
|||||||
|
|
||||||
/*------------------------------- INCLUDES ----------------------------------*/
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "device.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/*---------------------------------- Deps -----------------------------------*/
|
/*---------------------------------- Deps -----------------------------------*/
|
||||||
|
|
||||||
@@ -38,27 +36,24 @@ struct json_object;
|
|||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class Sprinkler
|
class Sprinkler : public Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Sprinkler(void);
|
Sprinkler(void);
|
||||||
~Sprinkler(void);
|
~Sprinkler(void);
|
||||||
|
|
||||||
int from_json(struct json_object *a_node);
|
// int from_json(struct json_object *a_node);
|
||||||
struct json_object *to_json(void) const;
|
// struct json_object *to_json(void) const;
|
||||||
|
|
||||||
int update(bool aState);
|
// int update(bool aState);
|
||||||
|
|
||||||
uint16_t get_id(void);
|
// uint16_t get_id(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int send_state(void);
|
// int send_state(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t m_id;
|
|
||||||
std::string m_name;
|
|
||||||
std::string m_speach_name;
|
|
||||||
bool m_state;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _SPRINKLER_H */
|
#endif /* _SPRINKLER_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user