new sequencer model parsing
This commit is contained in:
@@ -46,7 +46,6 @@
|
||||
"recurrence": 0
|
||||
},
|
||||
"actions": [
|
||||
[
|
||||
{
|
||||
"device_id": "shutters/1",
|
||||
"state": true
|
||||
@@ -55,29 +54,6 @@
|
||||
"device_id": "shutters/2",
|
||||
"state": true
|
||||
}
|
||||
],
|
||||
{
|
||||
"duration": 60
|
||||
},
|
||||
[
|
||||
{
|
||||
"device_id": "shutters/1",
|
||||
"state": false
|
||||
},
|
||||
{
|
||||
"device_id": "shutters/2",
|
||||
"state": false
|
||||
}
|
||||
],
|
||||
{
|
||||
"device_id": "shutters/1",
|
||||
"state": true,
|
||||
"duration": 60
|
||||
},
|
||||
{
|
||||
"device_id": "shutters/1",
|
||||
"state": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
77
sequences.json
Normal file
77
sequences.json
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"sequences": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "arrosage",
|
||||
"timer": {
|
||||
"active": true,
|
||||
"start_time": "17:30",
|
||||
"recurrence": 1
|
||||
},
|
||||
"actions": [
|
||||
{
|
||||
"device_id": "sprinkler\/7",
|
||||
"active": false,
|
||||
"duration": 2
|
||||
},
|
||||
{
|
||||
"device_id": "sprinkler\/8",
|
||||
"active": false,
|
||||
"duration": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "sapin",
|
||||
"timer": {
|
||||
"active": false,
|
||||
"start_time": "21:48",
|
||||
"recurrence": 0
|
||||
},
|
||||
"actions": [
|
||||
{
|
||||
"device_id": "light\/7",
|
||||
"active": false,
|
||||
"duration": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "volet",
|
||||
"timer": {
|
||||
"active": false,
|
||||
"start_time": "9:0",
|
||||
"recurrence": 0
|
||||
},
|
||||
"actions": [
|
||||
{
|
||||
"device_id": "\/0",
|
||||
"active": false,
|
||||
"duration": 0
|
||||
},
|
||||
{
|
||||
"device_id": "\/0",
|
||||
"active": false,
|
||||
"duration": 60
|
||||
},
|
||||
{
|
||||
"device_id": "\/0",
|
||||
"active": false,
|
||||
"duration": 0
|
||||
},
|
||||
{
|
||||
"device_id": "shutters\/1",
|
||||
"active": false,
|
||||
"duration": 60
|
||||
},
|
||||
{
|
||||
"device_id": "shutters\/1",
|
||||
"active": false,
|
||||
"duration": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -31,17 +31,18 @@ file(
|
||||
${workspaceRoot}/src/prog/domod/src/ubus/capabilities_shutters_model.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/ubus/capabilities_sprinklers_model.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/ubus/sequences_model.cpp
|
||||
# Timers
|
||||
# timers
|
||||
${workspaceRoot}/src/prog/domod/src/sequences/sequences-manager.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/sequences/sequence.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/sequences/timer.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/sequences/action.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/sequences/clock.cpp
|
||||
# helper
|
||||
${workspaceRoot}/src/prog/domod/src/helpers/strings.cpp
|
||||
)
|
||||
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/helpers/Tokenizer.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/helpers/Strings.cpp
|
||||
#)
|
||||
|
||||
add_executable (domod ${source_files})
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <cstdarg>
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Strings.h"
|
||||
#include "strings.h"
|
||||
|
||||
typedef std::string::value_type char_t;
|
||||
|
||||
@@ -42,7 +43,6 @@ char_t up_char (char_t ch)
|
||||
return std::use_facet<std::ctype<char_t>>(std::locale()).toupper(ch);
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn toupper
|
||||
*
|
||||
@@ -55,3 +55,29 @@ std::string toupper (const std::string &src)
|
||||
//return result;
|
||||
return src;
|
||||
}
|
||||
|
||||
std::string string_vsprintf(const char *format, std::va_list args)
|
||||
{
|
||||
va_list tmp_args; //unfortunately you cannot consume a va_list twice
|
||||
va_copy(tmp_args, args); //so we have to copy it
|
||||
const int required_len = vsnprintf(nullptr, 0, format, tmp_args) + 1;
|
||||
va_end(tmp_args);
|
||||
|
||||
std::string buf(required_len, '\0');
|
||||
if (std::vsnprintf(&buf[0], buf.size(), format, args) < 0)
|
||||
{
|
||||
throw std::runtime_error{"string_vsprintf encoding error"};
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string string_sprintf(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
std::string string_sprintf(const char *format, ...)
|
||||
{
|
||||
std::va_list args;
|
||||
va_start(args, format);
|
||||
std::string str{string_vsprintf(format, args)};
|
||||
va_end(args);
|
||||
return str;
|
||||
}
|
||||
@@ -31,5 +31,7 @@
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
std::string toupper (const std::string &src);
|
||||
std::string string_sprintf(const char *format, ...);
|
||||
|
||||
|
||||
#endif /* _HELPERS_STRINGS_H */
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
#include "action.h"
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Action
|
||||
*
|
||||
@@ -41,7 +40,7 @@
|
||||
*/
|
||||
Action::Action(void) : m_device_id(0),
|
||||
m_state(false),
|
||||
m_duration(0)
|
||||
m_duration(-1)
|
||||
|
||||
{
|
||||
}
|
||||
@@ -107,10 +106,13 @@ struct json_object *Action::to_json(void) const
|
||||
json_object_object_add(the_root_node, k_entry_device_id, json_object_new_string(the_device_id.c_str()));
|
||||
|
||||
// state
|
||||
json_object_object_add(the_root_node, k_entry_active, json_object_new_boolean(m_state));
|
||||
json_object_object_add(the_root_node, k_entry_state, json_object_new_boolean(m_state));
|
||||
|
||||
// duration
|
||||
if (m_duration != -1)
|
||||
{
|
||||
json_object_object_add(the_root_node, k_entry_duration, json_object_new_int(m_duration));
|
||||
}
|
||||
|
||||
return the_root_node;
|
||||
}
|
||||
@@ -198,7 +200,7 @@ bool Action::get_state(void) const
|
||||
*
|
||||
* @brief Return the Duration of the Event.
|
||||
*/
|
||||
uint16_t Action::get_duration(void) const
|
||||
int16_t Action::get_duration(void) const
|
||||
{
|
||||
return m_duration;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class Action
|
||||
uint16_t get_device_id(void) const;
|
||||
const std::string &get_capability(void) const;
|
||||
bool get_state(void) const;
|
||||
uint16_t get_duration(void) const;
|
||||
int16_t get_duration(void) const;
|
||||
|
||||
//bool is_in_progress(void) const;
|
||||
|
||||
@@ -66,7 +66,7 @@ class Action
|
||||
uint16_t m_device_id;
|
||||
std::string m_capability;
|
||||
bool m_state;
|
||||
uint16_t m_duration;
|
||||
int16_t m_duration;
|
||||
|
||||
//bool m_in_progress;
|
||||
};
|
||||
|
||||
@@ -101,7 +101,7 @@ int Sequence::from_json(struct json_object *a_node)
|
||||
*
|
||||
* @brief Export Sequence Object as JSON Object.
|
||||
*/
|
||||
struct json_object *Sequence::to_json(void) const
|
||||
struct json_object *Sequence::to_json(void)
|
||||
{
|
||||
std::vector<Action>::iterator the_action_it;
|
||||
struct json_object *the_root_node, *the_action_array_node;
|
||||
@@ -120,12 +120,12 @@ struct json_object *Sequence::to_json(void) const
|
||||
// actions
|
||||
the_action_array_node = json_object_new_array();
|
||||
json_object_object_add(the_root_node, k_entry_actions, the_action_array_node);
|
||||
#if 0
|
||||
|
||||
for (the_action_it = m_actions.begin(); the_action_it != m_actions.end(); the_action_it++)
|
||||
{
|
||||
//json_object_array_add(the_action_array_node, (*the_action_it).to_json());
|
||||
json_object_array_add(the_action_array_node, (*the_action_it).to_json());
|
||||
}
|
||||
#endif
|
||||
|
||||
return the_root_node;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
~Sequence(void);
|
||||
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void) const;
|
||||
struct json_object *to_json(void);
|
||||
|
||||
uint16_t get_id(void) const;
|
||||
const std::string &get_name(void) const;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "domo.h"
|
||||
|
||||
#include "helpers/strings.h"
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
/*------------------------------- DEFINES ----------------------------------*/
|
||||
@@ -105,7 +107,7 @@ struct json_object *Timer::to_json(void) const
|
||||
json_object_object_add(the_root_node, k_entry_active, json_object_new_boolean(m_active));
|
||||
|
||||
//start_time
|
||||
std::string the_start_time = std::to_string(m_hour) + ":" + std::to_string(m_minute);
|
||||
std::string the_start_time = string_sprintf("%.2d:%.2d", m_hour, m_minute);
|
||||
json_object_object_add(the_root_node, k_entry_start_time, json_object_new_string(the_start_time.c_str()));
|
||||
|
||||
// recurrence
|
||||
|
||||
Reference in New Issue
Block a user