-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisa.cpp
114 lines (95 loc) · 2.57 KB
/
lisa.cpp
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
/* LISA - LSCS Inference System Application
* (C) Dmitry 'MatrixS_Master' Solovyev, 2023-2025
* */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <sys/stat.h>
#include <string>
#include "lscs.h"
#define LISA_VERSION "0.0.4"
#define ERR(X,...) fprintf(stderr, "[LISA] ERROR: " X "\n", __VA_ARGS__)
#define ERRS(...) fprintf(stderr, "[LISA] ERROR: " __VA_ARGS__)
#ifndef NDEBUG
#define DBG(...) do { fprintf(stderr,"[LISA DBG] " __VA_ARGS__); fflush(stderr); } while (0)
#else
#define DBG(...)
#endif
using namespace std;
const char* argstrings[] = {
"-s file : load LSCS scheme",
"-t time : inter-step delay value (in ms)",
"-m file : use shutdown marker file",
NULL
};
string g_lscs_file, g_shutmark;
int g_timeout = 100;
void usage(const char* sname)
{
fprintf(stderr,"\nUsage: %s [OPTIONS]\n\nAvailable options:\n",sname);
const char** p = argstrings;
while (*p) fprintf(stderr,"\t%s\n",*p++);
fprintf(stderr,"\n\n");
}
int set_params(int argc, char* argv[])
{
int opt;
// parse params
while ((opt = getopt(argc,argv,"s:t:m:")) != -1) {
switch (opt) {
case 's':
g_lscs_file = optarg;
break;
case 't':
g_timeout = atoi(optarg);
break;
case 'm':
g_shutmark = optarg;
break;
default:
usage(argv[0]);
return -1;
}
}
// check'em
if (g_lscs_file.empty()) {
ERR("LSCS scheme file was not specified (%d args given)",argc-1);
return 1;
}
return 0;
}
int main(int argc, char* argv[])
{
fprintf(stderr,"LISA ver. " LISA_VERSION " (brain ver. " ANNA_VERSION ") starting up\n");
// get CLI arguments
if (argc < 2) {
usage(argv[0]);
return -1;
}
if (set_params(argc,argv)) return -1;
// create system
AnnaLSCS* sys = new AnnaLSCS(g_lscs_file);
if (!sys) return 10;
if (sys->getState() == ANNA_ERROR) {
ERR("Unable to create system: %s\n",sys->getError().c_str());
return 11;
}
// run main loop
while (sys->getState() != ANNA_ERROR) {
if (!g_shutmark.empty()) {
struct stat dummy;
if (!stat(g_shutmark.c_str(),&dummy)) break;
}
sys->Processing();
usleep(g_timeout * 1000);
}
// check for errors
if (sys->getState() == ANNA_ERROR)
ERR("%s\n",sys->getError().c_str());
// delete system
delete sys;
fprintf(stderr,"LISA ver. " LISA_VERSION " closing down\n");
return 0;
}