[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18752 - in libmwmodem/src: main tests
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18752 - in libmwmodem/src: main tests |
Date: |
Wed, 21 Dec 2011 18:45:32 +0100 |
Author: ruppa
Date: 2011-12-21 18:45:31 +0100 (Wed, 21 Dec 2011)
New Revision: 18752
Modified:
libmwmodem/src/main/libmwmodem.c
libmwmodem/src/tests/libmwmodem_test_ipv4.c
Log:
Modified: libmwmodem/src/main/libmwmodem.c
===================================================================
--- libmwmodem/src/main/libmwmodem.c 2011-12-21 16:39:45 UTC (rev 18751)
+++ libmwmodem/src/main/libmwmodem.c 2011-12-21 17:45:31 UTC (rev 18752)
@@ -216,9 +216,9 @@
hdr = (struct MWHeader*) buffer;
- if (1!=1)//TODO deklination der Erkennungsmerkmale der Message
+ if (hdr->header!=0x6a726f00)//TODO deklination der
Erkennungsmerkmale der Message
{
- fprintf(stderr, "Error: no MWModem compatible message
received!");
+ fprintf(stderr, "Error: no MWModem compatible message
received!\n");
return;
}
else
@@ -232,26 +232,26 @@
struct MWMODEM_Channel list2[package.num_channels];
list = list2;
-
+printf("%u\n", hdr->channelmax);
unsigned int i, currentBufferZelle;
- currentBufferZelle = 13;
- for(i=0;i<=package.num_channels; i++)
+ currentBufferZelle = 14;
+ for(i=0;i<package.num_channels; i++)
{
ptr = &buffer[currentBufferZelle];
chl = (struct MWChannel *) ptr; // later: bus
errors on SPARC architectures
- if(buffer[currentBufferZelle]==i)
+ if(chl->index==i)
{
-
if(buffer[currentBufferZelle]>MWMODEM_MOD_DUMMY
-
&&buffer[currentBufferZelle]<MWMODEM_MOD_RESERVED)
+ if(chl->modcod>MWMODEM_MOD_DUMMY
+ &&
chl->modcod<MWMODEM_MOD_RESERVED)
{
channel.modcode = (uint8_t)
chl->modcod;
}
else
{
- fprintf(stderr, "Error no
correct satellite modcode!");
+ fprintf(stderr, "Error no
correct satellite modcode!\n");
return;
}
Modified: libmwmodem/src/tests/libmwmodem_test_ipv4.c
===================================================================
--- libmwmodem/src/tests/libmwmodem_test_ipv4.c 2011-12-21 16:39:45 UTC (rev
18751)
+++ libmwmodem/src/tests/libmwmodem_test_ipv4.c 2011-12-21 17:45:31 UTC (rev
18752)
@@ -25,34 +25,37 @@
#include <malloc.h>
#include <stdint.h>
#include <errno.h>
+#include <malloc.h>
#define MW_MAGIC_NUMBER 0x6a726f00
static int global_ret;
-static void Callback(void *cls, const struct MWMODEM_Package *package)
+static void callback(void *cls, const struct MWMODEM_Package *package)
{
- if (package->header != MW_MAGIC_NUMBER)
+ if (package->header != MW_MAGIC_NUMBER)
{
- fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->Header!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->Header!\n");
global_ret = 2;
return;
}
if ((package->time.tv_nsec!=(1*MWMODEM_TACT_NANO_SEC)% (1000 * 1000 *
1000))&&
(package->time.tv_sec!=(1*MWMODEM_TACT_NANO_SEC)/ (1000 * 1000 * 1000)))
{
- printf("Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->time!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->time!\n");
global_ret = 3;
return;
}
if (package->symbolrate!=100)
{
- printf("Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->symbolrate!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->symbolrate!\n");
+ global_ret = 4;
return;
}
if (package->num_channels!=1)
{
- printf("Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->num_channels!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->num_channels!\n");
+ global_ret = 5;
return;
}
@@ -60,22 +63,26 @@
if (channel->modcode != 1)
{
- printf("Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->modcode!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->modcode!\n");
+ global_ret = 6;
return;
}
if (channel->queue != 10)
{
- printf("Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->queue!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->queue!\n");
+ global_ret = 7;
return;
}
if (channel->datasent != 10)
{
- printf("Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->datasent!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->datasent!\n");
+ global_ret = 8;
return;
}
if (channel->symbolratelimit != 10)
{
- printf("Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->symbolratelimit!\n");
+ fprintf(stderr, "Error: failure of Test from MWMODEM_run in
MWMODEM_InformationCallback at package->channel[0]->symbolratelimit!\n");
+ global_ret = 9;
return;
}
}
@@ -86,7 +93,7 @@
if (-1==socket)
{
- printf("Error: failure of Test from
MWMODEM_get_select_socket!\n");
+ fprintf(stderr, "Error: failure of Test from
MWMODEM_get_select_socket!\n");
return -1;
}
else
@@ -116,6 +123,50 @@
struct MWChannel *channel;
};
+static int fillDataBuffer(struct MWHeader d, char *buffer, int len)
+{
+ int i, j = 0;
+
+ for (i = sizeof(d.header) - 1; i >= 0 && j < len; i--, j++) {
+ buffer[j] = (char) (d.header >> i);
+ }
+
+ for (i = sizeof(d.time) - 1; i >= 0 && j < len; i--, j++) {
+ buffer[j] = (char) (d.time >> i);
+ }
+
+ for (i = sizeof(d.symbolrate) - 1; i >= 0 && j < len; i--, j++) {
+ buffer[j] = (char) (d.symbolrate >> i);
+ }
+
+ buffer[j] = (char) d.channelmax;
+ j+=1;
+
+ buffer[j] = (char) d.channel[d.channelmax-1].index;
+ j+=1;
+
+ buffer[j] = (char) d.channel[d.channelmax-1].modcod;
+ j+=1;
+
+ buffer[j] = (char) d.channel[d.channelmax-1].queue;
+ j+=1;
+
+ for (i = sizeof(d.channel[d.channelmax-1].datasent) - 1; i >= 0 && j < len;
i--, j++) {
+ buffer[j] = (char) (d.channel[d.channelmax-1].datasent >> i);
+ }
+
+ for (i = sizeof(d.channel[d.channelmax-1].symbolratelimit) - 1; i >= 0 && j
< len; i--, j++) {
+ buffer[j] = (char) (d.channel[d.channelmax-1].symbolratelimit >> i);
+ }
+
+ if (j > len) {
+ /* Error! The buffer wasn't big enough. */
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
static int generatedata()//TODO
{
const struct sockaddr *address;
@@ -125,23 +176,29 @@
int s;
struct MWHeader hdr;
- hdr.header = htons((uint32_t)0x6a726f00);
- hdr.time= htons(1);
- hdr.symbolrate=htons(100);
- hdr.channelmax=htons(1);
+ hdr.header = htonl(MW_MAGIC_NUMBER);
+ hdr.time= htonl(1);
+ hdr.symbolrate=htonl(100);
+ hdr.channelmax=1;
struct MWChannel chl;
- chl.index = htons(0);
- chl.modcod = htons(1);
- chl.queue = htons(10);
- chl.datasent = htons(10);
- chl.symbolratelimit=htons(10);
+ chl.index = 0;
+ chl.modcod = (uint8_t) 1;
+ chl.queue = 10;
+ chl.datasent = htonl(10);
+ chl.symbolratelimit=htonl(10);
struct MWChannel chlist[hdr.channelmax];
chlist[0] = chl;
hdr.channel =chlist;
- buffer = (char*) &hdr;
+ buffer = malloc(24);
+ if (-1 == fillDataBuffer(hdr, buffer, 24))
+ {
+ fprintf(stderr, "Error, the buffer was too small for the data
to send!\n");
+ return -1;
+ }
+
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (-1==s) return -1;
@@ -159,11 +216,13 @@
alen = sizeof (address4);
- if (-1== sendto(s, buffer, sizeof(struct MWHeader), 0, address, alen))
+ if (-1== sendto(s, buffer, sizeof(buffer), 0, address, alen))
{
+ free(buffer);
return -1;
}
+ free(buffer);
return 0;
}
@@ -176,36 +235,20 @@
}
MWMODEM_run(context);
- printf("Test of MWMODEM_run was successful!\n");
-
return 0;
}
-int testfree(struct MWMODEM_Context *context)
-{
- MWMODEM_free (context);
-
- printf("Test of MWMODEM_free was successful!\n");
-
- return 0;
-}
-
-
int main(void)
{
struct MWMODEM_Context *context;
- context = MWMODEM_init(port, AF_INET, &Callback, NULL);
+ context = MWMODEM_init(0, AF_INET, &callback, NULL);
- if (-1 == testinit(context, 0)) return -1;
-
if (-1 == testgetsocket(context)) return -1;
if (-1 == testrun(context)) return -1;
- if (-1 == testfree(context)) return -1;
+ MWMODEM_free (context);
- printf("All tests for the library with ipv4 and default port was
successful!\n");
-
return global_ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18752 - in libmwmodem/src: main tests,
gnunet <=