├── _config.yml ├── .gitignore ├── extras ├── examples │ ├── esp_idf │ │ ├── main │ │ │ └── CMakeLists.txt │ │ ├── partitions.csv │ │ ├── CMakeLists.txt │ │ └── sdkconfig.defaults │ ├── esp8266_rtos │ │ ├── main │ │ │ ├── component.mk │ │ │ └── CMakeLists.txt │ │ ├── CMakeLists.txt │ │ ├── partitions.csv │ │ ├── sdkconfig.defaults │ │ └── Makefile │ ├── linux │ │ └── CMakeLists.txt │ └── freertos_linux │ │ └── CMakeLists.txt ├── esp-idf │ └── readme.md ├── porting │ ├── linux │ │ ├── linux_platform.cpp │ │ ├── WiFiClient.h │ │ ├── linux_timers.h │ │ ├── IPAddress.cpp │ │ ├── supla │ │ │ ├── source │ │ │ │ ├── source.h │ │ │ │ ├── cmd.cpp │ │ │ │ ├── cmd.h │ │ │ │ └── file.h │ │ │ ├── sensor │ │ │ │ ├── binary_parsed.cpp │ │ │ │ ├── binary_parsed.h │ │ │ │ ├── thermometer_parsed.h │ │ │ │ ├── impulse_counter_parsed.h │ │ │ │ └── thermometer_parsed.cpp │ │ │ └── parser │ │ │ │ ├── parser.cpp │ │ │ │ ├── simple.h │ │ │ │ └── json.h │ │ ├── IPAddress.h │ │ ├── linux_file_state_logger.h │ │ ├── linux_timers.cpp │ │ ├── linux_network.h │ │ └── network_client.h │ ├── esp-idf │ │ ├── esp_platform.cpp │ │ ├── esp_idf_gpio.h │ │ ├── esp_idf_mutex.cpp │ │ ├── esp_idf_mutex.h │ │ ├── spiffs_storage.h │ │ └── esp_idf_web_server.h │ └── freertos_linux │ │ ├── freertos_platform.cpp │ │ ├── freertos_log.c │ │ ├── IPAddress.h │ │ └── CMakeLists.txt ├── test │ ├── doubles │ │ ├── log.cpp │ │ ├── timer_mock.h │ │ ├── board_mock.h │ │ ├── timer_mock.cpp │ │ ├── board_mock.cpp │ │ └── element_mock.h │ ├── SensorTests │ │ └── thermometer_tests.cpp │ ├── ConditionTests │ │ ├── on_greater_tests.cpp │ │ ├── on_greater_eq_tests.cpp │ │ ├── on_equal_tests.cpp │ │ ├── on_between_tests.cpp │ │ ├── on_between_eq_tests.cpp │ │ └── on_less_eq_tests.cpp │ └── CMakeLists.txt └── docker │ ├── freeRTOS │ ├── Dockerfile │ └── readme.md │ ├── esp-idf │ ├── Dockerfile │ └── readme.md │ ├── arduino-cli │ ├── readme.md │ └── Dockerfile │ └── esp8266_rtos_sdk │ ├── Dockerfile │ └── readme.md ├── src ├── nettle │ ├── nettle-stdint.h │ ├── README │ ├── rsa-verify.c │ └── version.h ├── supla │ ├── timer.h │ ├── crc16.h │ ├── log_wrapper.cpp │ ├── version.h │ ├── arduino_plafrom.cpp │ ├── action_handler.cpp │ ├── channel_extended.cpp │ ├── time.h │ ├── crc16.cpp │ ├── network │ │ ├── esp32_wifi.h │ │ ├── web_sender.cpp │ │ ├── web_sender.h │ │ ├── html │ │ │ ├── sw_update.h │ │ │ ├── sw_update_beta.h │ │ │ ├── custom_sw_update.h │ │ │ ├── wifi_parameters.h │ │ │ ├── status_led_parameters.h │ │ │ ├── device_info.h │ │ │ └── protocol_parameters.h │ │ ├── netif_wifi.cpp │ │ ├── netif_wifi.h │ │ └── html_element.h │ ├── mutex.h │ ├── auto_lock.h │ ├── action_handler.h │ ├── auto_lock.cpp │ ├── channel_extended.h │ ├── storage │ │ ├── littlefs_config.h │ │ └── eeprom.h │ ├── sensor │ │ ├── normally_open.h │ │ ├── hygro_meter.h │ │ ├── binary.h │ │ ├── hygro_meter.cpp │ │ ├── distance.cpp │ │ ├── distance.h │ │ ├── esp_free_heap.h │ │ ├── therm_hygro_meter.h │ │ ├── thermometer.h │ │ ├── virtual_thermometer.h │ │ ├── MAX6675_K.h │ │ ├── thermometer.cpp │ │ ├── MAXThermocouple.h │ │ ├── one_phase_electricity_meter.h │ │ ├── virtual_binary.h │ │ ├── therm_hygro_meter.cpp │ │ ├── Si7021_sonoff.h │ │ ├── virtual_therm_hygro_meter.h │ │ ├── binary.cpp │ │ ├── general_purpose_measurement_base.h │ │ ├── wind.h │ │ ├── rain.h │ │ ├── pressure.h │ │ ├── weight.h │ │ └── HC_SR04.h │ ├── sha256.cpp │ ├── supla_lib_config.h │ ├── mutex.cpp │ ├── sha256.h │ ├── at_channel.h │ ├── definitions.h │ ├── conditions │ │ ├── on_equal.cpp │ │ ├── on_less.cpp │ │ ├── on_less_eq.cpp │ │ ├── on_greater.cpp │ │ ├── on_greater_eq.cpp │ │ └── on_invalid.cpp │ ├── control │ │ ├── rgb_base.h │ │ ├── pin_status_led.h │ │ ├── virtual_relay.h │ │ ├── dimmer_leds.h │ │ ├── rgb_leds.h │ │ ├── dimmer_base.h │ │ ├── bistable_roller_shutter.h │ │ ├── light_relay.h │ │ ├── rgbw_leds.h │ │ ├── button.h │ │ ├── pin_status_led.cpp │ │ └── tripple_button_roller_shutter.h │ ├── device │ │ ├── last_state_logger.h │ │ └── sw_update.h │ ├── IEEE754tools.h │ ├── correction.h │ ├── rsa_verificator.cpp │ ├── uptime.h │ ├── rsa_verificator.h │ └── clock │ │ └── clock.h └── supla-common │ └── eh.h ├── .travis.yml ├── readme.md └── library.properties /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | extras/examples/esp_idf/sdkconfig 2 | **/build/* 3 | sdkconfig.old 4 | **/.cache/* 5 | -------------------------------------------------------------------------------- /extras/examples/esp_idf/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "main.cpp" 2 | INCLUDE_DIRS "" 3 | ) 4 | -------------------------------------------------------------------------------- /src/nettle/nettle-stdint.h: -------------------------------------------------------------------------------- 1 | #ifndef __NETTLE_STDINT_H 2 | #define __NETTLE_STDINT_H 3 | 4 | #include 5 | 6 | #endif /* __NETTLE_STDINT_H */ 7 | -------------------------------------------------------------------------------- /src/nettle/README: -------------------------------------------------------------------------------- 1 | nettle contain SHA256 and RSA related methods. 2 | Those methods are used in supla-device to verify signature of new firmware 3 | version downloaded from server (OTA). 4 | -------------------------------------------------------------------------------- /extras/examples/esp8266_rtos/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /extras/examples/esp8266_rtos/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_SRCS "main.cpp") 2 | set(COMPONENT_ADD_INCLUDEDIRS ".") 3 | 4 | 5 | # Embed the server root certificate into the final binary 6 | # 7 | # (If this was a component, we would set COMPONENT_EMBED_TXTFILES here.) 8 | set(COMPONENT_EMBED_TXTFILES supla_org_cert.pem) 9 | 10 | register_component() 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: linux 2 | dist: xenial 3 | sudo: false 4 | language: cpp 5 | 6 | addons: 7 | apt: 8 | sources: 9 | - ubuntu-toolchain-r-test 10 | packages: 11 | - g++-6 12 | 13 | script: 14 | - mkdir extras/test/build 15 | - cd extras/test/build 16 | - CXX=/usr/bin/g++-6 CC=/usr/bin/gcc-6 cmake .. 17 | - make 18 | - ./supladevicetests 19 | -------------------------------------------------------------------------------- /extras/examples/esp8266_rtos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | set(EXTRA_COMPONENT_DIRS "${SUPLA_DEVICE_PATH}/extras/esp-idf/") 6 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 7 | project(supla_esp8266-cmake) 8 | 9 | -------------------------------------------------------------------------------- /extras/examples/esp8266_rtos/partitions.csv: -------------------------------------------------------------------------------- 1 | # Partition table for 2MB flash 2 | # Name, Type, SubType, Offset, Size, Flags 3 | nvs, data, nvs, 0x9000, 16K, 4 | otadata, data, ota, 0xd000, 8K, 5 | phy_init, data, phy, 0xf000, 4K, 6 | ota_0, app, ota_0, 0x10000, 960K, 7 | spiffs, data, spiffs, 0x100000, 0x10000, 8 | ota_1, app, ota_1, 0x110000, 960K, 9 | 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # SUPLA project 2 | 3 | [SUPLA](https://www.supla.org) is an open source project for home automation. 4 | 5 | # This repository is no longer maintained 6 | 7 | Development of this project was moved to another repository: 8 | https://github.com/SUPLA/supla-device 9 | 10 | Please switch all your forks to new repository. All issues, pull requests, etc. 11 | should be created in new one. 12 | -------------------------------------------------------------------------------- /extras/examples/esp_idf/partitions.csv: -------------------------------------------------------------------------------- 1 | # Partition table 2 | # Name, Type, SubType, Offset, Size, Flags 3 | nvs, data, nvs, 0x9000, 16K, 4 | otadata, data, ota, 0xd000, 8K, 5 | phy_init, data, phy, 0xf000, 4K, 6 | factory, app, factory,0x10000, 1M, 7 | ota_0, app, ota_0, 0x110000, 1M, 8 | ota_1, app, ota_1, 0x210000, 1M, 9 | spiffs, data, spiffs, 0x310000, 0x10000, 10 | 11 | -------------------------------------------------------------------------------- /extras/esp-idf/readme.md: -------------------------------------------------------------------------------- 1 | This folder contain esp-idf component CMakefile.txt. 2 | It can be used for cmake based (idf.py) build on esp-idf for ESP32 targets and 3 | for cmake and make based builds for ESP8266_RTOS_SDK targets. 4 | Please add below line to your esp-idf project CMakefile.txt: 5 | 6 | `set(EXTRA_COMPONENT_DIRS "/home/user/path_to_supla_device/supla-device/extras/esp-idf/")` 7 | 8 | Or to Makefile: 9 | EXTRA_COMPONENT_DIRS := $(abspath ../../supla-device/extras/esp-idf) 10 | 11 | -------------------------------------------------------------------------------- /extras/examples/esp_idf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | if(NOT DEFINED ENV{SUPLA_DEVICE_PATH}) 6 | message(FATAL_ERROR "SUPLA_DEVICE_PATH env variable is not set") 7 | endif() 8 | 9 | set(EXTRA_COMPONENT_DIRS "$ENV{SUPLA_DEVICE_PATH}/extras/esp-idf/") 10 | 11 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 12 | project(supla_esp32) 13 | -------------------------------------------------------------------------------- /extras/examples/esp8266_rtos/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_IDF_TARGET_ESP8266=y 2 | CONFIG_IDF_TARGET="esp8266" 3 | 4 | CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y 5 | CONFIG_ESPTOOLPY_FLASHSIZE="2MB" 6 | CONFIG_SPI_FLASH_SIZE=0x200000 7 | 8 | CONFIG_PARTITION_TABLE_CUSTOM=y 9 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" 10 | CONFIG_PARTITION_TABLE_OFFSET=0x8000 11 | CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" 12 | 13 | CONFIG_FREERTOS_HZ=1000 14 | 15 | CONFIG_ESPTOOLPY_BAUD=921600 16 | CONFIG_ESPTOOLPY_BAUD_921600B=y 17 | CONFIG_ESPTOOLPY_BAUD_115200B=y 18 | 19 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=SuplaDevice 2 | author=AC SOFTWARE SP. Z O.O. 3 | maintainer=Krzysztof Lewandowski 4 | sentence=Library enables you to connect the device to the SUPLA automation system. 5 | paragraph=It provides easy interface for adding various sensors, relays, buttons, roller shutters, etc. that can be controlled via SUPLA Cloud and application on mobile device. 6 | url=https://github.com/SUPLA/supla-arduino 7 | architectures=avr,esp32,esp8266 8 | version=2.4.2 9 | dependencies= 10 | core-dependencies=arduino (>=1.5.0) 11 | category=Communication 12 | -------------------------------------------------------------------------------- /extras/examples/esp8266_rtos/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := supla-esp8266-mk 7 | 8 | ifdef SUPLA_DEVICE_PATH 9 | EXTRA_COMPONENT_DIRS := $(abspath ${SUPLA_DEVICE_PATH}/extras/esp-idf) 10 | $(info Using supla-device from SUPLA_DEVICE_PATH: ${SUPLA_DEVICE_PATH}) 11 | else 12 | EXTRA_COMPONENT_DIRS := $(abspath ../../supla-device/extras/esp-idf) 13 | $(info Using supla-device from relative path ../../supla-device/) 14 | endif 15 | 16 | CFLAGS += -DSUPLA_DEVICE 17 | CPPFLAGS += -DSUPLA_DEVICE 18 | 19 | include $(IDF_PATH)/make/project.mk 20 | 21 | -------------------------------------------------------------------------------- /extras/porting/linux/linux_platform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | void deviceSoftwareReset() { 22 | std::exit(1); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /extras/test/doubles/log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | 19 | void supla_log(int __pri, const char *__fmt, ...) { 20 | return; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /extras/porting/esp-idf/esp_platform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | void deviceSoftwareReset() { 22 | esp_restart(); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /extras/porting/freertos_linux/freertos_platform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | void deviceSoftwareReset() { 20 | // TODO(klew): implement device sw reset for freeRTOS 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/supla/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_TIMER_H_ 18 | #define SRC_SUPLA_TIMER_H_ 19 | 20 | namespace Supla { 21 | void initTimers(); 22 | }; 23 | 24 | #endif // SRC_SUPLA_TIMER_H_ 25 | -------------------------------------------------------------------------------- /extras/docker/freeRTOS/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | LABEL maintainer="Krzysztof Lewandowski " 3 | 4 | # Install required packages 5 | RUN apt update && \ 6 | DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y tzdata && \ 7 | apt install -y git wget flex bison gperf python3 python3-pip \ 8 | python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev \ 9 | dfu-util libusb-1.0-0 python-is-python3 gcc make libncurses-dev \ 10 | libpcap-dev libyaml-cpp-dev 11 | 12 | # Setup workdir 13 | RUN mkdir supla 14 | WORKDIR /supla 15 | 16 | # Download and install FreeRTOS 17 | RUN git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules 18 | 19 | # Download supla-device 20 | RUN git clone https://github.com/SUPLA/supla-device.git && mkdir projects 21 | WORKDIR /supla/projects 22 | 23 | ENV SUPLA_DEVICE_PATH="/supla/supla-device/" 24 | ENV SUPLA_FREERTOS_PATH="/supla/FreeRTOS/" 25 | ENV SUPLA_TOOLSET="freertos" 26 | 27 | -------------------------------------------------------------------------------- /extras/porting/freertos_linux/freertos_log.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | #include "log.h" 22 | 23 | void supla_vlog(int __pri, const char *message) { 24 | printf("%s\n", message); 25 | } 26 | -------------------------------------------------------------------------------- /src/supla/crc16.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CRC16_H_ 20 | #define SRC_SUPLA_CRC16_H_ 21 | 22 | #include 23 | 24 | uint16_t crc16_update(uint16_t crc, uint8_t a); 25 | 26 | #endif // SRC_SUPLA_CRC16_H_ 27 | -------------------------------------------------------------------------------- /extras/test/SensorTests/thermometer_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | TEST(ThermometerTests, BasicTest) { 22 | EXPECT_TRUE(true); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/supla/log_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifdef ARDUINO 18 | #include 19 | 20 | extern "C" void serialPrintLn(const char *); 21 | 22 | void serialPrintLn(const char *message) { 23 | Serial.println(message); 24 | } 25 | 26 | #endif /*ARDUINO*/ 27 | -------------------------------------------------------------------------------- /src/supla/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_VERSION_H_ 18 | #define SRC_SUPLA_VERSION_H_ 19 | 20 | #define SUPLA_SHORT_VERSION "2.4.2" 21 | const char suplaDeviceVersion[] = "User SW, lib " SUPLA_SHORT_VERSION; 22 | 23 | #endif // SRC_SUPLA_VERSION_H_ 24 | -------------------------------------------------------------------------------- /src/supla/arduino_plafrom.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | #ifdef ARDUINO 19 | 20 | #include "tools.h" 21 | 22 | void deviceSoftwareReset() { 23 | #ifndef __AVR__ 24 | ESP.restart(); 25 | #endif 26 | // TODO(klew): implement software reset for Arduino IDE based targets 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /extras/docker/esp-idf/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | LABEL maintainer="Krzysztof Lewandowski " 3 | 4 | # Install required packages 5 | RUN apt update && \ 6 | DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y tzdata && \ 7 | apt install -y git wget flex bison gperf python3 python3-pip \ 8 | python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev \ 9 | dfu-util libusb-1.0-0 python-is-python3 gcc make libncurses-dev 10 | 11 | # Setup workdir 12 | RUN mkdir supla 13 | WORKDIR /supla 14 | 15 | # Download and install espressif toolset and ESP8266 RTOS SDK 16 | RUN mkdir esp && \ 17 | cd esp && \ 18 | git clone --recursive https://github.com/espressif/esp-idf.git && \ 19 | cd esp-idf && \ 20 | ./install.sh all 21 | 22 | # Download supla-device 23 | RUN git clone https://github.com/SUPLA/supla-device.git && mkdir projects 24 | WORKDIR /supla/projects 25 | 26 | ENV SUPLA_DEVICE_PATH="/supla/supla-device" 27 | ENV ESP_TOOLSET="esp32" 28 | RUN echo "source /supla/esp/esp-idf/export.sh" >> ~/.bashrc 29 | 30 | -------------------------------------------------------------------------------- /extras/porting/linux/WiFiClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_WIFICLIENT_H_ 20 | #define EXTRAS_PORTING_LINUX_WIFICLIENT_H_ 21 | 22 | #include "network_client.h" 23 | 24 | typedef class Supla::NetworkClient WiFiClient; 25 | 26 | #endif // EXTRAS_PORTING_LINUX_WIFICLIENT_H_ 27 | -------------------------------------------------------------------------------- /src/supla/action_handler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "action_handler.h" 18 | 19 | Supla::ActionHandler::~ActionHandler() {} 20 | 21 | void Supla::ActionHandler::activateAction(int action) { 22 | (void)(action); 23 | } 24 | 25 | bool Supla::ActionHandler::deleteClient() { 26 | return false; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/supla/channel_extended.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "supla/channel_extended.h" 18 | 19 | namespace Supla { 20 | bool ChannelExtended::isExtended() { 21 | return true; 22 | } 23 | 24 | TSuplaChannelExtendedValue *ChannelExtended::getExtValue() { 25 | return &extValue; 26 | } 27 | 28 | }; // namespace Supla 29 | -------------------------------------------------------------------------------- /src/supla/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_TIME_H_ 18 | #define SRC_SUPLA_TIME_H_ 19 | 20 | #ifdef ARDUINO 21 | #include 22 | #else 23 | #include 24 | 25 | uint64_t millis(void); 26 | void delay(uint64_t); 27 | void delayMicroseconds(uint64_t); 28 | 29 | #endif 30 | 31 | #endif // SRC_SUPLA_TIME_H_ 32 | -------------------------------------------------------------------------------- /src/supla/crc16.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | 20 | #include "crc16.h" 21 | 22 | uint16_t crc16_update(uint16_t crc, uint8_t a) { 23 | int i; 24 | 25 | crc ^= a; 26 | for (i = 0; i < 8; ++i) { 27 | if (crc & 1) 28 | crc = (crc >> 1) ^ 0xA001; 29 | else 30 | crc = (crc >> 1); 31 | } 32 | 33 | return crc; 34 | } 35 | -------------------------------------------------------------------------------- /src/supla/network/esp32_wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | // DEPRECATED: please use esp_wifi.h instead 20 | 21 | #ifndef SRC_SUPLA_NETWORK_ESP32_WIFI_H_ 22 | #define SRC_SUPLA_NETWORK_ESP32_WIFI_H_ 23 | 24 | #include "esp_wifi.h" 25 | 26 | namespace Supla { 27 | typedef ESPWifi ESP32Wifi; 28 | }; 29 | 30 | #endif // SRC_SUPLA_NETWORK_ESP32_WIFI_H_ 31 | -------------------------------------------------------------------------------- /src/supla/network/web_sender.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | #include "web_sender.h" 22 | 23 | namespace Supla { 24 | 25 | WebSender::~WebSender() {} 26 | 27 | void WebSender::send(int number) { 28 | char buf[100]; 29 | snprintf(buf, sizeof(buf), "%d", number); 30 | send(buf); 31 | } 32 | }; // namespace Supla 33 | -------------------------------------------------------------------------------- /extras/porting/freertos_linux/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_FREERTOS_LINUX_IPADDRESS_H_ 20 | #define EXTRAS_PORTING_FREERTOS_LINUX_IPADDRESS_H_ 21 | 22 | #include 23 | 24 | typedef union { 25 | uint8_t addr[4]; 26 | uint32_t full; 27 | } IPAddress; 28 | 29 | #endif // EXTRAS_PORTING_FREERTOS_LINUX_IPADDRESS_H_ 30 | -------------------------------------------------------------------------------- /extras/porting/linux/linux_timers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_LINUX_TIMERS_H_ 20 | #define EXTRAS_PORTING_LINUX_LINUX_TIMERS_H_ 21 | 22 | namespace Supla { 23 | namespace Linux { 24 | namespace Timers { 25 | void init(); 26 | }; 27 | }; // namespace Linux 28 | }; // namespace Supla 29 | #endif // EXTRAS_PORTING_LINUX_LINUX_TIMERS_H_ 30 | -------------------------------------------------------------------------------- /src/supla/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_MUTEX_H_ 18 | #define SRC_SUPLA_MUTEX_H_ 19 | 20 | namespace Supla { 21 | 22 | class Mutex { 23 | public: 24 | static Mutex* Create(); 25 | virtual ~Mutex(); 26 | virtual void lock(); 27 | virtual void unlock(); 28 | protected: 29 | Mutex(); 30 | }; 31 | 32 | }; // namespace Supla 33 | #endif // SRC_SUPLA_MUTEX_H_ 34 | -------------------------------------------------------------------------------- /extras/test/doubles/timer_mock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | class TimerInterface { 21 | public: 22 | TimerInterface(); 23 | virtual ~TimerInterface(); 24 | virtual void initTimers() = 0; 25 | }; 26 | 27 | class TimerMock : public TimerInterface { 28 | public: 29 | MOCK_METHOD((void), initTimers, (), (override)); 30 | }; 31 | 32 | 33 | -------------------------------------------------------------------------------- /extras/examples/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | project(supla-device-linux) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CXX_STANDARD 17) 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 9 | set(CMAKE_BUILD_TYPE Debug) 10 | 11 | # SET( CMAKE_EXPORT_COMPILE_COMMANDS ON ) 12 | # Current board sources 13 | set(BOARD_SRC 14 | main.cpp 15 | ) 16 | 17 | link_libraries( "$<$,$,9.0>>:-lstdc++fs>" ) 18 | # supladevice library target is used in porting/linux cmake 19 | add_library(supladevice "") 20 | add_subdirectory($ENV{SUPLA_DEVICE_PATH} supla-device) 21 | add_subdirectory($ENV{SUPLA_DEVICE_PATH}/extras/porting/linux supla-porting-linux) 22 | 23 | include_directories( 24 | . 25 | ) 26 | 27 | add_executable(supla-device-linux 28 | ${BOARD_SRC} 29 | ) 30 | 31 | set_target_properties(supla-device-linux PROPERTIES LINK_LIBRARIES -pthread) 32 | target_link_libraries (supla-device-linux LINK_PUBLIC 33 | supladevice 34 | ) 35 | 36 | #target_compile_options(supla-device-linux PRIVATE -Wall -Wextra -Wpedantic -Werror) 37 | -------------------------------------------------------------------------------- /src/supla/auto_lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_AUTO_LOCK_H_ 18 | #define SRC_SUPLA_AUTO_LOCK_H_ 19 | 20 | namespace Supla { 21 | class Mutex; 22 | 23 | class AutoLock { 24 | public: 25 | explicit AutoLock(Mutex *); 26 | ~AutoLock(); 27 | void lock(); 28 | void unlock(); 29 | 30 | protected: 31 | Mutex* mutex; 32 | }; 33 | 34 | }; // namespace Supla 35 | #endif // SRC_SUPLA_AUTO_LOCK_H_ 36 | 37 | -------------------------------------------------------------------------------- /extras/examples/freertos_linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | project(supla-freertos-example) 4 | 5 | set(CMAKE_CXX_STANDARD 14) 6 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 7 | set(CMAKE_BUILD_TYPE Debug) 8 | 9 | # Current board sources 10 | set(BOARD_SRC 11 | main.cpp 12 | ) 13 | 14 | # All dependencies (supla-device + freeRTOS) will be compiled together 15 | # because freeRTOS build configuration depends on local board 16 | # FreeRTOSConfig.h file. supla-device depends on FreeRTOS.h and beacuse of 17 | # that everything depends on local board files... 18 | add_library(supladevice "") 19 | add_subdirectory($ENV{SUPLA_DEVICE_PATH} supla-device) 20 | add_subdirectory($ENV{SUPLA_DEVICE_PATH}/extras/porting/freertos_linux supla-device-freertos) 21 | 22 | target_sources(supladevice PUBLIC ${FREERTOS_SRC} ) 23 | 24 | include_directories( 25 | $ENV{SUPLA_DEVICE_PATH}/src 26 | . 27 | ) 28 | 29 | add_executable(supla-freertos-example 30 | ${BOARD_SRC} 31 | ) 32 | 33 | set_target_properties(supla-freertos-example PROPERTIES LINK_LIBRARIES -pthread) 34 | target_link_libraries (supla-freertos-example LINK_PUBLIC 35 | supladevice 36 | ) 37 | 38 | -------------------------------------------------------------------------------- /extras/porting/linux/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "IPAddress.h" 18 | #include 19 | 20 | IPAddress::IPAddress() {} 21 | 22 | IPAddress::IPAddress(uint8_t ip1, uint8_t ip2, uint8_t ip3, uint8_t ip4) { 23 | addr[0] = ip1; 24 | addr[1] = ip2; 25 | addr[2] = ip3; 26 | addr[3] = ip4; 27 | } 28 | 29 | IPAddress::IPAddress(const std::string &ip) { 30 | full = inet_addr(ip.c_str()); 31 | } 32 | -------------------------------------------------------------------------------- /extras/examples/esp_idf/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_IDF_CMAKE=y 2 | CONFIG_IDF_TARGET_ARCH_XTENSA=y 3 | CONFIG_IDF_TARGET_ARCH="xtensa" 4 | #CONFIG_IDF_TARGET="esp32" 5 | #CONFIG_IDF_TARGET_ESP32=y 6 | CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000 7 | 8 | CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y 9 | 10 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 11 | CONFIG_ESPTOOLPY_FLASHSIZE="4MB" 12 | CONFIG_PARTITION_TABLE_CUSTOM=y 13 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" 14 | CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" 15 | CONFIG_PARTITION_TABLE_OFFSET=0x8000 16 | CONFIG_PARTITION_TABLE_MD5=y 17 | 18 | CONFIG_ESP_TLS_USING_MBEDTLS=y 19 | 20 | CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 21 | CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 22 | CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584 23 | CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y 24 | 25 | CONFIG_ESP_MAIN_TASK_AFFINITY=0x0 26 | CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 27 | 28 | CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584 29 | 30 | CONFIG_FREERTOS_HZ=1000 31 | CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1536 32 | CONFIG_FREERTOS_ISR_STACKSIZE=1536 33 | CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 34 | 35 | # HTTP server buffer for parsing post messages 36 | CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024 37 | -------------------------------------------------------------------------------- /src/supla/action_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_ACTION_HANDLER_H_ 18 | #define SRC_SUPLA_ACTION_HANDLER_H_ 19 | 20 | namespace Supla { 21 | class ActionHandler { 22 | public: 23 | virtual ~ActionHandler(); 24 | virtual void handleAction(int event, int action) = 0; 25 | virtual void activateAction(int action); 26 | virtual bool deleteClient(); 27 | }; 28 | 29 | }; 30 | 31 | #endif // SRC_SUPLA_ACTION_HANDLER_H_ 32 | -------------------------------------------------------------------------------- /src/supla/auto_lock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "auto_lock.h" 18 | #include "mutex.h" 19 | 20 | Supla::AutoLock::AutoLock(Mutex *mut) : mutex(mut) { 21 | lock(); 22 | } 23 | 24 | Supla::AutoLock::~AutoLock() { 25 | unlock(); 26 | } 27 | 28 | void Supla::AutoLock::lock() { 29 | if (mutex) { 30 | mutex->lock(); 31 | } 32 | } 33 | 34 | void Supla::AutoLock::unlock() { 35 | if (mutex) { 36 | mutex->unlock(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /extras/test/doubles/board_mock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | class BoardInterface { 22 | public: 23 | BoardInterface(); 24 | ~BoardInterface(); 25 | 26 | static BoardInterface *instance; 27 | 28 | virtual void deviceSoftwareReset() = 0; 29 | }; 30 | 31 | 32 | class BoardMock : public BoardInterface { 33 | public: 34 | MOCK_METHOD(void, deviceSoftwareReset, (), (override)); 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /src/supla/network/web_sender.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_WEB_SENDER_H_ 20 | #define SRC_SUPLA_NETWORK_WEB_SENDER_H_ 21 | 22 | #include 23 | 24 | namespace Supla { 25 | 26 | class WebSender { 27 | public: 28 | virtual ~WebSender(); 29 | virtual void send(const char*, int size = -1) = 0; 30 | virtual void send(int number); 31 | }; 32 | }; // namespace Supla 33 | 34 | #endif // SRC_SUPLA_NETWORK_WEB_SENDER_H_ 35 | -------------------------------------------------------------------------------- /extras/test/doubles/timer_mock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | TimerInterface *timerInterfaceInstance = nullptr; 21 | 22 | TimerInterface::TimerInterface() { 23 | timerInterfaceInstance = this; 24 | } 25 | 26 | TimerInterface::~TimerInterface() { 27 | timerInterfaceInstance = nullptr; 28 | } 29 | 30 | 31 | void Supla::initTimers() { 32 | assert(timerInterfaceInstance); 33 | timerInterfaceInstance->initTimers(); 34 | } 35 | -------------------------------------------------------------------------------- /src/supla/channel_extended.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_CHANNEL_EXTENDED_H_ 18 | #define SRC_SUPLA_CHANNEL_EXTENDED_H_ 19 | 20 | #include "channel.h" 21 | 22 | namespace Supla { 23 | class ChannelExtended : public Channel { 24 | public: 25 | bool isExtended(); 26 | TSuplaChannelExtendedValue *getExtValue(); 27 | 28 | protected: 29 | TSuplaChannelExtendedValue extValue = {}; 30 | }; 31 | 32 | }; // namespace Supla 33 | 34 | #endif // SRC_SUPLA_CHANNEL_EXTENDED_H_ 35 | -------------------------------------------------------------------------------- /extras/porting/freertos_linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SUPLA_DEVICE_FREERTOS_SRCS 2 | freertos_platform.cpp 3 | freertos_log.c 4 | ) 5 | # FreeRTOS sources required for Linux compilation (from portable folder) 6 | set(FREERTOS_SRC 7 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/event_groups.c 8 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/list.c 9 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/queue.c 10 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/tasks.c 11 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/timers.c 12 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/croutine.c 13 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/portable/ThirdParty/GCC/Posix/port.c 14 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c 15 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/portable/MemMang/heap_3.c 16 | ) 17 | 18 | target_sources(supladevice 19 | PUBLIC 20 | ${SUPLA_DEVICE_FREERTOS_SRCS} 21 | ${FREERTOS_SRC} 22 | ) 23 | 24 | target_include_directories (supladevice 25 | PUBLIC 26 | ${CMAKE_CURRENT_SOURCE_DIR} 27 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/include 28 | $ENV{SUPLA_FREERTOS_PATH}/FreeRTOS/Source/portable/ThirdParty/GCC/Posix 29 | ) 30 | 31 | target_compile_definitions(supladevice PUBLIC SUPLA_FREERTOS) 32 | 33 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/source/source.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_SOURCE_SOURCE_H_ 20 | #define EXTRAS_PORTING_LINUX_SUPLA_SOURCE_SOURCE_H_ 21 | 22 | #include 23 | 24 | namespace Supla { 25 | 26 | namespace Source { 27 | class Source { 28 | public: 29 | virtual ~Source() {} 30 | virtual std::string getContent() = 0; 31 | }; 32 | }; // namespace Source 33 | }; // namespace Supla 34 | 35 | #endif // EXTRAS_PORTING_LINUX_SUPLA_SOURCE_SOURCE_H_ 36 | -------------------------------------------------------------------------------- /src/supla/storage/littlefs_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_STORAGE_LITTLEFS_CONFIG_H_ 20 | #define SRC_SUPLA_STORAGE_LITTLEFS_CONFIG_H_ 21 | 22 | #include "key_value.h" 23 | 24 | namespace Supla { 25 | 26 | class LittleFsConfig : public KeyValue { 27 | public: 28 | LittleFsConfig(); 29 | virtual ~LittleFsConfig(); 30 | bool init() override; 31 | void commit() override; 32 | }; 33 | }; // namespace Supla 34 | 35 | #endif // SRC_SUPLA_STORAGE_LITTLEFS_CONFIG_H_ 36 | -------------------------------------------------------------------------------- /src/supla/sensor/normally_open.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_NORMALLY_OPEN_H_ 20 | #define SRC_SUPLA_SENSOR_NORMALLY_OPEN_H_ 21 | 22 | #include "binary.h" 23 | 24 | namespace Supla { 25 | namespace Sensor { 26 | class NormallyOpen : public Binary { 27 | public: 28 | explicit NormallyOpen(int pin, bool pullUp = false) : Binary(pin, pullUp) { 29 | } 30 | }; 31 | 32 | }; // namespace Sensor 33 | }; // namespace Supla 34 | 35 | #endif // SRC_SUPLA_SENSOR_NORMALLY_OPEN_H_ 36 | -------------------------------------------------------------------------------- /extras/porting/esp-idf/esp_idf_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_ESP_IDF_ESP_IDF_GPIO_H_ 20 | #define EXTRAS_PORTING_ESP_IDF_ESP_IDF_GPIO_H_ 21 | 22 | #include 23 | 24 | void pinMode(uint8_t pin, uint8_t mode); 25 | int digitalRead(uint8_t pin); 26 | void digitalWrite(uint8_t pin, uint8_t val); 27 | void analogWrite(uint8_t pin, int val); 28 | unsigned int pulseIn(uint8_t pin, uint8_t val, uint64_t timeoutMicro); 29 | 30 | #endif // EXTRAS_PORTING_ESP_IDF_ESP_IDF_GPIO_H_ 31 | -------------------------------------------------------------------------------- /extras/porting/linux/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_IPADDRESS_H_ 20 | #define EXTRAS_PORTING_LINUX_IPADDRESS_H_ 21 | 22 | #include 23 | #include 24 | 25 | class IPAddress { 26 | public: 27 | IPAddress(); 28 | IPAddress(uint8_t ip1, uint8_t ip2, uint8_t ip3, uint8_t ip4); 29 | explicit IPAddress(const std::string &ip); 30 | 31 | union { 32 | uint8_t addr[4] = {}; 33 | uint32_t full; 34 | }; 35 | }; 36 | 37 | #endif // EXTRAS_PORTING_LINUX_IPADDRESS_H_ 38 | -------------------------------------------------------------------------------- /extras/porting/esp-idf/esp_idf_mutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "esp_idf_mutex.h" 18 | 19 | 20 | Supla::Mutex *Supla::Mutex::Create() { 21 | return new Supla::EspIdfMutex; 22 | } 23 | 24 | Supla::EspIdfMutex::~EspIdfMutex() { 25 | unlock(); 26 | } 27 | 28 | Supla::EspIdfMutex::EspIdfMutex() { 29 | mutex = xSemaphoreCreateMutex(); 30 | } 31 | 32 | void Supla::EspIdfMutex::lock() { 33 | xSemaphoreTake(mutex, portMAX_DELAY); 34 | } 35 | 36 | void Supla::EspIdfMutex::unlock() { 37 | xSemaphoreGive(mutex); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/supla/sha256.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "sha256.h" 18 | 19 | Supla::Sha256::Sha256() { 20 | sha256_init(&hash); 21 | } 22 | 23 | Supla::Sha256::~Sha256() { 24 | } 25 | 26 | void Supla::Sha256::update(const uint8_t *data, const int size) { 27 | sha256_update(&hash, size, static_cast(data)); 28 | } 29 | 30 | struct sha256_ctx* Supla::Sha256::getHash() { 31 | return &hash; 32 | } 33 | 34 | void Supla::Sha256::digest(uint8_t *output, int length) { 35 | sha256_digest(&hash, length, output); 36 | } 37 | -------------------------------------------------------------------------------- /src/supla/sensor/hygro_meter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_HYGRO_METER_H_ 20 | #define SRC_SUPLA_SENSOR_HYGRO_METER_H_ 21 | 22 | #include "thermometer.h" 23 | 24 | #define HUMIDITY_NOT_AVAILABLE -1 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class HygroMeter : public Thermometer { 29 | public: 30 | HygroMeter(); 31 | virtual double getHumi(); 32 | void iterateAlways(); 33 | }; 34 | 35 | }; // namespace Sensor 36 | }; // namespace Supla 37 | 38 | #endif // SRC_SUPLA_SENSOR_HYGRO_METER_H_ 39 | -------------------------------------------------------------------------------- /src/supla/supla_lib_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | /* 20 | * Put here all custom defines to customize library functionality 21 | * Supported defines: 22 | * SUPLA_COMM_DEBUG - enables logging of send and received data to/from server 23 | * 24 | */ 25 | #ifdef supla_lib_config_h_ 26 | #define SRC_SUPLA_SUPLA_LIB_CONFIG_H_ 27 | #endif // supla_lib_config_h_ 28 | 29 | #ifndef SRC_SUPLA_SUPLA_LIB_CONFIG_H_ 30 | #define SRC_SUPLA_SUPLA_LIB_CONFIG_H_ 31 | 32 | #define SUPLA_COMM_DEBUG 33 | 34 | #endif // SRC_SUPLA_SUPLA_LIB_CONFIG_H_ 35 | -------------------------------------------------------------------------------- /src/supla/mutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "mutex.h" 18 | 19 | #if defined(ARDUINO) || defined(SUPLA_TEST) || defined(SUPLA_LINUX) || \ 20 | defined(SUPLA_FREERTOS) 21 | // TODO(klew): implement mutex for Arduino targets on ESP 22 | Supla::Mutex *Supla::Mutex::Create() { 23 | // put target specific stuff here 24 | return new Supla::Mutex; 25 | } 26 | #endif 27 | 28 | Supla::Mutex::~Mutex() { 29 | unlock(); 30 | } 31 | 32 | Supla::Mutex::Mutex() { 33 | } 34 | 35 | 36 | void Supla::Mutex::lock() { 37 | } 38 | 39 | void Supla::Mutex::unlock() { 40 | } 41 | -------------------------------------------------------------------------------- /extras/test/doubles/board_mock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | #include "board_mock.h" 21 | #include 22 | 23 | BoardInterface::BoardInterface() { 24 | instance = this; 25 | } 26 | 27 | BoardInterface::~BoardInterface() { 28 | instance = nullptr; 29 | } 30 | 31 | BoardInterface *BoardInterface::instance = nullptr; 32 | 33 | 34 | void deviceSoftwareReset() { 35 | assert(BoardInterface::instance && 36 | "Please add BoardMock instance to your test"); 37 | BoardInterface::instance->deviceSoftwareReset(); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/supla/sha256.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_SHA256_H_ 18 | #define SRC_SUPLA_SHA256_H_ 19 | 20 | #include "nettle/sha2.h" 21 | 22 | /* 23 | * Simple wrapper for nettle SHA256 methods. 24 | */ 25 | 26 | namespace Supla { 27 | 28 | class Sha256 { 29 | public: 30 | Sha256(); 31 | ~Sha256(); 32 | void update(const uint8_t *data, const int size); 33 | struct sha256_ctx* getHash(); 34 | void digest(uint8_t *output, int length = 32); 35 | 36 | protected: 37 | struct sha256_ctx hash; 38 | }; 39 | 40 | }; // namespace Supla 41 | 42 | #endif // SRC_SUPLA_SHA256_H_ 43 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/source/cmd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | #include "cmd.h" 22 | 23 | Supla::Source::Cmd::Cmd(const char *cmd) : cmdLine(cmd) { 24 | } 25 | 26 | Supla::Source::Cmd::~Cmd() { 27 | } 28 | 29 | std::string Supla::Source::Cmd::getContent() { 30 | auto p = popen(cmdLine.c_str(), "r"); 31 | if (p) { 32 | std::string content; 33 | int c = 0; 34 | while ((c = fgetc(p)) != EOF) { 35 | content.append(1, static_cast(c)); 36 | } 37 | pclose(p); 38 | return content; 39 | } 40 | return std::string(""); 41 | } 42 | -------------------------------------------------------------------------------- /src/supla/sensor/binary.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_BINARY_H_ 20 | #define SRC_SUPLA_SENSOR_BINARY_H_ 21 | 22 | #include "../channel_element.h" 23 | 24 | namespace Supla { 25 | namespace Sensor { 26 | class Binary : public ChannelElement { 27 | public: 28 | Binary(int pin, bool pullUp); 29 | bool getValue(); 30 | void iterateAlways(); 31 | void onInit(); 32 | 33 | protected: 34 | int pin; 35 | bool pullUp; 36 | uint64_t lastReadTime; 37 | }; 38 | 39 | }; // namespace Sensor 40 | }; // namespace Supla 41 | 42 | #endif // SRC_SUPLA_SENSOR_BINARY_H_ 43 | -------------------------------------------------------------------------------- /src/supla/sensor/hygro_meter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "hygro_meter.h" 18 | #include 19 | 20 | Supla::Sensor::HygroMeter::HygroMeter() { 21 | channel.setType(SUPLA_CHANNELTYPE_HUMIDITYSENSOR); 22 | channel.setDefault(SUPLA_CHANNELFNC_HUMIDITY); 23 | } 24 | 25 | double Supla::Sensor::HygroMeter::getHumi() { 26 | return HUMIDITY_NOT_AVAILABLE; 27 | } 28 | 29 | void Supla::Sensor::HygroMeter::iterateAlways() { 30 | if (millis() - lastReadTime > 10000) { 31 | lastReadTime = millis(); 32 | channel.setNewValue(TEMPERATURE_NOT_AVAILABLE, getHumi()); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/supla/at_channel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_AT_CHANNEL_H_ 18 | #define SRC_SUPLA_AT_CHANNEL_H_ 19 | 20 | #include "channel.h" 21 | 22 | namespace Supla { 23 | 24 | class AtChannel : public Channel { 25 | public: 26 | void sendUpdate(void *srpc) override; 27 | void pushAction(int action); 28 | void activateAction(int action); 29 | int popAction(); 30 | void setRelatedChannel(uint8_t channelNumber); 31 | void setDisablesLocalOperation(uint32_t actions); 32 | 33 | protected: 34 | int actionToSend = 0; 35 | }; 36 | 37 | }; // namespace Supla 38 | 39 | #endif // SRC_SUPLA_AT_CHANNEL_H_ 40 | -------------------------------------------------------------------------------- /src/supla/sensor/distance.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "distance.h" 18 | #include 19 | 20 | Supla::Sensor::Distance::Distance() { 21 | channel.setType(SUPLA_CHANNELTYPE_DISTANCESENSOR); 22 | channel.setDefault(SUPLA_CHANNELFNC_DISTANCESENSOR); 23 | channel.setNewValue(DISTANCE_NOT_AVAILABLE); 24 | } 25 | 26 | double Supla::Sensor::Distance::getValue() { 27 | return DISTANCE_NOT_AVAILABLE; 28 | } 29 | 30 | void Supla::Sensor::Distance::iterateAlways() { 31 | if (lastReadTime + 100 < millis()) { 32 | lastReadTime = millis(); 33 | channel.setNewValue(getValue()); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/supla/sensor/distance.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_DISTANCE_H_ 20 | #define SRC_SUPLA_SENSOR_DISTANCE_H_ 21 | 22 | #include "supla/channel_element.h" 23 | 24 | #define DISTANCE_NOT_AVAILABLE -1.0 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class Distance : public ChannelElement { 29 | public: 30 | Distance(); 31 | 32 | virtual double getValue(); 33 | 34 | void iterateAlways() override; 35 | 36 | protected: 37 | uint64_t lastReadTime = 0; 38 | }; 39 | 40 | }; // namespace Sensor 41 | }; // namespace Supla 42 | 43 | #endif // SRC_SUPLA_SENSOR_DISTANCE_H_ 44 | -------------------------------------------------------------------------------- /src/supla/sensor/esp_free_heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_ESP_FREE_HEAP_H_ 20 | #define SRC_SUPLA_SENSOR_ESP_FREE_HEAP_H_ 21 | 22 | #include "supla/sensor/thermometer.h" 23 | 24 | namespace Supla { 25 | namespace Sensor { 26 | class EspFreeHeap : public Thermometer { 27 | public: 28 | void onInit() { 29 | channel.setNewValue(getValue()); 30 | } 31 | 32 | double getValue() { 33 | return ESP.getFreeHeap() / 1024.0; 34 | } 35 | 36 | protected: 37 | }; 38 | 39 | }; // namespace Sensor 40 | }; // namespace Supla 41 | 42 | #endif // SRC_SUPLA_SENSOR_ESP_FREE_HEAP_H_ 43 | -------------------------------------------------------------------------------- /src/supla/network/html/sw_update.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_SW_UPDATE_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_SW_UPDATE_H_ 21 | 22 | #include 23 | 24 | namespace Supla { 25 | 26 | namespace Html { 27 | 28 | class SwUpdate : public HtmlElement { 29 | public: 30 | SwUpdate(); 31 | virtual ~SwUpdate(); 32 | void send(Supla::WebSender* sender) override; 33 | bool handleResponse(const char* key, const char* value) override; 34 | }; 35 | 36 | }; // namespace Html 37 | }; // namespace Supla 38 | 39 | #endif // SRC_SUPLA_NETWORK_HTML_SW_UPDATE_H_ 40 | -------------------------------------------------------------------------------- /src/supla/network/html/sw_update_beta.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_SW_UPDATE_BETA_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_SW_UPDATE_BETA_H_ 21 | 22 | #include 23 | 24 | namespace Supla { 25 | 26 | namespace Html { 27 | 28 | class SwUpdateBeta : public HtmlElement { 29 | public: 30 | SwUpdateBeta(); 31 | virtual ~SwUpdateBeta(); 32 | void send(Supla::WebSender* sender) override; 33 | bool handleResponse(const char* key, const char* value) override; 34 | }; 35 | 36 | }; // namespace Html 37 | }; // namespace Supla 38 | 39 | #endif // SRC_SUPLA_NETWORK_HTML_SW_UPDATE_BETA_H_ 40 | -------------------------------------------------------------------------------- /src/supla/sensor/therm_hygro_meter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_THERM_HYGRO_METER_H_ 20 | #define SRC_SUPLA_SENSOR_THERM_HYGRO_METER_H_ 21 | 22 | #include "thermometer.h" 23 | 24 | #define HUMIDITY_NOT_AVAILABLE -1 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class ThermHygroMeter : public Thermometer { 29 | public: 30 | ThermHygroMeter(); 31 | void onInit() override; 32 | void iterateAlways() override; 33 | 34 | virtual double getTemp(); 35 | virtual double getHumi(); 36 | }; 37 | 38 | }; // namespace Sensor 39 | }; // namespace Supla 40 | 41 | #endif // SRC_SUPLA_SENSOR_THERM_HYGRO_METER_H_ 42 | -------------------------------------------------------------------------------- /src/supla/sensor/thermometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_THERMOMETER_H_ 20 | #define SRC_SUPLA_SENSOR_THERMOMETER_H_ 21 | 22 | #include "supla/channel_element.h" 23 | 24 | #define TEMPERATURE_NOT_AVAILABLE -275 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class Thermometer : public ChannelElement { 29 | public: 30 | Thermometer(); 31 | virtual double getValue(); 32 | void onInit() override; 33 | void iterateAlways() override; 34 | 35 | protected: 36 | uint64_t lastReadTime; 37 | }; 38 | 39 | }; // namespace Sensor 40 | }; // namespace Supla 41 | 42 | #endif // SRC_SUPLA_SENSOR_THERMOMETER_H_ 43 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/source/cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_SOURCE_CMD_H_ 20 | #define EXTRAS_PORTING_LINUX_SUPLA_SOURCE_CMD_H_ 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include "source.h" 27 | 28 | namespace Supla { 29 | 30 | namespace Source { 31 | class Cmd : public Source { 32 | public: 33 | explicit Cmd(const char *cmd); 34 | virtual ~Cmd(); 35 | std::string getContent() override; 36 | 37 | protected: 38 | std::string cmdLine; 39 | }; 40 | }; // namespace Source 41 | }; // namespace Supla 42 | 43 | #endif // EXTRAS_PORTING_LINUX_SUPLA_SOURCE_CMD_H_ 44 | -------------------------------------------------------------------------------- /extras/docker/arduino-cli/readme.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | 3 | This docker image contain whole toolset required to compile supla-device 4 | with arduino-cli. 5 | 6 | Arduino toolset is located in /supla/bin directory. 7 | supla-device is located in /supla/supla-device directory. 8 | By default supla-device is latest version fetched from github, however if 9 | you have your own local copy and you want to modify it, it will be better to 10 | mount your host's directory containing supla-device and use it insteat. In 11 | "Run" section there is example how to do it. 12 | 13 | There is also /supla/projects directory where you should mount host's directory 14 | which contain project you would like to build (see "Run" section). 15 | 16 | # Build 17 | 18 | `docker build --rm -f Dockerfile -t supla/supla-device/arduino-cli:local .` 19 | 20 | # Run 21 | 22 | Please provide your local machine's path to directory with project you would 23 | like to compile: 24 | 25 | `docker run --rm -it \ 26 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 27 | supla/supla-device/arduino-cli:local` 28 | 29 | If you want to mount local copy of supla-device, use: 30 | 31 | `docker run --rm -it \ 32 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 33 | --mount src=/home/user/your_path_to_supla/supla-device,target=/supla/supla-device,type=bind \ 34 | supla/supla-device/arduino-cli:local` 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/supla/definitions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_DEFINITIONS_H_ 20 | #define SRC_SUPLA_DEFINITIONS_H_ 21 | 22 | #ifdef ARDUINO 23 | #include 24 | #endif 25 | 26 | #ifndef LSBFIRST 27 | #define LSBFIRST 0 28 | #endif /*LSBFIRST*/ 29 | 30 | #ifndef LOW 31 | #define LOW 0 32 | #endif /*LOW*/ 33 | 34 | #ifndef HIGH 35 | #define HIGH 1 36 | #endif /*HIGH*/ 37 | 38 | #ifndef INPUT 39 | #define INPUT 0 40 | #endif /*INPUT*/ 41 | 42 | #ifndef INPUT_PULLUP 43 | #define INPUT_PULLUP 2 44 | #endif /*INPUT_PULLUP*/ 45 | 46 | #ifndef OUTPUT 47 | #define OUTPUT 1 48 | #endif /*OUTPUT*/ 49 | 50 | #endif // SRC_SUPLA_DEFINITIONS_H_ 51 | -------------------------------------------------------------------------------- /src/supla/network/html/custom_sw_update.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_CUSTOM_SW_UPDATE_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_CUSTOM_SW_UPDATE_H_ 21 | 22 | #include 23 | 24 | namespace Supla { 25 | 26 | namespace Html { 27 | 28 | class CustomSwUpdate : public HtmlElement { 29 | public: 30 | CustomSwUpdate(); 31 | virtual ~CustomSwUpdate(); 32 | void send(Supla::WebSender* sender) override; 33 | bool handleResponse(const char* key, const char* value) override; 34 | }; 35 | 36 | }; // namespace Html 37 | }; // namespace Supla 38 | 39 | #endif // SRC_SUPLA_NETWORK_HTML_CUSTOM_SW_UPDATE_H_ 40 | -------------------------------------------------------------------------------- /src/supla/conditions/on_equal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "../condition.h" 18 | 19 | class OnEqualCond : public Supla::Condition { 20 | public: 21 | using Supla::Condition::Condition; 22 | 23 | bool condition(double val, bool isValid) { 24 | if (isValid) { 25 | return val == threshold; 26 | } 27 | return false; 28 | } 29 | }; 30 | 31 | 32 | Supla::Condition *OnEqual(double threshold, bool useAlternativeMeasurement) { 33 | return new OnEqualCond(threshold, useAlternativeMeasurement); 34 | } 35 | 36 | Supla::Condition *OnEqual(double threshold, Supla::ConditionGetter *getter) { 37 | return new OnEqualCond(threshold, getter); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/supla/conditions/on_less.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "../condition.h" 18 | 19 | class OnLessCond : public Supla::Condition { 20 | public: 21 | using Supla::Condition::Condition; 22 | 23 | bool condition(double val, bool isValid) { 24 | if (isValid) { 25 | return val < threshold; 26 | } 27 | return false; 28 | } 29 | }; 30 | 31 | 32 | Supla::Condition *OnLess(double threshold, bool useAlternativeMeasurement) { 33 | return new OnLessCond(threshold, useAlternativeMeasurement); 34 | } 35 | 36 | Supla::Condition *OnLess(double threshold, Supla::ConditionGetter *getter) { 37 | return new OnLessCond(threshold, getter); 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /extras/docker/esp-idf/readme.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | 3 | This docker image contain whole toolset required to compile supla-device 4 | for ESP32 targets with `ESP-IDF SDK`. 5 | 6 | Espressif toolset and SDK is located in /supla/esp directory. 7 | supla-device is located in /supla/supla-device directory. 8 | By default supla-device is latest version fetched from github, however if 9 | you have your own local copy and you want to modify it, it will be better to 10 | mount your host's directory containing supla-device and use it insteat. In 11 | "Run" section there is example how to do it. 12 | 13 | There is also /supla/projects directory where you should mount host's directory 14 | which contain project you would like to build (see "Run" section). 15 | 16 | # Build 17 | 18 | `docker build --rm -f Dockerfile -t supla/supla-device/esp-idf:local .` 19 | 20 | # Run 21 | 22 | Please provide your local machine's path to directory with project you would 23 | like to compile: 24 | 25 | `docker run --rm -it \ 26 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 27 | supla/supla-device/esp-idf:local` 28 | 29 | If you want to mount local copy of supla-device, use: 30 | 31 | `docker run --rm -it \ 32 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 33 | --mount src=/home/user/your_path_to_supla/supla-device,target=/supla/supla-device,type=bind \ 34 | supla/supla-device/esp-idf:local` 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/supla/conditions/on_less_eq.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "../condition.h" 18 | 19 | class OnLessEqCond : public Supla::Condition { 20 | public: 21 | using Supla::Condition::Condition; 22 | 23 | bool condition(double val, bool isValid) { 24 | if (isValid) { 25 | return val <= threshold; 26 | } 27 | return false; 28 | } 29 | }; 30 | 31 | 32 | Supla::Condition *OnLessEq(double threshold, bool useAlternativeMeasurement) { 33 | return new OnLessEqCond(threshold, useAlternativeMeasurement); 34 | } 35 | 36 | Supla::Condition *OnLessEq(double threshold, Supla::ConditionGetter *getter) { 37 | return new OnLessEqCond(threshold, getter); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /extras/docker/esp8266_rtos_sdk/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | LABEL maintainer="Krzysztof Lewandowski " 3 | 4 | # Install required packages 5 | RUN apt update && \ 6 | DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y tzdata && \ 7 | apt install -y git wget flex bison gperf python3 python3-pip \ 8 | python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev \ 9 | dfu-util libusb-1.0-0 python-is-python3 gcc make libncurses-dev 10 | 11 | # Setup workdir 12 | RUN mkdir /supla 13 | WORKDIR /supla 14 | 15 | # Download and install espressif toolset and ESP8266 RTOS SDK 16 | RUN mkdir esp && \ 17 | cd esp && \ 18 | wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz && \ 19 | tar -xzf xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz && \ 20 | rm xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz && \ 21 | git clone --recursive https://github.com/espressif/ESP8266_RTOS_SDK.git && \ 22 | /usr/bin/python -m pip install --user -r /supla/esp/ESP8266_RTOS_SDK/requirements.txt 23 | 24 | # Download supla-device 25 | RUN git clone https://github.com/SUPLA/supla-device.git && mkdir projects 26 | WORKDIR /supla/projects 27 | 28 | ENV SUPLA_DEVICE_PATH="/supla/supla-device" 29 | ENV PATH="${PATH}:/supla/esp/xtensa-lx106-elf/bin" 30 | ENV ESP_TOOLSET="esp8266" 31 | RUN echo "source /supla/esp/ESP8266_RTOS_SDK/export.sh" >> ~/.bashrc 32 | 33 | -------------------------------------------------------------------------------- /src/supla/control/rgb_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CONTROL_RGB_BASE_H_ 20 | #define SRC_SUPLA_CONTROL_RGB_BASE_H_ 21 | 22 | #include "rgbw_base.h" 23 | 24 | namespace Supla { 25 | namespace Control { 26 | class RGBBase : public RGBWBase { 27 | public: 28 | RGBBase(); 29 | void setRGBW(int red, 30 | int green, 31 | int blue, 32 | int colorBrightness, 33 | int brightness, 34 | bool toggle = false); 35 | 36 | void onLoadState(); 37 | void onSaveState(); 38 | }; 39 | 40 | }; // namespace Control 41 | }; // namespace Supla 42 | 43 | #endif // SRC_SUPLA_CONTROL_RGB_BASE_H_ 44 | -------------------------------------------------------------------------------- /src/supla/sensor/virtual_thermometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_VIRTUAL_THERMOMETER_H_ 20 | #define SRC_SUPLA_SENSOR_VIRTUAL_THERMOMETER_H_ 21 | 22 | #include "thermometer.h" 23 | 24 | namespace Supla { 25 | namespace Sensor { 26 | class VirtualThermometer : public Supla::Sensor::Thermometer { 27 | public: 28 | double getValue() override { 29 | return temperature; 30 | } 31 | void setValue(double val) { 32 | temperature = val; 33 | } 34 | 35 | protected: 36 | double temperature = TEMPERATURE_NOT_AVAILABLE; 37 | }; 38 | }; // namespace Sensor 39 | }; // namespace Supla 40 | 41 | #endif // SRC_SUPLA_SENSOR_VIRTUAL_THERMOMETER_H_ 42 | -------------------------------------------------------------------------------- /src/supla/conditions/on_greater.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "../condition.h" 18 | 19 | class OnGreaterCond : public Supla::Condition { 20 | public: 21 | using Supla::Condition::Condition; 22 | 23 | bool condition(double val, bool isValid) { 24 | if (isValid) { 25 | return val > threshold; 26 | } 27 | return false; 28 | } 29 | }; 30 | 31 | 32 | Supla::Condition *OnGreater(double threshold, bool useAlternativeMeasurement) { 33 | return new OnGreaterCond(threshold, useAlternativeMeasurement); 34 | } 35 | 36 | Supla::Condition *OnGreater(double threshold, Supla::ConditionGetter *getter) { 37 | return new OnGreaterCond(threshold, getter); 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/supla/sensor/MAX6675_K.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_MAX6675_K_H_ 20 | #define SRC_SUPLA_SENSOR_MAX6675_K_H_ 21 | 22 | #include 23 | #include 24 | 25 | namespace Supla { 26 | namespace Sensor { 27 | class MAX6675_K : public Thermometer { 28 | public: 29 | MAX6675_K(uint8_t pin_CLK, uint8_t pin_CS, uint8_t pin_DO); 30 | double getValue(); 31 | 32 | private: 33 | void onInit(); 34 | byte spiRead(); 35 | 36 | protected: 37 | int8_t pin_CLK; 38 | int8_t pin_CS; 39 | int8_t pin_DO; 40 | }; 41 | 42 | }; // namespace Sensor 43 | }; // namespace Supla 44 | 45 | #endif // SRC_SUPLA_SENSOR_MAX6675_K_H_ 46 | -------------------------------------------------------------------------------- /extras/porting/esp-idf/esp_idf_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_ESP_IDF_ESP_IDF_MUTEX_H_ 20 | #define EXTRAS_PORTING_ESP_IDF_ESP_IDF_MUTEX_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace Supla { 27 | 28 | class EspIdfMutex : public Mutex { 29 | public: 30 | friend Supla::Mutex *Supla::Mutex::Create(); 31 | virtual ~EspIdfMutex(); 32 | void lock() override; 33 | void unlock() override; 34 | 35 | protected: 36 | EspIdfMutex(); 37 | 38 | SemaphoreHandle_t mutex = NULL; 39 | }; 40 | 41 | }; // namespace Supla 42 | 43 | #endif // EXTRAS_PORTING_ESP_IDF_ESP_IDF_MUTEX_H_ 44 | -------------------------------------------------------------------------------- /extras/porting/linux/linux_file_state_logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef EXTRAS_PORTING_LINUX_LINUX_FILE_STATE_LOGGER_H_ 18 | #define EXTRAS_PORTING_LINUX_LINUX_FILE_STATE_LOGGER_H_ 19 | 20 | #include 21 | 22 | #include 23 | 24 | namespace Supla { 25 | namespace Device { 26 | class FileStateLogger : public LastStateLogger { 27 | public: 28 | explicit FileStateLogger(const std::string &); 29 | void log(const char *) override; 30 | void addToFile(const char *line); 31 | 32 | protected: 33 | std::string file; 34 | }; 35 | }; // namespace Device 36 | }; // namespace Supla 37 | 38 | #endif // EXTRAS_PORTING_LINUX_LINUX_FILE_STATE_LOGGER_H_ 39 | -------------------------------------------------------------------------------- /src/supla/network/html/wifi_parameters.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_WIFI_PARAMETERS_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_WIFI_PARAMETERS_H_ 21 | 22 | #include 23 | 24 | class SuplaDeviceClass; 25 | 26 | namespace Supla { 27 | 28 | namespace Html { 29 | 30 | class WifiParameters : public HtmlElement { 31 | public: 32 | WifiParameters(); 33 | virtual ~WifiParameters(); 34 | void send(Supla::WebSender* sender) override; 35 | bool handleResponse(const char* key, const char* value) override; 36 | }; 37 | 38 | }; // namespace Html 39 | }; // namespace Supla 40 | 41 | #endif // SRC_SUPLA_NETWORK_HTML_WIFI_PARAMETERS_H_ 42 | -------------------------------------------------------------------------------- /src/supla/storage/eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_STORAGE_EEPROM_H_ 20 | #define SRC_SUPLA_STORAGE_EEPROM_H_ 21 | 22 | #include "storage.h" 23 | 24 | namespace Supla { 25 | 26 | class Eeprom : public Storage { 27 | public: 28 | explicit Eeprom(unsigned int storageStartingOffset = 0, 29 | int reservedSize = -1); 30 | bool init(); 31 | void commit(); 32 | 33 | protected: 34 | int readStorage(unsigned int, unsigned char *, int, bool); 35 | int writeStorage(unsigned int, const unsigned char *, int); 36 | 37 | int reservedSize; 38 | bool dataChanged; 39 | }; 40 | 41 | }; // namespace Supla 42 | 43 | #endif // SRC_SUPLA_STORAGE_EEPROM_H_ 44 | -------------------------------------------------------------------------------- /extras/docker/freeRTOS/readme.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | 3 | This docker image contain whole toolset required to compile supla-device 4 | for FreeRTOS Linux port and standard Linux variant. 5 | 6 | FreeRTOS is located in /supla/FreeRTOS directory. 7 | supla-device is located in /supla/supla-device directory. 8 | By default supla-device latest version is fetched from github during image 9 | build, however if you have your own local copy and you want to modify it, it 10 | will be better to mount your host's directory containing supla-device and 11 | use it instead. In "Run" section there is example how to do it. 12 | 13 | There is also /supla/projects directory where you should mount host's directory 14 | which contain project you would like to build (see "Run" section). 15 | 16 | # Build 17 | 18 | `docker build --rm -f Dockerfile -t supla/supla-device/freertos:local .` 19 | 20 | # Run 21 | 22 | Please provide your local machine's path to directory with project you would 23 | like to compile: 24 | 25 | `docker run --rm -it \ 26 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 27 | supla/supla-device/freertos:local` 28 | 29 | If you want to mount local copy of supla-device, use: 30 | 31 | `docker run --rm -it \ 32 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 33 | --mount src=/home/user/your_path_to_supla/supla-device,target=/supla/supla-device,type=bind \ 34 | supla/supla-device/freertos:local` 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/supla/network/html/status_led_parameters.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_STATUS_LED_PARAMETERS_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_STATUS_LED_PARAMETERS_H_ 21 | 22 | #include 23 | 24 | namespace Supla { 25 | 26 | namespace Html { 27 | 28 | class StatusLedParameters : public HtmlElement { 29 | public: 30 | StatusLedParameters(); 31 | virtual ~StatusLedParameters(); 32 | void send(Supla::WebSender* sender) override; 33 | bool handleResponse(const char* key, const char* value) override; 34 | }; 35 | 36 | }; // namespace Html 37 | }; // namespace Supla 38 | 39 | #endif // SRC_SUPLA_NETWORK_HTML_STATUS_LED_PARAMETERS_H_ 40 | -------------------------------------------------------------------------------- /extras/docker/esp8266_rtos_sdk/readme.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | 3 | This docker image contain whole toolset required to compile supla-device 4 | for ESP82xx target with `ESP8266_RTOS_SDK`. 5 | 6 | Espressif toolset and SDK is located in /supla/esp directory. 7 | supla-device is located in /supla/supla-device directory. 8 | By default supla-device is latest version fetched from github, however if 9 | you have your own local copy and you want to modify it, it will be better to 10 | mount your host's directory containing supla-device and use it insteat. In 11 | "Run" section there is example how to do it. 12 | 13 | There is also /supla/projects directory where you should mount host's directory 14 | which contain project you would like to build (see "Run" section). 15 | 16 | # Build 17 | 18 | `docker build --rm -f Dockerfile -t supla/supla-device/esp8266_rtos:local .` 19 | 20 | # Run 21 | 22 | Please provide your local machine's path to directory with project you would 23 | like to compile: 24 | 25 | `docker run --rm -it \ 26 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 27 | supla/supla-device/esp8266_rtos:local` 28 | 29 | If you want to mount local copy of supla-device, use: 30 | 31 | `docker run --rm -it \ 32 | --mount src=/home/user/my_projects,target=/supla/projects,type=bind \ 33 | --mount src=/home/user/your_path_to_supla/supla-device,target=/supla/supla-device,type=bind \ 34 | supla/supla-device/esp8266_rtos:local` 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/supla/sensor/thermometer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "thermometer.h" 18 | 19 | #include 20 | 21 | Supla::Sensor::Thermometer::Thermometer() : lastReadTime(0) { 22 | channel.setType(SUPLA_CHANNELTYPE_THERMOMETER); 23 | channel.setDefault(SUPLA_CHANNELFNC_THERMOMETER); 24 | } 25 | 26 | void Supla::Sensor::Thermometer::onInit() { 27 | channel.setNewValue(getValue()); 28 | } 29 | 30 | double Supla::Sensor::Thermometer::getValue() { 31 | return TEMPERATURE_NOT_AVAILABLE; 32 | } 33 | 34 | void Supla::Sensor::Thermometer::iterateAlways() { 35 | if (millis() - lastReadTime > 10000) { 36 | lastReadTime = millis(); 37 | channel.setNewValue(getValue()); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/supla/control/pin_status_led.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_CONTROL_PIN_STATUS_LED_H_ 18 | #define SRC_SUPLA_CONTROL_PIN_STATUS_LED_H_ 19 | 20 | #include "../element.h" 21 | 22 | namespace Supla { 23 | namespace Control { 24 | class PinStatusLed : public Element { 25 | public: 26 | PinStatusLed(uint8_t srcPin, uint8_t outPin, bool invert = false); 27 | 28 | void onInit(); 29 | void iterateAlways(); 30 | void setInvertedLogic(bool invertedLogic); 31 | 32 | protected: 33 | void updatePin(); 34 | 35 | uint8_t srcPin; 36 | uint8_t outPin; 37 | bool invert; 38 | }; 39 | 40 | }; // namespace Control 41 | }; // namespace Supla 42 | 43 | #endif // SRC_SUPLA_CONTROL_PIN_STATUS_LED_H_ 44 | -------------------------------------------------------------------------------- /src/supla/device/last_state_logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_DEVICE_LAST_STATE_LOGGER_H_ 18 | #define SRC_SUPLA_DEVICE_LAST_STATE_LOGGER_H_ 19 | 20 | #define LAST_STATE_LOGGER_BUFFER_SIZE 500 21 | 22 | namespace Supla { 23 | class Mutex; 24 | 25 | namespace Device { 26 | class LastStateLogger { 27 | public: 28 | LastStateLogger(); 29 | virtual void log(const char *); 30 | virtual char *getLog(); 31 | virtual bool prepareLastStateLog(); 32 | 33 | protected: 34 | char buffer[LAST_STATE_LOGGER_BUFFER_SIZE] = {}; 35 | int index = 0; 36 | Supla::Mutex *mutex = nullptr; 37 | }; 38 | }; // namespace Device 39 | }; // namespace Supla 40 | 41 | #endif // SRC_SUPLA_DEVICE_LAST_STATE_LOGGER_H_ 42 | -------------------------------------------------------------------------------- /src/supla/network/html/device_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_DEVICE_INFO_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_DEVICE_INFO_H_ 21 | 22 | #include 23 | 24 | class SuplaDeviceClass; 25 | 26 | namespace Supla { 27 | 28 | namespace Html { 29 | 30 | class DeviceInfo : public HtmlElement { 31 | public: 32 | explicit DeviceInfo(SuplaDeviceClass *sdc); 33 | virtual ~DeviceInfo(); 34 | virtual void send(Supla::WebSender *sender); 35 | // virtual bool handleResponse() = 0; 36 | protected: 37 | SuplaDeviceClass *sdc; 38 | }; 39 | 40 | }; // namespace Html 41 | }; // namespace Supla 42 | 43 | #endif // SRC_SUPLA_NETWORK_HTML_DEVICE_INFO_H_ 44 | -------------------------------------------------------------------------------- /src/supla/network/html/protocol_parameters.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_PROTOCOL_PARAMETERS_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_PROTOCOL_PARAMETERS_H_ 21 | 22 | #include 23 | 24 | class SuplaDeviceClass; 25 | 26 | namespace Supla { 27 | 28 | namespace Html { 29 | 30 | class ProtocolParameters : public HtmlElement { 31 | public: 32 | ProtocolParameters(); 33 | virtual ~ProtocolParameters(); 34 | void send(Supla::WebSender* sender) override; 35 | bool handleResponse(const char* key, const char* value) override; 36 | }; 37 | 38 | }; // namespace Html 39 | }; // namespace Supla 40 | 41 | #endif // SRC_SUPLA_NETWORK_HTML_PROTOCOL_PARAMETERS_H_ 42 | -------------------------------------------------------------------------------- /src/supla/control/virtual_relay.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CONTROL_VIRTUAL_RELAY_H_ 20 | #define SRC_SUPLA_CONTROL_VIRTUAL_RELAY_H_ 21 | 22 | #include "relay.h" 23 | 24 | namespace Supla { 25 | namespace Control { 26 | class VirtualRelay : public Relay { 27 | public: 28 | VirtualRelay(_supla_int_t functions = 29 | (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER)); 30 | 31 | void onInit(); 32 | void turnOn(_supla_int_t duration = 0); 33 | void turnOff(_supla_int_t duration = 0); 34 | bool isOn(); 35 | 36 | protected: 37 | bool state = false; 38 | }; 39 | 40 | }; // namespace Control 41 | }; // namespace Supla 42 | 43 | #endif // SRC_SUPLA_CONTROL_VIRTUAL_RELAY_H_ 44 | -------------------------------------------------------------------------------- /src/supla/sensor/MAXThermocouple.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_MAXTHERMOCOUPLE_H_ 20 | #define SRC_SUPLA_SENSOR_MAXTHERMOCOUPLE_H_ 21 | 22 | #include 23 | #include 24 | 25 | namespace Supla { 26 | namespace Sensor { 27 | class MAXThermocouple : public Thermometer { 28 | public: 29 | MAXThermocouple(uint8_t pin_CLK, uint8_t pin_CS, uint8_t pin_DO); 30 | double getValue(); 31 | 32 | private: 33 | void onInit(); 34 | uint32_t spiRead(void); 35 | 36 | protected: 37 | int8_t pin_CLK; 38 | int8_t pin_CS; 39 | int8_t pin_DO; 40 | }; 41 | 42 | }; // namespace Sensor 43 | }; // namespace Supla 44 | 45 | #endif // SRC_SUPLA_SENSOR_MAXTHERMOCOUPLE_H_ 46 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/sensor/binary_parsed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | #include "binary_parsed.h" 22 | 23 | Supla::Sensor::BinaryParsed::BinaryParsed(Supla::Parser::Parser *parser) 24 | : SensorParsed(parser) { 25 | } 26 | 27 | bool Supla::Sensor::BinaryParsed::getValue() { 28 | bool value = false; 29 | 30 | if (isParameterConfigured(Supla::Parser::State)) { 31 | if (refreshParserSource()) { 32 | double result = getParameterValue(Supla::Parser::State); 33 | if (result - 0.1 <= 1 && 1 <= result + 0.1) { 34 | value = true; 35 | } 36 | if (!parser->isValid()) { 37 | value = false; 38 | } 39 | } 40 | } 41 | return value; 42 | } 43 | -------------------------------------------------------------------------------- /extras/porting/linux/linux_timers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include // NOLINT(build/c++11) 24 | 25 | #include "linux_timers.h" 26 | 27 | void supla10msTimer() { 28 | while (1) { 29 | SuplaDevice.onTimer(); 30 | delay(10); 31 | } 32 | } 33 | 34 | void supla1msTimer() { 35 | while (1) { 36 | SuplaDevice.onFastTimer(); 37 | delay(1); 38 | } 39 | } 40 | 41 | void Supla::Linux::Timers::init() { 42 | supla_log(LOG_DEBUG, "Starting linux timers..."); 43 | std::thread standardTimer(supla10msTimer); 44 | standardTimer.detach(); 45 | 46 | std::thread fastTimer(supla1msTimer); 47 | fastTimer.detach(); 48 | } 49 | -------------------------------------------------------------------------------- /src/supla/IEEE754tools.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) TBD 2 | // 3 | // FILE: IEEE754tools.h 4 | // AUTHOR: Rob Tillaart 5 | // VERSION: 0.1.00 6 | // PURPOSE: IEEE754 tools 7 | // 8 | // http://playground.arduino.cc//Main/IEEE754tools 9 | // 10 | // Released to the public domain 11 | // not tested, use with care 12 | // 13 | 14 | #ifndef SRC_SUPLA_IEEE754TOOLS_H_ 15 | #define SRC_SUPLA_IEEE754TOOLS_H_ 16 | 17 | // IEEE754 float layout; 18 | struct IEEEfloat { 19 | uint32_t m:23; 20 | uint8_t e:8; 21 | uint8_t s:1; 22 | }; 23 | 24 | // for packing and unpacking a float 25 | typedef union _FLOATCONV { 26 | IEEEfloat p; 27 | float f; 28 | uint8_t b[4]; 29 | } _FLOATCONV; 30 | 31 | // Arduino UNO double layout: 32 | // the UNO has no 64 bit double, it is only able to map 23 bits of the mantisse 33 | // a filler is added. 34 | struct _DBL { 35 | uint32_t filler:29; 36 | uint32_t m:23; 37 | uint16_t e:11; 38 | uint8_t s:1; 39 | }; 40 | 41 | 42 | // for packing and unpacking a double 43 | typedef union _DBLCONV { 44 | // IEEEdouble p; 45 | _DBL p; 46 | double d; // !! is a 32bit float for UNO. 47 | uint8_t b[8]; 48 | } _DBLCONV; 49 | 50 | // 51 | // converts a float to a packed array of 8 bytes representing a 64 bit double 52 | // restriction exponent and mantisse. 53 | // 54 | // float; array of 8 bytes; LSBFIRST; MSBFIRST 55 | // 56 | // void float2DoublePacked(float number, byte* bar, int byteOrder=LSBFIRST); 57 | 58 | 59 | #endif // SRC_SUPLA_IEEE754TOOLS_H_ 60 | -------------------------------------------------------------------------------- /src/supla/network/netif_wifi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "netif_wifi.h" 18 | #include 19 | 20 | namespace Supla { 21 | 22 | Wifi::Wifi(const char *wifiSsid, const char *wifiPassword, unsigned char *ip) 23 | : Network(ip) { 24 | setSsid(wifiSsid); 25 | setPassword(wifiPassword); 26 | } 27 | 28 | void Wifi::setSsid(const char *wifiSsid) { 29 | if (wifiSsid) { 30 | strncpy(ssid, wifiSsid, MAX_SSID_SIZE); 31 | } 32 | } 33 | 34 | void Wifi::setPassword(const char *wifiPassword) { 35 | if (wifiPassword) { 36 | strncpy(password, wifiPassword, MAX_WIFI_PASSWORD_SIZE); 37 | } 38 | } 39 | 40 | bool Wifi::isWifiConfigRequired() { 41 | return true; 42 | } 43 | 44 | }; // namespace Supla 45 | -------------------------------------------------------------------------------- /extras/test/ConditionTests/on_greater_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TEST(OnGreaterTests, OnGreaterConditionTests) { 22 | auto cond = OnGreater(20); 23 | 24 | EXPECT_FALSE(cond->checkConditionFor(5)); 25 | EXPECT_FALSE(cond->checkConditionFor(15)); 26 | 27 | EXPECT_FALSE(cond->checkConditionFor(20)); 28 | EXPECT_TRUE(cond->checkConditionFor(20.001)); 29 | EXPECT_FALSE(cond->checkConditionFor(25)); 30 | 31 | EXPECT_FALSE(cond->checkConditionFor(5)); 32 | EXPECT_FALSE(cond->checkConditionFor(5)); 33 | EXPECT_FALSE(cond->checkConditionFor(5)); 34 | 35 | EXPECT_TRUE(cond->checkConditionFor(50)); 36 | EXPECT_FALSE(cond->checkConditionFor(5)); 37 | 38 | delete cond; 39 | } 40 | -------------------------------------------------------------------------------- /src/supla/conditions/on_greater_eq.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include "../condition.h" 20 | 21 | class OnGreaterEqCond : public Supla::Condition { 22 | public: 23 | using Supla::Condition::Condition; 24 | 25 | bool condition(double val, bool isValid) { 26 | if (isValid) { 27 | return val >= threshold; 28 | } 29 | return false; 30 | } 31 | }; 32 | 33 | Supla::Condition *OnGreaterEq(double threshold, 34 | bool useAlternativeMeasurement) { 35 | return new OnGreaterEqCond(threshold, useAlternativeMeasurement); 36 | } 37 | 38 | Supla::Condition *OnGreaterEq(double threshold, 39 | Supla::ConditionGetter *getter) { 40 | return new OnGreaterEqCond(threshold, getter); 41 | } 42 | -------------------------------------------------------------------------------- /src/supla/sensor/one_phase_electricity_meter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_ONE_PHASE_ELECTRICITY_METER_H_ 20 | #define SRC_SUPLA_SENSOR_ONE_PHASE_ELECTRICITY_METER_H_ 21 | 22 | #include "electricity_meter.h" 23 | 24 | namespace Supla { 25 | namespace Sensor { 26 | class OnePhaseElectricityMeter : public ElectricityMeter { 27 | public: 28 | OnePhaseElectricityMeter() { 29 | extChannel.setFlag(SUPLA_CHANNEL_FLAG_PHASE2_UNSUPPORTED); 30 | extChannel.setFlag(SUPLA_CHANNEL_FLAG_PHASE3_UNSUPPORTED); 31 | } 32 | 33 | virtual void readValuesFromDevice() { 34 | } 35 | 36 | void onInit() { 37 | } 38 | }; 39 | 40 | }; // namespace Sensor 41 | }; // namespace Supla 42 | 43 | #endif // SRC_SUPLA_SENSOR_ONE_PHASE_ELECTRICITY_METER_H_ 44 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/sensor/binary_parsed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_SENSOR_BINARY_PARSED_H_ 18 | #define EXTRAS_PORTING_LINUX_SUPLA_SENSOR_BINARY_PARSED_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "sensor_parsed.h" 26 | 27 | namespace Supla { 28 | namespace Parser { 29 | const char State[] = "state"; 30 | }; 31 | 32 | namespace Sensor { 33 | 34 | class BinaryParsed : public VirtualBinary, public SensorParsed { 35 | public: 36 | explicit BinaryParsed(Supla::Parser::Parser *); 37 | bool getValue() override; 38 | }; 39 | }; // namespace Sensor 40 | }; // namespace Supla 41 | 42 | #endif // EXTRAS_PORTING_LINUX_SUPLA_SENSOR_BINARY_PARSED_H_ 43 | -------------------------------------------------------------------------------- /extras/test/ConditionTests/on_greater_eq_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TEST(OnGreaterEqTests, OnGreaterEqConditionTests) { 22 | auto cond = OnGreaterEq(20); 23 | 24 | EXPECT_FALSE(cond->checkConditionFor(5)); 25 | EXPECT_FALSE(cond->checkConditionFor(15)); 26 | 27 | EXPECT_TRUE(cond->checkConditionFor(20)); 28 | EXPECT_FALSE(cond->checkConditionFor(20.001)); 29 | EXPECT_FALSE(cond->checkConditionFor(25)); 30 | 31 | EXPECT_FALSE(cond->checkConditionFor(5)); 32 | EXPECT_FALSE(cond->checkConditionFor(5)); 33 | EXPECT_FALSE(cond->checkConditionFor(5)); 34 | 35 | EXPECT_TRUE(cond->checkConditionFor(50)); 36 | EXPECT_FALSE(cond->checkConditionFor(5)); 37 | 38 | delete cond; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /extras/porting/esp-idf/spiffs_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_ESP_IDF_SPIFFS_STORAGE_H_ 20 | #define EXTRAS_PORTING_ESP_IDF_SPIFFS_STORAGE_H_ 21 | 22 | #include 23 | 24 | namespace Supla { 25 | 26 | class SpiffsStorage : public Storage { 27 | public: 28 | explicit SpiffsStorage(uint32_t size = 512); 29 | virtual ~SpiffsStorage(); 30 | bool init(); 31 | void commit(); 32 | 33 | protected: 34 | int readStorage(unsigned int, unsigned char *, int, bool); 35 | int writeStorage(unsigned int, const unsigned char *, int); 36 | 37 | bool dataChanged = false; 38 | char *buffer = nullptr; 39 | uint32_t bufferSize = 0; 40 | }; 41 | 42 | }; // namespace Supla 43 | 44 | #endif // EXTRAS_PORTING_ESP_IDF_SPIFFS_STORAGE_H_ 45 | -------------------------------------------------------------------------------- /src/supla/conditions/on_invalid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include "../condition.h" 20 | 21 | class OnInvalidCond : public Supla::Condition { 22 | public: 23 | explicit OnInvalidCond(bool useAlternativeMeasurement) 24 | : Supla::Condition(0, useAlternativeMeasurement) { 25 | } 26 | 27 | explicit OnInvalidCond(Supla::ConditionGetter *getter) 28 | : Supla::Condition(0, getter) { 29 | } 30 | 31 | bool condition(double val, bool isValid) { 32 | (void)(val); 33 | return !isValid; 34 | } 35 | }; 36 | 37 | Supla::Condition *OnInvalid(bool useAlternativeMeasurement) { 38 | return new OnInvalidCond(useAlternativeMeasurement); 39 | } 40 | 41 | Supla::Condition *OnInvalid(Supla::ConditionGetter *getter) { 42 | return new OnInvalidCond(getter); 43 | } 44 | -------------------------------------------------------------------------------- /src/supla/control/dimmer_leds.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CONTROL_DIMMER_LEDS_H_ 20 | #define SRC_SUPLA_CONTROL_DIMMER_LEDS_H_ 21 | 22 | #include "dimmer_base.h" 23 | 24 | namespace Supla { 25 | namespace Control { 26 | class DimmerLeds : public DimmerBase { 27 | public: 28 | explicit DimmerLeds(int brightnessPin); 29 | 30 | void setRGBWValueOnDevice(uint32_t red, 31 | uint32_t green, 32 | uint32_t blue, 33 | uint32_t colorBrightness, 34 | uint32_t brightness); 35 | 36 | void onInit(); 37 | 38 | protected: 39 | int brightnessPin; 40 | }; 41 | 42 | }; // namespace Control 43 | }; // namespace Supla 44 | 45 | #endif // SRC_SUPLA_CONTROL_DIMMER_LEDS_H_ 46 | -------------------------------------------------------------------------------- /src/supla/correction.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_CORRECTION_H_ 18 | #define SRC_SUPLA_CORRECTION_H_ 19 | 20 | #include 21 | 22 | namespace Supla { 23 | 24 | class Correction { 25 | public: 26 | static void add(uint8_t channelNumber, 27 | double correction, 28 | bool forSecondaryValue = false); 29 | static double get(uint8_t channelNumber, bool forSecondaryValue = false); 30 | static void clear(); 31 | 32 | protected: 33 | Correction(uint8_t channelNumber, double correction, bool forSecondaryValue); 34 | ~Correction(); 35 | 36 | static Correction *first; 37 | Correction *next; 38 | uint8_t channelNumber; 39 | double correction; 40 | bool forSecondaryValue; 41 | }; 42 | 43 | }; // namespace Supla 44 | 45 | #endif // SRC_SUPLA_CORRECTION_H_ 46 | -------------------------------------------------------------------------------- /src/supla/rsa_verificator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "rsa_verificator.h" 18 | 19 | Supla::RsaVerificator::RsaVerificator(const uint8_t *publicKeyBytes) { 20 | rsa_public_key_init(&publicKey); 21 | nettle_mpz_set_str_256_u(publicKey.n, RSA_NUM_BYTES, publicKeyBytes); 22 | mpz_set_ui(publicKey.e, RSA_PUBLIC_EXPONENT); 23 | rsa_public_key_prepare(&publicKey); 24 | } 25 | 26 | Supla::RsaVerificator::~RsaVerificator() { 27 | rsa_public_key_clear(&publicKey); 28 | } 29 | 30 | bool Supla::RsaVerificator::verify(Supla::Sha256 *hash, 31 | const uint8_t *signatureBytes) { 32 | nettle_mpz_init_set_str_256_u(signature, RSA_NUM_BYTES, signatureBytes); 33 | int result = rsa_sha256_verify(&publicKey, hash->getHash(), signature); 34 | mpz_clear(signature); 35 | 36 | return result == 1; 37 | } 38 | -------------------------------------------------------------------------------- /src/supla/control/rgb_leds.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CONTROL_RGB_LEDS_H_ 20 | #define SRC_SUPLA_CONTROL_RGB_LEDS_H_ 21 | 22 | #include "rgb_base.h" 23 | 24 | namespace Supla { 25 | namespace Control { 26 | class RGBLeds : public RGBBase { 27 | public: 28 | RGBLeds(int redPin, int greenPin, int bluePin); 29 | 30 | void setRGBWValueOnDevice(uint32_t red, 31 | uint32_t green, 32 | uint32_t blue, 33 | uint32_t colorBrightness, 34 | uint32_t brightness); 35 | 36 | void onInit(); 37 | 38 | protected: 39 | int redPin; 40 | int greenPin; 41 | int bluePin; 42 | }; 43 | 44 | }; // namespace Control 45 | }; // namespace Supla 46 | 47 | #endif // SRC_SUPLA_CONTROL_RGB_LEDS_H_ 48 | -------------------------------------------------------------------------------- /src/supla/sensor/virtual_binary.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_VIRTUAL_BINARY_H_ 20 | #define SRC_SUPLA_SENSOR_VIRTUAL_BINARY_H_ 21 | 22 | #include "../action_handler.h" 23 | #include "../actions.h" 24 | #include "../channel_element.h" 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class VirtualBinary : public ChannelElement, public ActionHandler { 29 | public: 30 | VirtualBinary(); 31 | virtual bool getValue(); 32 | void iterateAlways(); 33 | void onInit(); 34 | void handleAction(int event, int action); 35 | void set(); 36 | void clear(); 37 | void toggle(); 38 | 39 | protected: 40 | bool state; 41 | uint64_t lastReadTime; 42 | }; 43 | 44 | }; // namespace Sensor 45 | }; // namespace Supla 46 | 47 | #endif // SRC_SUPLA_SENSOR_VIRTUAL_BINARY_H_ 48 | -------------------------------------------------------------------------------- /extras/test/ConditionTests/on_equal_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TEST(OnEqualTests, OnEqualConditionTests) { 22 | auto cond = OnEqual(3.1415); 23 | 24 | EXPECT_FALSE(cond->checkConditionFor(5)); 25 | EXPECT_FALSE(cond->checkConditionFor(15)); 26 | 27 | EXPECT_TRUE(cond->checkConditionFor(3.1415)); 28 | EXPECT_FALSE(cond->checkConditionFor(20.001)); 29 | EXPECT_FALSE(cond->checkConditionFor(25)); 30 | 31 | EXPECT_FALSE(cond->checkConditionFor(5)); 32 | EXPECT_FALSE(cond->checkConditionFor(5)); 33 | EXPECT_FALSE(cond->checkConditionFor(5)); 34 | 35 | EXPECT_FALSE(cond->checkConditionFor(50)); 36 | EXPECT_TRUE(cond->checkConditionFor(3.1415)); 37 | EXPECT_FALSE(cond->checkConditionFor(5)); 38 | 39 | delete cond; 40 | } 41 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/parser/parser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "parser.h" 18 | #include 19 | #include 20 | 21 | Supla::Parser::Parser::Parser(Supla::Source::Source *src) : source(src) {} 22 | 23 | void Supla::Parser::Parser::addKey(const std::string& key, int index) { 24 | keys[key] = index; 25 | } 26 | 27 | bool Supla::Parser::Parser::isValid() { 28 | return valid; 29 | } 30 | 31 | bool Supla::Parser::Parser::refreshParserSource() { 32 | if (!lastRefreshTime || millis() - lastRefreshTime > refreshTimeMs) { 33 | lastRefreshTime = millis(); 34 | return refreshSource(); 35 | } 36 | return true; 37 | } 38 | 39 | void Supla::Parser::Parser::setRefreshTime(unsigned int timeMs) { 40 | if (timeMs < 10) { 41 | timeMs = 10; 42 | } 43 | refreshTimeMs = timeMs; 44 | } 45 | -------------------------------------------------------------------------------- /extras/test/ConditionTests/on_between_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TEST(OnBetweenTests, OnBetweenConditionTests) { 22 | auto cond = OnBetween(20, 30); 23 | 24 | EXPECT_FALSE(cond->checkConditionFor(5)); 25 | EXPECT_FALSE(cond->checkConditionFor(15)); 26 | 27 | EXPECT_FALSE(cond->checkConditionFor(20)); 28 | EXPECT_TRUE(cond->checkConditionFor(20.001)); 29 | EXPECT_FALSE(cond->checkConditionFor(25)); 30 | 31 | EXPECT_FALSE(cond->checkConditionFor(5)); 32 | EXPECT_FALSE(cond->checkConditionFor(5)); 33 | EXPECT_FALSE(cond->checkConditionFor(5)); 34 | 35 | EXPECT_FALSE(cond->checkConditionFor(50)); 36 | EXPECT_TRUE(cond->checkConditionFor(29)); 37 | EXPECT_FALSE(cond->checkConditionFor(5)); 38 | 39 | delete cond; 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/supla/uptime.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_UPTIME_H_ 18 | #define SRC_SUPLA_UPTIME_H_ 19 | 20 | #include 21 | #include "../supla-common/proto.h" 22 | 23 | namespace Supla { 24 | 25 | class Uptime { 26 | public: 27 | Uptime(); 28 | 29 | void iterate(uint64_t millis); 30 | void resetConnectionUptime(); 31 | void setConnectionLostCause(unsigned char cause); 32 | 33 | unsigned _supla_int_t getUptime(); 34 | unsigned _supla_int_t getConnectionUptime(); 35 | unsigned char getLastResetCause(); 36 | 37 | protected: 38 | uint64_t lastMillis; 39 | unsigned _supla_int_t deviceUptime; 40 | unsigned _supla_int_t connectionUptime; 41 | unsigned char lastConnectionResetCause; 42 | bool acceptConnectionLostCause; 43 | }; 44 | 45 | }; // namespace Supla 46 | 47 | #endif // SRC_SUPLA_UPTIME_H_ 48 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/parser/simple.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_PARSER_SIMPLE_H_ 20 | #define EXTRAS_PORTING_LINUX_SUPLA_PARSER_SIMPLE_H_ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "parser.h" 29 | 30 | namespace Supla { 31 | 32 | namespace Parser { 33 | class Simple : public Parser { 34 | public: 35 | explicit Simple(Supla::Source::Source *); 36 | virtual ~Simple(); 37 | 38 | bool isBasedOnIndex() override; 39 | bool refreshSource() override; 40 | 41 | double getValue(const std::string &key) override; 42 | 43 | protected: 44 | std::map values; 45 | }; 46 | }; // namespace Parser 47 | }; // namespace Supla 48 | 49 | #endif // EXTRAS_PORTING_LINUX_SUPLA_PARSER_SIMPLE_H_ 50 | -------------------------------------------------------------------------------- /src/supla/control/dimmer_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CONTROL_DIMMER_BASE_H_ 20 | #define SRC_SUPLA_CONTROL_DIMMER_BASE_H_ 21 | 22 | #include "rgbw_base.h" 23 | 24 | namespace Supla { 25 | namespace Control { 26 | class DimmerBase : public RGBWBase { 27 | public: 28 | DimmerBase(); 29 | 30 | void setRGBW(int red, 31 | int green, 32 | int blue, 33 | int colorBrightness, 34 | int brightness, 35 | bool toggle = false); 36 | 37 | void onLoadState(); 38 | void onSaveState(); 39 | 40 | protected: 41 | virtual void iterateDimmerRGBW(int rgbStep, int wStep); 42 | }; 43 | 44 | }; // namespace Control 45 | }; // namespace Supla 46 | 47 | #endif // SRC_SUPLA_CONTROL_DIMMER_BASE_H_ 48 | -------------------------------------------------------------------------------- /src/supla/network/netif_wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_NETIF_WIFI_H_ 20 | #define SRC_SUPLA_NETWORK_NETIF_WIFI_H_ 21 | 22 | #include "network.h" 23 | 24 | #define MAX_SSID_SIZE 32 25 | #define MAX_WIFI_PASSWORD_SIZE 64 26 | 27 | namespace Supla { 28 | class Wifi : public Supla::Network { 29 | public: 30 | Wifi(const char *wifiSsid = nullptr, 31 | const char *wifiPassword = nullptr, 32 | unsigned char *ip = nullptr); 33 | 34 | void setSsid(const char *wifiSsid) override; 35 | void setPassword(const char *wifiPassword) override; 36 | bool isWifiConfigRequired() override; 37 | 38 | protected: 39 | char ssid[MAX_SSID_SIZE] = {}; 40 | char password[MAX_WIFI_PASSWORD_SIZE] = {}; 41 | }; 42 | 43 | }; // namespace Supla 44 | 45 | #endif // SRC_SUPLA_NETWORK_NETIF_WIFI_H_ 46 | -------------------------------------------------------------------------------- /extras/docker/arduino-cli/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | LABEL maintainer="Krzysztof Lewandowski " 3 | 4 | # Install required packages 5 | RUN apt update && \ 6 | DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt install -y tzdata && \ 7 | apt install -y git wget cmake gcc make libpcap-dev curl \ 8 | python3 python-is-python3 python3-serial 9 | 10 | # Setup workdir 11 | RUN mkdir supla 12 | WORKDIR /supla 13 | 14 | # Download and install FreeRTOS 15 | RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh 16 | ENV PATH="${PATH}:/supla/bin" 17 | ENV ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS="http://arduino.esp8266.com/stable/package_esp8266com_index.json https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" 18 | RUN arduino-cli core install arduino:avr && \ 19 | arduino-cli lib install Ethernet && \ 20 | arduino-cli core update-index && \ 21 | arduino-cli core install esp32:esp32 && \ 22 | arduino-cli core install esp8266:esp8266 && \ 23 | arduino-cli lib install DallasTemperature && \ 24 | arduino-cli lib install "DHT Sensor Library" && \ 25 | arduino-cli lib install PZEM004Tv30 && \ 26 | cd ~/Arduino/libraries && \ 27 | git clone https://github.com/olehs/PZEM004T 28 | 29 | # Download supla-device 30 | RUN git clone https://github.com/SUPLA/supla-device.git && \ 31 | ln -s /supla/supla-device ~/Arduino/libraries/supla-device 32 | WORKDIR /supla/supla-device/examples 33 | 34 | ENV SUPLA_DEVICE_PATH="/supla/supla-device/" 35 | ENV SUPLA_TOOLSET="arduino-cli" 36 | 37 | -------------------------------------------------------------------------------- /src/supla/control/bistable_roller_shutter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_CONTROL_BISTABLE_ROLLER_SHUTTER_H_ 18 | #define SRC_SUPLA_CONTROL_BISTABLE_ROLLER_SHUTTER_H_ 19 | 20 | #include "roller_shutter.h" 21 | 22 | namespace Supla { 23 | namespace Control { 24 | class BistableRollerShutter : public RollerShutter { 25 | public: 26 | BistableRollerShutter(int pinUp, int pinDown, bool highIsOn = true); 27 | 28 | void onTimer() override; 29 | 30 | protected: 31 | void stopMovement() override; 32 | void relayDownOn() override; 33 | void relayUpOn() override; 34 | void relayUpOff() override; 35 | void relayDownOff() override; 36 | 37 | bool activeBiRelay; 38 | uint64_t toggleTime; 39 | }; 40 | 41 | }; // namespace Control 42 | }; // namespace Supla 43 | 44 | 45 | 46 | #endif // SRC_SUPLA_CONTROL_BISTABLE_ROLLER_SHUTTER_H_ 47 | -------------------------------------------------------------------------------- /src/supla/control/light_relay.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CONTROL_LIGHT_RELAY_H_ 20 | #define SRC_SUPLA_CONTROL_LIGHT_RELAY_H_ 21 | 22 | #include "relay.h" 23 | 24 | namespace Supla { 25 | namespace Control { 26 | class LightRelay : public Relay { 27 | public: 28 | explicit LightRelay(int pin, bool highIsOn = true); 29 | void handleGetChannelState(TDSC_ChannelState *channelState); 30 | int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request); 31 | void onLoadState(); 32 | void onSaveState(); 33 | void turnOn(_supla_int_t duration = 0); 34 | void iterateAlways(); 35 | 36 | protected: 37 | uint16_t lifespan; 38 | _supla_int_t turnOnSecondsCumulative; 39 | uint64_t turnOnTimestamp; 40 | }; 41 | 42 | }; // namespace Control 43 | }; // namespace Supla 44 | 45 | #endif // SRC_SUPLA_CONTROL_LIGHT_RELAY_H_ 46 | -------------------------------------------------------------------------------- /src/supla/rsa_verificator.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_RSA_VERIFICATOR_H_ 18 | #define SRC_SUPLA_RSA_VERIFICATOR_H_ 19 | 20 | /* 21 | * Simple wrapper for Nettle RSA methods used to verify sha256 hash 22 | * against another hash signed with RSA private key. 23 | */ 24 | 25 | #define RSA_NUM_BYTES 512 26 | #define RSA_PUBLIC_EXPONENT 65537 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace Supla { 33 | 34 | class RsaVerificator { 35 | public: 36 | explicit RsaVerificator(const uint8_t* publicKeyBytes); 37 | ~RsaVerificator(); 38 | bool verify(Supla::Sha256 *hash, const uint8_t *signatureBytes); 39 | protected: 40 | struct rsa_public_key publicKey; 41 | mpz_t signature; 42 | }; 43 | 44 | }; // namespace Supla 45 | 46 | #endif // SRC_SUPLA_RSA_VERIFICATOR_H_ 47 | -------------------------------------------------------------------------------- /src/supla/sensor/therm_hygro_meter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "therm_hygro_meter.h" 18 | #include 19 | 20 | Supla::Sensor::ThermHygroMeter::ThermHygroMeter() { 21 | channel.setType(SUPLA_CHANNELTYPE_HUMIDITYANDTEMPSENSOR); 22 | channel.setDefault(SUPLA_CHANNELFNC_HUMIDITYANDTEMPERATURE); 23 | } 24 | 25 | void Supla::Sensor::ThermHygroMeter::onInit() { 26 | channel.setNewValue(getTemp(), getHumi()); 27 | } 28 | 29 | double Supla::Sensor::ThermHygroMeter::getTemp() { 30 | return TEMPERATURE_NOT_AVAILABLE; 31 | } 32 | 33 | double Supla::Sensor::ThermHygroMeter::getHumi() { 34 | return HUMIDITY_NOT_AVAILABLE; 35 | } 36 | 37 | void Supla::Sensor::ThermHygroMeter::iterateAlways() { 38 | if (millis() - lastReadTime > 10000) { 39 | lastReadTime = millis(); 40 | channel.setNewValue(getTemp(), getHumi()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/source/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_SOURCE_FILE_H_ 20 | #define EXTRAS_PORTING_LINUX_SUPLA_SOURCE_FILE_H_ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include "source.h" 28 | 29 | namespace Supla { 30 | 31 | namespace Source { 32 | class File : public Source { 33 | public: 34 | explicit File(const char *filePath, int expirationSec = 10 * 60); 35 | virtual ~File(); 36 | std::string getContent() override; 37 | 38 | void setExpirationTime(int timeSec); 39 | 40 | protected: 41 | std::filesystem::path filePath; 42 | int fileExpirationSec = 10 * 60; 43 | bool fileIsTooOldLog = false; 44 | }; 45 | }; // namespace Source 46 | }; // namespace Supla 47 | 48 | #endif // EXTRAS_PORTING_LINUX_SUPLA_SOURCE_FILE_H_ 49 | -------------------------------------------------------------------------------- /src/supla/control/rgbw_leds.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_CONTROL_RGBW_LEDS_H_ 20 | #define SRC_SUPLA_CONTROL_RGBW_LEDS_H_ 21 | 22 | #include "rgbw_base.h" 23 | 24 | namespace Supla { 25 | namespace Control { 26 | class RGBWLeds : public RGBWBase { 27 | public: 28 | RGBWLeds(int redPin, int greenPin, int bluePin, int brightnessPin); 29 | 30 | void setRGBWValueOnDevice(uint32_t red, 31 | uint32_t green, 32 | uint32_t blue, 33 | uint32_t colorBrightness, 34 | uint32_t brightness); 35 | 36 | void onInit(); 37 | 38 | protected: 39 | int redPin; 40 | int greenPin; 41 | int bluePin; 42 | int brightnessPin; 43 | }; 44 | 45 | }; // namespace Control 46 | }; // namespace Supla 47 | 48 | #endif // SRC_SUPLA_CONTROL_RGBW_LEDS_H_ 49 | -------------------------------------------------------------------------------- /src/supla/sensor/Si7021_sonoff.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_SI7021_SONOFF_H_ 20 | #define SRC_SUPLA_SENSOR_SI7021_SONOFF_H_ 21 | 22 | #include 23 | #include 24 | 25 | namespace Supla { 26 | namespace Sensor { 27 | class Si7021Sonoff : public ThermHygroMeter { 28 | public: 29 | explicit Si7021Sonoff(int pin); 30 | double getTemp(); 31 | double getHumi(); 32 | 33 | private: 34 | void iterateAlways(); 35 | void onInit(); 36 | double readTemp(uint8_t* data); 37 | double readHumi(uint8_t* data); 38 | void read(); 39 | bool waitState(bool state); 40 | 41 | protected: 42 | int8_t pin; 43 | double temperature; 44 | double humidity; 45 | int8_t retryCount; 46 | }; 47 | 48 | }; // namespace Sensor 49 | }; // namespace Supla 50 | 51 | #endif // SRC_SUPLA_SENSOR_SI7021_SONOFF_H_ 52 | -------------------------------------------------------------------------------- /src/nettle/rsa-verify.c: -------------------------------------------------------------------------------- 1 | /* rsa-verify.c 2 | 3 | Verifying RSA signatures. 4 | 5 | Copyright (C) 2001, 2003 Niels Möller 6 | 7 | This file is part of GNU Nettle. 8 | 9 | GNU Nettle is free software: you can redistribute it and/or 10 | modify it under the terms of either: 11 | 12 | * the GNU Lesser General Public License as published by the Free 13 | Software Foundation; either version 3 of the License, or (at your 14 | option) any later version. 15 | 16 | or 17 | 18 | * the GNU General Public License as published by the Free 19 | Software Foundation; either version 2 of the License, or (at your 20 | option) any later version. 21 | 22 | or both in parallel, as here. 23 | 24 | GNU Nettle is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | General Public License for more details. 28 | 29 | You should have received copies of the GNU General Public License and 30 | the GNU Lesser General Public License along with this program. If 31 | not, see http://www.gnu.org/licenses/. 32 | */ 33 | 34 | #include "nettle/bignum.h" 35 | #include "nettle/rsa.h" 36 | 37 | int _rsa_verify(const struct rsa_public_key *key, 38 | const mpz_t m, 39 | const mpz_t s) { 40 | int res; 41 | 42 | mpz_t m1; 43 | 44 | if ((mpz_sgn(s) <= 0) || (mpz_cmp(s, key->n) >= 0)) return 0; 45 | 46 | mpz_init(m1); 47 | 48 | mpz_powm(m1, s, key->e, key->n); 49 | 50 | res = !mpz_cmp(m, m1); 51 | 52 | mpz_clear(m1); 53 | 54 | return res; 55 | } 56 | -------------------------------------------------------------------------------- /extras/test/ConditionTests/on_between_eq_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TEST(OnBetweenEqTests, OnBetweenEqConditionTests) { 22 | auto cond = OnBetweenEq(20, 30); 23 | 24 | EXPECT_FALSE(cond->checkConditionFor(5)); 25 | EXPECT_FALSE(cond->checkConditionFor(15)); 26 | 27 | EXPECT_TRUE(cond->checkConditionFor(20)); 28 | EXPECT_FALSE(cond->checkConditionFor(20.001)); 29 | EXPECT_FALSE(cond->checkConditionFor(25)); 30 | 31 | EXPECT_FALSE(cond->checkConditionFor(5)); 32 | EXPECT_FALSE(cond->checkConditionFor(5)); 33 | EXPECT_FALSE(cond->checkConditionFor(5)); 34 | 35 | EXPECT_FALSE(cond->checkConditionFor(50)); 36 | EXPECT_TRUE(cond->checkConditionFor(30)); 37 | EXPECT_FALSE(cond->checkConditionFor(5)); 38 | 39 | EXPECT_TRUE(cond->checkConditionFor(24)); 40 | 41 | delete cond; 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/supla/sensor/virtual_therm_hygro_meter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_VIRTUAL_THERM_HYGRO_METER_H_ 20 | #define SRC_SUPLA_SENSOR_VIRTUAL_THERM_HYGRO_METER_H_ 21 | 22 | #include "therm_hygro_meter.h" 23 | 24 | namespace Supla { 25 | namespace Sensor { 26 | class VirtualThermHygroMeter : public Supla::Sensor::ThermHygroMeter { 27 | public: 28 | double getTemp() override { 29 | return temperature; 30 | } 31 | 32 | double getHumi() override { 33 | return humidity; 34 | } 35 | 36 | void setTemp(double val) { 37 | temperature = val; 38 | } 39 | 40 | void setHumi(double val) { 41 | humidity = val; 42 | } 43 | 44 | protected: 45 | double temperature = TEMPERATURE_NOT_AVAILABLE; 46 | double humidity = HUMIDITY_NOT_AVAILABLE; 47 | }; 48 | }; // namespace Sensor 49 | }; // namespace Supla 50 | 51 | #endif // SRC_SUPLA_SENSOR_VIRTUAL_THERM_HYGRO_METER_H_ 52 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/sensor/thermometer_parsed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_SENSOR_THERMOMETER_PARSED_H_ 20 | #define EXTRAS_PORTING_LINUX_SUPLA_SENSOR_THERMOMETER_PARSED_H_ 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "sensor_parsed.h" 28 | 29 | namespace Supla { 30 | namespace Parser { 31 | const char Temperature[] = "temperature"; 32 | }; 33 | 34 | namespace Sensor { 35 | 36 | class ThermometerParsed : public Thermometer, public SensorParsed { 37 | public: 38 | explicit ThermometerParsed(Supla::Parser::Parser *); 39 | double getValue() override; 40 | void onInit() override; 41 | 42 | protected: 43 | bool isDataErrorLogged = false; 44 | }; 45 | }; // namespace Sensor 46 | }; // namespace Supla 47 | 48 | #endif // EXTRAS_PORTING_LINUX_SUPLA_SENSOR_THERMOMETER_PARSED_H_ 49 | -------------------------------------------------------------------------------- /src/supla/sensor/binary.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "binary.h" 18 | 19 | #include 20 | 21 | #include "../io.h" 22 | 23 | Supla::Sensor::Binary::Binary(int pin, bool pullUp = false) 24 | : pin(pin), pullUp(pullUp), lastReadTime(0) { 25 | channel.setType(SUPLA_CHANNELTYPE_SENSORNO); 26 | } 27 | 28 | bool Supla::Sensor::Binary::getValue() { 29 | return Supla::Io::digitalRead(channel.getChannelNumber(), pin) == LOW ? false 30 | : true; 31 | } 32 | 33 | void Supla::Sensor::Binary::iterateAlways() { 34 | if (lastReadTime + 100 < millis()) { 35 | lastReadTime = millis(); 36 | channel.setNewValue(getValue()); 37 | } 38 | } 39 | 40 | void Supla::Sensor::Binary::onInit() { 41 | Supla::Io::pinMode( 42 | channel.getChannelNumber(), pin, pullUp ? INPUT_PULLUP : INPUT); 43 | channel.setNewValue(getValue()); 44 | } 45 | -------------------------------------------------------------------------------- /extras/test/ConditionTests/on_less_eq_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TEST(OnEqualEqTests, OnLessEqConditionTests) { 22 | auto cond = OnLessEq(10); 23 | 24 | EXPECT_TRUE(cond->checkConditionFor(5)); 25 | EXPECT_FALSE(cond->checkConditionFor(15)); 26 | 27 | EXPECT_TRUE(cond->checkConditionFor(10)); 28 | EXPECT_FALSE(cond->checkConditionFor(9.9999)); 29 | 30 | // "On" conditions should fire actions only on transition to meet condition. 31 | EXPECT_FALSE(cond->checkConditionFor(5)); 32 | EXPECT_FALSE(cond->checkConditionFor(5)); 33 | EXPECT_FALSE(cond->checkConditionFor(5)); 34 | 35 | // Going back above threshold value, should reset expectation and it should return 36 | // true on next call with met condition 37 | EXPECT_FALSE(cond->checkConditionFor(50)); 38 | EXPECT_TRUE(cond->checkConditionFor(5)); 39 | 40 | delete cond; 41 | } 42 | -------------------------------------------------------------------------------- /src/supla/sensor/general_purpose_measurement_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_GENERAL_PURPOSE_MEASUREMENT_BASE_H_ 20 | #define SRC_SUPLA_SENSOR_GENERAL_PURPOSE_MEASUREMENT_BASE_H_ 21 | 22 | #include "supla/channel_element.h" 23 | 24 | namespace Supla { 25 | namespace Sensor { 26 | class GeneralPurposeMeasurementBase : public ChannelElement { 27 | public: 28 | GeneralPurposeMeasurementBase() : lastReadTime(0) { 29 | channel.setType(SUPLA_CHANNELTYPE_GENERAL_PURPOSE_MEASUREMENT); 30 | } 31 | 32 | virtual double getValue() = 0; 33 | 34 | void iterateAlways() { 35 | if (lastReadTime + 1000 < millis()) { 36 | lastReadTime = millis(); 37 | channel.setNewValue(getValue()); 38 | } 39 | } 40 | 41 | protected: 42 | uint64_t lastReadTime; 43 | }; 44 | 45 | }; // namespace Sensor 46 | }; // namespace Supla 47 | 48 | #endif // SRC_SUPLA_SENSOR_GENERAL_PURPOSE_MEASUREMENT_BASE_H_ 49 | -------------------------------------------------------------------------------- /src/supla/sensor/wind.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_WIND_H_ 20 | #define SRC_SUPLA_SENSOR_WIND_H_ 21 | 22 | #include "supla/channel_element.h" 23 | 24 | #define WIND_NOT_AVAILABLE -1 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class Wind : public ChannelElement { 29 | public: 30 | Wind() { 31 | channel.setType(SUPLA_CHANNELTYPE_WINDSENSOR); 32 | channel.setDefault(SUPLA_CHANNELFNC_WINDSENSOR); 33 | channel.setNewValue(WIND_NOT_AVAILABLE); 34 | } 35 | 36 | virtual double getValue() { 37 | return WIND_NOT_AVAILABLE; 38 | } 39 | 40 | void iterateAlways() { 41 | if (lastReadTime + 10000 < millis()) { 42 | lastReadTime = millis(); 43 | channel.setNewValue(getValue()); 44 | } 45 | } 46 | 47 | protected: 48 | uint64_t lastReadTime = 0; 49 | }; 50 | 51 | }; // namespace Sensor 52 | }; // namespace Supla 53 | 54 | #endif // SRC_SUPLA_SENSOR_WIND_H_ 55 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/parser/json.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_PARSER_JSON_H_ 20 | #define EXTRAS_PORTING_LINUX_SUPLA_PARSER_JSON_H_ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "parser.h" 30 | 31 | namespace Supla { 32 | namespace Parser { 33 | class Json : public Parser { 34 | public: 35 | explicit Json(Supla::Source::Source *); 36 | virtual ~Json(); 37 | 38 | bool refreshSource() override; 39 | 40 | double getValue(const std::string &key) override; 41 | 42 | bool isBasedOnIndex() override; 43 | bool isValid() override; 44 | 45 | protected: 46 | bool valid = false; 47 | std::map keys; 48 | 49 | nlohmann::json json; 50 | }; 51 | }; // namespace Parser 52 | }; // namespace Supla 53 | #endif // EXTRAS_PORTING_LINUX_SUPLA_PARSER_JSON_H_ 54 | -------------------------------------------------------------------------------- /src/supla/clock/clock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_CLOCK_CLOCK_H_ 18 | #define SRC_SUPLA_CLOCK_CLOCK_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace Supla { 25 | 26 | class Clock : public Element { 27 | public: 28 | Clock(); 29 | virtual bool isReady(); 30 | virtual int getYear(); 31 | virtual int getMonth(); 32 | virtual int getDay(); 33 | virtual int getDayOfWeek(); // 1 - Sunday, 2 - Monday 34 | virtual int getHour(); 35 | virtual int getMin(); 36 | virtual int getSec(); 37 | 38 | void onTimer(); 39 | bool iterateConnected(void *srpc); 40 | 41 | virtual void parseLocaltimeFromServer(TSDC_UserLocalTimeResult *result); 42 | 43 | protected: 44 | time_t localtime; 45 | uint64_t lastServerUpdate; 46 | uint64_t lastMillis; 47 | bool isClockReady; 48 | }; 49 | 50 | }; // namespace Supla 51 | 52 | #endif // SRC_SUPLA_CLOCK_CLOCK_H_ 53 | -------------------------------------------------------------------------------- /src/supla/sensor/rain.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_RAIN_H_ 20 | #define SRC_SUPLA_SENSOR_RAIN_H_ 21 | 22 | #include "supla/channel_element.h" 23 | 24 | #define RAIN_NOT_AVAILABLE -1 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class Rain : public ChannelElement { 29 | public: 30 | Rain() : lastReadTime(0) { 31 | channel.setType(SUPLA_CHANNELTYPE_RAINSENSOR); 32 | channel.setDefault(SUPLA_CHANNELFNC_RAINSENSOR); 33 | channel.setNewValue(RAIN_NOT_AVAILABLE); 34 | } 35 | 36 | virtual double getValue() { 37 | return RAIN_NOT_AVAILABLE; 38 | } 39 | 40 | void iterateAlways() { 41 | if (lastReadTime + 10000 < millis()) { 42 | lastReadTime = millis(); 43 | channel.setNewValue(getValue()); 44 | } 45 | } 46 | 47 | protected: 48 | uint64_t lastReadTime; 49 | }; 50 | 51 | }; // namespace Sensor 52 | }; // namespace Supla 53 | 54 | #endif // SRC_SUPLA_SENSOR_RAIN_H_ 55 | -------------------------------------------------------------------------------- /src/supla/control/button.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef SRC_SUPLA_CONTROL_BUTTON_H_ 18 | #define SRC_SUPLA_CONTROL_BUTTON_H_ 19 | 20 | #include 21 | #include "simple_button.h" 22 | 23 | namespace Supla { 24 | namespace Control { 25 | 26 | class Button : public SimpleButton { 27 | public: 28 | explicit Button(int pin, bool pullUp = false, bool invertLogic = false); 29 | 30 | void onTimer(); 31 | void setHoldTime(unsigned int timeMs); 32 | void repeatOnHoldEvery(unsigned int timeMs); 33 | void setMulticlickTime(unsigned int timeMs, bool bistableButton = false); 34 | bool isBistable() const; 35 | 36 | protected: 37 | unsigned int holdTimeMs; 38 | unsigned int repeatOnHoldMs; 39 | unsigned int multiclickTimeMs; 40 | uint64_t lastStateChangeMs; 41 | uint8_t clickCounter; 42 | unsigned int holdSend; 43 | bool bistable; 44 | }; 45 | 46 | }; // namespace Control 47 | }; // namespace Supla 48 | 49 | #endif // SRC_SUPLA_CONTROL_BUTTON_H_ 50 | -------------------------------------------------------------------------------- /src/supla/control/pin_status_led.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #include "../io.h" 18 | #include "pin_status_led.h" 19 | 20 | Supla::Control::PinStatusLed::PinStatusLed(uint8_t srcPin, 21 | uint8_t outPin, 22 | bool invert) 23 | : srcPin(srcPin), outPin(outPin), invert(invert) { 24 | } 25 | 26 | void Supla::Control::PinStatusLed::onInit() { 27 | updatePin(); 28 | Supla::Io::pinMode(outPin, OUTPUT); 29 | } 30 | 31 | void Supla::Control::PinStatusLed::iterateAlways() { 32 | updatePin(); 33 | } 34 | 35 | void Supla::Control::PinStatusLed::setInvertedLogic(bool invertedLogic) { 36 | invert = invertedLogic; 37 | updatePin(); 38 | } 39 | 40 | void Supla::Control::PinStatusLed::updatePin() { 41 | int value = Supla::Io::digitalRead(srcPin); 42 | value = invert ? !value : value; 43 | if (value != Supla::Io::digitalRead(outPin)) { 44 | Supla::Io::digitalWrite(outPin, value); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/supla/sensor/pressure.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_PRESSURE_H_ 20 | #define SRC_SUPLA_SENSOR_PRESSURE_H_ 21 | 22 | #include "supla/channel_element.h" 23 | 24 | #define PRESSURE_NOT_AVAILABLE -1 25 | 26 | namespace Supla { 27 | namespace Sensor { 28 | class Pressure : public ChannelElement { 29 | public: 30 | Pressure() : lastReadTime(0) { 31 | channel.setType(SUPLA_CHANNELTYPE_PRESSURESENSOR); 32 | channel.setDefault(SUPLA_CHANNELFNC_PRESSURESENSOR); 33 | channel.setNewValue(PRESSURE_NOT_AVAILABLE); 34 | } 35 | 36 | virtual double getValue() { 37 | return PRESSURE_NOT_AVAILABLE; 38 | } 39 | 40 | void iterateAlways() { 41 | if (lastReadTime + 10000 < millis()) { 42 | lastReadTime = millis(); 43 | channel.setNewValue(getValue()); 44 | } 45 | } 46 | 47 | protected: 48 | uint64_t lastReadTime; 49 | }; 50 | 51 | }; // namespace Sensor 52 | }; // namespace Supla 53 | 54 | #endif // SRC_SUPLA_SENSOR_PRESSURE_H_ 55 | -------------------------------------------------------------------------------- /src/supla/sensor/weight.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_WEIGHT_H_ 20 | #define SRC_SUPLA_SENSOR_WEIGHT_H_ 21 | 22 | #include "supla/channel_element.h" 23 | #include "supla/element.h" 24 | 25 | #define WEIGHT_NOT_AVAILABLE -1 26 | 27 | namespace Supla { 28 | namespace Sensor { 29 | class Weight : public ChannelElement { 30 | public: 31 | Weight() { 32 | channel.setType(SUPLA_CHANNELTYPE_WEIGHTSENSOR); 33 | channel.setDefault(SUPLA_CHANNELFNC_WEIGHTSENSOR); 34 | channel.setNewValue(WEIGHT_NOT_AVAILABLE); 35 | } 36 | 37 | virtual double getValue() { 38 | return WEIGHT_NOT_AVAILABLE; 39 | } 40 | 41 | void iterateAlways() { 42 | if (lastReadTime + 10000 < millis()) { 43 | lastReadTime = millis(); 44 | channel.setNewValue(getValue()); 45 | } 46 | } 47 | 48 | protected: 49 | uint64_t lastReadTime = 0; 50 | }; 51 | 52 | }; // namespace Sensor 53 | }; // namespace Supla 54 | 55 | #endif // SRC_SUPLA_SENSOR_WEIGHT_H_ 56 | -------------------------------------------------------------------------------- /extras/test/doubles/element_mock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | */ 16 | 17 | #ifndef _supla_element_mock_h 18 | #define _supla_element_mock_h 19 | 20 | #include 21 | #include 22 | 23 | class ElementMock : public Supla::Element { 24 | public: 25 | MOCK_METHOD(void, onInit, (), (override)); 26 | MOCK_METHOD(void, onLoadState, (), (override)); 27 | MOCK_METHOD(void, onSaveState, (), (override)); 28 | MOCK_METHOD(void, onRegistered, (), (override)); 29 | MOCK_METHOD(void, iterateAlways, (), (override)); 30 | MOCK_METHOD(bool, iterateConnected, (void *), (override)); 31 | MOCK_METHOD(void, onTimer, (), (override)); 32 | MOCK_METHOD(void, onFastTimer, (), (override)); 33 | MOCK_METHOD(int, handleNewValueFromServer, (TSD_SuplaChannelNewValue *), (override)); 34 | MOCK_METHOD(void, handleGetChannelState, (TDSC_ChannelState *), (override)); 35 | MOCK_METHOD(int, handleCalcfgFromServer, (TSD_DeviceCalCfgRequest *), (override)); 36 | 37 | }; 38 | 39 | #endif /*_supla_element_mock_h*/ 40 | -------------------------------------------------------------------------------- /src/supla/device/sw_update.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_DEVICE_SW_UPDATE_H_ 20 | #define SRC_SUPLA_DEVICE_SW_UPDATE_H_ 21 | 22 | #define SUPLA_MAX_URL_LENGTH 202 23 | 24 | #include 25 | 26 | namespace Supla { 27 | namespace Device { 28 | class SwUpdate { 29 | public: 30 | static SwUpdate *Create(SuplaDeviceClass *sdc, const char *newUrl); 31 | virtual ~SwUpdate(); 32 | 33 | virtual void start(); 34 | virtual void iterate() = 0; 35 | 36 | void setUrl(const char *newUrl); 37 | virtual bool isStarted(); 38 | virtual bool isFinished() = 0; 39 | virtual bool isAborted() = 0; 40 | void useBeta(); 41 | 42 | protected: 43 | explicit SwUpdate(SuplaDeviceClass *sdc, const char *newUrl = nullptr); 44 | 45 | bool beta = false; 46 | bool started = false; 47 | SuplaDeviceClass *sdc = nullptr; 48 | 49 | char url[SUPLA_MAX_URL_LENGTH] = {}; 50 | }; 51 | }; // namespace Device 52 | }; // namespace Supla 53 | 54 | #endif // SRC_SUPLA_DEVICE_SW_UPDATE_H_ 55 | -------------------------------------------------------------------------------- /extras/porting/linux/linux_network.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_LINUX_NETWORK_H_ 20 | #define EXTRAS_PORTING_LINUX_LINUX_NETWORK_H_ 21 | 22 | #include 23 | #include 24 | 25 | namespace Supla { 26 | 27 | class LinuxNetwork : public Network { 28 | public: 29 | LinuxNetwork(); 30 | ~LinuxNetwork() override; 31 | 32 | int read(void *buf, int count) override; 33 | int write(void *buf, int count) override; 34 | int connect(const char *server, int port = -1) override; 35 | bool connected() override; 36 | void disconnect() override; 37 | bool isReady() override; 38 | void setup() override; 39 | bool iterate() override; 40 | void fillStateData(TDSC_ChannelState *channelState) override; 41 | 42 | protected: 43 | bool isDeviceReady = false; 44 | SSL_CTX *ctx = nullptr; 45 | SSL *ssl = nullptr; 46 | int connectionFd = -1; 47 | }; 48 | 49 | }; // namespace Supla 50 | 51 | #endif // EXTRAS_PORTING_LINUX_LINUX_NETWORK_H_ 52 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/sensor/impulse_counter_parsed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_SUPLA_SENSOR_IMPULSE_COUNTER_PARSED_H_ 20 | #define EXTRAS_PORTING_LINUX_SUPLA_SENSOR_IMPULSE_COUNTER_PARSED_H_ 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "sensor_parsed.h" 28 | 29 | namespace Supla { 30 | namespace Parser { 31 | const char Counter[] = "counter"; 32 | }; 33 | 34 | namespace Sensor { 35 | 36 | class ImpulseCounterParsed : public ChannelElement, public SensorParsed { 37 | public: 38 | explicit ImpulseCounterParsed(Supla::Parser::Parser *); 39 | 40 | virtual unsigned _supla_int64_t getValue(); 41 | void onInit() override; 42 | void iterateAlways() override; 43 | 44 | protected: 45 | uint64_t lastReadTime = 0; 46 | bool isDataErrorLogged = false; 47 | }; 48 | }; // namespace Sensor 49 | }; // namespace Supla 50 | 51 | #endif // EXTRAS_PORTING_LINUX_SUPLA_SENSOR_IMPULSE_COUNTER_PARSED_H_ 52 | -------------------------------------------------------------------------------- /extras/porting/linux/supla/sensor/thermometer_parsed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | 21 | #include "thermometer_parsed.h" 22 | 23 | Supla::Sensor::ThermometerParsed::ThermometerParsed( 24 | Supla::Parser::Parser *parser) 25 | : SensorParsed(parser) { 26 | } 27 | 28 | void Supla::Sensor::ThermometerParsed::onInit() { 29 | channel.setNewValue(getValue()); 30 | } 31 | 32 | double Supla::Sensor::ThermometerParsed::getValue() { 33 | double value = TEMPERATURE_NOT_AVAILABLE; 34 | 35 | if (isParameterConfigured(Supla::Parser::Temperature)) { 36 | if (refreshParserSource()) { 37 | value = getParameterValue(Supla::Parser::Temperature); 38 | } 39 | if (!parser->isValid()) { 40 | if (!isDataErrorLogged) { 41 | isDataErrorLogged = true; 42 | supla_log(LOG_WARNING, "ThermometerParsed: source data error"); 43 | } 44 | return TEMPERATURE_NOT_AVAILABLE; 45 | } 46 | isDataErrorLogged = false; 47 | } 48 | return value; 49 | } 50 | -------------------------------------------------------------------------------- /extras/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.11) 2 | 3 | project(supladevice) 4 | 5 | enable_testing() 6 | 7 | set(CMAKE_CXX_STANDARD 17) 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 9 | set(CMAKE_BUILD_TYPE Debug) 10 | set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) 11 | 12 | include_directories(../../src) 13 | include_directories(doubles) 14 | 15 | add_subdirectory(../../src/ build) 16 | 17 | mark_as_advanced( 18 | BUILD_GMOCK 19 | BUILD_GTEST 20 | ) 21 | 22 | include(FetchContent) 23 | 24 | FetchContent_Declare( 25 | googletest 26 | GIT_REPOSITORY https://github.com/google/googletest.git 27 | GIT_TAG origin/main 28 | ) 29 | 30 | FetchContent_GetProperties(googletest) 31 | if(NOT googletest_POPULATED) 32 | FetchContent_Populate(googletest) 33 | add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) 34 | endif() 35 | 36 | file(GLOB TEST_SRC 37 | UptimeTests/*.cpp 38 | ChannelTests/*cpp 39 | IoTests/*.cpp 40 | ElementTests/*.cpp 41 | LocalActionTests/*.cpp 42 | SensorTests/*.cpp 43 | ChannelElementTests/*.cpp 44 | InternalPinOutputTests/*.cpp 45 | PinStatusLedTests/*.cpp 46 | ConditionTests/*.cpp 47 | RgbwDimmerTests/*.cpp 48 | ButtonTests/*.cpp 49 | StorageTests/*.cpp 50 | SuplaDeviceTests/*.cpp 51 | CorrectionTests/*cpp 52 | ActionTriggerTests/*cpp 53 | ElectricityMeterTests/*cpp 54 | ToolsTests/*cpp 55 | ) 56 | 57 | file(GLOB DOUBLE_SRC doubles/*.cpp) 58 | 59 | add_executable(supladevicetests ${TEST_SRC} ${DOUBLE_SRC}) 60 | 61 | target_link_libraries(supladevicetests 62 | gmock 63 | gtest 64 | gtest_main 65 | supladevicelib 66 | ) 67 | 68 | add_test(NAME supladevicetests 69 | COMMAND supladevicetests) 70 | 71 | target_compile_options(supladevicelib PRIVATE -Werror -Wall -Wextra -DSUPLA_TEST) 72 | -------------------------------------------------------------------------------- /src/supla/network/html_element.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_NETWORK_HTML_ELEMENT_H_ 20 | #define SRC_SUPLA_NETWORK_HTML_ELEMENT_H_ 21 | 22 | namespace Supla { 23 | 24 | class WebSender; 25 | 26 | enum HtmlSection { 27 | HTML_SECTION_FORM, 28 | HTML_SECTION_DEVICE_INFO, 29 | HTML_SECTION_NETWORK, 30 | HTML_SECTION_PROTOCOL, 31 | HTML_SECTION_BETA_FORM 32 | }; 33 | 34 | class HtmlElement { 35 | public: 36 | static HtmlElement *begin(); 37 | static HtmlElement *last(); 38 | 39 | static const char *selected(bool isSelected); 40 | 41 | HtmlElement *next(); 42 | 43 | explicit HtmlElement(HtmlSection section = HTML_SECTION_FORM); 44 | virtual ~HtmlElement(); 45 | virtual void send(Supla::WebSender *sender) = 0; 46 | virtual bool handleResponse(const char *key, const char *value); 47 | HtmlSection section; 48 | 49 | protected: 50 | static HtmlElement *firstPtr; 51 | HtmlElement *nextPtr = nullptr; 52 | }; 53 | 54 | }; // namespace Supla 55 | 56 | #endif // SRC_SUPLA_NETWORK_HTML_ELEMENT_H_ 57 | -------------------------------------------------------------------------------- /src/supla-common/eh.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | #ifndef EH_H_ 19 | #define EH_H_ 20 | 21 | #if !defined(ESP8266) && !defined(__AVR__) && !defined(_WIN32) && \ 22 | !defined(ESP32) && !defined(ARDUINO) && !defined(SUPLA_DEVICE) 23 | #include 24 | #endif 25 | 26 | #if !defined(__AVR__) && !defined(_WIN32) 27 | #include 28 | #endif 29 | 30 | #ifdef __AVR__ 31 | #include "proto.h" 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | typedef struct { 39 | int nfds; 40 | 41 | #ifndef _WIN32 42 | 43 | #ifdef __linux__ 44 | int epoll_fd; 45 | int fd1; 46 | #else 47 | int fd1[2]; 48 | #endif 49 | 50 | int fd2; 51 | int fd3; 52 | 53 | struct timeval tv; 54 | 55 | #endif 56 | } TEventHandler; 57 | 58 | TEventHandler *eh_init(void); 59 | void eh_add_fd(TEventHandler *eh, int fd); 60 | void eh_raise_event(TEventHandler *eh); 61 | int eh_wait(TEventHandler *eh, int usec); 62 | void eh_free(TEventHandler *eh); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* EH_H_ */ 69 | -------------------------------------------------------------------------------- /src/supla/sensor/HC_SR04.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef SRC_SUPLA_SENSOR_HC_SR04_H_ 20 | #define SRC_SUPLA_SENSOR_HC_SR04_H_ 21 | 22 | #include "supla/channel.h" 23 | #include "supla/sensor/distance.h" 24 | 25 | #define DURATION_COUNT 2 26 | 27 | namespace Supla { 28 | namespace Sensor { 29 | class HC_SR04 : public Distance { 30 | public: 31 | HC_SR04(int8_t trigPin, 32 | int8_t echoPin, 33 | int16_t minIn = 0, 34 | int16_t maxIn = 500, 35 | int16_t minOut = 0, 36 | int16_t maxOut = 500); 37 | void onInit(); 38 | virtual double getValue(); 39 | void setMinMaxIn(int16_t minIn, int16_t maxIn); 40 | void setMinMaxOut(int16_t minOut, int16_t maxOut); 41 | 42 | protected: 43 | int8_t _trigPin; 44 | int8_t _echoPin; 45 | int16_t _minIn; 46 | int16_t _maxIn; 47 | int16_t _minOut; 48 | int16_t _maxOut; 49 | char failCount; 50 | uint64_t readouts[5]; 51 | int index; 52 | }; 53 | 54 | }; // namespace Sensor 55 | }; // namespace Supla 56 | 57 | #endif // SRC_SUPLA_SENSOR_HC_SR04_H_ 58 | -------------------------------------------------------------------------------- /extras/porting/linux/network_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_LINUX_NETWORK_CLIENT_H_ 20 | #define EXTRAS_PORTING_LINUX_NETWORK_CLIENT_H_ 21 | 22 | #include "IPAddress.h" 23 | 24 | namespace Supla { 25 | class NetworkClient { 26 | public: 27 | NetworkClient(); 28 | virtual ~NetworkClient(); 29 | 30 | virtual int connect(IPAddress ip, uint16_t port); 31 | virtual int connect(const char *host, uint16_t port); 32 | virtual std::size_t write(uint8_t); 33 | virtual std::size_t write(const uint8_t *buf, std::size_t size); 34 | virtual std::size_t print(const char *); 35 | virtual std::size_t println(const char *); 36 | virtual std::size_t println(); 37 | 38 | virtual int available(); 39 | virtual int read(); 40 | virtual int read(uint8_t *buf, std::size_t size); 41 | virtual int read(char *buf, std::size_t size); 42 | 43 | virtual void stop(); 44 | virtual uint8_t connected(); 45 | 46 | protected: 47 | int connectionFd = -1; 48 | }; 49 | }; // namespace Supla 50 | 51 | #endif // EXTRAS_PORTING_LINUX_NETWORK_CLIENT_H_ 52 | -------------------------------------------------------------------------------- /extras/porting/esp-idf/esp_idf_web_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #ifndef EXTRAS_PORTING_ESP_IDF_ESP_IDF_WEB_SERVER_H_ 20 | #define EXTRAS_PORTING_ESP_IDF_ESP_IDF_WEB_SERVER_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace Supla { 27 | 28 | class EspIdfSender : public Supla::WebSender { 29 | public: 30 | explicit EspIdfSender(httpd_req_t *req); 31 | ~EspIdfSender(); 32 | void send(const char *, int) override; 33 | 34 | protected: 35 | httpd_req_t *reqHandler; 36 | bool error = false; 37 | }; 38 | 39 | class EspIdfWebServer : public Supla::WebServer { 40 | public: 41 | explicit EspIdfWebServer(HtmlGenerator *generator = nullptr); 42 | virtual ~EspIdfWebServer(); 43 | void start() override; 44 | void stop() override; 45 | 46 | bool handlePost(httpd_req_t *req); 47 | 48 | bool dataSaved = false; 49 | 50 | protected: 51 | httpd_handle_t server = {}; 52 | }; 53 | 54 | }; // namespace Supla 55 | 56 | #endif // EXTRAS_PORTING_ESP_IDF_ESP_IDF_WEB_SERVER_H_ 57 | -------------------------------------------------------------------------------- /src/supla/control/tripple_button_roller_shutter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) AC SOFTWARE SP. Z O.O. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | /* 20 | * This class allows to control roller shutters with 3 buttons: up, down, stop 21 | */ 22 | 23 | #ifndef SRC_SUPLA_CONTROL_TRIPPLE_BUTTON_ROLLER_SHUTTER_H_ 24 | #define SRC_SUPLA_CONTROL_TRIPPLE_BUTTON_ROLLER_SHUTTER_H_ 25 | 26 | #include "bistable_roller_shutter.h" 27 | 28 | namespace Supla { 29 | namespace Control { 30 | class TrippleButtonRollerShutter : public BistableRollerShutter { 31 | public: 32 | TrippleButtonRollerShutter(int pinUp, 33 | int pinDown, 34 | int pinStop, 35 | bool highIsOn = true); 36 | virtual ~TrippleButtonRollerShutter(); 37 | 38 | protected: 39 | void stopMovement() override; 40 | void switchOffRelays() override; 41 | bool inMove() override; 42 | virtual void relayStopOn(); 43 | virtual void relayStopOff(); 44 | 45 | int pinStop = 0; 46 | }; 47 | 48 | }; // namespace Control 49 | }; // namespace Supla 50 | 51 | #endif // SRC_SUPLA_CONTROL_TRIPPLE_BUTTON_ROLLER_SHUTTER_H_ 52 | -------------------------------------------------------------------------------- /src/nettle/version.h: -------------------------------------------------------------------------------- 1 | /* version.h 2 | 3 | Information about library version. 4 | 5 | Copyright (C) 2015 Red Hat, Inc. 6 | Copyright (C) 2015 Niels Möller 7 | 8 | This file is part of GNU Nettle. 9 | 10 | GNU Nettle is free software: you can redistribute it and/or 11 | modify it under the terms of either: 12 | 13 | * the GNU Lesser General Public License as published by the Free 14 | Software Foundation; either version 3 of the License, or (at your 15 | option) any later version. 16 | 17 | or 18 | 19 | * the GNU General Public License as published by the Free 20 | Software Foundation; either version 2 of the License, or (at your 21 | option) any later version. 22 | 23 | or both in parallel, as here. 24 | 25 | GNU Nettle is distributed in the hope that it will be useful, 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 28 | General Public License for more details. 29 | 30 | You should have received copies of the GNU General Public License and 31 | the GNU Lesser General Public License along with this program. If 32 | not, see http://www.gnu.org/licenses/. 33 | */ 34 | 35 | #ifndef NETTLE_VERSION_H_INCLUDED 36 | #define NETTLE_VERSION_H_INCLUDED 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Individual version numbers in decimal */ 43 | #define NETTLE_VERSION_MAJOR 3 44 | #define NETTLE_VERSION_MINOR 3 45 | 46 | #define NETTLE_USE_MINI_GMP 1 47 | 48 | /* We need a preprocessor constant for GMP_NUMB_BITS, simply using 49 | sizeof(mp_limb_t) * CHAR_BIT is not good enough. */ 50 | #if NETTLE_USE_MINI_GMP 51 | # define GMP_NUMB_BITS (sizeof(unsigned long) * 8) 52 | #endif 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* NETTLE_VERSION_H_INCLUDED */ 59 | --------------------------------------------------------------------------------