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' },
71 {
"update", no_argument, 0,
'u' },
106 printf(
"Usage: %s [OPTIONS] \n", argv[0]);
107 printf(
" --host,-h <host> Hostname or IP\n");
108 printf(
" [--verbose] Verbose mode\n");
109 printf(
" [--list-nodes,-d] Dump info about lamps\n");
110 printf(
" [--list-groups] Show all known groups\n");
111 printf(
" [--wait,-w <value>] Wait for value/10 seconds\n");
112 printf(
" [--time,-t <value>] Set fading time in 1/10 seconds\n");
113 printf(
" [--name,-n <value>] Name of the lamp to be manipulated\n");
114 printf(
" [--group,-g <value>] Name of the lamp to be manipulated\n");
115 printf(
" [--port,-p <port>] Port, default 4000\n");
116 printf(
" [--on,-0] Turn lamp on\n");
117 printf(
" [--off,-1] Turn lamp off\n");
118 printf(
" [--level,-l <value>] Set intensity level. Range 0 to 100\n");
119 printf(
" [--cct,-c <value>] CCT to be set.\n");
120 printf(
" [--rgbw,-r <value>] Set color. Give color as r,g,b,w. Color values from 0 to 255\n");
121 printf(
" [--update,-u] Refresh a node's information (requires name set before)\n");
122 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");
123 printf(
"\n All other commands needs either a name or group set before.\n");
127 if (!
name)
return NULL;
134 fprintf(stderr,
"ERROR: Node %s not found\n",
name);
139 if (!
name)
return NULL;
146 fprintf(stderr,
"ERROR: Group %s not found\n",
name);
155 command_on = command_on > 0 ? 1 : 0;
157 type =
"Broadcast";
name =
"";
170 printf(
"%s %s switch %s\n", type,
name , command_on ?
"on" :
"off");
243 printf(
"update_node ret=%d\n", ret);
249 struct sockaddr_in serv_addr;
250 struct hostent *server;
252 sockfd = socket(AF_INET, SOCK_STREAM, 0);
255 perror(
"ERROR opening socket");
260 if (server == NULL) {
261 fprintf(stderr,
"ERROR, no such host\n");
265 bzero((
char *) &serv_addr,
sizeof(serv_addr));
266 serv_addr.sin_family = AF_INET;
267 bcopy((
char *) server->h_addr, (
char *)&serv_addr.sin_addr.s_addr, server->h_length);
268 serv_addr.sin_port = htons(
port);
271 if (connect(
sockfd, (
struct sockaddr*) &serv_addr,
sizeof(serv_addr)) < 0) {
272 perror(
"ERROR connecting");
278 fprintf(stderr,
"Could not set fd\n");
288 "Error during node scan -- lets see if we've got partial data\n");
295 "Error during group scan -- lets see if we've got partial group data\n");
331 if (state < 0)
return "err";
346 printf(
"|------------------|------------------|---------|--------|---------|-----|-----|------|-----|-----|-----|-----|---|\n");
347 printf(
"| Name | MAC | type | group | online | 0/1 | dim | CCT | Red | Grn | Blu | Wht | s |\n");
348 printf(
"|------------------|------------------|---------|--------|---------|-----|-----|------|-----|-----|-----|-----|---|\n");
369 printf(
"no nodes found\n");
371 printf(
"|------------------|------------------|---------|--------|---------|-----|-----|------|-----|-----|-----|-----|---|\n");
377 printf(
"|------------------|----|--------|----------------\n");
378 printf(
"| Group Name | id | mask | Group members\n");
379 printf(
"|------------------|----|--------|----------------\n");
386 printf(
"|------------------|----|--------|----------------\n");
391 int main(
int argc,
char *argv[]) {
392 int option_index = 0;
401 fprintf(stderr,
"Cannot allocate library context\n");
407 c = getopt_long(argc, argv,
"dc:r:l:n:h:p:01t:w:g:u", long_options,
470 port = strtol(optarg, NULL, 10);
474 fadetime = strtol(optarg, NULL, 10);
488 int tme = strtol(optarg, NULL, 10);
490 ts.tv_sec = tme / 10;
491 ts.tv_nsec = (tme % 10 ) * 100 * 1000 * 1000;
493 if (0 == nanosleep(&ts,&ts))
break;
494 if (errno != EINTR)
break;
LIGHTIFY_EXPORT int lightify_new(struct lightify_ctx **ctx, void *reserved)
LIGHTIFY_EXPORT const char * lightify_group_get_name(struct lightify_group *grp)
LIGHTIFY_EXPORT int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime)
LIGHTIFY_EXPORT int lightify_group_get_id(struct lightify_group *grp)
LIGHTIFY_EXPORT struct lightify_group * lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current)
LIGHTIFY_EXPORT int lightify_group_request_brightness(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int level, unsigned int fadetime)
LIGHTIFY_EXPORT int lightify_group_request_scan(struct lightify_ctx *ctx)
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)
LIGHTIFY_EXPORT int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff)
LIGHTIFY_EXPORT struct lightify_node * lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode)
int lightify_skt_setfd(struct lightify_ctx *ctx, int socket)
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)
enum lightify_node_type lightify_node_get_lamptype(struct lightify_node *node)
int lightify_node_get_cct(struct lightify_node *node)
int lightify_node_get_red(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_node_request_brightness(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int level, unsigned int fadetime)
uint16_t lightify_node_get_grpadr(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff)
int lightify_node_get_green(struct lightify_node *node)
int lightify_node_is_on(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)
LIGHTIFY_EXPORT struct lightify_node * lightify_node_get_next(struct lightify_ctx *ctx, struct lightify_node *node)
int lightify_node_get_onlinestate(struct lightify_node *node)
int lightify_node_is_stale(struct lightify_node *node)
uint64_t lightify_node_get_nodeadr(struct lightify_node *node)
int lightify_node_get_blue(struct lightify_node *node)
const char * lightify_node_get_name(struct lightify_node *node)
int lightify_node_get_white(struct lightify_node *node)
LIGHTIFY_EXPORT int lightify_node_request_scan(struct lightify_ctx *ctx)
LIGHTIFY_EXPORT int lightify_node_request_update(struct lightify_ctx *ctx, struct lightify_node *node)
int lightify_node_get_brightness(struct lightify_node *node)
@ LIGHTIFY_EXT_COLOUR_LIGHT
struct lightify_node * find_node_per_name(struct lightify_ctx *ctx, const char *name)
int main(int argc, char *argv[])
const char * decode_lamptype(int type)
void command_update_node(struct lightify_ctx *ctx)
void command_set_cct(struct lightify_ctx *ctx)
const char * decode_online_state(int state)
void dump_groups(struct lightify_ctx *ctx)
void command_set_lvl(struct lightify_ctx *ctx)
const char * decode_onoff_sate(int state)
void command_set_rgbw(struct lightify_ctx *ctx)
void command_set_0_1(struct lightify_ctx *ctx, int command_on)
void setup_connection(struct lightify_ctx *ctx)
struct lightify_group * find_grp_per_name(struct lightify_ctx *ctx, const char *name)
void dump_nodes_state(struct lightify_ctx *ctx)
struct lightify_ctx * ctx
struct lightify_ctx * ctx