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
Redmine
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
Erik Jansson
LabComm
Commits
17ce406d
Commit
17ce406d
authored
10 years ago
by
Sven Gestegård Robertz
Browse files
Options
Downloads
Patches
Plain Diff
more c decoder refactoring
parent
979cef40
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/c/labcomm_decoder.c
+58
-34
58 additions, 34 deletions
lib/c/labcomm_decoder.c
with
58 additions
and
34 deletions
lib/c/labcomm_decoder.c
+
58
−
34
View file @
17ce406d
...
...
@@ -127,6 +127,11 @@ void labcomm_decoder_free(struct labcomm_decoder* d)
}
#endif
/* d - decoder to read from
registry - decoder to lookup signatures (registry != d only if
nesting decoders, e.g., when decoding pragma)
kind - type to decode (sample 0x02, or TODO: typedef/binding )
*/
static
int
decode_sample_def
(
struct
labcomm_decoder
*
d
,
struct
labcomm_decoder
*
registry
,
int
kind
)
...
...
@@ -153,6 +158,7 @@ static int decode_sample_def(struct labcomm_decoder *d,
goto
free_signature_name
;
}
signature
.
signature
=
labcomm_memory_alloc
(
d
->
memory
,
1
,
signature
.
size
);
//XXX d->reader???
if
(
d
->
reader
->
error
<
0
)
{
result
=
d
->
reader
->
error
;
goto
free_signature_name
;
...
...
@@ -164,14 +170,14 @@ static int decode_sample_def(struct labcomm_decoder *d,
goto
free_signature_signature
;
}
}
labcomm_scheduler_data_lock
(
d
->
scheduler
);
LABCOMM_SIGNATURE_ARRAY_FOREACH
(
d
->
local
,
struct
sample_entry
,
i
)
{
labcomm_scheduler_data_lock
(
registry
->
scheduler
);
LABCOMM_SIGNATURE_ARRAY_FOREACH
(
registry
->
local
,
struct
sample_entry
,
i
)
{
struct
sample_entry
*
s
;
int
*
remote_to_local
;
result
=
-
ENOENT
;
s
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
local
,
struct
sample_entry
,
i
);
s
=
LABCOMM_SIGNATURE_ARRAY_REF
(
registry
->
memory
,
registry
->
local
,
struct
sample_entry
,
i
);
if
(
s
->
signature
&&
s
->
signature
->
size
==
signature
.
size
&&
strcmp
(
s
->
signature
->
name
,
signature
.
name
)
==
0
&&
...
...
@@ -180,15 +186,15 @@ static int decode_sample_def(struct labcomm_decoder *d,
s
->
remote_index
=
remote_index
;
local_signature
=
s
->
signature
;
local_index
=
i
;
remote_to_local
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
remote_to_local
,
int
,
remote_to_local
=
LABCOMM_SIGNATURE_ARRAY_REF
(
registry
->
memory
,
registry
->
remote_to_local
,
int
,
remote_index
);
*
remote_to_local
=
i
;
result
=
remote_index
;
break
;
}
}
labcomm_scheduler_data_unlock
(
d
->
scheduler
);
labcomm_scheduler_data_unlock
(
registry
->
scheduler
);
if
(
local_signature
)
{
labcomm_reader_start
(
d
->
reader
,
d
->
reader
->
action_context
,
local_index
,
remote_index
,
local_signature
,
...
...
@@ -264,6 +270,11 @@ static int decoder_skip(struct labcomm_decoder *d, int len, int tag)
}
return
tag
;
}
/* d - decoder to read from
registry - decoder to lookup signatures (registry != d only if
nesting decoders, e.g., when decoding pragma)
len - length of the labcomm packet )
*/
static
int
decode_pragma
(
struct
labcomm_decoder
*
d
,
struct
labcomm_decoder
*
registry
,
int
len
)
...
...
@@ -337,6 +348,11 @@ static labcomm_decoder_function lookup_h(struct labcomm_decoder *d,
labcomm_scheduler_data_unlock
(
d
->
scheduler
);
return
do_decode
;
}
/* d - decoder to read from
registry - decoder to lookup signatures (registry != d only if
nesting decoders, e.g., when decoding pragma)
remote_index - received type index )
*/
static
int
decode_and_handle
(
struct
labcomm_decoder
*
d
,
struct
labcomm_decoder
*
registry
,
int
remote_index
)
...
...
@@ -350,7 +366,7 @@ static int decode_and_handle(struct labcomm_decoder *d,
.
handler
=
NULL
,
.
context
=
NULL
,
};
labcomm_decoder_function
do_decode
=
lookup_h
(
d
,
&
wrap
,
remote_index
,
&
local_index
);
labcomm_decoder_function
do_decode
=
lookup_h
(
registry
,
&
wrap
,
remote_index
,
&
local_index
);
result
=
*
local_index
;
if
(
do_decode
)
{
do_decode
(
d
->
reader
,
call_handler
,
&
wrap
);
...
...
@@ -366,6 +382,10 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
{
return
internal_decode_one
(
d
,
d
);
}
/* d - decoder to read from
registry - decoder to lookup signatures (registry != d only if
nesting decoders, e.g., when decoding pragma)
*/
int
internal_decode_one
(
struct
labcomm_decoder
*
d
,
struct
labcomm_decoder
*
registry
)
{
...
...
@@ -388,15 +408,15 @@ int internal_decode_one(struct labcomm_decoder *d,
fprintf
(
stderr
,
"No VERSION %d %d
\n
"
,
remote_index
,
length
);
result
=
-
ECONNRESET
;
}
else
if
(
remote_index
==
LABCOMM_SAMPLE_DEF
)
{
result
=
decode_sample_def
(
d
,
d
,
remote_index
);
result
=
decode_sample_def
(
d
,
registry
,
remote_index
);
}
else
if
(
remote_index
==
LABCOMM_PRAGMA
){
result
=
decode_pragma
(
d
,
d
,
length
);
result
=
decode_pragma
(
d
,
registry
,
length
);
}
else
if
(
remote_index
<
LABCOMM_USER
)
{
//fprintf(stderr, "SKIP %d %d\n", remote_index, length);
//result = remote_index;
result
=
decoder_skip
(
d
,
length
,
remote_index
);
}
else
{
result
=
decode_and_handle
(
d
,
d
,
remote_index
);
result
=
decode_and_handle
(
d
,
registry
,
remote_index
);
}
out:
return
result
;
...
...
@@ -406,11 +426,15 @@ int labcomm_decoder_run(struct labcomm_decoder *d)
{
return
internal_decoder_run
(
d
,
d
);
}
/* d - decoder to read from
registry - decoder to lookup signatures (registry != d only if
nesting decoders, e.g., when decoding pragma)
*/
int
internal_decoder_run
(
struct
labcomm_decoder
*
d
,
struct
labcomm_decoder
*
registry
)
{
int
res
;
while
(
(
res
=
labcomm_decoder
_decode_one
(
d
))
>
0
)
{
while
(
(
res
=
internal
_decode_one
(
d
,
registry
))
>
0
)
{
}
return
res
;
}
...
...
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