--- /dev/null
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+
+ int main(int argc, char* argv[])
+ {
+
+ int server_id;
+ struct sockaddr_in server_address;
+ int connection_id;
+ char * message;
+ int messageSize;
+
+ if (argc != 2) {
+
+ printf("Expecting one argument\n");
+ exit(EXIT_FAILURE);
+ }
+
+ server_id = socket(AF_INET, SOCK_STREAM, 0);
+
+ server_address.sin_family = AF_INET;
+ server_address.sin_addr.s_addr = htonl(INADDR_ANY);
+ server_address.sin_port = htons(atoi(argv[1]));
+
+ printf("Binding socket... "); fflush(stdout);
+ bind(server_id, (struct sockaddr *) &server_address, sizeof(server_address));
+ printf("[OK]\n");
+
+ printf("Listening socket... "); fflush(stdout);
+ listen(server_id, 1);
+ printf("[OK]\n");
+
+ printf("Waiting for connection..."); fflush(stdout);
+ connection_id = accept(server_id, (struct sockaddr*) NULL, NULL);
+ printf("[OK]\n");
+
+ message = (char *) malloc(sizeof(char) * 1024 * 10);
+
+ while( (messageSize = recv(connection_id, message, 1024 * 10, 0)) > 0) {
+
+ message[messageSize] = 0x00;
+
+ printf("Received (%u): %s\n",messageSize,message);
+
+ }
+
+ printf("messageSize = %d\n",messageSize);
+
+ }
\ No newline at end of file
}
+ obj->fp = (FILE *) NULL;
+
+ obj->smessage = (char *) malloc(sizeof(char) * (1024 + 1024 * msg_pots_config->nPots));
+
obj->in = (msg_pots_obj *) NULL;
return obj;
void snk_pots_destroy(snk_pots_obj * obj) {
+ free((void *) obj->smessage);
+
format_destroy(obj->format);
interface_destroy(obj->interface);
break;
case interface_socket:
+
+ obj->sclient.sin_family = AF_INET;
+ obj->sclient.sin_port = htons(obj->interface->port);
+ obj->sid = socket(AF_INET, SOCK_STREAM, 0);
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ if ( (connect(obj->sid, (struct sockaddr *) &(obj->sclient), sizeof(obj->sclient))) < 0 ) {
+
+ printf("Cannot connect to server\n");
+ exit(EXIT_FAILURE);
+
+ }
break;
case interface_socket:
- printf("Not implemented yet.\n");
- exit(EXIT_FAILURE);
+ close(obj->sid);
break;
int snk_pots_process_socket(snk_pots_obj * obj) {
- printf("Not implemented\n");
- exit(EXIT_FAILURE);
+ int rtnValue;
+ unsigned int iPot;
+
+ if (obj->in->timeStamp != 0) {
+
+ switch(obj->format->type) {
+
+ case format_float:
+
+ obj->smessage[0] = 0x00;
+
+ sprintf(obj->smessage,"%s{\n",obj->smessage);
+ sprintf(obj->smessage,"%s \"timeStamp\": %llu,\n",obj->smessage,obj->in->timeStamp);
+ sprintf(obj->smessage,"%s \"src\": [\n",obj->smessage);
+
+ for (iPot = 0; iPot < obj->nPots; iPot++) {
+
+ sprintf(obj->smessage,"%s { x = %+1.3f, y = %+1.3f, z = %+1.3f, E = %+1.3f }", obj->smessage,
+ obj->in->pots->array[iPot*4+0], obj->in->pots->array[iPot*4+1], obj->in->pots->array[iPot*4+2], obj->in->pots->array[iPot*4+3]);
+
+ if (iPot != (obj->nPots - 1)) {
+
+ sprintf(obj->smessage,"%s,",obj->smessage);
+
+ }
+
+ sprintf(obj->smessage,"%s\n",obj->smessage);
+
+ }
+
+ sprintf(obj->smessage,"%s ]\n",obj->smessage);
+ sprintf(obj->smessage,"%s}\n",obj->smessage);
+
+ if (send(obj->sid, obj->smessage, strlen(obj->smessage), 0) < 0) {
+ printf("Could not send message.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ rtnValue = 0;
+
+ break;
+
+ }
+
+ }
+ else {
+
+ rtnValue = -1;
+
+ }
+
+ return rtnValue;
}