[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18462 - in libmwmodem: . src/main src/tests
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18462 - in libmwmodem: . src/main src/tests |
Date: |
Tue, 6 Dec 2011 15:21:20 +0100 |
Author: ruppa
Date: 2011-12-06 15:21:20 +0100 (Tue, 06 Dec 2011)
New Revision: 18462
Modified:
libmwmodem/configure.ac
libmwmodem/src/main/libmwmodem.c
libmwmodem/src/tests/libmwmodem_test.c
Log:
Modified: libmwmodem/configure.ac
===================================================================
--- libmwmodem/configure.ac 2011-12-06 14:19:35 UTC (rev 18461)
+++ libmwmodem/configure.ac 2011-12-06 14:21:20 UTC (rev 18462)
@@ -1,5 +1,5 @@
AC_PREREQ(2.57)
-AC_INIT([libmwmodem], [0.0.1], address@hidden)
+AC_INIT([libmwmodem], [0.0.1], address@hidden)
AM_INIT_AUTOMAKE([libmwmodem], [0.0.1])
AC_CONFIG_SRCDIR([src/main/libmwmodem.c])
AC_CONFIG_HEADERS([config.h])
Modified: libmwmodem/src/main/libmwmodem.c
===================================================================
--- libmwmodem/src/main/libmwmodem.c 2011-12-06 14:19:35 UTC (rev 18461)
+++ libmwmodem/src/main/libmwmodem.c 2011-12-06 14:21:20 UTC (rev 18462)
@@ -34,13 +34,11 @@
*/
struct MWMODEM_Context{
int socket;
- int af_int;
- MWMODEM_InformationCallback cb;
+ int af_int;
+ MWMODEM_InformationCallback cb;
void *cls;
};
-// TESTCASE!???
-
struct MWMODEM_Context * MWMODEM_init (uint16_t port, int af_int,
MWMODEM_InformationCallback cb, void *cb_cls)
{
struct MWMODEM_Context *context;
@@ -51,18 +49,20 @@
if ( (af_int!=AF_INET) && (af_int!=AF_INET6) )
{
- fprintf(stderr,
- "Error: expected af_int to be AF_INET or AF_INET6!\n");
+ fprintf(stderr,
+ "Error: expected af_int to be AF_INET or
AF_INET6!\n");
return NULL;
}
context = malloc(sizeof(struct MWMODEM_Context));
+
if(NULL == context)
{
fprintf(stderr,
"Error: failed to malloc space for structure
MWMODEM_Context: %s\n", strerror(errno));
return NULL;
}
+
context->cb = cb;
context->af_int = af_int;
context->socket = socket(af_int, SOCK_DGRAM, IPPROTO_UDP);
@@ -189,86 +189,89 @@
}
{
- char buffer[package_length];
+ char buffer[package_length];
- if (fc->af_int == AF_INET)
- {
- from_length = sizeof (fromv4);
- from = (struct sockaddr *) &fromv4;
- }
- else /* AF_INET6 */
- {
- from_length = sizeof (fromv6);
- from = (struct sockaddr *) &fromv6;
- }
- if (-1==(rret = recvfrom(fc->socket, buffer, sizeof(buffer), 0, from,
&from_length)))
- {
- fprintf(stderr, "Error: no message received!");
- return;
- }
- if (rret != package_length)
- {
- fprintf (stderr, "Received packet of unexpected size!\n");
- return; /* good luck */
- }
+ if (fc->af_int == AF_INET)
+ {
+ from_length = sizeof (fromv4);
+ from = (struct sockaddr *) &fromv4;
+ }
+ else /* AF_INET6 */
+ {
+ from_length = sizeof (fromv6);
+ from = (struct sockaddr *) &fromv6;
+ }
- hdr = (struct MWHeader*) buffer;
+ if (-1==(rret = recvfrom(fc->socket, buffer, sizeof(buffer), 0,
from, &from_length)))
+ {
+ fprintf(stderr, "Error: no message received!");
+ return;
+ }
- if (1!=1)//TODO deklination der Erkennungsmerkmale der Message
- {
- fprintf(stderr, "Error: no MWModem compatible message received!");
- return;
- }
- else
- {
- package.header = ntohl(hdr->header);
- unsigned long long nstime = ntohl(hdr->time) *
MWMODWM_TACT_NANO_SEC;
- package.time.tv_nsec = nstime % (1000 * 1000 * 1000);
- package.time.tv_sec = nstime / (1000 * 1000 * 1000);
- package.symbolrate = ntohl(hdr->symbolrate);
- package.num_channels = (uint8_t) hdr->channelmax;
+ if (rret != package_length)
+ {
+ fprintf (stderr, "Received packet of unexpected
size!\n");
+ return; /* good luck */
+ }
- struct MWMODEM_Channel list2[package.num_channels];
- list = list2;
+ hdr = (struct MWHeader*) buffer;
- unsigned int i, currentBufferZelle;
- currentBufferZelle = 13;
- for(i=0;i<=package.num_channels; i++)
+ if (1!=1)//TODO deklination der Erkennungsmerkmale der Message
{
- ptr = &buffer[currentBufferZelle];
+ fprintf(stderr, "Error: no MWModem compatible message
received!");
+ return;
+ }
+ else
+ {
+ package.header = ntohl(hdr->header);
+ unsigned long long nstime = ntohl(hdr->time) *
MWMODWM_TACT_NANO_SEC;
+ package.time.tv_nsec = nstime % (1000 * 1000 * 1000);
+ package.time.tv_sec = nstime / (1000 * 1000 * 1000);
+ package.symbolrate = ntohl(hdr->symbolrate);
+ package.num_channels = (uint8_t) hdr->channelmax;
- chl = (struct MWChannel *) ptr; // later: bus errors on
SPARC architectures
+ struct MWMODEM_Channel list2[package.num_channels];
+ list = list2;
- if(buffer[currentBufferZelle]==i)
+ unsigned int i, currentBufferZelle;
+ currentBufferZelle = 13;
+ for(i=0;i<=package.num_channels; i++)
{
+ ptr = &buffer[currentBufferZelle];
- if(buffer[currentBufferZelle]>MWMODEM_MOD_DUMMY
-
&&buffer[currentBufferZelle]<MWMODEM_MOD_RESERVED)
+ chl = (struct MWChannel *) ptr; // later: bus
errors on SPARC architectures
+
+ if(buffer[currentBufferZelle]==i)
{
- channel.modcode = (uint8_t) chl->modcod;
- }
- else
- {
- fprintf(stderr, "Error no correct
satellite modcode!");
- return;
- }
- channel.queue = (uint8_t) chl->queue;
+
if(buffer[currentBufferZelle]>MWMODEM_MOD_DUMMY
+
&&buffer[currentBufferZelle]<MWMODEM_MOD_RESERVED)
+ {
+ channel.modcode = (uint8_t)
chl->modcod;
+ }
+ else
+ {
+ fprintf(stderr, "Error no
correct satellite modcode!");
+ return;
+ }
- channel.datasent = ntohl(chl->datasent);
+ channel.queue = (uint8_t) chl->queue;
- channel.symbolratelimit =
ntohl(chl->symbolratelimit);
+ channel.datasent = ntohl(chl->datasent);
- list[i] = channel;
+ channel.symbolratelimit =
ntohl(chl->symbolratelimit);
- currentBufferZelle+=11;
+ list[i] = channel;
+
+ currentBufferZelle+=11;
+ }
}
}
- }
package.channel = list;
fc->cb(fc->cls, &package);
+
}
}
Modified: libmwmodem/src/tests/libmwmodem_test.c
===================================================================
--- libmwmodem/src/tests/libmwmodem_test.c 2011-12-06 14:19:35 UTC (rev
18461)
+++ libmwmodem/src/tests/libmwmodem_test.c 2011-12-06 14:21:20 UTC (rev
18462)
@@ -21,17 +21,34 @@
#include <string.h>
#include <netinet/in.h>
#include <stdio.h>
+#include <malloc.h>
-int testinit(struct MWMODEM_Context *context1, struct MWMODEM_Context
*context2, int port)
+void MWMODEM_InformationCallback(void *cls,
+ const struct MWMODEM_Package
*package)
{
+
+}
+
+int testinit(struct MWMODEM_Context *context, int port)
+{
+ void (*cb)(NULL, const struct MWMODEM_Package);
+ *cb = MWMODEM_InformationCallback;
+ if (-1==port)
+ {
+ context = MWMODEM_init(0, AF_INET, cb, NULL);
+ }
+ else
+ {
+
+ }
return -1;
}
-int testgetsocket(struct MWMODEM_Context *context1, struct MWMODEM_Context
*context2, int *socket1, int *socket2)
+int testgetsocket(struct MWMODEM_Context *context, int *socket)
{
- *socket1 = MWMODEM_get_select_socket(context1);
- *socket2 = MWMODEM_get_select_socket(context2);
- if (-1==*socket1 || -1==*socket2)
+ *socket = MWMODEM_get_select_socket(context);
+
+ if (-1==*socket)
{
printf("Error: failure of Test from
MWMODEM_get_select_socket!");
return -1;
@@ -43,41 +60,47 @@
}
}
-void generatedata(int *socket1, int *socket2)
+void generatedata(int socket)
{
}
-int testrun(struct MWMODEM_Context *context1, struct MWMODEM_Context
*context2, int *socket1, int *socket2)
+int testrun(struct MWMODEM_Context *context, int socket)
{
- generatedata(socket1, socket2);
- MWMODEM_run(context1);
- MWMODEM_run(context2);
+ generatedata(socket);
+ MWMODEM_run(context);
return 0;
}
-int testfree(struct MWMODEM_Context *context1, struct MWMODEM_Context
*context2)
+int testfree(struct MWMODEM_Context *context)
{
- MWMODEM_free (context1);
- MWMODEM_free (context2);
+ MWMODEM_free (context);
return 0;
}
int main(void)
{
- struct MWMODEM_Context context1, context2;
- int socket1, socket2;
- int port=5;
+ struct MWMODEM_Context *context;
+ int socket;
+ context = malloc(sizeof(context));
- if (-1 == testinit(&context1, &context2, port)) return -1;
+ if (-1 == testinit(context, -1)) return -1;
- if (-1 == testgetsocket(&context1, &context2, &socket1, &socket2))
return -1;
+ if (-1 == testgetsocket(context, &socket)) return -1;
- if (-1 == testrun(&context1, &context2, &socket1, &socket2)) return -1;
+ if (-1 == testrun(context, socket)) return -1;
- if (-1 == testfree(&context1, &context2)) return -1;
+ if (-1 == testfree(context)) return -1;
+ if (-1 == testinit(context, 5)) return -1;
+
+ if (-1 == testgetsocket(context, &socket)) return -1;
+
+ if (-1 == testrun(context, socket)) return -1;
+
+ if (-1 == testfree(context)) return -1;
+
return 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18462 - in libmwmodem: . src/main src/tests,
gnunet <=