Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
moberg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
moberg
Commits
c6e37217
Commit
c6e37217
authored
6 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup code, fix underflow error
parent
6ca5f79f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/serial2002/serial2002.c
+7
-14
7 additions, 14 deletions
plugins/serial2002/serial2002.c
plugins/serial2002/serial2002_lib.c
+3
-8
3 additions, 8 deletions
plugins/serial2002/serial2002_lib.c
with
10 additions
and
22 deletions
plugins/serial2002/serial2002.c
+
7
−
14
View file @
c6e37217
...
@@ -133,12 +133,13 @@ static struct moberg_status analog_out_write(
...
@@ -133,12 +133,13 @@ static struct moberg_status analog_out_write(
struct
moberg_channel_context
*
channel
=
&
analog_out
->
channel_context
;
struct
moberg_channel_context
*
channel
=
&
analog_out
->
channel_context
;
struct
moberg_device_context
*
device
=
channel
->
device
;
struct
moberg_device_context
*
device
=
channel
->
device
;
struct
analog_map
map
=
device
->
analog_out
.
map
[
channel
->
index
];
struct
analog_map
map
=
device
->
analog_out
.
map
[
channel
->
index
];
long
as_long
=
value
-
map
.
min
/
map
.
delta
;
long
as_long
=
(
value
-
map
.
min
)
/
map
.
delta
;
if
(
as_long
<
0
)
{
if
(
as_long
<
0
)
{
value
=
0
;
as_long
=
0
;
}
else
if
(
as_long
>
map
.
maxdata
)
{
}
else
if
(
as_long
>
map
.
maxdata
)
{
as_long
=
map
.
maxdata
;
as_long
=
map
.
maxdata
;
}
}
struct
serial2002_data
data
=
{
is_channel
,
map
.
index
,
as_long
};
struct
serial2002_data
data
=
{
is_channel
,
map
.
index
,
as_long
};
return
serial2002_write
(
device
->
port
.
fd
,
data
);
return
serial2002_write
(
device
->
port
.
fd
,
data
);
}
}
...
@@ -204,7 +205,6 @@ return_result:
...
@@ -204,7 +205,6 @@ return_result:
return
result
;
return
result
;
err_einval:
err_einval:
return
MOBERG_ERRNO
(
EINVAL
);
return
MOBERG_ERRNO
(
EINVAL
);
fprintf
(
stderr
,
"%s
\n
"
,
__FUNCTION__
);
return
MOBERG_OK
;
return
MOBERG_OK
;
}
}
...
@@ -218,6 +218,7 @@ static struct moberg_device_context *new_context(struct moberg *moberg,
...
@@ -218,6 +218,7 @@ static struct moberg_device_context *new_context(struct moberg *moberg,
result
->
moberg
=
moberg
;
result
->
moberg
=
moberg
;
result
->
dlclose
=
dlclose
;
result
->
dlclose
=
dlclose
;
result
->
dlhandle
=
dlhandle
;
result
->
dlhandle
=
dlhandle
;
result
->
port
.
timeout
=
100000
;
}
}
return
result
;
return
result
;
}
}
...
@@ -258,9 +259,10 @@ static void remap_analog(
...
@@ -258,9 +259,10 @@ static void remap_analog(
remap
->
map
[
remap
->
count
].
delta
=
remap
->
map
[
remap
->
count
].
delta
=
(
remap
->
map
[
remap
->
count
].
max
-
remap
->
map
[
remap
->
count
].
min
)
/
(
remap
->
map
[
remap
->
count
].
max
-
remap
->
map
[
remap
->
count
].
min
)
/
remap
->
map
[
remap
->
count
].
maxdata
;
remap
->
map
[
remap
->
count
].
maxdata
;
}
}
else
{
remap
->
map
[
remap
->
count
].
delta
=
1
.
0
;
fprintf
(
stderr
,
"%d -> %d
\n
"
,
remap
->
count
,
i
);
}
remap
->
count
++
;
remap
->
count
++
;
}
}
}
}
...
@@ -276,7 +278,6 @@ static void remap_digital(
...
@@ -276,7 +278,6 @@ static void remap_digital(
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
if
(
channel
[
i
].
kind
==
kind
)
{
if
(
channel
[
i
].
kind
==
kind
)
{
remap
->
map
[
remap
->
count
].
index
=
i
;
remap
->
map
[
remap
->
count
].
index
=
i
;
fprintf
(
stderr
,
"%d -> %d
\n
"
,
remap
->
count
,
i
);
remap
->
count
++
;
remap
->
count
++
;
}
}
}
}
...
@@ -287,7 +288,6 @@ static struct moberg_status device_open(struct moberg_device_context *device)
...
@@ -287,7 +288,6 @@ static struct moberg_status device_open(struct moberg_device_context *device)
struct
moberg_status
result
;
struct
moberg_status
result
;
int
fd
=
-
1
;
int
fd
=
-
1
;
fprintf
(
stderr
,
"%s
\n
"
,
__FUNCTION__
);
if
(
device
->
port
.
count
==
0
)
{
if
(
device
->
port
.
count
==
0
)
{
fd
=
open
(
device
->
port
.
name
,
O_RDWR
);
fd
=
open
(
device
->
port
.
name
,
O_RDWR
);
if
(
fd
<
0
)
{
goto
err_errno
;
}
if
(
fd
<
0
)
{
goto
err_errno
;
}
...
@@ -323,10 +323,8 @@ static struct moberg_status device_open(struct moberg_device_context *device)
...
@@ -323,10 +323,8 @@ static struct moberg_status device_open(struct moberg_device_context *device)
device
->
port
.
fd
=
fd
;
device
->
port
.
fd
=
fd
;
}
}
device
->
port
.
count
++
;
device
->
port
.
count
++
;
fprintf
(
stderr
,
"OPENED %d
\n
"
,
device
->
port
.
count
);
return
MOBERG_OK
;
return
MOBERG_OK
;
err_errno:
err_errno:
fprintf
(
stderr
,
"ERRNO %d
\n
"
,
errno
);
result
=
MOBERG_ERRNO
(
errno
);
result
=
MOBERG_ERRNO
(
errno
);
err_result:
err_result:
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
...
@@ -337,16 +335,13 @@ err_result:
...
@@ -337,16 +335,13 @@ err_result:
static
struct
moberg_status
device_close
(
struct
moberg_device_context
*
device
)
static
struct
moberg_status
device_close
(
struct
moberg_device_context
*
device
)
{
{
fprintf
(
stderr
,
"%s
\n
"
,
__FUNCTION__
);
if
(
device
->
port
.
count
<
0
)
{
errno
=
ENODEV
;
goto
err_errno
;
}
if
(
device
->
port
.
count
<
0
)
{
errno
=
ENODEV
;
goto
err_errno
;
}
device
->
port
.
count
--
;
device
->
port
.
count
--
;
if
(
device
->
port
.
count
==
0
)
{
if
(
device
->
port
.
count
==
0
)
{
fprintf
(
stderr
,
"CLOSE
\n
"
);
if
(
close
(
device
->
port
.
fd
)
<
0
)
{
goto
err_errno
;
}
if
(
close
(
device
->
port
.
fd
)
<
0
)
{
goto
err_errno
;
}
}
}
return
MOBERG_OK
;
return
MOBERG_OK
;
err_errno:
err_errno:
fprintf
(
stderr
,
"CLOSE %d
\n
"
,
errno
);
return
MOBERG_ERRNO
(
errno
);
return
MOBERG_ERRNO
(
errno
);
}
}
...
@@ -371,14 +366,12 @@ static int channel_down(struct moberg_channel *channel)
...
@@ -371,14 +366,12 @@ static int channel_down(struct moberg_channel *channel)
static
struct
moberg_status
channel_open
(
struct
moberg_channel
*
channel
)
static
struct
moberg_status
channel_open
(
struct
moberg_channel
*
channel
)
{
{
fprintf
(
stderr
,
"%s
\n
"
,
__FUNCTION__
);
struct
moberg_status
result
=
device_open
(
channel
->
context
->
device
);
struct
moberg_status
result
=
device_open
(
channel
->
context
->
device
);
return
result
;
return
result
;
}
}
static
struct
moberg_status
channel_close
(
struct
moberg_channel
*
channel
)
static
struct
moberg_status
channel_close
(
struct
moberg_channel
*
channel
)
{
{
fprintf
(
stderr
,
"%s
\n
"
,
__FUNCTION__
);
struct
moberg_status
result
=
device_close
(
channel
->
context
->
device
);
struct
moberg_status
result
=
device_close
(
channel
->
context
->
device
);
return
result
;
return
result
;
}
}
...
...
This diff is collapsed.
Click to expand it.
plugins/serial2002/serial2002_lib.c
+
3
−
8
View file @
c6e37217
...
@@ -33,7 +33,6 @@ static struct moberg_status tty_write(int fd, unsigned char *buf, int count)
...
@@ -33,7 +33,6 @@ static struct moberg_status tty_write(int fd, unsigned char *buf, int count)
while
(
n
<
count
)
{
while
(
n
<
count
)
{
int
written
=
write
(
fd
,
&
buf
[
n
],
count
-
n
);
int
written
=
write
(
fd
,
&
buf
[
n
],
count
-
n
);
if
(
written
==
0
)
{
if
(
written
==
0
)
{
fprintf
(
stderr
,
"Failed to write
\n
"
);
return
MOBERG_ERRNO
(
ENODATA
);
return
MOBERG_ERRNO
(
ENODATA
);
}
else
if
(
written
<
0
)
{
}
else
if
(
written
<
0
)
{
return
MOBERG_ERRNO
(
errno
);
return
MOBERG_ERRNO
(
errno
);
...
@@ -50,7 +49,7 @@ static struct moberg_status tty_read(int fd, long timeout, unsigned char *value)
...
@@ -50,7 +49,7 @@ static struct moberg_status tty_read(int fd, long timeout, unsigned char *value)
while
(
1
)
{
while
(
1
)
{
pollfd
.
fd
=
fd
;
pollfd
.
fd
=
fd
;
pollfd
.
events
=
POLLRDNORM
|
POLLRDBAND
|
POLLIN
|
POLLHUP
|
POLLERR
;
pollfd
.
events
=
POLLRDNORM
|
POLLRDBAND
|
POLLIN
|
POLLHUP
|
POLLERR
;
int
err
=
poll
(
&
pollfd
,
1
,
timeout
);
int
err
=
poll
(
&
pollfd
,
1
,
timeout
/
1000
);
if
(
err
>=
1
)
{
if
(
err
>=
1
)
{
break
;
break
;
}
else
if
(
err
==
0
)
{
}
else
if
(
err
==
0
)
{
...
@@ -100,14 +99,11 @@ struct moberg_status serial2002_read(int f, long timeout,
...
@@ -100,14 +99,11 @@ struct moberg_status serial2002_read(int f, long timeout,
}
}
length
++
;
length
++
;
if
(
data
<
0
)
{
if
(
length
<
6
&&
data
&
0x80
)
{
fprintf
(
stderr
,
"serial2002 error
\n
"
);
break
;
}
else
if
(
length
<
6
&&
data
&
0x80
)
{
value
->
value
=
(
value
->
value
<<
7
)
|
(
data
&
0x7f
);
value
->
value
=
(
value
->
value
<<
7
)
|
(
data
&
0x7f
);
}
else
if
(
length
==
6
&&
data
&
0x80
)
{
}
else
if
(
length
==
6
&&
data
&
0x80
)
{
fprintf
(
stderr
,
"Too long
\n
"
);
value
->
kind
=
is_invalid
;
value
->
kind
=
is_invalid
;
return
MOBERG_ERRNO
(
EFBIG
);
break
;
break
;
}
else
{
}
else
{
if
(
length
==
1
)
{
if
(
length
==
1
)
{
...
@@ -180,7 +176,6 @@ static double interpret_value(int value)
...
@@ -180,7 +176,6 @@ static double interpret_value(int value)
result
*=
1e-6
;
result
*=
1e-6
;
break
;
break
;
}
}
fprintf
(
stderr
,
"%f
\n
"
,
result
);
return
result
;
return
result
;
}
}
...
...
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