Add datamodel
This commit is contained in:
@@ -11,6 +11,9 @@ include_directories (${CMAKE_SOURCE_DIR}/domo-iot/lib/include)
|
|||||||
include_directories (${CMAKE_SOURCE_DIR}/libevent/include)
|
include_directories (${CMAKE_SOURCE_DIR}/libevent/include)
|
||||||
include_directories (${CMAKE_SOURCE_DIR}/build/libevent/include)
|
include_directories (${CMAKE_SOURCE_DIR}/build/libevent/include)
|
||||||
include_directories (${CMAKE_SOURCE_DIR}/qlibc/include)
|
include_directories (${CMAKE_SOURCE_DIR}/qlibc/include)
|
||||||
|
include_directories (${CMAKE_SOURCE_DIR}/json-c)
|
||||||
|
include_directories (${CMAKE_SOURCE_DIR}/build/json-c)
|
||||||
|
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
#set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror=strict-aliasing")
|
#set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror=strict-aliasing")
|
||||||
|
|
||||||
@@ -18,9 +21,13 @@ file(
|
|||||||
GLOB_RECURSE
|
GLOB_RECURSE
|
||||||
source_files
|
source_files
|
||||||
main.c
|
main.c
|
||||||
|
devices/devices_manager.c
|
||||||
|
devices/device.c
|
||||||
|
devices/outlet_dio.c
|
||||||
|
devices/shutter.c
|
||||||
|
devices/sprinkler.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
add_executable (domo-iot ${source_files})
|
add_executable (domo-iot ${source_files})
|
||||||
|
|
||||||
target_link_libraries (domo-iot
|
target_link_libraries (domo-iot
|
||||||
@@ -30,6 +37,7 @@ target_link_libraries (domo-iot
|
|||||||
qlibc-static
|
qlibc-static
|
||||||
qlibcext-static
|
qlibcext-static
|
||||||
event
|
event
|
||||||
|
json-c
|
||||||
)
|
)
|
||||||
|
|
||||||
install (TARGETS domo-iot DESTINATION local/bin)
|
install (TARGETS domo-iot DESTINATION local/bin)
|
||||||
|
|||||||
151
src/devices/device.c
Normal file
151
src/devices/device.c
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
/*!
|
||||||
|
* device.c
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||||
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||||
|
|
||||||
|
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <json.h>
|
||||||
|
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
|
#include "domo.h"
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
/*----------------------------- PUBLIC FUNCTIONS ----------------------------*/
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
device_t *device_new(void)
|
||||||
|
{
|
||||||
|
device_t *device = NEW_OBJECT(device_t);
|
||||||
|
if (device == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero((void *)device, sizeof(device_t));
|
||||||
|
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void device_free(device_t *device)
|
||||||
|
{
|
||||||
|
if (device == NULL)
|
||||||
|
return;
|
||||||
|
if (device->name != NULL)
|
||||||
|
free(device->name);
|
||||||
|
if (device->speech_name != NULL)
|
||||||
|
free(device->speech_name);
|
||||||
|
|
||||||
|
free(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void device_set_id(device_t *device, uint16_t id)
|
||||||
|
{
|
||||||
|
device->id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
uint16_t device_get_id(device_t *device)
|
||||||
|
{
|
||||||
|
return device->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int device_from_json(device_t *device, struct json_object *node)
|
||||||
|
{
|
||||||
|
int16_t id = -1;
|
||||||
|
struct json_object *value_node;
|
||||||
|
|
||||||
|
// id
|
||||||
|
if (json_object_object_get_ex(node, k_entry_id, &value_node))
|
||||||
|
{
|
||||||
|
device->id = json_object_get_int(value_node);
|
||||||
|
}
|
||||||
|
// name
|
||||||
|
if (json_object_object_get_ex(node, k_entry_name, &value_node))
|
||||||
|
{
|
||||||
|
device->name = strdup(json_object_get_string(value_node));
|
||||||
|
}
|
||||||
|
// speech_name
|
||||||
|
if (json_object_object_get_ex(node, k_entry_speech_name, &value_node))
|
||||||
|
{
|
||||||
|
device->speech_name = strdup(json_object_get_string(value_node));
|
||||||
|
}
|
||||||
|
// state
|
||||||
|
if (json_object_object_get_ex(node, k_entry_state, &value_node))
|
||||||
|
{
|
||||||
|
device->state = json_object_get_boolean(value_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity checks
|
||||||
|
if (device->name == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object *device_to_json_object(device_t *device)
|
||||||
|
{
|
||||||
|
struct json_object *root_node;
|
||||||
|
|
||||||
|
root_node = json_object_new_object();
|
||||||
|
|
||||||
|
device_to_json(device, root_node);
|
||||||
|
|
||||||
|
return root_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int device_to_json(device_t *device, struct json_object *node)
|
||||||
|
{
|
||||||
|
// id
|
||||||
|
json_object_object_add(node, k_entry_id, json_object_new_int(device->id));
|
||||||
|
// name
|
||||||
|
json_object_object_add(node, k_entry_name, json_object_new_string(device->name));
|
||||||
|
// speech_name
|
||||||
|
if (device->speech_name != NULL)
|
||||||
|
json_object_object_add(node, k_entry_speech_name, json_object_new_string(device->speech_name));
|
||||||
|
// state
|
||||||
|
json_object_object_add(node, k_entry_state, json_object_new_boolean(device->state));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
65
src/devices/device.h
Normal file
65
src/devices/device.h
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*!
|
||||||
|
* device.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DEVICE_H
|
||||||
|
#define _DEVICE_H
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/*--------------------------------- DEPS ------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object;
|
||||||
|
|
||||||
|
/*------------------------------- TYPEDEFS ----------------------------------*/
|
||||||
|
|
||||||
|
typedef struct device_s device_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device Container.
|
||||||
|
*/
|
||||||
|
struct device_s
|
||||||
|
{
|
||||||
|
uint16_t id;
|
||||||
|
char *name;
|
||||||
|
char *speech_name;
|
||||||
|
bool state;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--------------------------- PUBLIC FUNCTIONS -------------------------------*/
|
||||||
|
|
||||||
|
extern device_t *device_new(void);
|
||||||
|
extern void device_free(device_t *device);
|
||||||
|
|
||||||
|
extern void device_set_id(device_t *device, uint16_t id);
|
||||||
|
extern uint16_t device_get_id(device_t *device);
|
||||||
|
|
||||||
|
extern int device_from_json(device_t *device, struct json_object *node);
|
||||||
|
extern struct json_object *device_to_json_object(device_t *device);
|
||||||
|
extern int device_to_json(device_t *device, struct json_object *node);
|
||||||
|
|
||||||
|
#endif /*_DEVICE_H */
|
||||||
258
src/devices/devices_manager.c
Normal file
258
src/devices/devices_manager.c
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
/*!
|
||||||
|
* devices_manager.c
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 23/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||||
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||||
|
|
||||||
|
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include <json.h>
|
||||||
|
#include <json_util.h>
|
||||||
|
|
||||||
|
#include "macro.h"
|
||||||
|
#include "domo.h"
|
||||||
|
|
||||||
|
#include "devices_manager.h"
|
||||||
|
|
||||||
|
/*----------------------------- LOCAL FUNCTIONS ----------------------------*/
|
||||||
|
|
||||||
|
int load_outlets(devices_manager_t *dm, struct json_object *node);
|
||||||
|
int create_outlet(struct json_object *node);
|
||||||
|
|
||||||
|
int load_shutters(devices_manager_t *dm, struct json_object *node);
|
||||||
|
int create_shutter(devices_manager_t *dm, struct json_object *node);
|
||||||
|
|
||||||
|
int load_sprinklers(devices_manager_t *dm, struct json_object *node);
|
||||||
|
int create_sprinkler(devices_manager_t *dm, struct json_object *node);
|
||||||
|
|
||||||
|
/*----------------------------- PUBLIC FUNCTIONS ----------------------------*/
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
devices_manager_t *devices_manager_new(void)
|
||||||
|
{
|
||||||
|
devices_manager_t *devices_manager = NEW_OBJECT(devices_manager_t);
|
||||||
|
if (devices_manager == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero((void *)devices_manager, sizeof(devices_manager_t));
|
||||||
|
|
||||||
|
// Initialize instance.
|
||||||
|
devices_manager->outlets = qhashtbl(0, 0);
|
||||||
|
devices_manager->shutters = qhashtbl(0, 0);
|
||||||
|
devices_manager->sprinklers = qhashtbl(0, 0);
|
||||||
|
|
||||||
|
return devices_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void devices_manager_free(devices_manager_t *devices_manager)
|
||||||
|
{
|
||||||
|
if (devices_manager == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (devices_manager->outlets)
|
||||||
|
{
|
||||||
|
devices_manager->outlets->free(devices_manager->outlets);
|
||||||
|
}
|
||||||
|
if (devices_manager->shutters)
|
||||||
|
{
|
||||||
|
devices_manager->shutters->free(devices_manager->shutters);
|
||||||
|
}
|
||||||
|
if (devices_manager->sprinklers)
|
||||||
|
{
|
||||||
|
devices_manager->sprinklers->free(devices_manager->sprinklers);
|
||||||
|
}
|
||||||
|
free(devices_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int devices_manager_load(devices_manager_t *dm)
|
||||||
|
{
|
||||||
|
struct json_object *the_root_node, *the_value_node;
|
||||||
|
DEBUG("Devices::load...\n");
|
||||||
|
|
||||||
|
the_root_node = json_object_from_file(dm->file_path);
|
||||||
|
if (the_root_node == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed to parse the Devices File (%s).\n", dm->file_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json_object_object_get_ex(the_root_node, kOutletEntry, &the_value_node))
|
||||||
|
{
|
||||||
|
load_outlets(dm, the_value_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
|
||||||
|
{
|
||||||
|
load_shutters(dm, the_value_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json_object_object_get_ex(the_root_node, kSprinklerEntry, &the_value_node))
|
||||||
|
{
|
||||||
|
load_sprinklers(dm, the_value_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean the json object. */
|
||||||
|
json_object_put(the_root_node);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int devices_manager_save(devices_manager_t *dm)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
char *devices_manager_get(devices_manager_t *dm, const char *capability)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
char *devices_manager_get_by_id(devices_manager_t *dm, const char *capability, uint32_t id)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int devices_manager_set(devices_manager_t *dm, const char *capability, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int devices_manager_set_state(devices_manager_t *dm, const char *capability, int id, bool state)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int devices_manager_create(devices_manager_t *dm, const char *a_capability, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int devices_manager_update(devices_manager_t *dm, const char *a_capability, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int devices_manager_delete(devices_manager_t *dm, const char *a_capability, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn load_outlets
|
||||||
|
*
|
||||||
|
* @brief Load outlets Object From a Json Node.
|
||||||
|
*/
|
||||||
|
int load_outlets(devices_manager_t *dm, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("DevicesManager::load_outlets\n");
|
||||||
|
|
||||||
|
/* Get Outlets */
|
||||||
|
if (json_object_get_type(node) == json_type_array)
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
struct json_object *outlet_node;
|
||||||
|
|
||||||
|
length = json_object_array_length(node);
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
OutletDio* the_outlet = new OutletDio;
|
||||||
|
the_outlet_node = json_object_array_get_idx(a_node, i);
|
||||||
|
the_outlet->from_json(the_outlet_node);
|
||||||
|
|
||||||
|
m_outlets.add(the_outlet);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int load_shutters(devices_manager_t *dm, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int create_shutter(devices_manager_t *dm, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int load_sprinklers(devices_manager_t *dm, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int create_sprinkler(devices_manager_t *dm, struct json_object *node)
|
||||||
|
{
|
||||||
|
DEBUG("TODO");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
74
src/devices/devices_manager.h
Normal file
74
src/devices/devices_manager.h
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*!
|
||||||
|
* devices_manager.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DEVICES_MANAGER_H
|
||||||
|
#define _DEVICES_MANAGER_H
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <qlibc/qlibc.h>
|
||||||
|
|
||||||
|
/*--------------------------------- DEPS ------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object;
|
||||||
|
|
||||||
|
/*------------------------------- TYPEDEFS ----------------------------------*/
|
||||||
|
|
||||||
|
typedef struct devices_manager_s devices_manager_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device Manager Container.
|
||||||
|
*/
|
||||||
|
struct devices_manager_s
|
||||||
|
{
|
||||||
|
char *file_path;
|
||||||
|
|
||||||
|
qhashtbl_t *outlets;
|
||||||
|
qhashtbl_t *shutters;
|
||||||
|
qhashtbl_t *sprinklers;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--------------------------- PUBLIC FUNCTIONS -------------------------------*/
|
||||||
|
|
||||||
|
extern devices_manager_t *devices_manager_new(void);
|
||||||
|
extern void devices_manager_free(devices_manager_t *devices_manager);
|
||||||
|
|
||||||
|
extern int devices_manager_load(devices_manager_t *dm);
|
||||||
|
extern int devices_manager_save(devices_manager_t *dm);
|
||||||
|
|
||||||
|
extern char *devices_manager_get(devices_manager_t *dm, const char *capability);
|
||||||
|
extern char *devices_manager_get_by_id(devices_manager_t *dm, const char *capability, uint32_t id);
|
||||||
|
|
||||||
|
extern int devices_manager_set(devices_manager_t *dm, const char *capability, struct json_object *node);
|
||||||
|
extern int devices_manager_set_state(devices_manager_t *dm, const char *capability, int id, bool state);
|
||||||
|
|
||||||
|
extern int devices_manager_create(devices_manager_t *dm, const char *a_capability, struct json_object *node);
|
||||||
|
extern int devices_manager_update(devices_manager_t *dm, const char *a_capability, struct json_object *node);
|
||||||
|
extern int devices_manager_delete(devices_manager_t *dm, const char *a_capability, struct json_object *node);
|
||||||
|
|
||||||
|
#endif /*_DEVICES_MANAGER_H */
|
||||||
140
src/devices/outlet_dio.c
Normal file
140
src/devices/outlet_dio.c
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/*!
|
||||||
|
* outlet_dio.c
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||||
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||||
|
|
||||||
|
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <json.h>
|
||||||
|
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
|
#include "domo.h"
|
||||||
|
#include "outlet_dio.h"
|
||||||
|
|
||||||
|
/*----------------------------- PUBLIC FUNCTIONS ----------------------------*/
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
outlet_dio_t *outlet_dio_new(void)
|
||||||
|
{
|
||||||
|
outlet_dio_t *outlet = NEW_OBJECT(outlet_dio_t);
|
||||||
|
if (outlet == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero((void *)outlet, sizeof(outlet_dio_t));
|
||||||
|
|
||||||
|
outlet->device = device_new();
|
||||||
|
|
||||||
|
return outlet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void outlet_dio_free(outlet_dio_t *outlet)
|
||||||
|
{
|
||||||
|
if (outlet == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (outlet->device != NULL)
|
||||||
|
device_free(outlet->device);
|
||||||
|
|
||||||
|
if (outlet->zone != NULL)
|
||||||
|
free(outlet->zone);
|
||||||
|
|
||||||
|
free(outlet);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int outlet_dio_from_json(outlet_dio_t *outlet, struct json_object *node)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
struct json_object *value_node;
|
||||||
|
|
||||||
|
result = device_from_json(outlet->device, node);
|
||||||
|
if (result < 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
// zone
|
||||||
|
if (json_object_object_get_ex(node, k_entry_zone, &value_node))
|
||||||
|
{
|
||||||
|
outlet->zone = strdup(json_object_get_string(value_node));
|
||||||
|
}
|
||||||
|
// sender
|
||||||
|
if (json_object_object_get_ex(node, k_entry_sender, &value_node))
|
||||||
|
{
|
||||||
|
outlet->sender_id = json_object_get_int(value_node);
|
||||||
|
}
|
||||||
|
// switch
|
||||||
|
if (json_object_object_get_ex(node, k_entry_switch, &value_node))
|
||||||
|
{
|
||||||
|
outlet->switch_id = json_object_get_int(value_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity checks.
|
||||||
|
// if ((the_switch == -1) || (the_sender == -1))
|
||||||
|
// return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object *outlet_dio_to_json_object(outlet_dio_t *outlet)
|
||||||
|
{
|
||||||
|
struct json_object *root_node;
|
||||||
|
|
||||||
|
root_node = json_object_new_object();
|
||||||
|
|
||||||
|
outlet_dio_to_json(outlet, root_node);
|
||||||
|
|
||||||
|
return root_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int outlet_dio_to_json(outlet_dio_t *outlet, struct json_object *node)
|
||||||
|
{
|
||||||
|
// Get Devices fields
|
||||||
|
device_to_json(outlet->device, node);
|
||||||
|
|
||||||
|
// zone
|
||||||
|
if (outlet->zone != NULL)
|
||||||
|
json_object_object_add(node, k_entry_zone, json_object_new_string(outlet->zone));
|
||||||
|
|
||||||
|
// sender
|
||||||
|
json_object_object_add(node, k_entry_sender, json_object_new_int(outlet->sender_id));
|
||||||
|
// switch
|
||||||
|
json_object_object_add(node, k_entry_switch, json_object_new_int(outlet->switch_id));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
64
src/devices/outlet_dio.h
Normal file
64
src/devices/outlet_dio.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*!
|
||||||
|
* outlet_dio.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _OUTLET_DIO_H
|
||||||
|
#define _OUTLET_DIO_H
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
/*--------------------------------- DEPS ------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object;
|
||||||
|
|
||||||
|
/*------------------------------- TYPEDEFS ----------------------------------*/
|
||||||
|
|
||||||
|
typedef struct outlet_dio_s outlet_dio_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outlet Dio Container.
|
||||||
|
*/
|
||||||
|
struct outlet_dio_s
|
||||||
|
{
|
||||||
|
device_t *device;
|
||||||
|
char *zone;
|
||||||
|
uint32_t sender_id;
|
||||||
|
uint8_t switch_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--------------------------- PUBLIC FUNCTIONS -------------------------------*/
|
||||||
|
|
||||||
|
extern outlet_dio_t *outlet_dio_new(void);
|
||||||
|
extern void outlet_dio_free(outlet_dio_t *outlet);
|
||||||
|
|
||||||
|
extern int outlet_dio_from_json(outlet_dio_t *outlet, struct json_object *node);
|
||||||
|
extern struct json_object *outlet_dio_to_json_object(outlet_dio_t *outlet);
|
||||||
|
extern int outlet_dio_to_json(outlet_dio_t *outlet, struct json_object *node);
|
||||||
|
|
||||||
|
#endif /*_OUTLET_DIO_H */
|
||||||
124
src/devices/shutter.c
Normal file
124
src/devices/shutter.c
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/*!
|
||||||
|
* shutter.c
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||||
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||||
|
|
||||||
|
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <json.h>
|
||||||
|
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
|
#include "domo.h"
|
||||||
|
#include "shutter.h"
|
||||||
|
|
||||||
|
/*----------------------------- PUBLIC FUNCTIONS ----------------------------*/
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
shutter_t *shutter_new(void)
|
||||||
|
{
|
||||||
|
shutter_t *shutter = NEW_OBJECT(shutter_t);
|
||||||
|
if (shutter == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero((void *)shutter, sizeof(shutter_t));
|
||||||
|
|
||||||
|
shutter->outlet_dio = outlet_dio_new();
|
||||||
|
|
||||||
|
return shutter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void shutter_free(shutter_t *shutter)
|
||||||
|
{
|
||||||
|
if (shutter == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (shutter->outlet_dio != NULL)
|
||||||
|
outlet_dio_free(shutter->outlet_dio);
|
||||||
|
|
||||||
|
free(shutter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int shutter_from_json(shutter_t *shutter, struct json_object *node)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
struct json_object *value_node;
|
||||||
|
|
||||||
|
result = outlet_dio_from_json(shutter->outlet_dio, node);
|
||||||
|
if (result < 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
// speed up
|
||||||
|
if (json_object_object_get_ex(node, k_entry_speed_up, &value_node))
|
||||||
|
{
|
||||||
|
shutter->speed_up = json_object_get_int(value_node);
|
||||||
|
}
|
||||||
|
// speed down
|
||||||
|
if (json_object_object_get_ex(node, k_entry_speed_down, &value_node))
|
||||||
|
{
|
||||||
|
shutter->speed_down = json_object_get_int(value_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object *shutter_to_json_object(shutter_t *shutter)
|
||||||
|
{
|
||||||
|
struct json_object *root_node;
|
||||||
|
|
||||||
|
root_node = json_object_new_object();
|
||||||
|
|
||||||
|
shutter_to_json(shutter, root_node);
|
||||||
|
|
||||||
|
return root_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int shutter_to_json(shutter_t *shutter, struct json_object *node)
|
||||||
|
{
|
||||||
|
// Get Generic Dio fields
|
||||||
|
outlet_dio_to_json(shutter->outlet_dio, node);
|
||||||
|
|
||||||
|
// speed up
|
||||||
|
json_object_object_add(node, k_entry_speed_up, json_object_new_int(shutter->speed_up));
|
||||||
|
// speed down
|
||||||
|
json_object_object_add(node, k_entry_speed_down, json_object_new_int(shutter->speed_down));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
63
src/devices/shutter.h
Normal file
63
src/devices/shutter.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*!
|
||||||
|
* shutter.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SHUTTER_H
|
||||||
|
#define _SHUTTER_H
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "outlet_dio.h"
|
||||||
|
|
||||||
|
/*--------------------------------- DEPS ------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object;
|
||||||
|
|
||||||
|
/*------------------------------- TYPEDEFS ----------------------------------*/
|
||||||
|
|
||||||
|
typedef struct shutter_s shutter_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutter Container.
|
||||||
|
*/
|
||||||
|
struct shutter_s
|
||||||
|
{
|
||||||
|
outlet_dio_t *outlet_dio;
|
||||||
|
uint8_t speed_up;
|
||||||
|
uint8_t speed_down;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--------------------------- PUBLIC FUNCTIONS -------------------------------*/
|
||||||
|
|
||||||
|
extern shutter_t *shutter_new(void);
|
||||||
|
extern void shutter_free(shutter_t *shutter);
|
||||||
|
|
||||||
|
extern int shutter_from_json(shutter_t *shutter, struct json_object *node);
|
||||||
|
extern struct json_object *shutter_to_json_object(shutter_t *shutter);
|
||||||
|
extern int shutter_to_json(shutter_t *shutter, struct json_object *node);
|
||||||
|
|
||||||
|
#endif /*_SHUTTER_H */
|
||||||
108
src/devices/sprinkler.c
Normal file
108
src/devices/sprinkler.c
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/*!
|
||||||
|
* sprinkler.c
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||||
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||||
|
|
||||||
|
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <json.h>
|
||||||
|
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
|
#include "domo.h"
|
||||||
|
#include "sprinkler.h"
|
||||||
|
|
||||||
|
/*----------------------------- PUBLIC FUNCTIONS ----------------------------*/
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
sprinkler_t *sprinkler_new(void)
|
||||||
|
{
|
||||||
|
sprinkler_t *sprinkler = NEW_OBJECT(sprinkler_t);
|
||||||
|
if (sprinkler == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero((void *)sprinkler, sizeof(sprinkler_t));
|
||||||
|
|
||||||
|
sprinkler->device = device_new();
|
||||||
|
|
||||||
|
return sprinkler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void sprinkler_free(sprinkler_t *sprinkler)
|
||||||
|
{
|
||||||
|
if (sprinkler == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (sprinkler->device != NULL)
|
||||||
|
device_free(sprinkler->device);
|
||||||
|
|
||||||
|
free(sprinkler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int sprinkler_from_json(sprinkler_t *sprinkler, struct json_object *node)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
struct json_object *value_node;
|
||||||
|
|
||||||
|
result = device_from_json(sprinkler->device, node);
|
||||||
|
if (result < 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object *sprinkler_to_json_object(sprinkler_t *sprinkler)
|
||||||
|
{
|
||||||
|
struct json_object *root_node;
|
||||||
|
|
||||||
|
root_node = json_object_new_object();
|
||||||
|
|
||||||
|
sprinkler_to_json(sprinkler, root_node);
|
||||||
|
|
||||||
|
return root_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int sprinkler_to_json(sprinkler_t *sprinkler, struct json_object *node)
|
||||||
|
{
|
||||||
|
// Get Devices fields
|
||||||
|
device_to_json(sprinkler->device, node);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
61
src/devices/sprinkler.h
Normal file
61
src/devices/sprinkler.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*!
|
||||||
|
* sprinkler.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SPRINKLER_H
|
||||||
|
#define _SPRINKLER_H
|
||||||
|
|
||||||
|
/*------------------------------- INCLUDES ----------------------------------*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
/*--------------------------------- DEPS ------------------------------------*/
|
||||||
|
|
||||||
|
struct json_object;
|
||||||
|
|
||||||
|
/*------------------------------- TYPEDEFS ----------------------------------*/
|
||||||
|
|
||||||
|
typedef struct sprinkler_s sprinkler_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sprinkler Container.
|
||||||
|
*/
|
||||||
|
struct sprinkler_s
|
||||||
|
{
|
||||||
|
device_t *device;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--------------------------- PUBLIC FUNCTIONS -------------------------------*/
|
||||||
|
|
||||||
|
extern sprinkler_t *sprinkler_new(void);
|
||||||
|
extern void sprinkler_free(sprinkler_t *sprinkler);
|
||||||
|
|
||||||
|
extern int sprinkler_from_json(sprinkler_t *sprinkler, struct json_object *node);
|
||||||
|
extern struct json_object *sprinkler_to_json_object(sprinkler_t *sprinkler);
|
||||||
|
extern int sprinkler_to_json(sprinkler_t *sprinkler, struct json_object *node);
|
||||||
|
|
||||||
|
#endif /*_SPRINKLER_H */
|
||||||
66
src/domo.h
Normal file
66
src/domo.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*!
|
||||||
|
* domo.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2019, 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: 24/12/2019
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DOMO_H
|
||||||
|
#define _DOMO_H
|
||||||
|
|
||||||
|
/*------------------------------- DEFINES ----------------------------------*/
|
||||||
|
|
||||||
|
/* Device */
|
||||||
|
|
||||||
|
/* Device type. */
|
||||||
|
#define kOutletEntry "outlets"
|
||||||
|
#define kShutterEntry "shutters"
|
||||||
|
#define kSprinklerEntry "sprinklers"
|
||||||
|
|
||||||
|
#define k_entry_devices "devices"
|
||||||
|
|
||||||
|
#define k_entry_sequences "sequences"
|
||||||
|
|
||||||
|
/* device */
|
||||||
|
#define k_entry_id "id"
|
||||||
|
#define k_entry_name "name"
|
||||||
|
#define k_entry_speech_name "speech_name"
|
||||||
|
#define k_entry_state "state"
|
||||||
|
|
||||||
|
/* outlet */
|
||||||
|
#define k_entry_zone "zone"
|
||||||
|
#define k_entry_sender "sender"
|
||||||
|
#define k_entry_switch "switch"
|
||||||
|
|
||||||
|
/* shutter */
|
||||||
|
#define k_entry_speed_up "speed_up"
|
||||||
|
#define k_entry_speed_down "speed_down"
|
||||||
|
|
||||||
|
/* sequence */
|
||||||
|
#define k_entry_active "active"
|
||||||
|
#define k_entry_start_time "start_time"
|
||||||
|
#define k_entry_recurrence "recurrence"
|
||||||
|
#define k_entry_timer "timer"
|
||||||
|
#define k_entry_device_id "device_id"
|
||||||
|
#define k_entry_duration "duration"
|
||||||
|
#define k_entry_actions "actions"
|
||||||
|
|
||||||
|
#endif /*_DOMO_H */
|
||||||
Reference in New Issue
Block a user