Mercurial > pt1.oyama
annotate src/recpt1ctl.c @ 164:7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
KNOWN ISSUE: Cannnot split BS-TBS(BS1_1).
enable compile recpt1ctl.
SID can specified by recpt1ctl.
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Mon, 01 Oct 2012 21:52:05 +0900 |
parents | 9c7bc6c0327e |
children | 061ef2cd98f0 |
rev | line source |
---|---|
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
1 #include <sys/types.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
2 #include <sys/ipc.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
3 #include <sys/msg.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
4 #include <stdio.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
5 #include <stdlib.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
6 #include <string.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
7 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
8 #include <ctype.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
9 #include <getopt.h> |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
10 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
11 #include "version.h" |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
12 #include "pt1_common.h" |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
13 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
14 void |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
15 show_usage(char *cmd) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
16 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
17 fprintf(stderr, "Usage: \n%s --pid pid [--channel channel] [--extend time_to_extend] [--time recording_time]\n", cmd); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
18 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
19 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
20 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
21 void |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
22 show_options(void) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
23 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
24 fprintf(stderr, "Options:\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
25 fprintf(stderr, "--pid: Process id of recpt1 to control\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
26 fprintf(stderr, "--channel: Tune to specified channel\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
27 fprintf(stderr, "--extend: Extend recording time\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
28 fprintf(stderr, "--time: Set total recording time\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
29 fprintf(stderr, "--help: Show this help\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
30 fprintf(stderr, "--version: Show version\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
31 fprintf(stderr, "--list: Show channel list\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
32 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
33 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
34 void |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
35 show_channels(void) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
36 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
37 FILE *f; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
38 char *home; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
39 char buf[255], filename[255]; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
40 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
41 fprintf(stderr, "Available Channels:\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
42 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
43 home = getenv("HOME"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
44 sprintf(filename, "%s/.recpt1-channels", home); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
45 f = fopen(filename, "r"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
46 if(f) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
47 while(fgets(buf, 255, f)) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
48 fprintf(stderr, "%s", buf); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
49 fclose(f); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
50 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
51 else |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
52 fprintf(stderr, "13-62: Terrestrial Channels\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
53 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
54 fprintf(stderr, "101ch: NHK BS1\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
55 fprintf(stderr, "102ch: NHK BS2\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
56 fprintf(stderr, "103ch: NHK BShi\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
57 fprintf(stderr, "141ch: BS Nittele\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
58 fprintf(stderr, "151ch: BS Asahi\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
59 fprintf(stderr, "161ch: BS-TBS\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
60 fprintf(stderr, "171ch: BS Japan\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
61 fprintf(stderr, "181ch: BS Fuji\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
62 fprintf(stderr, "191ch: WOWOW\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
63 fprintf(stderr, "200ch: Star Channel\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
64 fprintf(stderr, "211ch: BS11 Digital\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
65 fprintf(stderr, "222ch: TwellV\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
66 fprintf(stderr, "CS2-CS24: CS Channels\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
67 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
68 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
69 int |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
70 parse_time(char *rectimestr, int *recsec) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
71 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
72 /* indefinite */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
73 if(!strcmp("-", rectimestr)) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
74 *recsec = -1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
75 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
76 /* colon */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
77 else if(strchr(rectimestr, ':')) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
78 int n1, n2, n3; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
79 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
80 *recsec = n1 * 3600 + n2 * 60 + n3; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
81 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
82 *recsec = n1 * 3600 + n2 * 60; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
83 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
84 /* HMS */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
85 else { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
86 char *tmpstr; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
87 char *p1, *p2; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
88 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
89 tmpstr = strdup(rectimestr); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
90 p1 = tmpstr; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
91 while(*p1 && !isdigit(*p1)) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
92 p1++; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
93 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
94 /* hour */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
95 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
96 *p2 = '\0'; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
97 *recsec += atoi(p1) * 3600; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
98 p1 = p2 + 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
99 while(*p1 && !isdigit(*p1)) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
100 p1++; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
101 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
102 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
103 /* minute */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
104 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
105 *p2 = '\0'; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
106 *recsec += atoi(p1) * 60; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
107 p1 = p2 + 1; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
108 while(*p1 && !isdigit(*p1)) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
109 p1++; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
110 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
111 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
112 /* second */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
113 *recsec += atoi(p1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
114 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
115 free(tmpstr); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
116 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
117 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
118 return 0; /* success */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
119 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
120 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
121 int |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
122 main(int argc, char **argv) |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
123 { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
124 int msqid; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
125 int msgflg = IPC_CREAT | 0666; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
126 key_t key = 0; |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
127 int recsec = 0, extsec=0; |
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
128 char *channel = NULL; |
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
129 pt1_message_buf sbuf; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
130 size_t buf_length; |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
131 char *sid_list = NULL; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
132 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
133 int result; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
134 int option_index; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
135 struct option long_options[] = { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
136 { "pid", 1, NULL, 'p'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
137 { "channel", 1, NULL, 'c'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
138 { "extend", 1, NULL, 'e'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
139 { "time", 1, NULL, 't'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
140 { "help", 0, NULL, 'h'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
141 { "version", 0, NULL, 'v'}, |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
142 { "list", 0, NULL, 'l'}, |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
143 { "sid", 1, NULL, 'i'}, |
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
144 { "SID", 1, NULL, 'i'}, |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
145 {0, 0, NULL, 0} /* terminate */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
146 }; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
147 |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
148 while((result = getopt_long(argc, argv, "p:c:e:t:hvli", |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
149 long_options, &option_index)) != -1) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
150 switch(result) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
151 case 'h': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
152 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
153 show_usage(argv[0]); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
154 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
155 show_options(); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
156 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
157 show_channels(); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
158 fprintf(stderr, "\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
159 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
160 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
161 case 'v': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
162 fprintf(stderr, "%s %s\n", argv[0], version); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
163 fprintf(stderr, "control command for recpt1.\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
164 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
165 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
166 case 'l': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
167 show_channels(); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
168 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
169 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
170 /* following options require argument */ |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
171 case 'p': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
172 key = (key_t)atoi(optarg); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
173 fprintf(stderr, "Pid = %d\n", key); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
174 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
175 case 'c': |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
176 channel = optarg; |
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
177 fprintf(stderr, "Channel = %s\n", channel); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
178 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
179 case 'e': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
180 parse_time(optarg, &extsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
181 fprintf(stderr, "Extend %d sec\n", extsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
182 break; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
183 case 't': |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
184 parse_time(optarg, &recsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
185 fprintf(stderr, "Total recording time = %d sec\n", recsec); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
186 break; |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
187 case 'i': |
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
188 sid_list = optarg; |
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
189 break; |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
190 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
191 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
192 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
193 if(!key) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
194 fprintf(stderr, "Arguments are necessary!\n"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
195 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
196 exit(1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
197 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
198 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
199 if ((msqid = msgget(key, msgflg )) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
200 perror("msgget"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
201 exit(1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
202 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
203 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
204 sbuf.mtype = 1; |
164
7d8a5bb874ad
EXPERIMENTAL: Change phisical channel by mq_recv().
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
124
diff
changeset
|
205 sprintf(sbuf.mtext, "ch=%s t=%d e=%d i=%s", channel, recsec, extsec, sid_list); |
78
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
206 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
207 buf_length = strlen(sbuf.mtext) + 1 ; |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
208 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
209 if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) { |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
210 perror("msgsnd"); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
211 exit(1); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
212 } |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
213 |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
214 exit(0); |
5a0126d8af17
landed ipc control functionality branch
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
215 } |