Initial commit

This commit is contained in:
jpk 2017-08-27 18:09:01 +02:00
parent 7d6a8fecbe
commit f88c046ca7
3 changed files with 44 additions and 25 deletions

23
lw12.c
View File

@ -10,10 +10,6 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
//#include <netdb.h>
#include "lw12.h"
@ -45,22 +41,3 @@ int lw12_sendcmd(int sockfd, struct sockaddr_in *addr, char *cmd) {
return 0;
}
int main() {
int sockfd = 0;
struct sockaddr_in server_addr;
char serverip[] = "192.168.178.24";
uint16_t serverport = 5000;
lw12_connect(&sockfd, &server_addr, serverport, serverip);
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_ON);
usleep(2000000);
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_OFF);
close(sockfd);
return 0;
}

13
lw12.h
View File

@ -8,12 +8,21 @@
#ifndef LW12_H
#define LW12_H
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define LW12_CMD_LENGTH 9
#define LIGHTS_ON "\x7e\x04\x04\x01\xff\xff\xff\x00\xef"
#define LIGHTS_OFF "\x7e\x04\x04\x00\x00\x0f\xff\x00\xef"
#define LIGHTS_INIT "\x7e\x07\x05\x03\xff\xbf\x40\x00\xef"
#define LIGHTS_OFF "\x7e\x04\x04\x00\x00\x0f\x00\x00\xef"
// set lights "7e070503{red:02x}{green:02x}{blue:02x}00ef"
#define LIGHT_COLOR "\x7\xe\x07\x05\x03\x00\x00\x00\x00\xef"
#define LIGHT_COLOR "\x7e\x07\x05\x03\x00\x00\x00\x00\xef"
int lw12_connect(int *sockfd, struct sockaddr_in *addr, uint16_t port,
char *hostname);
int lw12_sendcmd(int sockfd, struct sockaddr_in *addr, char *cmd);
#endif /* !LW12_H */

33
lw12ctl.c Normal file
View File

@ -0,0 +1,33 @@
/*
* lw12ctl.c
* Copyright (C) 2017 jpk <jpk@thor>
*
* Distributed under terms of the MIT license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include "lw12.h"
int main() {
int sockfd = 0;
struct sockaddr_in server_addr;
char serverip[] = "192.168.178.24";
uint16_t serverport = 5000;
lw12_connect(&sockfd, &server_addr, serverport, serverip);
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_ON);
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_INIT);
usleep(2000000);
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_OFF);
close(sockfd);
return 0;
}