Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabComm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
LabComm
Commits
f695e6ca
Commit
f695e6ca
authored
13 years ago
by
Sven Robertz
Browse files
Options
Downloads
Patches
Plain Diff
merged example: sending works
parent
a4d22b52
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/simple_java/thr_compile.sh
+4
-2
4 additions, 2 deletions
examples/simple_java/thr_compile.sh
examples/simple_java/thr_example.c
+125
-0
125 additions, 0 deletions
examples/simple_java/thr_example.c
with
129 additions
and
2 deletions
examples/simple_java/thr_compile.sh
+
4
−
2
View file @
f695e6ca
gcc
-o
thr_encoder
-L
../../lib/c
-I
.
-I
../../lib/c thr_encoder.c gen/simple.c ../../lib/c/labcomm_thr_reader_writer.c ../../lib/c/ThrottleDrv/
*
.c
-llabcomm
#
gcc -o thr_encoder -L ../../lib/c -I . -I ../../lib/c thr_encoder.c gen/simple.c ../../lib/c/labcomm_thr_reader_writer.c ../../lib/c/ThrottleDrv/*.c -llabcomm
gcc
-o
thr_decoder
-L
../../lib/c
-I
.
-I
../../lib/c thr_decoder.c gen/simple.c ../../lib/c/labcomm_thr_reader_writer.c ../../lib/c/ThrottleDrv/
*
.c
-llabcomm
#gcc -o thr_decoder -L ../../lib/c -I . -I ../../lib/c thr_decoder.c gen/simple.c ../../lib/c/labcomm_thr_reader_writer.c ../../lib/c/ThrottleDrv/*.c -llabcomm
gcc
-o
thr_example
-L
../../lib/c
-I
.
-I
../../lib/c thr_example.c gen/simple.c ../../lib/c/labcomm_thr_reader_writer.c ../../lib/c/ThrottleDrv/
*
.c
-llabcomm
This diff is collapsed.
Click to expand it.
examples/simple_java/thr_example.c
0 → 100644
+
125
−
0
View file @
f695e6ca
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<fcntl.h>
#include
<labcomm_thr_reader_writer.h>
#include
"gen/simple.h"
#include
"ThrottleDrv/throttle_drv.h"
static
int
encode
(
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
,
0xe3
,
0x81
,
0xbf
};
/* other host MAC address, hardcoded...... :-( */
unsigned
char
chn_id
=
0x01
;
unsigned
short
frag_size
=
60
;
unsigned
short
freq
=
1000
;
/* milliseconds */
char
*
ifname
=
argv
[
1
];
char
*
dest_mac_str
=
argv
[
2
];
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."
);
}
else
{
p_thr_chn
=
thr_open_chn
(
dest_mac
,
chn_id
,
frag_size
,
freq
,
NULL
);
encoder
=
labcomm_encoder_new
(
labcomm_thr_writer
,
p_thr_chn
);
labcomm_encoder_register_simple_TwoInts
(
encoder
);
labcomm_encoder_register_simple_IntString
(
encoder
);
simple_IntString
is
;
is
.
x
=
24
;
is
.
s
=
"Hello, LabComm!"
;
printf
(
"Encoding IntString, x=%d, s=%s
\n
"
,
is
.
x
,
is
.
s
);
labcomm_encode_simple_IntString
(
encoder
,
&
is
);
simple_TwoInts
ti
;
ti
.
a
=
13
;
ti
.
b
=
37
;
printf
(
"Encoding TwoInts, a=%d, b=%d
\n
"
,
ti
.
a
,
ti
.
b
);
labcomm_encode_simple_TwoInts
(
encoder
,
&
ti
);
//client_exit(fd);
}
}
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<fcntl.h>
#include
<labcomm_thr_reader_writer.h>
#include
"gen/simple.h"
#include
"ThrottleDrv/throttle_drv.h"
static
void
handle_simple_TwoInts
(
simple_TwoInts
*
v
,
void
*
context
)
{
printf
(
"Got TwoInts. a=%d, b=%d
\n
"
,
v
->
a
,
v
->
b
);
}
static
void
handle_simple_IntString
(
simple_IntString
*
v
,
void
*
context
)
{
printf
(
"Got IntString. x=%d, s=%s
\n
"
,
v
->
x
,
v
->
s
);
}
static
int
decode
(
int
argc
,
char
*
argv
[])
{
struct
thr_chn_t
*
p_thr_chn
=
NULL
;
struct
labcomm_decoder
*
decoder
;
void
*
context
=
NULL
;
int
ret
=
0
;
unsigned
char
dest_mac
[
ETH_ADR_SIZE
]
=
{
0x06
,
0x05
,
0x04
,
0x03
,
0x02
,
0x01
};
/* other host MAC address, hardcoded...... :-( */
unsigned
char
chn_id
=
0x01
;
unsigned
short
frag_size
=
60
;
unsigned
short
freq
=
1000
;
/* milliseconds */
unsigned
char
data
[
200
];
char
*
ifname
=
argv
[
1
];
char
*
dest_mac_str
=
argv
[
2
];
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."
);
}
else
{
p_thr_chn
=
thr_open_chn
(
dest_mac
,
chn_id
,
frag_size
,
freq
,
labcomm_decoder_decode_one
);
decoder
=
labcomm_decoder_new
(
labcomm_thr_reader
,
p_thr_chn
);
if
(
!
decoder
)
{
printf
(
"Failed to allocate decoder %s:%d
\n
"
,
__FUNCTION__
,
__LINE__
);
return
1
;
}
labcomm_decoder_register_simple_TwoInts
(
decoder
,
handle_simple_TwoInts
,
context
);
labcomm_decoder_register_simple_IntString
(
decoder
,
handle_simple_IntString
,
context
);
printf
(
"Decoding:
\n
"
);
do
{
ret
=
thr_receive
(
p_thr_chn
,
data
,
decoder
);
}
while
(
-
1
!=
ret
);
{
printf
(
"Throttle Send receive failure."
);
}
printf
(
"--- End Of File ---:
\n
"
);
labcomm_decoder_free
(
decoder
);
//server_exit(fd);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
==
2
)
{
return
decode
(
argc
,
argv
);
}
else
if
(
argc
==
3
)
{
return
encode
(
argc
,
argv
);
}
else
{
printf
(
"Usage:
\n
For encoding ethN xx:xx:xx:xx:xx:xx
\n
For decoding ethN
\n
"
);
return
1
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment