Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elphel-apps-camogm
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
elphel-apps-camogm
Commits
1438b135
Commit
1438b135
authored
Jul 06, 2016
by
Mikhail Karpenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set socket port number from command line options
parent
0de5ece0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
17 deletions
+49
-17
camogm.c
camogm.c
+27
-10
camogm.h
camogm.h
+18
-3
camogm_read.c
camogm_read.c
+4
-4
No files found.
camogm.c
View file @
1438b135
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include <sys/uio.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <string.h>
#include <string.h>
#include <getopt.h>
#include "camogm_ogm.h"
#include "camogm_ogm.h"
#include "camogm_jpeg.h"
#include "camogm_jpeg.h"
...
@@ -103,7 +104,7 @@ typedef enum {
...
@@ -103,7 +104,7 @@ typedef enum {
int
debug_level
;
int
debug_level
;
FILE
*
debug_file
;
FILE
*
debug_file
;
void
camogm_init
(
camogm_state
*
state
,
char
*
pipe_name
);
void
camogm_init
(
camogm_state
*
state
,
char
*
pipe_name
,
uint16_t
port_num
);
int
camogm_start
(
camogm_state
*
state
);
int
camogm_start
(
camogm_state
*
state
);
int
camogm_stop
(
camogm_state
*
state
);
int
camogm_stop
(
camogm_state
*
state
);
void
camogm_reset
(
camogm_state
*
state
);
void
camogm_reset
(
camogm_state
*
state
);
...
@@ -190,7 +191,7 @@ void put_uint64(void *buf, u_int64_t val)
...
@@ -190,7 +191,7 @@ void put_uint64(void *buf, u_int64_t val)
* @param[in] pipe_name pointer to command pipe name string
* @param[in] pipe_name pointer to command pipe name string
* @return none
* @return none
*/
*/
void
camogm_init
(
camogm_state
*
state
,
char
*
pipe_name
)
void
camogm_init
(
camogm_state
*
state
,
char
*
pipe_name
,
uint16_t
port_num
)
{
{
const
char
sserial
[]
=
"elp0"
;
const
char
sserial
[]
=
"elp0"
;
int
*
ipser
=
(
int
*
)
sserial
;
int
*
ipser
=
(
int
*
)
sserial
;
...
@@ -231,6 +232,7 @@ void camogm_init(camogm_state *state, char *pipe_name)
...
@@ -231,6 +232,7 @@ void camogm_init(camogm_state *state, char *pipe_name)
state
->
rawdev
.
curr_pos_r
=
state
->
rawdev
.
start_pos
;
state
->
rawdev
.
curr_pos_r
=
state
->
rawdev
.
start_pos
;
state
->
active_chn
=
ALL_CHN_ACTIVE
;
state
->
active_chn
=
ALL_CHN_ACTIVE
;
state
->
rawdev
.
mmap_default_size
=
MMAP_CHUNK_SIZE
;
state
->
rawdev
.
mmap_default_size
=
MMAP_CHUNK_SIZE
;
state
->
sock_port
=
port_num
;
}
}
/**
/**
...
@@ -1666,13 +1668,13 @@ int open_files(camogm_state *state)
...
@@ -1666,13 +1668,13 @@ int open_files(camogm_state *state)
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
const
char
usage
[]
=
"This program allows recording of the video/images acquired by Elphel camera to the storage media.
\n
"
\
const
char
usage
[]
=
"This program allows recording of the video/images acquired by Elphel camera to the storage media.
\n
"
\
"It is designed to run in the background and accept commands through a named pipe.
\n\n
"
\
"It is designed to run in the background and accept commands through a named pipe
or a socket
.
\n\n
"
\
"Usage:
\n\n
"
\
"Usage:
\n\n
"
\
"%s
<named_pipe_name
>
\n\n
"
\
"%s
-n <named_pipe_name> -p <port_number
>
\n\n
"
\
"i.e.:
\n\n
"
\
"i.e.:
\n\n
"
\
"%s
/var/state/camogm_cmd
\n\n
"
\
"%s
-n /var/state/camogm_cmd -p 1234
\n\n
"
\
"When the program is runnin
i
g you may send commands by writing strings to the command file
\n
"
\
"When the program is running you may send commands by writing strings to the command file
\n
"
\
"(/var/state/camogm_cmd in the example above). The complete list of available commands is available
\n
"
\
"(/var/state/camogm_cmd in the example above)
or to the socket
. The complete list of available commands is available
\n
"
\
"on Elphel Wiki (http://wiki.elphel.com/index.php?title=Camogm), here is the example of usage
\n
"
\
"on Elphel Wiki (http://wiki.elphel.com/index.php?title=Camogm), here is the example of usage
\n
"
\
"from the shell prompt in the camera:
\n\n
"
\
"from the shell prompt in the camera:
\n\n
"
\
"echo
\"
status; exif=1; format=jpeg;status=/var/tmp/camogm.status
\"
> /var/state/camogm_cmd
\n\n
"
\
"echo
\"
status; exif=1; format=jpeg;status=/var/tmp/camogm.status
\"
> /var/state/camogm_cmd
\n\n
"
\
...
@@ -1684,14 +1686,29 @@ int main(int argc, char *argv[])
...
@@ -1684,14 +1686,29 @@ int main(int argc, char *argv[])
"buffer, it only retrieves that data from the buffer (waiting when needed), packages it to selected
\n
"
\
"buffer, it only retrieves that data from the buffer (waiting when needed), packages it to selected
\n
"
\
"format and stores the result files.
\n\n
"
;
"format and stores the result files.
\n\n
"
;
int
ret
;
int
ret
;
int
opt
;
uint16_t
port_num
;
char
pipe_name_str
[
ELPHEL_PATH_MAX
]
=
{
0
};
// no command line options processing yet
if
((
argc
<
5
)
||
(
argv
[
1
][
1
]
==
'-'
))
{
if
((
argc
<
2
)
||
(
argv
[
1
][
1
]
==
'-'
))
{
printf
(
usage
,
argv
[
0
],
argv
[
0
]);
printf
(
usage
,
argv
[
0
],
argv
[
0
]);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
while
((
opt
=
getopt
(
argc
,
argv
,
"n:p:h"
))
!=
-
1
)
{
switch
(
opt
)
{
case
'n'
:
strncpy
(
pipe_name_str
,
(
const
char
*
)
optarg
,
ELPHEL_PATH_MAX
-
1
);
break
;
case
'p'
:
port_num
=
(
uint16_t
)
atoi
((
const
char
*
)
optarg
);
break
;
case
'h'
:
printf
(
usage
,
argv
[
0
],
argv
[
0
]);
return
EXIT_SUCCESS
;
}
}
camogm_init
(
&
sstate
,
argv
[
1
]
);
camogm_init
(
&
sstate
,
pipe_name_str
,
port_num
);
if
(
pthread_mutex_init
(
&
sstate
.
mutex
,
NULL
)
!=
0
)
{
if
(
pthread_mutex_init
(
&
sstate
.
mutex
,
NULL
)
!=
0
)
{
perror
(
"Unable to initialize mutex
\n
"
);
perror
(
"Unable to initialize mutex
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
...
camogm.h
View file @
1438b135
...
@@ -89,11 +89,25 @@ enum state_flags {
...
@@ -89,11 +89,25 @@ enum state_flags {
* The start position of raw device buffer
* The start position of raw device buffer
* @var rawdev_buffer::end_pos
* @var rawdev_buffer::end_pos
* The end position of raw device buffer
* The end position of raw device buffer
* @var rawdev_buffer::curr_pos
* @var rawdev_buffer::curr_pos
_r
* Current read position in raw device buffer
* Current read position in raw device buffer
* @var rawdev_buffer::curr_pos_w
* Current write position in raw device buffer
* @var rawdevice_buffer::mmap_default_size
* The default size of memory mapped disk region
* @var rawdevice_buffer::mmap_current_size
* The size of currently memory mapped disk region. Can be less then #mmap_default_size
* @var rawdevice_buffer::mmap_offset
* Current offset (in bytes) from the beginning of raw device buffer
* @var rawdev_buffer::file_start
* @var rawdev_buffer::file_start
* Pointer to the beginning of current file. This pointer is set during raw device reading and
* Pointer to the beginning of current file. This pointer is set during raw device reading and
* updated every time new file is found.
* updated every time new file is found.
* @var rawdevice_buffer::tid
* The ID of raw device reading thread
* @var rawdev_buffer::thread_state
* The state of the reading thread. Used to interrupt current operation
* @var rawdev_buffer::disk_mmap
* Pointer to memory mapped buffer region
*/
*/
typedef
struct
{
typedef
struct
{
int
rawdev_fd
;
int
rawdev_fd
;
...
@@ -101,15 +115,15 @@ typedef struct {
...
@@ -101,15 +115,15 @@ typedef struct {
uint32_t
overrun
;
uint32_t
overrun
;
uint64_t
start_pos
;
uint64_t
start_pos
;
uint64_t
end_pos
;
uint64_t
end_pos
;
volatile
uint64_t
curr_pos_r
;
uint64_t
curr_pos_w
;
uint64_t
curr_pos_w
;
unsigned
char
*
disk_mmap
;
uint64_t
mmap_default_size
;
uint64_t
mmap_default_size
;
uint64_t
mmap_current_size
;
uint64_t
mmap_current_size
;
uint64_t
mmap_offset
;
uint64_t
mmap_offset
;
volatile
uint64_t
curr_pos_r
;
uint64_t
file_start
;
uint64_t
file_start
;
pthread_t
tid
;
pthread_t
tid
;
volatile
int
thread_state
;
volatile
int
thread_state
;
unsigned
char
*
disk_mmap
;
}
rawdev_buffer
;
}
rawdev_buffer
;
/**
/**
...
@@ -201,6 +215,7 @@ typedef struct {
...
@@ -201,6 +215,7 @@ typedef struct {
int
rawdev_op
;
///< flag indicating writing to raw device
int
rawdev_op
;
///< flag indicating writing to raw device
rawdev_buffer
rawdev
;
///< contains pointers to raw device buffer
rawdev_buffer
rawdev
;
///< contains pointers to raw device buffer
unsigned
int
active_chn
;
///< bitmask of active sensor ports
unsigned
int
active_chn
;
///< bitmask of active sensor ports
uint16_t
sock_port
;
///< command socket port number
}
camogm_state
;
}
camogm_state
;
extern
int
debug_level
;
extern
int
debug_level
;
...
...
camogm_read.c
View file @
1438b135
...
@@ -723,20 +723,20 @@ bool is_in_range(struct range *range, struct disk_index *indx)
...
@@ -723,20 +723,20 @@ bool is_in_range(struct range *range, struct disk_index *indx)
return
false
;
return
false
;
}
}
#define PORT_NUMBER 3456
/**
/**
* @brief Prepare socket for communication
* @brief Prepare socket for communication
* @param[out] socket_fd pointer to socket descriptor
* @param[out] socket_fd pointer to socket descriptor
* @param[in] port_num socket port number
* @return none
* @return none
*/
*/
void
prep_socket
(
int
*
socket_fd
)
void
prep_socket
(
int
*
socket_fd
,
uint16_t
port_num
)
{
{
int
opt
=
1
;
int
opt
=
1
;
struct
sockaddr_in
sock
;
struct
sockaddr_in
sock
;
memset
((
char
*
)
&
sock
,
0
,
sizeof
(
struct
sockaddr_in
));
memset
((
char
*
)
&
sock
,
0
,
sizeof
(
struct
sockaddr_in
));
sock
.
sin_family
=
AF_INET
;
sock
.
sin_family
=
AF_INET
;
sock
.
sin_port
=
htons
(
PORT_NUMBER
);
sock
.
sin_port
=
htons
(
port_num
);
*
socket_fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
*
socket_fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
setsockopt
(
*
socket_fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
opt
,
sizeof
(
opt
));
setsockopt
(
*
socket_fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
char
*
)
&
opt
,
sizeof
(
opt
));
bind
(
*
socket_fd
,
(
struct
sockaddr
*
)
&
sock
,
sizeof
(
struct
sockaddr_in
));
bind
(
*
socket_fd
,
(
struct
sockaddr
*
)
&
sock
,
sizeof
(
struct
sockaddr_in
));
...
@@ -904,7 +904,7 @@ void *reader(void *arg)
...
@@ -904,7 +904,7 @@ void *reader(void *arg)
.
sockfd_temp
=
&
fd
.
sockfd_temp
=
&
fd
};
};
prep_socket
(
&
sockfd
);
prep_socket
(
&
sockfd
,
state
->
sock_port
);
pthread_cleanup_push
(
exit_thread
,
&
exit_state
);
pthread_cleanup_push
(
exit_thread
,
&
exit_state
);
while
(
true
)
{
while
(
true
)
{
fd
=
accept
(
sockfd
,
NULL
,
0
);
fd
=
accept
(
sockfd
,
NULL
,
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment