random ai stuff

This commit is contained in:
matst80
2025-11-21 18:12:55 +01:00
commit 60f5783a26
187 changed files with 25197 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
ATTRS{idVendor}=="1781", SUBSYSTEM=="usb", ACTION=="add", MODE="664", GROUP="plugdev", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}", ENV{ID_SERIAL_SHORT}="$attr{serial}", RUN+="@CMAKE_INSTALL_PREFIX@/share/telldus-core/helpers/udev.sh"
ENV{ID_VENDOR_ID}=="1781", SUBSYSTEM=="usb", ACTION=="remove", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}", ENV{ID_SERIAL_SHORT}="$attr{serial}", RUN+="@CMAKE_INSTALL_PREFIX@/share/telldus-core/helpers/udev.sh"

View File

@@ -0,0 +1,79 @@
PROJECT(tdadmin)
cmake_policy(SET CMP0005 NEW)
SET (tdadmin_DESCRIPTION
"a command line utility to edit devices and controllers for Telldus TellStick"
)
SET(tdadmin_SRCS
main.cpp
)
ADD_EXECUTABLE(tdadmin
${tdadmin_SRCS}
)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/driver
)
ADD_DEFINITIONS( -DVERSION="${DISPLAYED_VERSION}" )
IF (WIN32)
FIND_LIBRARY(TELLDUSCORE_LIBRARY TelldusCore)
TARGET_LINK_LIBRARIES(tdadmin
${TELLDUSCORE_LIBRARY}
)
ELSEIF (APPLE)
TARGET_LINK_LIBRARIES(tdadmin
TelldusCore
)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
# FreeBSD does not have argp in base libc; port devel/argp-standalone is required.
FIND_LIBRARY(ARGP_LIBRARY argp)
TARGET_LINK_LIBRARIES(tdadmin
${CMAKE_BINARY_DIR}/client/libtelldus-core.so
${ARGP_LIBRARY}
)
ELSE (WIN32)
TARGET_LINK_LIBRARIES(tdadmin
${CMAKE_BINARY_DIR}/client/libtelldus-core.so
)
ENDIF (WIN32)
IF (UNIX)
IF (GENERATE_MAN)
ADD_CUSTOM_COMMAND(
TARGET tdadmin
POST_BUILD
COMMAND help2man -n ${tdadmin_DESCRIPTION} ./tdadmin > tdadmin.1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating man file tdadmin.1"
)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/tdadmin.1 DESTINATION share/man/man1)
ENDIF (GENERATE_MAN)
ENDIF (UNIX)
INSTALL(TARGETS tdadmin RUNTIME DESTINATION sbin)
IF (UNIX AND NOT APPLE)
SET(UDEV_RULES_DIR "/etc/udev/rules.d" CACHE PATH "The directory where udev store its rules" )
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/05-tellstick.rules
${CMAKE_BINARY_DIR}/parsed/05-tellstick.rules
@ONLY
)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/udev.sh
${CMAKE_BINARY_DIR}/parsed/udev.sh
@ONLY
)
INSTALL(FILES ${CMAKE_BINARY_DIR}/parsed/05-tellstick.rules
DESTINATION ${UDEV_RULES_DIR}
)
INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/parsed/udev.sh
DESTINATION share/telldus-core/helpers/
)
ENDIF (UNIX AND NOT APPLE)

View File

@@ -0,0 +1,88 @@
#include "../client/telldus-core.h"
#include <stdlib.h>
#include <errno.h>
#include <argp.h>
#include <string>
const char *argp_program_version = "tdadmin " VERSION ;
const char *argp_program_bug_address = "<info.tech@telldus.com>";
static char args_doc[] = "COMMAND ACTION";
static char doc[] = "TellStick admin tool -- a command line utility to edit devices and controllers for Telldus TellStick";
const int VID = 1;
const int PID = 2;
const int SERIAL = 3;
static struct argp_option options[] = {
{0,0,0,0,
"COMMAND: controller, ACTION: connect/disconnect\n"
"Tells the daemon to add or remove a TellStick (duo)"
},
{"vid",VID,"VID",0, "The vendor id (1781)" },
{"pid",PID,"PID",0,"The product id (0c30 or 0c31)" },
{"serial",SERIAL,"SERIAL",0,"The usb serial number" },
{ 0 }
};
static std::string command, action;
int vid, pid;
static std::string serial;
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
switch (key) {
case PID:
pid = strtol(arg, NULL, 16);
break;
case SERIAL:
serial = arg;
break;
case VID:
vid = strtol(arg, NULL, 16);
break;
case ARGP_KEY_NO_ARGS:
argp_usage (state);
case ARGP_KEY_ARG:
if (state->next == state->argc) {
argp_usage (state);
}
command = arg;
action = state->argv[state->next];
state->next = state->argc;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = { options, parse_opt, args_doc, doc };
void handle_controller(void) {
if (vid == 0 || pid == 0) {
fprintf(stderr, "Missing parameter vid or pid\n");
}
if (action.compare("connect") == 0) {
tdConnectTellStickController(vid,pid,serial.c_str());
} else if (action.compare("disconnect") == 0) {
tdDisconnectTellStickController(vid,pid,serial.c_str());
}
}
int main(int argc, char **argv) {
argp_parse (&argp, argc, argv, 0, 0, 0);
if (command.compare("controller") == 0) {
handle_controller();
}
return 0;
}

9
telldus-core/tdadmin/udev.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
if [ "${ID_VENDOR_ID}" = "1781" ]; then
if [ "${ACTION}" = "add" ]; then
@CMAKE_INSTALL_PREFIX@/sbin/tdadmin controller connect --pid=${ID_MODEL_ID} --vid=${ID_VENDOR_ID} --serial=${ID_SERIAL_SHORT}
elif [ "${ACTION}" = "remove" ]; then
@CMAKE_INSTALL_PREFIX@/sbin/tdadmin controller disconnect --pid=${ID_MODEL_ID} --vid=${ID_VENDOR_ID} --serial=${ID_SERIAL_SHORT}
fi
fi