#include #include #include #include #include #include #include #include #include #define SOCKETNAME "/tmp/monitord.socket" int docommand(int command, char *buf, int buflen) { int socketfd, count; struct sockaddr_un servaddr; socketfd = socket(AF_UNIX, SOCK_STREAM, 0); if (socketfd < 0) { perror("socket_open"); return -1; } memset(&servaddr, 0, sizeof(servaddr)); servaddr.sun_family = AF_UNIX; strncpy(servaddr.sun_path, SOCKETNAME, 108); if (connect(socketfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) { perror("socket_connect"); return -1; } send(socketfd, &command, sizeof(int), 0); count = recv(socketfd, buf, buflen, MSG_WAITALL); close(socketfd); return count; } int gettotal() { int total, count; count = docommand(0, (char *) &total, sizeof(int)); if (count != sizeof(int)) return -1; return total; } void getspeeds(float *rx, float *tx) { char buf[sizeof(float) * 2]; int count; count = docommand(1, buf, sizeof(buf)); if (count != sizeof(buf)) { *rx = *tx = -1.; return; } memcpy(rx, buf, sizeof(float)); memcpy(tx, buf + sizeof(float), sizeof(float)); } float gettemp1() { float temp = 85.; docommand(3, (char *) &temp, sizeof(float)); return temp; } float gettemp2() { float temp = 85.; docommand(4, (char *) &temp, sizeof(float)); return temp; } int main() { float rx, tx; printf("Total is %d\n", gettotal()); getspeeds(&rx, &tx); printf("Speeds are RX %0.2f TX %0.2f\n", rx, tx); printf("Temperatures are vesi %0.2f, ilma %0.2f\n", gettemp1(), gettemp2()); return 0; }