From 1e18522fe6045bdb0f083500b1eb2226190f32f8 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 3 Feb 2011 23:52:20 +0100 Subject: [PATCH] minor improvements --- Makefile | 5 ++++- src/fnctl.c | 2 +- src/fnpom.c | 27 ++++++++++++++++++--------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 3e32183..44524ff 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,15 @@ fnvum_fftw: fnvum_fftw.c libfn.c fnpom: fnpom.c libfn.c $(CC) $(LDFLAGS) fnpom.o libfn.o -o bin/fnpom -l json + +fnctl: libfn.c fnctl.c + $(CC) $(LDFLAGS) fnctl.o libfn.o -o bin/fnctl fnvum.c: $(CC) $(CFLAGS) src/fnvum.c -o fnvum.o fnpom.c: - $(CC) $(CFLAGS) src/fnpom.c -o fnpom.o + $(CC) $(CFLAGS) src/fnpom.c -o fnpom.o -g fnvum_fftw.c: $(CC) $(CFLAGS) src/fnvum_fftw.c -o fnvum_fftw.o -g diff --git a/src/fnctl.c b/src/fnctl.c index dbaa0fb..11e99c0 100644 --- a/src/fnctl.c +++ b/src/fnctl.c @@ -8,7 +8,7 @@ #include #include -#include "libfn.h" +#include "../lib/libfn.h" /* local commands (>= 0xA0) */ #define LOCAL_CMD_EEPROM 0xA0 diff --git a/src/fnpom.c b/src/fnpom.c index 3a9fd08..90ef894 100644 --- a/src/fnpom.c +++ b/src/fnpom.c @@ -44,6 +44,7 @@ char * http_get(char * response, size_t bytes, char * host, char * port, char * memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; /* both IPv4 & IPv6 */ hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; getaddrinfo(host, port, &hints, &res); @@ -59,7 +60,11 @@ char * http_get(char * response, size_t bytes, char * host, char * port, char * send(sd, request, strlen(request), 0); /* receive data */ - do { count = recv(sd, response, bytes, 0); } while (count > 0); + while (count = recv(sd, response, bytes, 0) > 0) + if (count < 0) { + perror("Error receiving data"); + exit(-1); + } /* close socket */ close(sd); @@ -127,20 +132,24 @@ int main(int argc, char * argv[]) { fd = open(device, O_RDWR | O_NOCTTY); if (fd < 0) { - perror(port); + perror(device); exit(-1); } oldtio = fn_init(fd); fn_sync(fd); - struct remote_msg_fade_rgb_t fn_cmd; - fn_cmd.step = 255; - fn_cmd.delay = 0; - fn_cmd.color = gradient; - fn_cmd.address = 255; - fn_cmd.cmd = REMOTE_CMD_FADE_RGB; + struct remote_msg_fade_rgb_t fn_cmd = { + 255, /* address */ + REMOTE_CMD_FADE_RGB, /* command */ + 255, /* step */ + 0, /* delay */ + gradient /* color */ + }; - fn_send(fd, &fn_cmd); + if (fn_send(fd, (struct remote_msg_t *) &fn_cmd) < 0) { + perror(device); + exit(-1); + } /* housekeeping */ json_tokener_free(json_tok); /* free json objects */