introducing tty device path as mandatory parameter
This commit is contained in:
parent
50df669b40
commit
f55a83b5fc
3 changed files with 31 additions and 11 deletions
34
moxerver.c
34
moxerver.c
|
@ -7,7 +7,8 @@
|
|||
/* Prints help message. */
|
||||
void usage() {
|
||||
//TODO maybe some styling should be done
|
||||
fprintf(stderr, "Usage: moxerver -p port [-h]\n\n");
|
||||
fprintf(stderr, "Usage: moxerver -p tcp_port -t tty_path [-h]\n");
|
||||
fprintf(stderr, "- tcp_port must be in range 4001 to 4008\n\n");
|
||||
}
|
||||
|
||||
/* MoxaNix main program loop. */
|
||||
|
@ -17,7 +18,10 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
struct server_t server;
|
||||
struct client_t client; //TODO working with only 1 client, this can be expanded into a list
|
||||
unsigned int port;
|
||||
struct tty_t tty_dev;
|
||||
|
||||
unsigned int tcp_port = -1;
|
||||
char tty_path[DEV_PATH] = {'\0'};
|
||||
|
||||
fd_set read_fds;
|
||||
int fdmax;
|
||||
|
@ -25,22 +29,26 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
|
||||
/* grab arguments */
|
||||
if (argc == 1) {
|
||||
if (argc <= 1) {
|
||||
fprintf(stderr, "error parsing arguments\n");
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
while ((ret = getopt(argc, argv, ":p:h")) != -1) {
|
||||
while ((ret = getopt(argc, argv, ":p:t:h")) != -1) {
|
||||
switch (ret) {
|
||||
/* get server port number */
|
||||
case 'p':
|
||||
port = (unsigned int) atoi(optarg);
|
||||
tcp_port = (unsigned int) atoi(optarg);
|
||||
/* check port range */
|
||||
if (port < 4001 || port > 4008) {
|
||||
if (tcp_port < 4001 || tcp_port > 4008) {
|
||||
fprintf(stderr, "error: port number out of 4001-4008 range\n");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
/* get tty device path */
|
||||
case 't':
|
||||
sprintf(tty_path, optarg);
|
||||
break;
|
||||
/* print help and exit */
|
||||
case 'h':
|
||||
usage();
|
||||
|
@ -51,15 +59,25 @@ int main(int argc, char *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
if (strlen(tty_path) == 0) {
|
||||
fprintf(stderr, "error parsing arguments\n");
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* introduction message */
|
||||
fprintf(stderr, "=== MoxaNix ===\n");
|
||||
|
||||
//TODO remove the following line after development phase
|
||||
fprintf(stderr, "TCP port: %d, TTY device path: %s\n", tcp_port, tty_path);
|
||||
|
||||
/* initialize */
|
||||
server_setup(&server, port);
|
||||
server_setup(&server, tcp_port);
|
||||
client.socket = -1;
|
||||
|
||||
//TODO this is a good place to create and start the TTY thread
|
||||
|
||||
//TODO this is a good place to create and start the TTY thread, use "tty_path" when opening device
|
||||
|
||||
|
||||
/* loop with timeouts waiting for client connection */
|
||||
while (1) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <termios.h>
|
||||
|
||||
#define DATA_BUFLEN 128
|
||||
|
||||
#define DEV_PATH 32
|
||||
|
||||
struct server_t {
|
||||
int socket; /* server socket */
|
||||
|
@ -27,6 +27,7 @@ struct client_t {
|
|||
struct tty_t {
|
||||
int fd; /* tty file descriptor */
|
||||
struct termios ttyset; /* tty termios settings */
|
||||
char path[DEV_PATH]; /* tty device path */
|
||||
char data[DATA_BUFLEN]; /* buffer for data received from tty */
|
||||
};
|
||||
|
||||
|
@ -50,7 +51,7 @@ int client_write(struct client_t *client, char *databuf, int datalen);
|
|||
|
||||
|
||||
/* Opens the tty device and configures it. */
|
||||
int tty_open(struct tty_t *tty_dev);
|
||||
int tty_open(struct tty_t *tty_dev, char* path);
|
||||
/* Closes the tty device. */
|
||||
int tty_close(struct tty_t *tty_dev);
|
||||
/* Reconfigures the tty device. */
|
||||
|
|
3
tty.c
3
tty.c
|
@ -2,11 +2,12 @@
|
|||
|
||||
|
||||
/* Opens the tty device and configures it. */
|
||||
int tty_open(struct tty_t *tty_dev) {
|
||||
int tty_open(struct tty_t *tty_dev, char* path) {
|
||||
// PROPOSAL:
|
||||
// open tty device to get file descriptor @tty_dev.fd
|
||||
// setup tty device parameters @tty_dev.ttyset
|
||||
// apply settings by calling tcsetattr(fd, ttyset)
|
||||
// on success copy path to @tty_dev.path
|
||||
return 0;
|
||||
}
|
||||
/* Closes the tty device. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue