Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
comm
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
labrobotica
drivers
comm
Commits
79e9c99b
Commit
79e9c99b
authored
13 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Internal changes in the base CComm class to improve the efficiency of the data handling.
parent
bd7b17db
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/CMakeLists.txt
+2
-2
2 additions, 2 deletions
src/CMakeLists.txt
src/comm.cpp
+8
-15
8 additions, 15 deletions
src/comm.cpp
src/comm.h
+2
-1
2 additions, 1 deletion
src/comm.h
src/cqueue.cpp
+118
-0
118 additions, 0 deletions
src/cqueue.cpp
src/cqueue.h
+31
-0
31 additions, 0 deletions
src/cqueue.h
with
161 additions
and
18 deletions
src/CMakeLists.txt
+
2
−
2
View file @
79e9c99b
...
@@ -33,9 +33,9 @@ ELSE(FTDI_INCLUDE_DIR AND FTDI_LIBRARY)
...
@@ -33,9 +33,9 @@ ELSE(FTDI_INCLUDE_DIR AND FTDI_LIBRARY)
ENDIF
(
FTDI_INCLUDE_DIR AND FTDI_LIBRARY
)
ENDIF
(
FTDI_INCLUDE_DIR AND FTDI_LIBRARY
)
# edit the following line to add all the source code files of the library
# edit the following line to add all the source code files of the library
SET
(
sources ./comm.cpp ./commexceptions.cpp ./serial/rs232.cpp ./serial/rs232exceptions.cpp ./sockets/socket.cpp ./sockets/socketclient.cpp ./sockets/socketserver.cpp ./sockets/socketexceptions.cpp ./can/can.cpp
)
SET
(
sources ./comm.cpp
./cqueue.cpp
./commexceptions.cpp ./serial/rs232.cpp ./serial/rs232exceptions.cpp ./sockets/socket.cpp ./sockets/socketclient.cpp ./sockets/socketserver.cpp ./sockets/socketexceptions.cpp ./can/can.cpp
)
# edit the following line to add all the header files of the library
# edit the following line to add all the header files of the library
SET
(
headers ./comm.h ./commexceptions.h ./serial/rs232.h ./serial/rs232exceptions.h ./sockets/socket.h ./sockets/socketclient.h ./sockets/socketserver.h ./sockets/socketexceptions.h ./can/can.h
)
SET
(
headers ./comm.h
./cqueue.h
./commexceptions.h ./serial/rs232.h ./serial/rs232exceptions.h ./sockets/socket.h ./sockets/socketclient.h ./sockets/socketserver.h ./sockets/socketexceptions.h ./can/can.h
)
IF
(
BUILD_FTDI
)
IF
(
BUILD_FTDI
)
SET
(
sources
${
sources
}
./usb_ftdi/ftdiserver.cpp ./usb_ftdi/ftdimodule.cpp ./usb_ftdi/ftdiexceptions.cpp
)
SET
(
sources
${
sources
}
./usb_ftdi/ftdiserver.cpp ./usb_ftdi/ftdimodule.cpp ./usb_ftdi/ftdiexceptions.cpp
)
...
...
This diff is collapsed.
Click to expand it.
src/comm.cpp
+
8
−
15
View file @
79e9c99b
...
@@ -105,8 +105,7 @@ void CComm::config(void *config)
...
@@ -105,8 +105,7 @@ void CComm::config(void *config)
int
CComm
::
read
(
unsigned
char
*
data
,
int
len
)
int
CComm
::
read
(
unsigned
char
*
data
,
int
len
)
{
{
int
num_available
=
0
;
int
num_read
=
0
;
int
i
=
0
;
if
(
data
==
NULL
)
if
(
data
==
NULL
)
{
{
...
@@ -118,17 +117,12 @@ int CComm::read(unsigned char *data,int len)
...
@@ -118,17 +117,12 @@ int CComm::read(unsigned char *data,int len)
if
(
this
->
state
==
configured
||
this
->
state
==
sending
)
if
(
this
->
state
==
configured
||
this
->
state
==
sending
)
{
{
this
->
access_comm
.
enter
();
this
->
access_comm
.
enter
();
num_
available
=
this
->
receive_queue
.
size
(
);
num_
read
=
this
->
receive_queue
.
read
(
data
,
len
);
if
(
len
>
num_
available
)
if
(
len
>
num_
read
)
{
{
len
=
num_
available
;
len
=
num_
read
;
this
->
event_server
->
reset_event
(
this
->
rx_event_id
);
this
->
event_server
->
reset_event
(
this
->
rx_event_id
);
}
}
for
(
i
=
0
;
i
<
len
;
i
++
)
{
data
[
i
]
=*
this
->
receive_queue
.
begin
();
this
->
receive_queue
.
pop_front
();
}
this
->
access_comm
.
exit
();
this
->
access_comm
.
exit
();
return
len
;
return
len
;
}
}
...
@@ -186,7 +180,7 @@ unsigned int CComm::get_num_data(void)
...
@@ -186,7 +180,7 @@ unsigned int CComm::get_num_data(void)
if
(
this
->
state
==
configured
||
this
->
state
==
sending
)
if
(
this
->
state
==
configured
||
this
->
state
==
sending
)
{
{
this
->
access_comm
.
enter
();
this
->
access_comm
.
enter
();
num
=
this
->
receive_queue
.
size
();
num
=
this
->
receive_queue
.
get_num_data
();
this
->
access_comm
.
exit
();
this
->
access_comm
.
exit
();
}
}
...
@@ -230,7 +224,7 @@ void CComm::close(void)
...
@@ -230,7 +224,7 @@ void CComm::close(void)
throw
;
throw
;
}
}
/* flush the data queues */
/* flush the data queues */
this
->
receive_queue
.
erase
(
this
->
receive_queue
.
begin
(),
this
->
receive_queue
.
end
()
);
this
->
receive_queue
.
flush
(
);
/* change the current state */
/* change the current state */
this
->
state
=
created
;
this
->
state
=
created
;
this
->
access_comm
.
exit
();
this
->
access_comm
.
exit
();
...
@@ -271,7 +265,7 @@ void *CComm::comm_thread(void *param)
...
@@ -271,7 +265,7 @@ void *CComm::comm_thread(void *param)
void
CComm
::
on_receive
(
void
)
void
CComm
::
on_receive
(
void
)
{
{
unsigned
char
*
data
=
NULL
;
unsigned
char
*
data
=
NULL
;
int
num
=
0
,
num_read
=
0
,
i
=
0
;
int
num
=
0
,
num_read
=
0
;
if
((
num
=
this
->
hard_get_num_data
())
==-
1
)
if
((
num
=
this
->
hard_get_num_data
())
==-
1
)
{
{
...
@@ -295,8 +289,7 @@ void CComm::on_receive(void)
...
@@ -295,8 +289,7 @@ void CComm::on_receive(void)
}
}
else
else
{
{
for
(
i
=
0
;
i
<
num
;
i
++
)
this
->
receive_queue
.
write
(
data
,
num
);
this
->
receive_queue
.
push_back
(
data
[
i
]);
if
(
!
this
->
event_server
->
event_is_set
(
this
->
rx_event_id
))
if
(
!
this
->
event_server
->
event_is_set
(
this
->
rx_event_id
))
{
{
this
->
event_server
->
set_event
(
this
->
rx_event_id
);
this
->
event_server
->
set_event
(
this
->
rx_event_id
);
...
...
This diff is collapsed.
Click to expand it.
src/comm.h
+
2
−
1
View file @
79e9c99b
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include
"eventserver.h"
#include
"eventserver.h"
#include
"threadserver.h"
#include
"threadserver.h"
#include
"mutex.h"
#include
"mutex.h"
#include
"cqueue.h"
typedef
enum
{
created
,
configured
,
opened
,
sending
}
comm_states
;
typedef
enum
{
created
,
configured
,
opened
,
sending
}
comm_states
;
...
@@ -135,7 +136,7 @@ class CComm
...
@@ -135,7 +136,7 @@ class CComm
* function get_num_data() returns the number of bytes in this queue. By default,
* function get_num_data() returns the number of bytes in this queue. By default,
* this queue is empty.
* this queue is empty.
*/
*/
std
::
list
<
unsigned
char
>
receive_queue
;
CQueue
receive_queue
;
/**
/**
* \brief current state of the communication device
* \brief current state of the communication device
*
*
...
...
This diff is collapsed.
Click to expand it.
src/cqueue.cpp
0 → 100755
+
118
−
0
View file @
79e9c99b
#include
"cqueue.h"
CQueue
::
CQueue
()
{
this
->
size
=
QUEUE_DEFAULT_SIZE
;
this
->
data
=
new
unsigned
char
[
this
->
size
];
this
->
num_data
=
0
;
this
->
read_pointer
=
0
;
this
->
write_pointer
=
0
;
}
CQueue
::
CQueue
(
int
size
)
{
this
->
size
=
size
;
this
->
data
=
new
unsigned
char
[
this
->
size
];
this
->
num_data
=
0
;
this
->
read_pointer
=
0
;
this
->
write_pointer
=
0
;
}
void
CQueue
::
resize
(
int
new_size
)
{
}
int
CQueue
::
read
(
unsigned
char
*
data
,
int
len
)
{
int
num_data_to_end
=
0
;
this
->
queue_access
.
enter
();
if
(
len
>
this
->
num_data
)
len
=
this
->
num_data
;
num_data_to_end
=
this
->
size
-
this
->
read_pointer
;
if
(
num_data_to_end
<
len
)
{
memcpy
(
data
,
&
this
->
data
[
read_pointer
],
num_data_to_end
);
memcpy
(
&
data
[
num_data_to_end
],
this
->
data
,
len
-
num_data_to_end
);
this
->
read_pointer
=
len
-
num_data_to_end
;
this
->
num_data
-=
len
;
}
else
{
memcpy
(
data
,
&
this
->
data
[
this
->
read_pointer
],
len
);
this
->
read_pointer
+=
len
;
this
->
num_data
-=
len
;
}
this
->
queue_access
.
exit
();
return
len
;
}
int
CQueue
::
write
(
unsigned
char
*
data
,
int
len
)
{
int
num_data_to_end
=
0
;
this
->
queue_access
.
enter
();
if
(
len
>
(
this
->
size
-
this
->
num_data
))
len
=
this
->
size
-
this
->
num_data
;
num_data_to_end
=
this
->
size
-
this
->
write_pointer
;
if
(
num_data_to_end
<
len
)
{
memcpy
(
&
this
->
data
[
this
->
write_pointer
],
data
,
num_data_to_end
);
memcpy
(
this
->
data
,
&
data
[
num_data_to_end
],
len
-
num_data_to_end
);
this
->
write_pointer
=
len
-
num_data_to_end
;
this
->
num_data
+=
len
;
}
else
{
memcpy
(
&
this
->
data
[
this
->
write_pointer
],
data
,
len
);
this
->
write_pointer
+=
len
;
this
->
num_data
+=
len
;
}
this
->
queue_access
.
exit
();
return
len
;
}
int
CQueue
::
get_num_data
(
void
)
{
return
this
->
num_data
;
}
bool
CQueue
::
is_empty
(
void
)
{
if
(
this
->
num_data
==
0
)
return
true
;
else
return
false
;
}
bool
CQueue
::
is_full
(
void
)
{
if
(
this
->
num_data
==
this
->
size
)
return
true
;
else
return
false
;
}
void
CQueue
::
flush
(
void
)
{
this
->
queue_access
.
enter
();
this
->
read_pointer
=
0
;
this
->
write_pointer
=
0
;
this
->
num_data
=
0
;
this
->
queue_access
.
exit
();
}
CQueue
::~
CQueue
()
{
if
(
this
->
data
!=
NULL
)
{
delete
[]
this
->
data
;
this
->
data
=
NULL
;
}
this
->
num_data
=
0
;
this
->
read_pointer
=
0
;
this
->
write_pointer
=
0
;
}
This diff is collapsed.
Click to expand it.
src/cqueue.h
0 → 100755
+
31
−
0
View file @
79e9c99b
#ifndef _CQUEUE_H
#define _CQUEUE_H
#include
<string.h>
#include
"mutex.h"
#define QUEUE_DEFAULT_SIZE 1024
class
CQueue
{
private:
int
size
;
int
num_data
;
int
read_pointer
;
int
write_pointer
;
unsigned
char
*
data
;
CMutex
queue_access
;
public:
CQueue
();
CQueue
(
int
size
);
void
resize
(
int
new_size
);
int
read
(
unsigned
char
*
data
,
int
len
);
int
write
(
unsigned
char
*
data
,
int
len
);
int
get_num_data
(
void
);
bool
is_empty
(
void
);
bool
is_full
(
void
);
void
flush
(
void
);
~
CQueue
();
};
#endif
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