Skip to content

Commit

Permalink
Работа с GSM и последовательными портами вообще. Больше функций для р…
Browse files Browse the repository at this point in the history
…аботы с строками. И ещё разное.
  • Loading branch information
Sheridan committed Sep 2, 2024
1 parent 3c89787 commit 37919ab
Show file tree
Hide file tree
Showing 33 changed files with 1,373 additions and 136 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(PahoMqttCpp REQUIRED)
find_package(AngelScript REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Nova REQUIRED)
find_package(Iconv REQUIRED)
pkg_check_modules(JSONCPP REQUIRED jsoncpp)

option(CMAKE_BUILD_TYPE "Build type" Release)
Expand All @@ -26,7 +27,7 @@ if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-DHA_DEBUG)
endif (CMAKE_BUILD_TYPE STREQUAL Debug)

set(PACKAGE_VERSION "0.5.6")
set(PACKAGE_VERSION "0.5.7")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in"
Expand Down Expand Up @@ -101,7 +102,12 @@ set(HA_HEADERS
src/scripting/script/cscriptenvironment.h
src/scripting/script/cscriptobject.h
src/scripting/script/cscriptsmanager.h
src/serial/cserial.h
src/serial/cserialcommunication.h
src/serial/cserialwatcher.h
src/serial/devices/gsm/cgsm.h
src/st.h
src/tools/iconv/ciconv.h
src/tools/singletone/csingletone.h
src/utils/numeric.h
src/utils/random.h
Expand Down Expand Up @@ -157,6 +163,11 @@ set(HA_SOURCES
src/scripting/script/cscriptenvironment.cpp
src/scripting/script/cscriptobject.cpp
src/scripting/script/cscriptsmanager.cpp
src/serial/cserial.cpp
src/serial/cserialcommunication.cpp
src/serial/cserialwatcher.cpp
src/serial/devices/gsm/cgsm.cpp
src/tools/iconv/ciconv.cpp
src/tools/singletone/csingletone.cpp
src/utils/numeric.cpp
src/utils/random.cpp
Expand All @@ -181,6 +192,7 @@ target_link_libraries(homed-angel
jsoncpp
${ANGELSCRIPT_LIBRARY}
${NOVA_LIBRARIES}
${Iconv_LIBRARIES}
# ${Boost_LIBRARIES}
)

Expand All @@ -205,7 +217,7 @@ set(CPACK_DEBIAN_PACKAGE_USER "homed")
set(CPACK_DEBIAN_PACKAGE_GROUP "homed")
set(CPACK_DEBIAN_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CMAKE_SYSTEM_PROCESSOR}.deb")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/deploy/debian/control.extra")
set(CPACK_DEBIAN_PACKAGE_POST_INSTALL "${CMAKE_CURRENT_SOURCE_DIR}/deploy/debian//post_install.sh")
set(CPACK_DEBIAN_PACKAGE_POST_INSTALL "${CMAKE_CURRENT_SOURCE_DIR}/deploy/debian/post_install.sh")


include(CPack)
2 changes: 1 addition & 1 deletion scripts/astro.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "classes/daytime.as"
bool do_it = true;
bool do_it = false;

// CTimerContinuous @timer_continuous;

Expand Down
2 changes: 1 addition & 1 deletion scripts/buttons.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bool do_it = true;
bool do_it = false;
bool rgb_running = false;

void onButton1(CProperty @property)
Expand Down
28 changes: 17 additions & 11 deletions scripts/datetime.as
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@

bool do_it = false;
CDateTime dt();
CTimeInterval ti(1234567890);

void initialize()
{
logger.nfo(" now: " + dt.asString("%Y.%m.%d %H:%M:%S"));
logger.nfo(" now date: " + dt.asString("%Y.%m.%d"));
logger.nfo(" now time: " + dt.asString("%H:%M:%S"));
logger.nfo(" interval: " + ti.asString());
logger.nfo("now + interval: " + (dt + ti).asString("%Y.%m.%d %H:%M:%S"));
logger.nfo(" string dt: " + CDateTime("2020.05.05 12:32:25").asString());
logger.nfo(" string date: " + CDateTime("2024.05.05").asString());
logger.nfo(" string time: " + CDateTime("12:32:22").asString());
logger.nfo(" string time: " + CDateTime("23:32:22").asString());
if(do_it)
{
logger.nfo(" now: " + dt.asString("%Y.%m.%d %H:%M:%S"));
logger.nfo(" now date: " + dt.asString("%Y.%m.%d"));
logger.nfo(" now time: " + dt.asString("%H:%M:%S"));
logger.nfo(" interval: " + ti.asString());
logger.nfo("now + interval: " + (dt + ti).asString("%Y.%m.%d %H:%M:%S"));
logger.nfo(" string dt: " + CDateTime("2020.05.05 12:32:25").asString());
logger.nfo(" string date: " + CDateTime("2024.05.05").asString());
logger.nfo(" string time: " + CDateTime("12:32:22").asString());
logger.nfo(" string time: " + CDateTime("23:32:22").asString());
}
}

void deinitialize()
{
logger.nfo("Start time: " + dt.asString());
if(do_it)
{
logger.nfo("Start time: " + dt.asString());
}
}
2 changes: 1 addition & 1 deletion scripts/devices_list.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bool do_it = true;
bool do_it = false;

void listProperties(CProperties @ps)
{
Expand Down
26 changes: 26 additions & 0 deletions scripts/gsm.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bool do_it = true;
CGsm @gsm;

void initialize()
{
if(do_it)
{
@gsm = CGsm("/dev/ttyUSB0", br115200);
while(!gsm.ready())
{
logger.wrn("[/dev/ttyUSB0] GSM is not ready");
sleep(1000);
}
logger.nfo(" OP: " + gsm.operatorName());
logger.nfo(" Signal: " + gsm.signalLevel());
logger.nfo(" Adapter: " + gsm.adapterName());
logger.nfo("Firmvare: " + gsm.firmwareVersion());
if(gsm.sendSms("+71111111111", "⛩️ Тестовое сообщение из скрипта"))
{
logger.nfo("SMS sent");
}
}
}

void deinitialize()
{}
78 changes: 43 additions & 35 deletions scripts/init.as
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bool do_it = false;

void setIfNot(CProperty @property, string value) { if(property.last().asString() != value) { logger.nfo("Setting default value for " + property.name() + ": " + value); property.set(value); sleep(500); } }
void setIfNot(CProperty @property, bool value) { if(property.last().asBool () != value) { logger.nfo("Setting default value for " + property.name() + ": " + value); property.set(value); sleep(500); } }
void setIfNot(CProperty @property, int value) { if(property.last().asInt () != value) { logger.nfo("Setting default value for " + property.name() + ": " + value); property.set(value); sleep(500); } }
Expand Down Expand Up @@ -56,50 +58,56 @@ void resetDevicesStatus()

void initialize()
{
logger.nfo("Initialize start");
if(do_it)
{
logger.nfo("Initialize start");

setDefaultSwitchBehaviour("PowerSocket_CCTVMonitor" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_KitchenFitoLamp" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_KitchenNightLamp", "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_PrinterHome" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCBackLight" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCMonitors" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPComputer" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCSound" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCSubWoofer" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_Street" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_WarmFloor" , "default", "previous", false, "" );
setDefaultSwitchBehaviour("PowerSocket_WaterPump" , "default", "previous", false, "" );
setDefaultSwitchBehaviour("LedRGB_BedStairs" , "" , "off" , false, "" );
setDefaultSwitchBehaviour("LedRGB_Showcase" , "" , "off" , false, "" );
setDefaultSwitchBehaviour("LightRelay_Bar" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_BathLamp" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_BathMirror" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_Hall" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_KitchenTable" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_KitchenWorktop" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_Lobby" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("Relay_WaterPump" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("PowerSocket_CCTVMonitor" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_KitchenFitoLamp" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_KitchenNightLamp", "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_PrinterHome" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCBackLight" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCMonitors" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPComputer" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCSound" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_SPCSubWoofer" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_Street" , "default", "off" , false, "" );
setDefaultSwitchBehaviour("PowerSocket_WarmFloor" , "default", "previous", false, "" );
setDefaultSwitchBehaviour("PowerSocket_WaterPump" , "default", "previous", false, "" );
setDefaultSwitchBehaviour("LedRGB_BedStairs" , "" , "off" , false, "" );
setDefaultSwitchBehaviour("LedRGB_Showcase" , "" , "off" , false, "" );
setDefaultSwitchBehaviour("LightRelay_Bar" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_BathLamp" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_BathMirror" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_Hall" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_KitchenTable" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_KitchenWorktop" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("LightRelay_Lobby" , "default", "off" , false, "toggle");
setDefaultSwitchBehaviour("Relay_WaterPump" , "default", "off" , false, "toggle");

setDefaultTHBehaviour("Temperature_Hall" , "celsius", 19, 26, 30, 50);
setDefaultTHBehaviour("Temperature_BedRoom", "celsius", 19, 26, 30, 50);
setDefaultTHBehaviour("Temperature_Kitchen", "celsius", 19, 26, 30, 50);
setDefaultTHBehaviour("Temperature_Hall" , "celsius", 19, 26, 30, 50);
setDefaultTHBehaviour("Temperature_BedRoom", "celsius", 19, 26, 30, 50);
setDefaultTHBehaviour("Temperature_Kitchen", "celsius", 19, 26, 30, 50);

homed.property(dtZigbee, "Temperature_HallOutDoor" , "temperature").subscribe(script_name, "bindStreetTempToLobby", false);
homed.property(dtZigbee, "Temperature_WaterPumpOutDoor", "temperature").subscribe(script_name, "bindStreetTempToBed" , false);
homed.property(dtZigbee, "Temperature_HallOutDoor" , "temperature").subscribe(script_name, "bindStreetTempToLobby", false);
homed.property(dtZigbee, "Temperature_WaterPumpOutDoor", "temperature").subscribe(script_name, "bindStreetTempToBed" , false);

resetDevicesStatus();
resetDevicesStatus();

logger.nfo("Initialize done");
logger.nfo("Initialize done");
}
}

void deinitialize()
{
for(int i = 1; i <= 8; i++)
if(do_it)
{
setIfNot(homed.property(dtZigbee, "Informer_One", to_string(i), "status"), "off");
}
setIfNot(homed.property(dtZigbee, "Siren_Lobby", "alarm"), false);
for(int i = 1; i <= 8; i++)
{
setIfNot(homed.property(dtZigbee, "Informer_One", to_string(i), "status"), "off");
}
setIfNot(homed.property(dtZigbee, "Siren_Lobby", "alarm"), false);

resetDevicesStatus();
resetDevicesStatus();
}
}
39 changes: 39 additions & 0 deletions scripts/ota.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
bool do_it = false;
void otaRefresh(string device)
{
logger.nfo("Query refresh for " + device);
CJson json();
json["device"] = device;
json["action"] = "otaRefresh";
mqtt.publish("homed/command/zigbee", json.toStyledString());
}

void onDeviceActive(CProperty @property)
{
otaRefresh(property.device().name());
property.unsubscribe(script_name, "onDeviceActive");
}

void listDevices()
{
CDevices @ds = homed.devices(dtZigbee);
for(uint16 i = 0; i < ds.size(); i++)
{
CDevice @d = ds.get(i);
// otaRefresh(d.name());
homed.property(dtZigbee, d.name(), "lastSeen").subscribe(script_name, "onDeviceActive", false);
}
}


void initialize()
{
if(do_it)
{
listDevices();
}
}

void deinitialize()
{
}
59 changes: 32 additions & 27 deletions scripts/strings.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "includes/log_helpers.as"

bool do_it = false;

void checkStrings(CStrings &in ss)
{
logger.nfo("original"); log_strings(ss);
Expand All @@ -13,35 +15,38 @@ void checkStrings(CStrings &in ss)

void initialize()
{
logger.nfo("String");
logger.nfo(" hash: " + calculate_hash("string"));
logger.nfo(" upper: " + to_upper("SomeString"));
logger.nfo(" lower: " + to_lower("SomeString"));
logger.nfo(" snake: " + to_snake_case("SomeString"));
logger.nfo(" camel: " + to_camel_case("some_string"));
if(do_it)
{
logger.nfo("String");
logger.nfo(" hash: " + calculate_hash("string"));
logger.nfo(" upper: " + to_upper("SomeString"));
logger.nfo(" lower: " + to_lower("SomeString"));
logger.nfo(" snake: " + to_snake_case("SomeString"));
logger.nfo(" camel: " + to_camel_case("some_string"));

logger.nfo("Strings");
CStrings ss;
int count = 16, size = 2;
for (int i = 0; i<count; i++) { ss.push_back(to_string(i)); } checkStrings(ss); ss.resize(0);
for (int i = 0; i<count; i++) { ss.push_back(to_string(i) + random_string(size)); } checkStrings(ss); ss.resize(0);
for (int i = 0; i<count; i++) { ss.push_back(to_string(random(0, 128))); } checkStrings(ss); ss.resize(0);
logger.nfo("String to int");
logger.nfo(" int: " + to_int("123"));
logger.nfo(" double: " + to_double("123.345"));
logger.nfo("hex to int: " + hex_to_int("402"));
logger.nfo("int to hex: " + int_to_hex(123456789));
logger.nfo("Strings");
CStrings ss;
int count = 16, size = 2;
for (int i = 0; i<count; i++) { ss.push_back(to_string(i)); } checkStrings(ss); ss.resize(0);
for (int i = 0; i<count; i++) { ss.push_back(to_string(i) + random_string(size)); } checkStrings(ss); ss.resize(0);
for (int i = 0; i<count; i++) { ss.push_back(to_string(random(0, 128))); } checkStrings(ss); ss.resize(0);
logger.nfo("String to int");
logger.nfo(" int: " + to_int("123"));
logger.nfo(" double: " + to_double("123.345"));
logger.nfo("hex to int: " + hex_to_int("402"));
logger.nfo("int to hex: " + int_to_hex(123456789));

logger.nfo("Random numeric");
logger.nfo(" random int: " + random(0, 128));
logger.nfo("random float: " + random(0.01, 0.1));
logger.nfo("Random numeric");
logger.nfo(" random int: " + random(0, 128));
logger.nfo("random float: " + random(0.01, 0.1));

logger.nfo("Random string");
logger.nfo("random: " + random_string(128));
logger.nfo("random: " + random_string("-=:|+", 64));
logger.nfo("random: " + random_string("Sheridan", 16));
logger.nfo("Random string");
logger.nfo("random: " + random_string(128));
logger.nfo("random: " + random_string("-=:|+", 64));
logger.nfo("random: " + random_string("Sheridan", 16));

logger.nfo("Numeric to string");
int int_value = 123; logger.nfo("int: " + to_string(int_value ));
double double_value = 0.123; logger.nfo("int: " + to_string(double_value));
logger.nfo("Numeric to string");
int int_value = 123; logger.nfo("int: " + to_string(int_value ));
double double_value = 0.123; logger.nfo("int: " + to_string(double_value));
}
}
2 changes: 1 addition & 1 deletion scripts/subfolder/json.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../includes/log_helpers.as"
bool do_it = true;
bool do_it = false;


void initialize()
Expand Down
9 changes: 5 additions & 4 deletions scripts/subfolder/many-to-one.as
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ void initialize()
{
if(do_it)
{
for( int n = 0; n <= 4; n++ )
{
logger.nfo('First logs ' + n);
}

logger.nfo(script_name + " init");
homed.property(dtZigbee, "LightRelay_BathMirror" , "status" ).subscribe(script_name, "allEvents" , false);
homed.property(dtZigbee, "Temperature_WaterPumpOutDoor", "temperature").subscribe(script_name, "allEvents" , false);
Expand All @@ -56,8 +61,4 @@ void initialize()
homed.property(dtZigbee, "DoorSensor_Hall" , "contact" ).subscribe(script_name, "changedOnly", true);
homed.property(dtZigbee, "HumanDetector_Kitchen" , "occupancy" ).subscribe(script_name, "changedOnly", true);
}
for( int n = 0; n <= 4; n++ )
{
logger.nfo('First logs ' + n);
}
}
7 changes: 7 additions & 0 deletions src/homed/model/entities/cproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ void CProperty::set(const CValue &value)
HA_ST->homed()->publishValue(device(), endpoint(), this, value);
}

void CProperty::setIfNotEqual(const std::string &value) { setIfNotEqual(CValue(value, storage())); }
void CProperty::setIfNotEqual(const int &value) { setIfNotEqual(CValue(value, storage())); }
void CProperty::setIfNotEqual(const double &value) { setIfNotEqual(CValue(value, storage())); }
void CProperty::setIfNotEqual(const bool &value) { setIfNotEqual(CValue(value, storage())); }
void CProperty::setIfNotEqual(const CColor &value) { setIfNotEqual(CValue(value, storage())); }
void CProperty::setIfNotEqual(const CValue &value) { if(last().compareValue(value)) { set(value); } }


}
}
Loading

0 comments on commit 37919ab

Please sign in to comment.