add: rename controller command

This commit is contained in:
Tobias Reisinger 2019-08-04 23:44:38 +02:00
parent 08699c8817
commit 2be5532778
3 changed files with 11 additions and 4 deletions

View file

@ -1,5 +1,6 @@
#include <netdb.h> #include <netdb.h>
#include <models/controller_dbo.h> #include <models/controller_dbo.h>
#include <config.h>
#include "api_v1_controllers.h" #include "api_v1_controllers.h"
using namespace api::v1; using namespace api::v1;
@ -86,6 +87,7 @@ controllers::put_one_by_id(const HttpRequestPtr &req, std::function<void(const H
auto resp = HttpResponse::newHttpResponse(); auto resp = HttpResponse::newHttpResponse();
if(controllers[0]->update()) if(controllers[0]->update())
{ {
controllers[0]->command(config::command_code_set_name, controllers[0]->name);
resp = HttpResponse::newHttpJsonResponse(controllers[0]->to_json()); resp = HttpResponse::newHttpJsonResponse(controllers[0]->to_json());
} }
else else

View file

@ -9,9 +9,12 @@
#include "globals.h" #include "globals.h"
controller_dbo::~controller_dbo() controller_dbo::~controller_dbo()
{
if(this->relays)
{ {
relay_dbo::free_list(this->relays); relay_dbo::free_list(this->relays);
} }
}
static bool controller_db_update_insert(controller_dbo *controller, sqlite3_stmt *stmt) static bool controller_db_update_insert(controller_dbo *controller, sqlite3_stmt *stmt)
{ {
@ -214,16 +217,18 @@ controller_dbo::get_by(helpers::sql_filter_builder **filters)
bool bool
controller_dbo::command(int command_code, const char *payload) controller_dbo::command(int command_code, const char *payload)
{ {
char port[6]; char port_str[6];
sprintf(port, "%d", this->port); sprintf(port_str, "%d", this->port);
int controller_socket = helpers::open_tcp_connection(this->ip, port); int controller_socket = helpers::open_tcp_connection(this->ip, port_str);
if(!controller_socket) if(!controller_socket)
{ {
LOG_ERROR << "Can't open command socket " << this->ip << ":" << port_str;
return false; return false;
} }
LOG_DEBUG << "Commanding (" << command_code << ") " << payload;
send(controller_socket, &command_code, 1, 0); send(controller_socket, &command_code, 1, 0);
send(controller_socket, payload, strlen(payload), 0); send(controller_socket, payload, strlen(payload), 0);
close(controller_socket); close(controller_socket);