@@ -23,6 +23,7 @@ struct laurent_options {
2323 const char * server ;
2424 const char * password ;
2525 unsigned int relay ;
26+ int usb_relay ;
2627};
2728
2829struct laurent {
@@ -42,6 +43,7 @@ void *laurent_parse_options(struct device_parser *dp)
4243
4344 options = calloc (1 , sizeof (* options ));
4445 options -> password = DEFAULT_PASSWORD ;
46+ options -> usb_relay = -1 ;
4547
4648 device_parser_accept (dp , YAML_MAPPING_START_EVENT , NULL , 0 );
4749 while (device_parser_accept (dp , YAML_SCALAR_EVENT , key , TOKEN_LENGTH )) {
@@ -54,6 +56,8 @@ void *laurent_parse_options(struct device_parser *dp)
5456 options -> password = strdup (value );
5557 else if (!strcmp (key , "relay" ))
5658 options -> relay = strtoul (value , NULL , 0 );
59+ else if (!strcmp (key , "usb_relay" ))
60+ options -> usb_relay = strtoul (value , NULL , 0 );
5761 else
5862 errx (1 , "%s: unknown option \"%s\"" , __func__ , key );
5963 }
@@ -124,7 +128,7 @@ static void *laurent_open(struct device *dev)
124128 return laurent ;
125129}
126130
127- static int laurent_power (struct device * dev , bool on )
131+ static int laurent_control (struct device * dev , unsigned int relay , bool on )
128132{
129133 struct laurent * laurent = dev -> cdb ;
130134 char buf [BUFSIZ ];
@@ -145,7 +149,7 @@ static int laurent_power(struct device *dev, bool on)
145149
146150 len = snprintf (buf , sizeof (buf ), "GET /cmd.cgi?psw=%s&cmd=REL,%u,%d HTTP/1.0\r\n\r\n" ,
147151 laurent -> options -> password ,
148- laurent -> options -> relay ,
152+ relay ,
149153 on );
150154 if (len < 0 ) {
151155 warn ("asprintf failed\n" );
@@ -190,8 +194,30 @@ static int laurent_power(struct device *dev, bool on)
190194 return -1 ;
191195}
192196
197+ static int laurent_power (struct device * dev , bool on )
198+ {
199+ struct laurent * laurent = dev -> cdb ;
200+
201+ return laurent_control (dev ,
202+ laurent -> options -> relay ,
203+ on );
204+ }
205+
206+ static void laurent_usb (struct device * dev , bool on )
207+ {
208+ struct laurent * laurent = dev -> cdb ;
209+
210+ if (laurent -> options -> usb_relay < 0 )
211+ return ;
212+
213+ laurent_control (dev ,
214+ laurent -> options -> usb_relay ,
215+ on );
216+ }
217+
193218const struct control_ops laurent_ops = {
194219 .parse_options = laurent_parse_options ,
195220 .open = laurent_open ,
196221 .power = laurent_power ,
222+ .usb = laurent_usb ,
197223};
0 commit comments