50 static int verbose_flag;
52 static struct option long_options[] = {
54 {
"verbose", no_argument, &verbose_flag, 1 },
55 {
"brief", no_argument, &verbose_flag, 0 },
58 {
"cct", required_argument, 0,
'c' },
59 {
"rgbw", required_argument, 0,
'r' },
60 {
"level", required_argument, 0,
'l' },
61 {
"name", required_argument, 0,
'n' },
62 {
"host", required_argument, 0,
'h' },
63 {
"port", required_argument, 0,
'p' },
64 {
"on", required_argument, 0,
'0' },
65 {
"off", required_argument, 0,
'1' },
66 {
"time", required_argument, 0,
't' },
67 {
"list-nodes", no_argument, 0,
'd' },
68 {
"wait", required_argument, 0,
'w' },
69 {
"list-groups", no_argument, 0, 2},
70 {
"group", required_argument, 0,
'g' },
105 printf(
"Usage: %s [OPTIONS] \n", argv[0]);
106 printf(
" --host,-h <host> Hostname or IP\n");
107 printf(
" [--verbose] Verbose mode\n");
108 printf(
" [--list-nodes,-d] Dump info about lamps\n");
109 printf(
" [--list-groups] Show all known groups\n");
110 printf(
" [--wait,-w <value>] Wait for value/10 seconds\n");
111 printf(
" [--time,-t <value>] Set fading time in 1/10 seconds\n");
112 printf(
" [--name,-n <value>] Name of the lamp to be manipulated\n");
113 printf(
" [--group,-g <value>] Name of the lamp to be manipulated\n");
114 printf(
" [--port,-p <port>] Port, default 4000\n");
115 printf(
" [--on,-0] Turn lamp on\n");
116 printf(
" [--off,-1] Turn lamp off\n");
117 printf(
" [--level,-l <value>] Set intensity level. Range 0 to 100\n");
118 printf(
" [--cct,-c <value>] CCT to be set.\n");
119 printf(
" [--rgbw,-r <value>] Set color. Give color as r,g,b,w. Color values from 0 to 255\n");
120 printf(
"\n Host must be given before any command. Commands on and off can broadcast to all lamps if name is not given before.\n");
124 if (!name)
return NULL;
131 fprintf(stderr,
"ERROR: Node %s not found\n", name);
136 if (!name)
return NULL;
143 fprintf(stderr,
"ERROR: Group %s not found\n", name);
153 command_on = command_on > 0 ? 1 : 0;
155 type =
"Broadcast"; name =
"";
168 printf(
"%s %s switch %s\n", type, name , command_on ?
"on" :
"off");
210 printf(
"%s %s rgbw %d,%d,%d,%d in time %d\n", type, name,
command_r_r,
238 struct sockaddr_in serv_addr;
239 struct hostent *server;
241 sockfd = socket(AF_INET, SOCK_STREAM, 0);
244 perror(
"ERROR opening socket");
249 if (server == NULL) {
250 fprintf(stderr,
"ERROR, no such host\n");
254 bzero((
char *) &serv_addr,
sizeof(serv_addr));
255 serv_addr.sin_family = AF_INET;
256 bcopy((
char *) server->h_addr, (
char *)&serv_addr.sin_addr.s_addr, server->h_length);
257 serv_addr.sin_port = htons(
port);
260 if (connect(
sockfd, (
struct sockaddr*) &serv_addr,
sizeof(serv_addr)) < 0) {
261 perror(
"ERROR connecting");
267 fprintf(stderr,
"Could not set fd\n");
277 "Error during node scan -- lets see if we've got partial data\n");
284 "Error during group scan -- lets see if we've got partial group data\n");
319 if (state < 0)
return "err";
334 printf(
"|------------------|------------------|---------|--------|---------|-----|-----|------|-----|-----|-----|-----|---|\n");
335 printf(
"| Name | MAC | type | group | online | 0/1 | dim | CCT | Red | Grn | Blu | Wht | s |\n");
336 printf(
"|------------------|------------------|---------|--------|---------|-----|-----|------|-----|-----|-----|-----|---|\n");
357 printf(
"no nodes found\n");
359 printf(
"|------------------|------------------|---------|--------|---------|-----|-----|------|-----|-----|-----|-----|---|\n");
365 printf(
"|------------------|----|--------|----------------\n");
366 printf(
"| Group Name | id | mask | Group members\n");
367 printf(
"|------------------|----|--------|----------------\n");
374 printf(
"|------------------|----|--------|----------------\n");
379 int main(
int argc,
char *argv[]) {
380 int option_index = 0;
389 fprintf(stderr,
"Cannot allocate library context\n");
395 c = getopt_long(argc, argv,
"dc:r:l:n:h:p:01t:w:g:", long_options,
458 port = strtol(optarg, NULL, 10);
462 fadetime = strtol(optarg, NULL, 10);
476 int tme = strtol(optarg, NULL, 10);
478 ts.tv_sec = tme / 10;
479 ts.tv_nsec = (tme % 10 ) * 100 * 1000 * 1000;
481 if (0 == nanosleep(&ts,&ts))
break;
482 if (errno != EINTR)
break;
LIGHTIFY_EXPORT int lightify_node_request_rgbw(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int r, unsigned int g, unsigned int b, unsigned int w, unsigned int fadetime)
void command_set_lvl(struct lightify_ctx *ctx)
int main(int argc, char *argv[])
int lightify_skt_setfd(struct lightify_ctx *ctx, int socket)
struct lightify_node * find_node_per_name(struct lightify_ctx *ctx, const char *name)
LIGHTIFY_EXPORT int lightify_node_request_scan(struct lightify_ctx *ctx)
const char * lightify_node_get_name(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff)
LIGHTIFY_EXPORT int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff)
int lightify_node_get_brightness(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_group_request_scan(struct lightify_ctx *ctx)
uint64_t lightify_node_get_nodeadr(struct lightify_node *node)
int lightify_node_is_stale(struct lightify_node *node)
LIGHTIFY_EXPORT struct lightify_group * lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current)
void command_set_rgbw(struct lightify_ctx *ctx)
LIGHTIFY_EXPORT int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime)
int lightify_node_is_on(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_group_get_id(struct lightify_group *grp)
struct lightify_group * find_grp_per_name(struct lightify_ctx *ctx, const char *name)
LIGHTIFY_EXPORT struct lightify_node * lightify_node_get_next(struct lightify_ctx *ctx, struct lightify_node *node)
struct lightify_ctx * ctx
LIGHTIFY_EXPORT int lightify_group_request_brightness(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int level, unsigned int fadetime)
uint16_t lightify_node_get_grpadr(struct lightify_node *node)
void dump_groups(struct lightify_ctx *ctx)
int lightify_node_get_red(struct lightify_node *node)
LIGHTIFY_EXPORT struct lightify_node * lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode)
void command_set_0_1(struct lightify_ctx *ctx, int command_on)
int lightify_node_get_cct(struct lightify_node *node)
const char * decode_lamptype(int type)
LIGHTIFY_EXPORT int lightify_node_request_brightness(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int level, unsigned int fadetime)
int lightify_node_get_white(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_new(struct lightify_ctx **ctx, void *reserved)
const char * decode_online_state(int state)
void command_set_cct(struct lightify_ctx *ctx)
void setup_connection(struct lightify_ctx *ctx)
enum lightify_node_type lightify_node_get_lamptype(struct lightify_node *node)
int lightify_node_get_onlinestate(struct lightify_node *node)
int lightify_node_get_green(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_node_request_cct(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int cct, unsigned int fadetime)
int lightify_node_get_blue(struct lightify_node *node)
void dump_nodes_state(struct lightify_ctx *ctx)
struct lightify_ctx * ctx
LIGHTIFY_EXPORT const char * lightify_group_get_name(struct lightify_group *grp)
LIGHTIFY_EXPORT int lightify_group_request_rgbw(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int r, unsigned int g, unsigned int b, unsigned int w, unsigned int fadetime)
const char * decode_onoff_sate(int state)