telldus-core: Add new package.

Signed-off-by: Peter Liedholm <PeterFromSwe884@gmail.com>
This commit is contained in:
Peter Liedholm
2019-01-19 17:04:14 +01:00
parent 2a4d79be0d
commit 03f255c9f0
8 changed files with 220 additions and 0 deletions
@@ -0,0 +1,21 @@
Added missing includes required by openwrt. Expected to be portable.
--- a/common/Socket_unix.cpp
+++ b/common/Socket_unix.cpp
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
+#include <sys/select.h> // POSIX.1-2001
#include <sys/un.h>
#include <fcntl.h>
#include <math.h>
--- a/service/ConnectionListener_unix.cpp
+++ b/service/ConnectionListener_unix.cpp
@@ -13,6 +13,7 @@
#include <fcntl.h>
#include <errno.h>
#include <string>
+#include <cstring> // strcpy
#include "service/ConnectionListener.h"
#include "common/Socket.h"
@@ -0,0 +1,23 @@
Added a typecast (signed/unsigned char problem). Should be portable.
--- a/service/ProtocolIkea.cpp
+++ b/service/ProtocolIkea.cpp
@@ -23,7 +23,7 @@ int ProtocolIkea::methods() const {
std::string ProtocolIkea::getStringForMethod(int method, unsigned char level, Controller *) {
const char B1[] = {84, 84, 0};
- const char B0[] = {170, 0};
+ const char B0[] = {(char)170, 0};
int intSystem = this->getIntParameter(L"system", 1, 16)-1;
int intFadeStyle = TelldusCore::comparei(this->getStringParameter(L"fade", L"true"), L"true");
--- a/service/ProtocolX10.cpp
+++ b/service/ProtocolX10.cpp
@@ -22,7 +22,7 @@ int ProtocolX10::methods() const {
std::string ProtocolX10::getStringForMethod(int method, unsigned char data, Controller *controller) {
const unsigned char S = 59, L = 169;
const char B0[] = {S, S, 0};
- const char B1[] = {S, L, 0};
+ const char B1[] = {S, (char)L, 0};
const unsigned char START_CODE[] = {'S', 255, 1, 255, 1, 255, 1, 100, 255, 1, 180, 0};
const unsigned char STOP_CODE[] = {S, 0};
@@ -0,0 +1,11 @@
Added a missing initialisation that under special circumstanses causes seg fault.
--- a/service/SettingsConfuse.cpp
+++ b/service/SettingsConfuse.cpp
@@ -435,6 +435,7 @@ bool readVarConfig(cfg_t **cfg) {
FILE *fp = fopen(VAR_CONFIG_FILE, "re"); // e for setting O_CLOEXEC on the file handle
if (!fp) {
+ (*cfg) = 0;
Log::warning("Unable to open var config file, %s", VAR_CONFIG_FILE);
return false;
}
@@ -0,0 +1,45 @@
Adopted to OpenWrt target. Most likely these changes go elsewhere when done right.
--- a/service/CMakeLists.txt
+++ b/service/CMakeLists.txt
@@ -98,7 +98,7 @@ IF (UNIX AND NOT APPLE)
IF (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
SET(DEFAULT_STATE_INSTALL_DIR "/var/spool")
ELSE ()
- SET(DEFAULT_STATE_INSTALL_DIR "/var/state")
+ SET(DEFAULT_STATE_INSTALL_DIR "/tmp/state") # OpenWrt has var as symlink to tmp
ENDIF ()
SET(STATE_INSTALL_DIR "${DEFAULT_STATE_INSTALL_DIR}" CACHE PATH "The directory to store state information of the devices")
--- a/tdadmin/CMakeLists.txt
+++ b/tdadmin/CMakeLists.txt
@@ -38,8 +38,11 @@ ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeB
${ARGP_LIBRARY}
)
ELSE (WIN32)
+ # Linux, in this case openwrt that requires argp-standalone
+ FIND_LIBRARY(ARGP_LIBRARY argp)
TARGET_LINK_LIBRARIES(tdadmin
${CMAKE_BINARY_DIR}/client/libtelldus-core.so
+ ${ARGP_LIBRARY}
)
ENDIF (WIN32)
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -66,12 +66,16 @@ ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeB
)
ELSE (APPLE)
#### Linux ####
+ #FIND_LIBRARY(ICONV_LIBRARY iconv) Does not work
ADD_DEFINITIONS( -D_LINUX )
LIST(APPEND telldus-common_SRCS
Event_unix.cpp
EventHandler_unix.cpp
Socket_unix.cpp
)
+ LIST(APPEND telldus-common_LIBRARIES
+ ${ICONV_LIBRARY}
+ )
ENDIF (APPLE)
@@ -0,0 +1,18 @@
On OpenWrt targets the tmp filesystem is wiped upon power cycle, so files
requires to be created.
--- a/service/SettingsConfuse.cpp
+++ b/service/SettingsConfuse.cpp
@@ -436,6 +436,13 @@ bool readVarConfig(cfg_t **cfg) {
FILE *fp = fopen(VAR_CONFIG_FILE, "re"); // e for setting O_CLOEXEC on the file handle
if (!fp) {
(*cfg) = 0;
+ fp = fopen(VAR_CONFIG_FILE, "we"); // If missing, create file if possible
+ if(fp) {
+ fclose(fp);
+ }
+ else {
+ Log::warning("Unable to create var config file, %s", VAR_CONFIG_FILE);
+ }
Log::warning("Unable to open var config file, %s", VAR_CONFIG_FILE);
return false;
}