update light controller
This commit is contained in:
216
docs/api/tests-api.md
Normal file
216
docs/api/tests-api.md
Normal file
@@ -0,0 +1,216 @@
|
||||
# Test all the ubus API of domo.
|
||||
|
||||
|
||||
## domo.capabilities
|
||||
|
||||
### list
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.capabilities list
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"capabilities": [
|
||||
{
|
||||
"name": "lights",
|
||||
"speach_name": "lumière"
|
||||
},
|
||||
{
|
||||
"name": "shutters",
|
||||
"speach_name": "volet"
|
||||
},
|
||||
{
|
||||
"name": "sprinklers",
|
||||
"speach_name": "station"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## domo.lights
|
||||
|
||||
### create
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights create
|
||||
```
|
||||
|
||||
### list
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights list
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"lights": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Bureau JB",
|
||||
"speach_name": "bureau",
|
||||
"zone": "",
|
||||
"state": true,
|
||||
"sender": 12797322,
|
||||
"interruptor": 0
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Salon",
|
||||
"speach_name": "salon",
|
||||
"zone": "",
|
||||
"state": false,
|
||||
"sender": 12797322,
|
||||
"interruptor": 1
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Sapin",
|
||||
"speach_name": "sapin",
|
||||
"zone": "",
|
||||
"state": false,
|
||||
"sender": 12797322,
|
||||
"interruptor": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### read
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights read "{\"id\":2}"
|
||||
```
|
||||
|
||||
### update
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights update
|
||||
```
|
||||
|
||||
### delete
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights delete
|
||||
```
|
||||
|
||||
## domo.sequences
|
||||
|
||||
### create
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sequences create
|
||||
```
|
||||
|
||||
### list
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sequences list
|
||||
```
|
||||
|
||||
### read
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sequences read
|
||||
```
|
||||
|
||||
### update
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sequences update
|
||||
```
|
||||
|
||||
### delete
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sequences delete
|
||||
```
|
||||
|
||||
## domo.shutters
|
||||
|
||||
### create
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.shutters create
|
||||
```
|
||||
|
||||
### list
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.shutters list
|
||||
```
|
||||
|
||||
### read
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.shutters read
|
||||
```
|
||||
|
||||
### update
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.shutters update
|
||||
```
|
||||
|
||||
### delete
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.shutters delete
|
||||
```
|
||||
|
||||
### up
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.shutters up
|
||||
```
|
||||
|
||||
### down
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.shutters down
|
||||
```
|
||||
|
||||
## domo.sprinklers
|
||||
|
||||
### create
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sprinklers create
|
||||
```
|
||||
|
||||
### list
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sprinklers list
|
||||
```
|
||||
|
||||
### read
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sprinklers read
|
||||
```
|
||||
|
||||
### update
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sprinklers update
|
||||
```
|
||||
|
||||
### delete
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sprinklers delete
|
||||
```
|
||||
|
||||
### open
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sprinklers open
|
||||
```
|
||||
|
||||
### close
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.sprinklers close
|
||||
```
|
||||
@@ -39,6 +39,7 @@ file(
|
||||
${workspaceRoot}/src/prog/domod/src/sequences/clock.cpp
|
||||
# helper
|
||||
${workspaceRoot}/src/prog/domod/src/helpers/strings.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/helpers/controller.cpp
|
||||
)
|
||||
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp
|
||||
|
||||
@@ -155,6 +155,18 @@ std::string DevicesManager::get(const std::string &a_capability)
|
||||
return the_output;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn get
|
||||
*
|
||||
* @brief get the list of devices of a specific capabilities.
|
||||
*/
|
||||
std::string DevicesManager::get(const std::string &a_capability, uint32_t an_id)
|
||||
{
|
||||
std::string the_result;
|
||||
#warning TODO
|
||||
return the_result;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn set
|
||||
*
|
||||
|
||||
@@ -50,6 +50,7 @@ class DevicesManager
|
||||
int save(void);
|
||||
|
||||
std::string get(const std::string &a_capability);
|
||||
std::string get(const std::string &a_capability, uint32_t an_id);
|
||||
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);
|
||||
|
||||
|
||||
71
src/prog/domod/src/helpers/controller.cpp
Normal file
71
src/prog/domod/src/helpers/controller.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/*!
|
||||
* controller.cpp
|
||||
*
|
||||
* Copyright (c) 2015-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: 02/05/2018
|
||||
*
|
||||
*/
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
extern "C" {
|
||||
#include <libubox/blobmsg_json.h>
|
||||
}
|
||||
|
||||
#define k_entry_id "id"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn get_id_from_blob
|
||||
*
|
||||
* @brief get an id from a blob.
|
||||
*/
|
||||
int get_id_from_blob(struct blob_attr *a_msg, uint32_t &an_id)
|
||||
{
|
||||
int the_result;
|
||||
char *the_string;
|
||||
struct json_object *the_root_node, *the_value_node;
|
||||
the_string = blobmsg_format_json(a_msg, true);
|
||||
|
||||
the_root_node = json_tokener_parse(the_string);
|
||||
free(the_string);
|
||||
|
||||
if (the_root_node == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed parse the parameters.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
the_result = -1;
|
||||
|
||||
// id
|
||||
if (json_object_object_get_ex(the_root_node, k_entry_id, &the_value_node))
|
||||
{
|
||||
an_id = json_object_get_int(the_value_node);
|
||||
the_result = 0;
|
||||
}
|
||||
|
||||
json_object_put(the_root_node);
|
||||
|
||||
return the_result;
|
||||
}
|
||||
37
src/prog/domod/src/helpers/controller.h
Normal file
37
src/prog/domod/src/helpers/controller.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*!
|
||||
* controller.cpp
|
||||
*
|
||||
* Copyright (c) 2015-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: 02/05/2018
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HELPERS_CONTROLLER_H
|
||||
#define _HELPERS_CONTROLLER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct blob_attr;
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
int get_id_from_blob(struct blob_attr *a_msg, uint32_t &an_id);
|
||||
|
||||
#endif /* _HELPERS_CONTROLLER_H */
|
||||
@@ -31,6 +31,8 @@ extern "C" {
|
||||
#include <libubox/blobmsg_json.h>
|
||||
}
|
||||
|
||||
#include "helpers/controller.h"
|
||||
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
#include "domo.h"
|
||||
@@ -110,10 +112,28 @@ int LightsController::list(struct ubus_context *a_ctx, struct ubus_request_data
|
||||
*
|
||||
* @brief Read a specific sequence object.
|
||||
*/
|
||||
int LightsController::read(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
|
||||
int LightsController::read(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||
{
|
||||
uint32_t the_id, the_result;
|
||||
struct blob_buf the_buf = {0};
|
||||
printf("%s\n", __PRETTY_FUNCTION__);
|
||||
return 0;
|
||||
|
||||
if (get_id_from_blob(a_msg, the_id) != 0)
|
||||
{
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
printf ("update id: %d\n", the_id);
|
||||
|
||||
blob_buf_init(&the_buf, 0);
|
||||
|
||||
blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kLightEntry, the_id).c_str());
|
||||
|
||||
the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);
|
||||
|
||||
blob_buf_free(&the_buf);
|
||||
|
||||
return the_result;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user