#include #include #include #include #include #include #include #include #include #define SOCKETNAME "/tmp/monitord.socket" #define CMD_TRAFFIC_TOTAL 0 #define CMD_TRAFFIC_SPEEDS 1 #define CMD_TEMP_VESI 3 #define CMD_TEMP_ULKOILMA 4 int rpc_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; } /* Public functions */ int rpc_traffic_total() { int total, count; count = rpc_docommand(CMD_TRAFFIC_TOTAL, (char *) &total, sizeof(int)); if (count != sizeof(int)) return -1; return total; } void rpc_traffic_speeds(float *rx, float *tx) { char buf[sizeof(float) * 2]; int count; count = rpc_docommand(CMD_TRAFFIC_SPEEDS, buf, sizeof(buf)); if (count != sizeof(buf)) { *rx = *tx = -1.; return; } memcpy(rx, buf, sizeof(float)); memcpy(tx, buf + sizeof(float), sizeof(float)); } float rpc_temperature_vesi() { float temp = 85.; rpc_docommand(CMD_TEMP_VESI, (char *) &temp, sizeof(float)); return temp; } float rpc_temperature_ulkoilma() { float temp = 85.; rpc_docommand(CMD_TEMP_ULKOILMA, (char *) &temp, sizeof(float)); return temp; }