changeset 93:8c7f537d0a21

edited Scope.h with ifdefs to be compatible with udpio plugin
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 21 Jul 2015 21:18:45 +0100
parents a55dcdcebdcd
children 2fe6690fcab7
files include/Scope.h resources/network/udp-server.c
diffstat 2 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/include/Scope.h	Tue Jul 21 17:17:37 2015 +0100
+++ b/include/Scope.h	Tue Jul 21 21:18:45 2015 +0100
@@ -4,7 +4,7 @@
 #include <cmath>
 #include <UdpClient.h>
 
-#define NETWORK_AUDIO_BUFFER_SIZE 2048 
+#define NETWORK_AUDIO_BUFFER_SIZE 400
 struct networkAudio{
 	int timestamp;
 	int currentBuffer;
@@ -32,12 +32,17 @@
         
         for(int n=0; n<numChannels; n++){
             channel[n].doneOnTime=1;
-            channel[n].index=2;
+            channel[n].index=2; //leave space for the heading message (channel, timestamp)
             channel[n].timestamp=0;
             channel[n].currentBuffer=0;
             channel[n].toBeSent=false;
+#ifdef BUILD_FOR_UDPRECEIVE_PLUGIN
+            channel[n].udpClient.setPort(9999+n);
+            channel[n].udpClient.setServer("192.168.7.1");
+#else
             channel[n].udpClient.setPort(9999);
             channel[n].udpClient.setServer("127.0.0.1");
+#endif /* BUILD_FOR_UDPRECEIVE_PLUGIN */
     	}
     }
     void setup(float _sampleRate);
@@ -83,7 +88,10 @@
     for(int n=0; n<gOscilloscopeInstance->numChannels; n++){
 		if(gOscilloscopeInstance->channel[n].toBeSent){
 			gOscilloscopeInstance->channel[n].toBeSent=false;
-			gOscilloscopeInstance->channel[n].udpClient.send(gOscilloscopeInstance->channel[n].buffers[!gOscilloscopeInstance->channel[n].currentBuffer],NETWORK_AUDIO_BUFFER_SIZE*sizeof(float));
+			gOscilloscopeInstance->channel[n].udpClient.send(
+				gOscilloscopeInstance->channel[n].buffers[!gOscilloscopeInstance->channel[n].currentBuffer],
+				NETWORK_AUDIO_BUFFER_SIZE*sizeof(float)
+			);
 			gOscilloscopeInstance->channel[n].doneOnTime=1;
 		}
 	}
--- a/resources/network/udp-server.c	Tue Jul 21 17:17:37 2015 +0100
+++ b/resources/network/udp-server.c	Tue Jul 21 21:18:45 2015 +0100
@@ -23,8 +23,11 @@
    socklen_t fromlen;
    struct sockaddr_in server;
    struct sockaddr_in from;
-   char buf[1024];
-
+   float buf[2048];
+   int i=0;
+   for(i=0; i<2048; i++){
+     buf[i]=0;
+   }
    if (argc < 2) {
       fprintf(stderr, "ERROR, no port provided\n");
       exit(0);
@@ -41,10 +44,11 @@
        error("binding");
    fromlen = sizeof(struct sockaddr_in);
    while (1) {
-       n = recvfrom(sock,buf,1024,0,(struct sockaddr *)&from,&fromlen);
+       n = recvfrom(sock,buf,2048,0,(struct sockaddr *)&from,&fromlen);
        if (n < 0) error("recvfrom");
-       write(1,"Received a datagram: ",21);
-       write(1,buf,n);
+       printf("Received a datagram of size %d: \n", n);
+       for(i=0; i<n/sizeof(float); i+=8)
+	       printf("[%05d]: %+f, %+f, %+f, %+f, %+f, %+f, %+f, %+f\n",i,buf[0+i],buf[1+i],buf[2+i],buf[3+i],buf[4+i],buf[5+i],buf[6+i],buf[7+i]);
        n = sendto(sock,"Got your message\n",17,
                   0,(struct sockaddr *)&from,fromlen);
        if (n  < 0) error("sendto");