00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <string.h>
00037
00038 #define MOTE
00039 #include "sensix.h"
00040 #include "sense_impl.h"
00041 #include "sense_endian.h"
00042 #include "mote_impl.h"
00043 #include "mote_types.h"
00044 #include "mote_sensix.h"
00045 #include "mote_networking.h"
00046 #include "mote_state.h"
00047
00048
00049 int test_endian_conversion() {
00050 int fail = 0;
00051 byte_t ptr[WORDSIZE];
00052 uint_t uval_out;
00053 const uint_t uval_in = MAX_VALUE;
00054 int_t sval_out;
00055 const int_t sval_in = -(MAX_VALUE / 2);
00056
00057 network_order(ptr, uval_in);
00058 host_order((WORD*)&(uval_out), ptr, WORDSIZE, false, false);
00059 if (uval_in != uval_out) {
00060 fprintf(stderr, " endian conversion failed - unsigned: %u vs %u.\n",
00061 uval_in, uval_out);
00062 fail--;
00063 }
00064
00065 network_order(ptr, sval_in);
00066 host_order((WORD*)&(sval_out), ptr, WORDSIZE, false, true);
00067 if (sval_in != sval_out) {
00068 fprintf(stderr, " endian conversion failed - signed: %d vs %d.\n",
00069 sval_in, sval_out);
00070 fail--;
00071 }
00072
00073 return fail;
00074 }
00075
00076
00077 int main() {
00078 if (test_endian_conversion() == 0)
00079 fprintf(stdout, " endian conversion passed.\n");
00080
00081 return 0;
00082 }