summaryrefslogtreecommitdiff
path: root/src/MtsIoSysfs.cpp
blob: c7e892a6c40ec4f8e06aede5b5140a92bc468364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**********************************************************************
 * COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC.
 *
 * ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF
 * MULTI-TECH SYSTEMS, INC.
 *
 * MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY
 * INFORMATION AND/OR TRADE SECRET.
 *
 * NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION,
 * DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL
 * INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC.
 * USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A
 * WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED.
 *
 ***********************************************************************/

#include "Device.h"

#define COMMMAND_EXTRA "--"
#define COMMMAND_INIT "init"
#define COMMMAND_JSON "json"
#define COMMMAND_LOAD_FPGA "load-fpga"
#define COMMMAND_SHOW "show"
#define COMMMAND_SHOW_TRIGGER "show-trigger"
#define COMMMAND_STORE "store"
#define COMMMAND_STORE_TRIGGER "store-trigger"
#define COMMMAND_VERSION "version"

enum action_code {
    ACTION_NONE,
    ACTION_VERSION,
    ACTION_INIT,
    ACTION_JSON,
    ACTION_LOAD_FPGA,
    ACTION_SHOW,
    ACTION_SHOW_TRIGGER,
    ACTION_STORE,
    ACTION_STORE_TRIGGER,
};

static enum action_code action;

int main(int argc, char **argv) {
    Device m;
    action = ACTION_NONE;
    if (argc < 2) {
        m.printUsage(argv[0]);
    }
    std::string fpgaFilePath = "";
    std::string forcedAP = "";
    std::string name = "";
    std::string data = "";

    MTS::Logger::setPrintLevel(MTS::Logger::PrintLevel::INFO_LEVEL, true);
    int c;
    static struct option long_options[] = {
        {"help", no_argument, nullptr, 'h'},
        {"data", required_argument, nullptr, 'd'},
        {"input", required_argument, nullptr, 'i'},
        {"init", no_argument, nullptr, 'I'},
        {"json", no_argument, nullptr, 'j'},
        {"load-fpga", optional_argument, nullptr, 'l'},
        {"path", required_argument, nullptr, 'p'},
        {"show", required_argument, nullptr, 's'},
        {"show-trigger", required_argument, nullptr, 'S'},
        {"store", required_argument, nullptr, 't'},
        {"show-trigger", required_argument, nullptr, 'T'},
        {"version", no_argument, nullptr, 'v'},
        {"verbose", no_argument, nullptr, 'V'},
        {nullptr, no_argument, nullptr, 0}};

    for (;;) {
        int option_index = 0;

        c = getopt_long(argc, argv, "d:hi:Ijl:p:s:St:T:vV", long_options,
                        &option_index);
        if (c == -1)
            break;
        switch (c) {
        case 'v': {
            action = ACTION_VERSION;
            break;
        }
        case 'V': {
            MTS::Logger::setPrintLevel(MTS::Logger::PrintLevel::DEBUG_LEVEL,
                                       true);
            break;
        }
        case 'd': {
            data = optarg;
            break;
        }
        case 'i': {
            fpgaFilePath = optarg;
            break;
        }
        case 'p': {
            forcedAP = optarg;
            break;
        }
        case 'I': {
            action = ACTION_INIT;
            break;
        }
        case 'j': {
            action = ACTION_JSON;
            break;
        }
        case 's': {
            action = ACTION_SHOW;
            name = optarg;
            break;
        }
        case 'S': {
            action = ACTION_SHOW_TRIGGER;
            name = optarg;
            break;
        }
        case 't': {
            action = ACTION_STORE;
            name = optarg;
            break;
        }
        case 'T': {
            action = ACTION_STORE_TRIGGER;
            name = optarg;
            break;
        }
        case 'L': {
            action = ACTION_LOAD_FPGA;
            break;
        }
        case '?': {
            printError("%s option requires arguement", optopt);
            break;
        }
        case 'h':
        default:
            m.printUsage(argv[0]);
            exit(0);
        }
    }

    /* Handle old non POSIX compliant command names. */
    int index;
    for (index = optind; index < argc; index++) {
        if (strcmp(argv[index], COMMMAND_INIT) == 0) {
            action = ACTION_INIT;
        } else if (strcmp(argv[index], COMMMAND_JSON) == 0) {
            action = ACTION_JSON;
        } else if (strcmp(argv[index], COMMMAND_SHOW) == 0) {
            if (argv[index + 1]) {
                action = ACTION_SHOW;
                name = argv[index + 1];
            } else {
                action = ACTION_NONE;
            }
        } else if (strcmp(argv[index], COMMMAND_STORE) == 0) {
            if (argv[index + 1]) {
                action = ACTION_STORE;
                name = argv[index + 1];
                if (argv[index + 2]) {
                    data = argv[index + 2];
                }
            } else {
                action = ACTION_NONE;
            }
        } else if (strcmp(argv[index], COMMMAND_SHOW_TRIGGER) == 0) {
            if (argv[index + 1]) {
                action = ACTION_SHOW_TRIGGER;
                name = argv[index + 1];
            } else {
                action = ACTION_NONE;
            }
        } else if (strcmp(argv[index], COMMMAND_STORE_TRIGGER) == 0) {
            if (argv[index + 1]) {
                action = ACTION_STORE_TRIGGER;
                name = argv[index + 1];
                if (argv[index + 2]) {
                    data = argv[index + 2];
                }
            } else {
                action = ACTION_NONE;
            }
        } else if (strcmp(argv[index], COMMMAND_LOAD_FPGA) == 0) {
            action = ACTION_LOAD_FPGA;
        } else if (strcmp(argv[index], COMMMAND_VERSION) == 0) {
            action = ACTION_VERSION;
        } else if (strcmp(argv[index], COMMMAND_EXTRA) == 0) {
            if (argv[index + 1]) {
                data = argv[index + 1];
            }
        }
    }

    switch (action) {
    case ACTION_NONE: {
        m.printUsage(argv[0]);
    }
    case ACTION_SHOW: {
        m.show(name);
    }
    case ACTION_SHOW_TRIGGER: {
        m.showTrigger(name);
    }
    case ACTION_STORE: {
        m.store(name, data);
    }
    case ACTION_STORE_TRIGGER: {
        m.storeTrigger(name, data);
    }
    case ACTION_INIT: {
        m.init();
    }
    case ACTION_JSON: {
        m.json();
    }
    case ACTION_LOAD_FPGA: {
        Mtac15Fpga mtac15Fpga(fpgaFilePath, forcedAP);
        return mtac15Fpga.upgradeFpga();
    }
    case ACTION_VERSION: {
        m.printVersion(argv[0]);
    }
    default: { m.printUsage(argv[0]); }
    }

    return 0;
}