Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Erik Jansson
LabComm
Commits
78559879
Commit
78559879
authored
Mar 06, 2013
by
Sven Robertz
Browse files
merge of new coding and new error handling
parents
9ff9e3c2
4427041c
Changes
23
Hide whitespace changes
Inline
Side-by-side
compiler/build.xml
View file @
78559879
...
...
@@ -4,7 +4,7 @@
clean - removes all generated files and class files
Targets for working from Eclipse:
gen - generates java files
genClea
n - removes all generated files and their class files
cleanGe
n - removes all generated files and their class files
-->
<project
name=
"LabComm"
default=
"build"
basedir=
"."
>
...
...
@@ -77,7 +77,9 @@ classpath="tools/jastadd2.jar"/>
<!-- delete all .class files recursively -->
<delete>
<fileset
dir=
"."
includes=
"**/*.class"
/>
<fileset
dir=
"."
includes=
"labComm.jar"
/>
</delete>
</target>
...
...
examples/simple/compile.sh
View file @
78559879
(
cd
../../lib/c
;
make
)
(
cd
../../lib/c
;
make
-e
LABCOMM_NO_EXPERIMENTAL
=
true
)
(
cd
../../compiler
;
ant jar
)
java
-jar
../../compiler/labComm.jar
--java
=
gen
--c
=
gen/simple.c
--h
=
gen/simple.h
--python
=
gen/simple.py simple.lc
...
...
examples/wiki_example/data.java
View file @
78559879
...
...
@@ -56,7 +56,7 @@ public class data implements LabCommSample {
}
private
static
byte
[]
signature
=
new
byte
[]
{
0
,
0
,
0
,
37
,
37
,
};
}
examples/wiki_example/example.c
View file @
78559879
...
...
@@ -4,30 +4,30 @@
static
unsigned
char
signature_bytes_log_message
[]
=
{
// struct { 2 fields
0
,
0
,
0
,
17
,
0
,
0
,
0
,
2
,
17
,
2
,
// int 'sequence'
0
,
0
,
0
,
8
,
8
,
115
,
101
,
113
,
117
,
101
,
110
,
99
,
101
,
0
,
0
,
0
,
35
,
35
,
// array [_] 'line'
0
,
0
,
0
,
4
,
4
,
108
,
105
,
110
,
101
,
// array [_]
0
,
0
,
0
,
16
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
16
,
1
,
0
,
// struct { 2 fields
0
,
0
,
0
,
17
,
0
,
0
,
0
,
2
,
17
,
2
,
// boolean 'last'
0
,
0
,
0
,
4
,
4
,
108
,
97
,
115
,
116
,
0
,
0
,
0
,
32
,
32
,
// string 'data'
0
,
0
,
0
,
4
,
4
,
100
,
97
,
116
,
97
,
0
,
0
,
0
,
39
,
39
,
// }
// }
// }
...
...
@@ -39,7 +39,7 @@ labcomm_signature_t labcomm_signature_example_log_message = {
signature_bytes_log_message
};
static
unsigned
char
signature_bytes_data
[]
=
{
0
,
0
,
0
,
37
,
37
,
};
labcomm_signature_t
labcomm_signature_example_data
=
{
LABCOMM_SAMPLE
,
"data"
,
...
...
@@ -58,7 +58,7 @@ static void decode_log_message(
{
example_log_message
v
;
v
.
sequence
=
labcomm_decode_int
(
d
);
v
.
line
.
n_0
=
labcomm_decode_
int
(
d
);
v
.
line
.
n_0
=
labcomm_decode_
packed32
(
d
);
v
.
line
.
a
=
malloc
(
sizeof
(
v
.
line
.
a
[
0
])
*
v
.
line
.
n_0
);
{
int
i_0_0
;
...
...
@@ -106,7 +106,7 @@ static void encode_log_message(
labcomm_encode_type_index
(
e
,
&
labcomm_signature_example_log_message
);
{
labcomm_encode_int
(
e
,
(
*
v
).
sequence
);
labcomm_encode_
int
(
e
,
(
*
v
).
line
.
n_0
);
labcomm_encode_
packed32
(
e
,
(
*
v
).
line
.
n_0
);
{
int
i_0_0
;
for
(
i_0_0
=
0
;
i_0_0
<
(
*
v
).
line
.
n_0
;
i_0_0
++
)
{
...
...
examples/wiki_example/example.encoded
View file @
78559879
No preview for this file type
lib/c/Makefile
View file @
78559879
CC
=
gcc
CFLAGS
=
-g
-I
.
## Macros
liblabcomm.a
:
labcomm.o labcomm_fd_reader_writer.o experimental/labcomm_udp_reader_writer.o
\
experimental/udp_hack.o experimental/ethaddr.o
\
experimental/labcomm_thr_reader_writer.o
\
experimental/ThrottleDrv/ethernet_drv.o experimental/ThrottleDrv/throttle_drv.o
# Use LLVM clang if it's found.
CC
=
$(
shell
hash
clang 2>/dev/null
&&
echo
clang
||
echo
gcc
)
CFLAGS
=
-g
-Wall
-I
.
LDFLAGS
=
-L
.
LDLIBS_TEST
=
-lcunit
-llabcomm
OBJS
=
labcomm.o labcomm_fd_reader_writer.o labcomm_mem_reader.o labcomm_mem_writer.o
LABCOMMC_PATH
=
../../compiler
LABCOMMC_JAR
=
$(LABCOMMC_PATH)
/labComm.jar
TEST_DIR
=
test
TESTDATA_DIR
=
$(TEST_DIR)
/testdata
TEST_GEN_DIR
=
$(TESTDATA_DIR)
/gen
CREATED_DIRS
=
$(TEST_DIR)
$(TESTDATA_DIR)
$(TEST_GEN_DIR)
# Disable experimental objects by invoking make like `make -e LABCOMM_NO_EXPERIMENTAL=true`
ifneq
($(LABCOMM_NO_EXPERIMENTAL),true)
OBJS
+=
experimental/udp_hack.o experimental/ethaddr.o
\
experimental/labcomm_thr_reader_writer.o
\
experimental/ThrottleDrv/ethernet_drv.o
\
experimental/ThrottleDrv/throttle_drv.o
\
experimental/labcomm_udp_reader_writer.o
endif
## Targets
.PHONY
:
all run-test clean distclean
all
:
liblabcomm.a test/test_labcomm_errors
liblabcomm.a
:
$(OBJS)
ar
-r
liblabcomm.a
$^
labcomm.o
:
labcomm.c labcomm.h labcomm_private.h
labcomm_fd_reader_writer.o
:
labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h labcomm.h labcomm_private.h
labcomm_mem_reader.o
:
labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
labcomm_mem_writer.o
:
labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
ethaddr.o
:
ethaddr.c
%o
:
%c %h
$(CREATED_DIRS)
:
mkdir
-p
$@
run-test
:
$(TEST_DIR)/test_labcomm_errors |$(TEST_DIR)
test
/test_labcomm_errors
$(TEST_DIR)/test_labcomm_errors
:
$(TEST_DIR)/test_labcomm_errors.o liblabcomm.a |$(TEST_DIR)
$(CC)
$(CFLAGS)
$(LDFLAGS)
-llabcomm
-o
$@
$^
$(TEST_DIR)/test_labcomm_errors.o
:
$(TEST_DIR)/test_labcomm_errors.c $(TEST_DIR)/test_labcomm_errors.h |$(TEST_DIR)
cd test
;
$(CC)
$(CFLAGS)
-I
..
-c
$(
patsubst
$(TEST_DIR)
/%, %,
$^
)
$(TEST_DIR)/test_labcomm.o
:
$(TEST_DIR)/test_labcomm.c $(TEST_GEN_DIR)/test_sample.h |$(TEST_DIR)
$(CC)
-c
$(CFLAGS)
-o
$@
$<
$(TEST_DIR)/test_labcomm
:
$(TEST_DIR)/test_labcomm.o $(TEST_GEN_DIR)/test_sample.o liblabcomm.a
$(CC)
$(CFLAGS)
$(LDFLAGS)
$(
filter-out
%.a,
$^
)
$(LDLIBS)
$(LDLIBS_TEST)
-o
$@
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h
:
$(TESTDATA_DIR)/%.lc $(LABCOMMC_JAR) |$(TEST_GEN_DIR)
java
-jar
$(LABCOMMC_JAR)
--c
=
$(
patsubst
%.h,%.c,
$@
)
--h
=
$(
patsubst
%.c,%.h,
$@
)
$<
$(LABCOMMC_JAR)
:
@
echo
"======Building LabComm compiler======"
cd
$(LABCOMMC_PATH)
;
ant jar
@
echo
"======End building LabComm compiler======"
%.o
:
%.c %.h
clean
:
rm
*
.o experimental/
*
.o experimental/ThrottleDrv/
*
.o
$(RM)
*
.o
$(RM)
experimental/
*
.o experimental/ThrottleDrv/
*
.o
$(RM)
test
/
*
.o
$(RM)
test
/
*
.gch
$(RM)
test
/test_labcomm_errors
$(RM)
$(TEST_DIR)
/test_labcomm
distclean
:
clean
rm
liblabcomm.a
$(RM)
liblabcomm.a
lib/c/cppmacros.h
0 → 100644
View file @
78559879
// C Preprocessor macros.
#ifndef CPP_MACROS_H
#define CPP_MACROS_H
#define X_EMPTY(mac) var ## 1
#define EMPTY(mac) X_EMPTY(mac) // Returns 1 if macro mac is empty.
#endif
lib/c/experimental/ThrottleDrv/display.h
View file @
78559879
#define PC_MODE
#ifdef PC_MODE
#include
<stdio.h>
#define DISPLAY_ERR(s) perror(s);
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include
<stdio.h>
#endif
#else
#define DISPLAY_ERR(s) ;
#endif
lib/c/experimental/ThrottleDrv/ethernet_drv.c
View file @
78559879
#include
<stdlib.h>
#include
<string.h>
#include
<unistd.h>
#include
<stdio.h>
#include
<errno.h>
#include
<sys/socket.h>
#include
<sys/ioctl.h>
...
...
@@ -14,6 +13,10 @@
#include
"ethernet_drv.h"
#include
"display.h"
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include
<stdio.h>
#endif
/** LOCAL FUNCTIONS **/
...
...
lib/c/experimental/ethaddr.c
View file @
78559879
#include
<stdio.h>
#include
"ethaddr.h"
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include
<stdio.h>
#endif
#if ETH_ALEN != 6
#warning "Assumption that ETH_ALEN == 6 appears false. Here be dragons."
#endif
...
...
lib/c/experimental/udp_hack.c
View file @
78559879
#include
<arpa/inet.h>
#include
<netinet/in.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<sys/types.h>
#include
<sys/socket.h>
#include
<unistd.h>
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include
<stdio.h>
#endif
#define BUFLEN 512
#define NPACK 10
#define PORT 9930
...
...
lib/c/labcomm.c
View file @
78559879
#include
<errno.h>
#include
<string.h>
#include
<stdio.h>
#ifndef __VXWORKS__
#include
<strings.h>
#ifdef ARM_CORTEXM3_CODESOURCERY
#include
<string.h>
#else
#include
<strings.h>
#endif
#endif
#include
<stdlib.h>
#ifdef __VXWORKS__
#if (CPU == PPC603)
#undef _LITTLE_ENDIAN
#ifndef ARM_CORTEXM3_CODESOURCERY
#include
<stdlib.h>
#endif
#if (CPU == PENTIUM4)
#undef _BIG_ENDIAN
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include
<stdio.h>
#endif
#ifdef __VXWORKS__
#if (CPU == PPC603)
#undef _LITTLE_ENDIAN
#endif
#if (CPU == PENTIUM4)
#undef _BIG_ENDIAN
#endif
#endif
#include
"labcomm.h"
#include
"labcomm_private.h"
...
...
@@ -35,6 +49,83 @@ typedef struct labcomm_decoder_context {
labcomm_sample_entry_t
*
sample
;
}
labcomm_decoder_context_t
;
void
labcomm_register_error_handler_encoder
(
struct
labcomm_encoder
*
encoder
,
labcomm_error_handler_callback
callback
)
{
encoder
->
on_error
=
callback
;
encoder
->
writer
.
on_error
=
callback
;
}
void
labcomm_register_error_handler_decoder
(
struct
labcomm_decoder
*
decoder
,
labcomm_error_handler_callback
callback
)
{
decoder
->
on_error
=
callback
;
decoder
->
reader
.
on_error
=
callback
;
}
/* Error strings. _must_ be the same order as in enum labcomm_error */
const
char
*
labcomm_error_strings
[]
=
{
"Enum begin guard. DO NO use this as an error."
,
"Encoder has no registration for this signature."
,
"Encoder is missing do_register"
,
"Encoder is missing do_encode"
,
"The labcomm buffer is full and it."
,
"Decoder is missing do_register"
,
"Decoder is missing do_decode_one"
,
"Decoder: Unknown datatype"
,
"Decoder: index mismatch"
,
"Decoder: type not found"
,
"This function is not yet implemented."
,
"User defined error."
,
"Could not allocate memory."
,
"Enum end guard. DO NO use this as an error."
};
const
char
*
labcomm_error_get_str
(
enum
labcomm_error
error_id
)
{
const
char
*
error_str
=
NULL
;
// Check if this is a known error ID.
if
(
error_id
>=
LABCOMM_ERROR_ENUM_BEGIN_GUARD
&&
error_id
<=
LABCOMM_ERROR_ENUM_END_GUARD
)
{
error_str
=
labcomm_error_strings
[
error_id
];
}
return
error_str
;
}
void
labcomm_decoder_register_new_datatype_handler
(
struct
labcomm_decoder
*
d
,
labcomm_handle_new_datatype_callback
on_new_datatype
)
{
d
->
on_new_datatype
=
on_new_datatype
;
}
int
on_new_datatype
(
labcomm_decoder_t
*
d
,
labcomm_signature_t
*
sig
)
{
d
->
on_error
(
LABCOMM_ERROR_DEC_UNKNOWN_DATATYPE
,
4
,
"%s(): unknown datatype '%s'
\n
"
,
__FUNCTION__
,
sig
->
name
);
return
0
;
}
void
on_error_fprintf
(
enum
labcomm_error
error_id
,
size_t
nbr_va_args
,
...)
{
#ifndef LABCOMM_NO_STDIO
const
char
*
err_msg
=
labcomm_error_get_str
(
error_id
);
// The final string to print.
if
(
err_msg
==
NULL
)
{
err_msg
=
"Error with an unknown error ID occured."
;
}
fprintf
(
stderr
,
"%s
\n
"
,
err_msg
);
if
(
nbr_va_args
>
0
)
{
va_list
arg_pointer
;
va_start
(
arg_pointer
,
nbr_va_args
);
fprintf
(
stderr
,
"%s
\n
"
,
"Extra info {"
);
char
*
print_format
=
va_arg
(
arg_pointer
,
char
*
);
vfprintf
(
stderr
,
print_format
,
arg_pointer
);
fprintf
(
stderr
,
"}
\n
"
);
va_end
(
arg_pointer
);
}
#else
;
// If labcomm can't be compiled with stdio the user will have to make an own error callback functionif he/she needs error reporting.
#endif
}
static
labcomm_sample_entry_t
*
get_sample_by_signature_address
(
labcomm_sample_entry_t
*
head
,
labcomm_signature_t
*
signature
)
...
...
@@ -135,7 +226,7 @@ static void do_encode(
if
(
sample
&&
sample
->
encode
)
{
sample
->
encode
(
encoder
,
value
);
}
else
{
printf
(
"Encoder has n
o registration for %s
\n
"
,
signature
->
name
);
encoder
->
on_error
(
LABCOMM_ERROR_ENC_NO_REG_SIGNATURE
,
2
,
"N
o registration for %s
.
\n
"
,
signature
->
name
);
}
}
...
...
@@ -148,7 +239,7 @@ labcomm_encoder_t *labcomm_encoder_new(
labcomm_encoder_context_t
*
context
;
context
=
malloc
(
sizeof
(
labcomm_encoder_context_t
));
context
->
sample
=
0
;
context
->
sample
=
NULL
;
context
->
index
=
LABCOMM_USER
;
result
->
context
=
context
;
result
->
writer
.
context
=
writer_context
;
...
...
@@ -158,8 +249,10 @@ labcomm_encoder_t *labcomm_encoder_new(
result
->
writer
.
pos
=
0
;
result
->
writer
.
write
=
writer
;
result
->
writer
.
write
(
&
result
->
writer
,
labcomm_writer_alloc
);
result
->
writer
.
on_error
=
on_error_fprintf
;
result
->
do_register
=
do_encoder_register
;
result
->
do_encode
=
do_encode
;
result
->
on_error
=
on_error_fprintf
;
}
return
result
;
}
...
...
@@ -169,10 +262,11 @@ void labcomm_internal_encoder_register(
labcomm_signature_t
*
signature
,
labcomm_encode_typecast_t
encode
)
{
if
(
e
&&
e
->
do_register
)
{
// Will segfault if e == NULL.
if
(
e
->
do_register
)
{
e
->
do_register
(
e
,
signature
,
encode
);
}
else
{
printf
(
"Encoder is missing do_register
\n
"
);
e
->
on_error
(
LABCOMM_ERROR_ENC_MISSING_DO_REG
,
0
);
}
}
...
...
@@ -181,10 +275,11 @@ void labcomm_internal_encode(
labcomm_signature_t
*
signature
,
void
*
value
)
{
if
(
e
&&
e
->
do_encode
)
{
// Will segfault if e == NULL
if
(
e
->
do_encode
)
{
e
->
do_encode
(
e
,
signature
,
value
);
}
else
{
printf
(
"Encoder is missing do_encode
\n
"
);
e
->
on_error
(
LABCOMM_ERROR_ENC_MISSING_DO_ENCODE
,
0
);
}
}
...
...
@@ -196,8 +291,18 @@ void labcomm_internal_encoder_user_action(labcomm_encoder_t *e,
void
labcomm_encoder_free
(
labcomm_encoder_t
*
e
)
{
e
->
writer
.
write
(
&
e
->
writer
,
labcomm_writer_free
);
labcomm_encoder_context_t
*
econtext
=
(
labcomm_encoder_context_t
*
)
e
->
context
;
labcomm_sample_entry_t
*
sentry
=
econtext
->
sample
;
labcomm_sample_entry_t
*
sentry_next
;
while
(
sentry
!=
NULL
)
{
sentry_next
=
sentry
->
next
;
free
(
sentry
);
sentry
=
sentry_next
;
}
free
(
e
->
context
);
free
(
e
);
}
...
...
@@ -253,7 +358,8 @@ static void collect_flat_signature(
int
type
=
labcomm_decode_packed32
(
decoder
);
// printf("%s: type=%x\n", __FUNCTION__, type);
if
(
type
>=
LABCOMM_USER
)
{
printf
(
"Implement %s ... (1) for type 0x%x
\n
"
,
__FUNCTION__
,
type
);
decoder
->
on_error
(
LABCOMM_ERROR_UNIMPLEMENTED_FUNC
,
3
,
"Implement %s ... (1) for type 0x%x
\n
"
,
__FUNCTION__
,
type
);
}
else
{
//labcomm_encode_int(signature_writer, type);
labcomm_encode_packed32
(
signature_writer
,
type
);
...
...
@@ -292,7 +398,8 @@ static void collect_flat_signature(
case
LABCOMM_STRING
:
{
}
break
;
default:
{
printf
(
"Implement %s (2) for type 0x%x...
\n
"
,
__FUNCTION__
,
type
);
decoder
->
on_error
(
LABCOMM_ERROR_UNIMPLEMENTED_FUNC
,
3
,
"Implement %s (2) for type 0x%x...
\n
"
,
__FUNCTION__
,
type
);
}
break
;
}
}
...
...
@@ -351,12 +458,12 @@ static int do_decode_one(labcomm_decoder_t *d)
entry
=
get_sample_by_signature_value
(
context
->
sample
,
&
signature
);
if
(
!
entry
)
{
// Unknown datatype, bail out
fprintf
(
stderr
,
"%s: unknown datatype '%s' (id=0x%x)
\n
"
,
__FUNCTION__
,
signature
.
name
,
index
);
/*d->on_error(LABCOMM_ERROR_DEC_UNKNOWN_DATATYPE, 4,
"%s
()
: unknown datatype '%s' (id=0x%x)\n",
__FUNCTION__, signature.name, index);*/
d
->
on_new_datatype
(
d
,
&
signature
);
}
else
if
(
entry
->
index
&&
entry
->
index
!=
index
)
{
fprintf
(
stderr
,
"%s: index mismatch '%s' (id=0x%x != 0x%x)
\n
"
,
__FUNCTION__
,
signature
.
name
,
entry
->
index
,
index
);
d
->
on_error
(
LABCOMM_ERROR_DEC_INDEX_MISMATCH
,
5
,
"%s(): index mismatch '%s' (id=0x%x != 0x%x)
\n
"
,
__FUNCTION__
,
signature
.
name
,
entry
->
index
,
index
);
}
else
{
// TODO unnessesary, since entry->index == index in above if statement
entry
->
index
=
index
;
}
free
(
signature
.
name
);
...
...
@@ -371,8 +478,9 @@ static int do_decode_one(labcomm_decoder_t *d)
entry
=
get_sample_by_index
(
context
->
sample
,
result
);
if
(
!
entry
)
{
fprintf
(
stderr
,
"%s: type not found (id=0x%x)
\n
"
,
__FUNCTION__
,
result
);
// printf("Error: %s: type not found (id=0x%x)\n",
//__FUNCTION__, result);
d
->
on_error
(
LABCOMM_ERROR_DEC_TYPE_NOT_FOUND
,
3
,
"%s(): type not found (id=0x%x)
\n
"
,
__FUNCTION__
,
result
);
result
=
-
ENOENT
;
}
else
{
entry
->
decoder
(
d
,
entry
->
handler
,
entry
->
context
);
...
...
@@ -401,8 +509,11 @@ labcomm_decoder_t *labcomm_decoder_new(
result
->
reader
.
pos
=
0
;
result
->
reader
.
read
=
reader
;
result
->
reader
.
read
(
&
result
->
reader
,
labcomm_reader_alloc
);
result
->
reader
.
on_error
=
on_error_fprintf
;
result
->
do_register
=
do_decoder_register
;
result
->
do_decode_one
=
do_decode_one
;
result
->
on_error
=
on_error_fprintf
;
result
->
on_new_datatype
=
on_new_datatype
;
}
return
result
;
}
...
...
@@ -414,23 +525,25 @@ void labcomm_internal_decoder_register(
labcomm_handler_typecast_t
handler
,
void
*
handler_context
)
{
if
(
d
&&
d
->
do_register
)
{
// Will segfault if d == NULL
if
(
d
->
do_register
)
{
d
->
do_register
(
d
,
signature
,
type_decoder
,
handler
,
handler_context
);
}
else
{
printf
(
"Decoder is missing do_register
\n
"
);
d
->
on_error
(
LABCOMM_ERROR_DEC_MISSING_DO_REG
,
0
);
}
}
int
labcomm_decoder_decode_one
(
labcomm_decoder_t
*
d
)
{
int
result
=
-
1
;
if
(
d
&&
d
->
do_decode_one
)
// Will segfault if decoder == NULL.
if
(
d
->
do_decode_one
)
{
result
=
d
->
do_decode_one
(
d
);
}
else
{
printf
(
"Decoder is missing do_decode_one
\n
"
);
d
->
on_error
(
LABCOMM_ERROR_DEC_MISSING_DO_DECODE_ONE
,
0
);
}
return
result
;
}
...
...
@@ -444,5 +557,16 @@ void labcomm_decoder_run(labcomm_decoder_t *d)
void
labcomm_decoder_free
(
labcomm_decoder_t
*
d
)
{
d
->
reader
.
read
(
&
d
->
reader
,
labcomm_reader_free
);
labcomm_decoder_context_t
*
context
=
(
labcomm_decoder_context_t
*
)
d
->
context
;
labcomm_sample_entry_t
*
entry
=
context
->
sample
;
labcomm_sample_entry_t
*
entry_next
;
while
(
entry
!=
NULL
)
{
entry_next
=
entry
->
next
;
free
(
entry
);
entry
=
entry_next
;
}
free
(
d
->
context
);
free
(
d
);
}
lib/c/labcomm.h
View file @
78559879
#ifndef _LABCOMM_H_
#define _LABCOMM_H_
#include
<endian.h>
#include
<stdio.h>
#ifdef ARM_CORTEXM3_CODESOURCERY
#include
<machine/endian.h>
#else
#include
<endian.h>
#endif
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include
<stdio.h>
#endif
#include
<stdlib.h>
#include
<string.h>
#include
<stdarg.h>
/* Forward declaration */
struct
labcomm_encoder
;
struct
labcomm_decoder
;
/*
* Signature entry
...
...
@@ -17,11 +31,62 @@ typedef struct {
unsigned
char
*
signature
;
}
labcomm_signature_t
;
/*
* Error handling.
*/
/* Error IDs */
enum
labcomm_error
{
LABCOMM_ERROR_ENUM_BEGIN_GUARD
,
// _must_ be the first enum element. labcomm_error_get_str() depends on this.
LABCOMM_ERROR_ENC_NO_REG_SIGNATURE
,
LABCOMM_ERROR_ENC_MISSING_DO_REG
,
LABCOMM_ERROR_ENC_MISSING_DO_ENCODE
,
LABCOMM_ERROR_ENC_BUF_FULL
,
LABCOMM_ERROR_DEC_MISSING_DO_REG
,
LABCOMM_ERROR_DEC_MISSING_DO_DECODE_ONE
,
LABCOMM_ERROR_DEC_UNKNOWN_DATATYPE
,
LABCOMM_ERROR_DEC_INDEX_MISMATCH
,
LABCOMM_ERROR_DEC_TYPE_NOT_FOUND
,
LABCOMM_ERROR_UNIMPLEMENTED_FUNC
,
LABCOMM_ERROR_MEMORY
,
LABCOMM_ERROR_USER_DEF
,
LABCOMM_ERROR_ENUM_END_GUARD
// _must_ be the last enum element. labcomm_error_get_str() depends on this.