int stop = 0;
DECLARE_VERBOSE_LEVEL (morep, INFO);
+DECLARE_VERBOSE_LEVEL (simul, INFO);
#define BUFMAX 4096
/* read a file */
char *read_stream (FILE *sd, int *plen)
{
- VERBOSE (morep, TRACE, PRINTF ("read_stream\n"));
+ VERBOSE (simul, TRACE, PRINTF ("read_stream\n"));
/* read and store */
char *buffer = NULL;
} while (blocklen > 0);
/* check size */
- VERBOSE (morep, DEBUG, PRINTF ("read length: %d\n", length));
+ VERBOSE (simul, DEBUG, PRINTF ("read length: %d\n", length));
if (length == 0) {
free (buffer);
buffer = NULL;
case 'l':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("%s: log file not specified\n", progname));
+ VERBOSE (simul, ERROR, PRINTF ("%s: log file not specified\n", progname));
return 1;
}
logname = arg;
case 'r':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("%s: receiver url not specified\n", progname));
+ VERBOSE (simul, ERROR, PRINTF ("%s: receiver url not specified\n", progname));
return 1;
}
url = arg;
case 's':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("%s: service not specified\n", progname));
+ VERBOSE (simul, ERROR, PRINTF ("%s: service not specified\n", progname));
return 1;
}
servname = arg;
case 't':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("%s: transmitter url not specified\n", progname));
+ VERBOSE (simul, ERROR, PRINTF ("%s: transmitter url not specified\n", progname));
return 1;
}
url = arg;
case 'v':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("%s: verbose level not specified\n", progname));
+ VERBOSE (simul, ERROR, PRINTF ("%s: morep verbose level not specified\n", progname));
return 1;
}
CHANGE_VERBOSE_LEVEL (morep, atoi (arg));
break;
+ case 'V':
+ arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ VERBOSE (simul, ERROR, PRINTF ("%s: simulator verbose level not specified\n", progname));
+ return 1;
+ }
+ CHANGE_VERBOSE_LEVEL (simul, atoi (arg));
+ break;
case 'h':
default:
- printf ("usage: %s [-h] [-l log] [-r url] [-s serv] [-t url] [-v level] [file]\n", progname);
+ printf ("usage: %s [-h] [-l log] [-r url] [-s serv] [-t url] [-v level] [-V level] [file]\n", progname);
return (c != 'h');
}
}
nbcomms++;
} else {
- VERBOSE (morep, ERROR, PRINTF ("can't connect on url '%s'\n", url));
+ VERBOSE (simul, ERROR, PRINTF ("can't connect on url '%s'\n", url));
return -1;
}
} else {
- VERBOSE (morep, ERROR, PRINTF ("no more communication channel avaliable (%d)\n", nbcomms));
+ VERBOSE (simul, ERROR, PRINTF ("no more communication channel avaliable (%d)\n", nbcomms));
return -1;
}
mode = -1;
/* checks */
if (nbcomms == 0) {
- VERBOSE (morep, ERROR, PRINTF ("no communication channel\n"));
+ VERBOSE (simul, ERROR, PRINTF ("no communication channel\n"));
return -1;
}
if (filename != NULL) {
fid = fopen (filename, "r");
if (fid == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("can't open script file '%s' for reading\n", filename));
+ VERBOSE (simul, ERROR, PRINTF ("can't open script file '%s' for reading\n", filename));
return -1;
}
}
fclose (fid);
}
if (script == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("no script read\n"));
+ VERBOSE (simul, ERROR, PRINTF ("no script read\n"));
return -1;
}
} else {
log = fopen (logname, "w");
if (log == NULL) {
- VERBOSE (morep, ERROR, PRINTF ("can't open log file '%s' for writing\n", logname));
+ VERBOSE (simul, ERROR, PRINTF ("can't open log file '%s' for writing\n", logname));
return -1;
}
}
/* special keywords */
if (strncmp (line, "SLEEP", 5) == 0) {
int duration = atoi (line + 5);
- VERBOSE (morep, INFO, PRINTF ("sleep %dms\n", duration));
+ VERBOSE (simul, INFO, PRINTF ("sleep %dms\n", duration));
usleep (duration * 1000);
continue;
}
/* analyse line */
mode = (*line == 'R') ? 0 : (*line == 'T') ? 1 : -1;
if (mode == -1) {
- VERBOSE (morep, WARNING, PRINTF ("unrecognize line '%s'\n", line));
+ VERBOSE (simul, WARNING, PRINTF ("unrecognize line '%s'\n", line));
continue;
}
int offset = 1;
/* find MOREP by service name */
for (int i = 0; ((service_list + i)->service_id != noserv_e) && (serv == NULL); i++) {
service_t *s = service_list + i;
- VERBOSE (morep, TRACE, PRINTF ("test %c[%s]\n", *line, s->name));
+ VERBOSE (simul, TRACE, PRINTF ("test %c[%s]\n", *line, s->name));
if (strncmp (line + offset, s->name, strlen (s->name)) == 0) {
comm = mode ? &(s->rx) : &(s->tx);
serv = s;
/* find MOREP by ethertype */
for (int j = 0; (j < nbcomms) && (comm == NULL); j++) {
comm_t *c = comm_list + j;
- VERBOSE (morep, TRACE, PRINTF ("test %c[%s]\n", c->mode ? 'T' : 'R', c->etype));
+ VERBOSE (simul, TRACE, PRINTF ("test %c[%s]\n", c->mode ? 'T' : 'R', c->etype));
if ((strncmp (line + offset, c->etype, strlen (c->etype)) == 0) && (c->mode == mode)) {
comm = c;
for (int i = 0; ((service_list + i)->service_id != noserv_e) && (serv == NULL); i++) {
}
/* check media and service */
if ((comm == NULL) || (serv == NULL)) {
- VERBOSE (morep, TRACE, PRINTF ("no morep found '%s'\n", line));
+ VERBOSE (simul, TRACE, PRINTF ("no morep found '%s'\n", line));
continue;
}
- VERBOSE (morep, DEBUG, PRINTF ("work with %c[%s]\n", comm->mode ? 'T' : 'R', serv->name));
+ VERBOSE (simul, DEBUG, PRINTF ("work with %c[%s]\n", comm->mode ? 'T' : 'R', serv->name));
/* skip space */
tmp = line + offset;
/* get message type by name */
for (int i = 0; ((message_list + i)->service_id != noserv_e) && (msg == NULL); i++) {
message_t *m = message_list + i;
- VERBOSE (morep, TRACE, PRINTF ("test %s\n", m->name));
+ VERBOSE (simul, TRACE, PRINTF ("test %s\n", m->name));
if (strncmp (line + offset, m->name, strlen (m->name)) == 0) {
msg = m;
offset += strlen (m->name);
/* get message type by id */
if (msg == NULL) {
if (strncmp (line + offset, "MSG", 3) != 0) {
- VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
+ VERBOSE (simul, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
continue;
}
tmp = line + offset + 3;
uint8_t msgtype = strtol (tmp, &tmp, 0);
offset = tmp - line;
if ((*tmp != ' ') && (*tmp != '\t')) {
- VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
+ VERBOSE (simul, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
continue;
}
/* find message */
/* check message and service */
if (serv->service_id != msg->service_id) {
- VERBOSE (morep, WARNING, PRINTF ("message %s is not allowed for service %s (line '%s')\n", msg->name, serv->name, line));
+ VERBOSE (simul, WARNING, PRINTF ("message %s is not allowed for service %s (line '%s')\n", msg->name, serv->name, line));
continue;
}
- VERBOSE (morep, DEBUG, PRINTF ("work with message %s\n", msg->name));
+ VERBOSE (simul, DEBUG, PRINTF ("work with message %s\n", msg->name));
CHANNEL_t msg_channel = {0};
CLEAR_DATA_t msg_clear_data = {0};
parse_status (line + offset, &msg_status);
break;
default:
- VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
+ VERBOSE (simul, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
continue;
}
/* check msg type */
if (msgtype != msg->msgtype) {
- VERBOSE (morep, WARNING, PRINTF ("R%sx SEQ=%d MSG=%d: expected msgtype %d\n", comm->etype, seqnum, msgtype, msg->msgtype));
+ VERBOSE (simul, WARNING, PRINTF ("R%sx SEQ=%d MSG=%d: expected msgtype %d\n", comm->etype, seqnum, msgtype, msg->msgtype));
}
/* deserialize message */
deserial_status (payload, len, &msg_status);
break;
default:
- VERBOSE (morep, WARNING, PRINTF ("can't deserialize message R%s[%02x]'\n", comm->etype, msgtype));
+ VERBOSE (simul, WARNING, PRINTF ("can't deserialize message R%s[%02x]'\n", comm->etype, msgtype));
continue;
}
fclose (log);
}
- return rc;
+ return rc + GET_VERBOSE_ERRORS (morep) + GET_VERBOSE_ERRORS (simul);
}
/* test: morep_simulator.exe -h | grep usage */
-/* test: morep_simulator.exe -l 2>&1 | grep 'log file not specified' */
-/* test: morep_simulator.exe -r 2>&1 | grep 'url not specified' */
-/* test: morep_simulator.exe -s 2>&1 | grep 'service not specified' */
-/* test: morep_simulator.exe -t 2>&1 | grep 'url not specified' */
+/* test: morep_simulator.exe -l | grep 'log file not specified' */
+/* test: morep_simulator.exe -r | grep 'url not specified' */
+/* test: morep_simulator.exe -s | grep 'service not specified' */
+/* test: morep_simulator.exe -t | grep 'url not specified' */
+/* test: morep_simulator.exe -v | grep 'morep verbose level not specified' */
+/* test: morep_simulator.exe -V | grep 'simulator verbose level not specified' */
/* test: morep_simulator.exe -l - -t lo://00:00:00:00:00:00/0809 -v 4 script-lo.eth */
-/* test: morep_simulator.exe -l script-cross_crypto.log -s CROSS_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-cross_crypto.eth */
-/* test: morep_simulator.exe -l script-local_crypto.log -s LOCAL_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-local_crypto.eth */
-/* test: morep_simulator.exe -l script-provisioning.log -s PROVISIONING -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-provisioning.eth */
-/* test: morep_simulator.exe -l script-prng.log -s PRNG -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-prng.eth */
-/* test: morep_simulator.exe -l script-bypass.log -s BYPASS -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-bypass.eth */
-/* test: morep_simulator.exe -l script-control.log -s CONTROL -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-control.eth -v 3 */
+/* test: morep_simulator.exe -l script-cross_crypto.log -s CROSS_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-cross_crypto.eth -V 3 */
+/* test: morep_simulator.exe -l script-local_crypto.log -s LOCAL_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-local_crypto.eth -V 3 */
+/* test: morep_simulator.exe -l script-provisioning.log -s PROVISIONING -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-provisioning.eth -V 3 */
+/* test: morep_simulator.exe -l script-prng.log -s PRNG -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-prng.eth -V 3 */
+/* test: morep_simulator.exe -l script-bypass.log -s BYPASS -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-bypass.eth -V 3 */
+/* test: morep_simulator.exe -l script-control.log -s CONTROL -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-control.eth -v 3 -V 3 */
/* vim: set ts=4 sw=4 si et: */