lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * * Copyright 2023 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | * |
| 19 | */ |
| 20 | #include "zlog_com.h" |
| 21 | |
| 22 | /** |
| 23 | * ºê¶¨Òå |
| 24 | */ |
| 25 | |
| 26 | /** |
| 27 | * Íⲿ±äÁ¿ÒýÓà |
| 28 | */ |
| 29 | extern int port; |
| 30 | extern int debug; |
| 31 | extern char *machinename; |
| 32 | extern char *sttyparms; |
| 33 | extern char *linkname; |
| 34 | extern int isdaemon; |
| 35 | extern int curConnects; |
| 36 | extern int writeonly; |
| 37 | extern char *sdevname; |
| 38 | extern int maxConnects; |
| 39 | extern T_COMM_FS_PARAM gFsSaveParam; |
| 40 | |
| 41 | /** |
| 42 | * Íⲿº¯ÊýÉùÃ÷ |
| 43 | */ |
| 44 | extern int zLogAgt_Savefs_Main(int fd_devfile); |
| 45 | extern int zLogAgt_NetSerial_Main(int fd_usb); |
| 46 | |
| 47 | /** |
| 48 | * È«¾Ö±äÁ¿¶¨Òå |
| 49 | */ |
| 50 | |
| 51 | /** |
| 52 | * ¾Ö²¿º¯ÊýÉùÃ÷ |
| 53 | */ |
| 54 | static void pusage(char *progname); |
| 55 | |
| 56 | /** |
| 57 | * ¾Ö²¿º¯Êý¶¨Òå |
| 58 | */ |
| 59 | int zLogAgt_argv_proc(int argc, char *argv[]) |
| 60 | { |
| 61 | int opt; |
| 62 | extern char *optarg; |
| 63 | |
| 64 | while ((opt=getopt(argc,argv,"ed:f:t:m:p:r:s:l:wx:")) != EOF) |
| 65 | switch (opt) { |
| 66 | case 'd': |
| 67 | sdevname = optarg; |
| 68 | break; |
| 69 | case 'f': |
| 70 | gFsSaveParam.localFsPath = optarg; |
| 71 | break; |
| 72 | case 't': |
| 73 | gFsSaveParam.tMaxLogsize = atoi(optarg); |
| 74 | break; |
| 75 | case 'e': |
| 76 | isdaemon = 1; |
| 77 | break; |
| 78 | case 'm': |
| 79 | maxConnects = atoi(optarg); |
| 80 | break; |
| 81 | case 'p': |
| 82 | port = atoi(optarg); |
| 83 | break; |
| 84 | case 'r': |
| 85 | machinename = optarg; |
| 86 | break; |
| 87 | case 's': |
| 88 | sttyparms = optarg; |
| 89 | break; |
| 90 | case 'l': |
| 91 | linkname = optarg; |
| 92 | break; |
| 93 | case 'x': |
| 94 | debug = atoi(optarg); |
| 95 | break; |
| 96 | case 'w': |
| 97 | writeonly = 1; |
| 98 | break; |
| 99 | default: |
| 100 | pusage(argv[0]); |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | static void pusage(char *progname) |
| 106 | { |
| 107 | printf("log trace serial version 1.3. Usage:\n"); |
| 108 | printf("local save:[-d devicepath] [-f \"log save path\"][-s \"stty params\"] \n\n"); |
| 109 | printf("net serial:[-d devicepath] [-r machinename] [-p netport] [-s \"stty params\"] [-m maxconnect] \n\n"); |
| 110 | printf("-d devpath I/O device, either serial port or pseudo-tty master: (for example: ttyUSB0)\n"); |
| 111 | printf("-f local fs path Specifiy log save path: (for example: /tmp/logfile)\n"); |
| 112 | printf("-t total log size Specifiy the total log size can be saved /\n"); |
| 113 | printf("-r machinename The remote machine name to connect to. If not\n"); |
| 114 | printf(" specified, then this is the server side.\n"); |
| 115 | printf("-p netport Specifiy IP port# (default 23000)\n"); |
| 116 | printf("-s \"stty params\" If serial port, specify stty parameters, see man stty\n"); |
| 117 | printf("-m max-connections Maximum number of simultaneous client connections to allow\n"); |
| 118 | printf("-e Run as a daemon program\n"); |
| 119 | printf("-x debuglevel Set debug level, 0 is default, 1,2 give more info\n"); |
| 120 | printf("-l linkname If the device name is a pseudo-tty, create a link to the slave\n"); |
| 121 | printf("-w Only write to the device, no reading\n"); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * main º¯Êý¶¨Òå |
| 126 | */ |
| 127 | int main(int argc, char *argv[]) |
| 128 | { |
| 129 | int devfd = 0; |
| 130 | |
| 131 | zLogAgt_argv_proc(argc, argv); |
| 132 | |
| 133 | if (sdevname == NULL) { |
| 134 | printf("devpath is not config\n"); |
| 135 | exit(1); |
| 136 | } |
| 137 | |
| 138 | devfd = open(sdevname, O_RDWR, 0755); |
| 139 | if (devfd < 0) { |
| 140 | printf("Open of %s failed: %m\n", sdevname); |
| 141 | exit(2); |
| 142 | } |
| 143 | |
| 144 | if (sttyparms) |
| 145 | set_tty(devfd, sttyparms); |
| 146 | else |
| 147 | set_tty(devfd, ZLOG_DEFAULT_TTYBAUD); |
| 148 | |
| 149 | /*Èç¹û±£´æµ½´ó°å±¾µØÎļþϵͳ*/ |
| 150 | if(gFsSaveParam.localFsPath) |
| 151 | zLogAgt_Savefs_Main(devfd); |
| 152 | else |
| 153 | zLogAgt_NetSerial_Main(devfd); |
| 154 | } |
| 155 | |