diff --git a/examples/simple_java/thr_decoder.c b/examples/simple_java/thr_decoder.c index de5907cf3e70390d4c6b33f2320cff9e9490f739..401416824661b5d81a000265864b7968910128e6 100644 --- a/examples/simple_java/thr_decoder.c +++ b/examples/simple_java/thr_decoder.c @@ -24,8 +24,20 @@ int main(int argc, char *argv[]) { unsigned short freq = 1000; /* milliseconds */ unsigned char data[200]; - char *filename = argv[1]; - if (-1 == thr_init("eth2")) + char *ifname = argv[1]; + char *dest_mac_str = argv[2]; + + if(argc != 3) { + printf("usage: thr_encoder ethN xx:xx:xx:xx:xx:xx\n"); + return 1; + } + + if(parse_MAC_address(dest_mac_str, dest_mac)) { + printf("failed to parse dest MAC address\n"); + return 1; + } + + if (-1 == thr_init(ifname)) { printf("Throttle Init failure."); } diff --git a/examples/simple_java/thr_encoder.c b/examples/simple_java/thr_encoder.c index 6466175521f38900b89a333c071e683d778b2e95..492c8c289b5dc1e930a00398b28273ce89bd6920 100644 --- a/examples/simple_java/thr_encoder.c +++ b/examples/simple_java/thr_encoder.c @@ -10,13 +10,26 @@ int main(int argc, char *argv[]) { struct thr_chn_t *p_thr_chn = NULL; struct labcomm_encoder *encoder; int i, j; - unsigned char dest_mac[ETH_ADR_SIZE] = {0x00, 0x09, 0x6b, 0x10, 0xf3, 0x80}; /* other host MAC address, hardcoded...... :-( */ +// unsigned char dest_mac[ETH_ADR_SIZE] = {0x00, 0x09, 0x6b, 0x10, 0xf3, 0x80}; /* other host MAC address, hardcoded...... :-( */ + unsigned char dest_mac[ETH_ADR_SIZE] = {0x00, 0x09, 0x6b, 0xe3, 0x81, 0xbf}; /* other host MAC address, hardcoded...... :-( */ unsigned char chn_id = 0x01; unsigned short frag_size = 60; unsigned short freq = 1000; /* milliseconds */ - char *filename = argv[1]; - if (-1 == thr_init("eth0")) + char *ifname = argv[1]; + char *dest_mac_str = argv[2]; + + if(argc != 3) { + printf("usage: thr_encoder ethN xx:xx:xx:xx:xx:xx\n"); + return 1; + } + + if(parse_MAC_address(dest_mac_str, dest_mac)) { + printf("failed to parse dest MAC address\n"); + return 1; + } + + if (-1 == thr_init(ifname)) { printf("Throttle Init failure."); } diff --git a/examples/simple_java/udp_compile.sh b/examples/simple_java/udp_compile.sh index 6d3c5658817f94326b5a82d1934f4f82d6fa3239..9f3479567639fb69888c4d3bbbc4456ccc0e559a 100644 --- a/examples/simple_java/udp_compile.sh +++ b/examples/simple_java/udp_compile.sh @@ -1,3 +1,3 @@ -gcc -o udp_encoder -L ../../lib/c -I . -I ../../lib/c udp_encoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm +gcc -g -o udp_encoder -L ../../lib/c -I . -I ../../lib/c udp_encoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm -gcc -o udp_decoder -L ../../lib/c -I . -I ../../lib/c udp_decoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm +gcc -g -o udp_decoder -L ../../lib/c -I . -I ../../lib/c udp_decoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm diff --git a/lib/c/Makefile b/lib/c/Makefile index 13e49745dfc35e338805cf24abbfc77f2a2d3ae5..7ef5643a4f75c4ac54863b2009274517d04e203c 100644 --- a/lib/c/Makefile +++ b/lib/c/Makefile @@ -1,11 +1,14 @@ -liblabcomm.a : labcomm.o labcomm_fd_reader_writer.o - ar -r liblabcomm.a labcomm.o labcomm_fd_reader_writer.o +CC = gcc +CFLAGS = -g + +liblabcomm.a : labcomm.o labcomm_fd_reader_writer.o ethaddr.o + ar -r liblabcomm.a labcomm.o labcomm_fd_reader_writer.o ethaddr.o labcomm.o : labcomm.c labcomm.h labcomm_private.h - gcc -c labcomm.c labcomm_fd_reader_writer.o : labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h labcomm.h labcomm_private.h - gcc -c labcomm_fd_reader_writer.c + +ethaddr.o: ethaddr.c clean: rm *.o diff --git a/lib/c/ethaddr.c b/lib/c/ethaddr.c new file mode 100644 index 0000000000000000000000000000000000000000..29dab1a6b510071f4455e0e3662c21a7e45334aa --- /dev/null +++ b/lib/c/ethaddr.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "ethaddr.h" + + +/* parse a string on the format 00:01:02:0d:0e:0f into a char array + * the mac_addr argument must be at least six bytes. + * returns 0 on success, or -1 on error + */ +int parse_MAC_address(const char *str, unsigned char mac_addr[]) +{ + int res = sscanf(str, "%x:%x:%x:%x:%x:%x", &mac_addr[0], &mac_addr[1], + &mac_addr[2], &mac_addr[3], &mac_addr[4], &mac_addr[5]); + return (res == 6? 0 : -1); + +} + +#if 0 +/* test program */ +int main(int argc, char *argv[]) +{ + int i; + unsigned char a[6]; + int res = parse_MAC_address(argv[1], a); + if(res) { + perror("Failed to parse MAC address"); + } + printf("%x.%x.%x.%x.%x.%x\n", a[0], a[1], a[2], a[3], a[4], a[5]); + return 0; +} +#endif diff --git a/lib/c/ethaddr.h b/lib/c/ethaddr.h new file mode 100644 index 0000000000000000000000000000000000000000..605c86e03f417afa2dfcff8ed2f7b0fae07d0b3f --- /dev/null +++ b/lib/c/ethaddr.h @@ -0,0 +1,8 @@ +#ifndef ETHADDR_H +#define ETHADDR_H +/* parse a string on the format 00:01:02:0d:0e:0f into a char array + * the mac_addr argument must be at least six bytes. + * returns 0 on success, or -1 on error + */ +int parse_MAC_address(const char *str, unsigned char mac_addr[]); +#endif