From: hadaq Date: Sun, 18 Jul 2010 21:51:07 +0000 (+0000) Subject: new error handling X-Git-Tag: v6.0~246 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=944ccbd1a98ad122d5391576748f667bebb0ee75;p=trbnettools.git new error handling --- diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 7fcdb60..1809bd4 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -34,17 +35,54 @@ static int hexMode = HEXMODE; -static const char trbcmd_version[] = "$Revision: 2.54 $"; +static const char trbcmd_version[] = "$Revision: 2.55 $"; #define BACKLOG 10 static uint16_t tcp_port = 55555; static int tcp_debug = 0; /* turn to 0 to suppress TCP/IP output */ -/* ---- User Buffer Size ----------------------------------------------- */ +/* ---- User Buffer Size ------------------------------------------------ */ static const size_t NUM_ENDPOINTS = 1024; /* Maximum of 16KByte */ static size_t USER_BUFFER_SIZE = 0; +/* ---- Error Handling -------------------------------------------------- */ + +static FILE *scriptFile = NULL; +static unsigned int lineCtr = 0; + +typedef enum { + INVALID = 0, + DEBUG = 1, + WARNING = 2, + ERROR = 3 +} ErrType; + +static const char errTypeString[4][32] = { + ">INVALID", + ">DEBUG", + ">WARNING", + ">ERROR" +}; + +static void logError(int type, const char* format, ...) +{ + char fmt[512] = ""; + va_list args; + + va_start(args, format); + + if (scriptFile != NULL) { + snprintf(fmt, 512, "%s: Line #%d: %s", + errTypeString[type], lineCtr, format); + } else { + snprintf(fmt, 512, "%s: %s", errTypeString[type], format); + } + + vfprintf(stderr, fmt, args); + va_end(args); +} + /* ------ MAIN ---------------------------------------------------------- */ void usage(const char *progName) @@ -132,7 +170,6 @@ void usage(const char *progName) int start(int argc, char **argv) { - FILE *scriptFile = NULL; char scriptFileName[256] = ""; char cmd[CMD_MAX_NUM][CMD_SIZE]; char *cmdLine = NULL; @@ -198,23 +235,22 @@ int start(int argc, char **argv) if (strlen(scriptFileName) > 0) { if (strncmp(scriptFileName, "-", 256) == 0) { scriptFile = stdin; - fprintf(stderr, "name: %s\n", "STDIN"); } else { scriptFile = fopen(scriptFileName, "r"); if (scriptFile == NULL) { - fprintf(stderr, "Error opening ScriptFile '%s': %s\n", - scriptFileName, strerror(errno)); + logError(ERROR, "opening ScriptFile '%s': %s\n", + scriptFileName, strerror(errno)); return -1; } } } - + /* Start repeat-loop */ while ((loop == -1) || (loopCtr++ < loop)) { - unsigned int lineCtr = 0; ssize_t scriptStatus = 0; /* Start script-file-loop */ + lineCtr = 0; while (scriptStatus != -1) { if (scriptFile == NULL) { /* Get command from function-call */ @@ -243,7 +279,7 @@ int start(int argc, char **argv) continue; } else { /* Error reading line */ - fprintf(stderr, "Error reading script-file\n"); + logError(ERROR, "reading rewind script-file\n"); return -1; } } @@ -257,7 +293,6 @@ int start(int argc, char **argv) } /* Split up cmdLine */ - sscanf(cmdLine, "%s %s %s %s %s %s %s %s %s %s", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], cmd[8], cmd[9]); @@ -285,11 +320,7 @@ int start(int argc, char **argv) uint32_t value = 0; if (cmdLen != 4) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -305,22 +336,12 @@ int start(int argc, char **argv) } if (trb_register_write(trb_address, reg_address, value) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("write_register failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "write_register failed %s\n"); + return -1; } else { - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bit(s) have been set:\n%s\n", + trb_strterm(trb_term)); } } @@ -335,11 +356,7 @@ int start(int argc, char **argv) int i; if (cmdLen != 3) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -360,27 +377,18 @@ int start(int argc, char **argv) status = trb_register_read(trb_address, reg_address, data, NUM_ENDPOINTS * 2); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("read_register failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "read_register failed %s\n", + trb_strerror(trb_errno)); } else { for (i = 0; i < status; i += 2) { fprintf(stdout, "0x%04x 0x%08x\n", data[i], data[i + 1]); } - + /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); - } + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bit(s) have been set:\n%s\n", + trb_strterm(trb_term)); + } } free(data); @@ -400,11 +408,7 @@ int start(int argc, char **argv) unsigned int i; if (cmdLen != 5) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -430,13 +434,9 @@ int start(int argc, char **argv) status = trb_register_read_mem(trb_address, reg_address, option, size, data, USER_BUFFER_SIZE); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("read_register_mem failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "read_register_mem failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { /* Print data-buffer */ p = data; @@ -451,13 +451,9 @@ int start(int argc, char **argv) } } /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } free(data); @@ -479,11 +475,7 @@ int start(int argc, char **argv) int status; if (cmdLen != 5) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -498,7 +490,7 @@ int start(int argc, char **argv) } else { file = fopen(fileName, "r"); if (file == NULL) { - fprintf(stderr, "Error opening file '%s': %s\n", + logError(ERROR, "opening file '%s': %s\n", fileName, strerror(errno)); return -1; } @@ -534,25 +526,17 @@ int start(int argc, char **argv) status = trb_register_write_mem(trb_address, reg_address, option, data, size); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("write_register_memory failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "write_register_memory failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } - + free(data); } else if (strncmp(cmd[0], "i", CMD_SIZE) == 0) { @@ -566,11 +550,7 @@ int start(int argc, char **argv) unsigned int i; if (cmdLen != 2) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -588,13 +568,9 @@ int start(int argc, char **argv) status = trb_read_uid(trb_address, uidBuffer, NUM_ENDPOINTS * 4); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("read_uid failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "read_uid failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { for (i = 0; ((i < (unsigned int)status) && (i < NUM_ENDPOINTS * 4)); @@ -604,13 +580,9 @@ int start(int argc, char **argv) uidBuffer[i], uidBuffer[i + 1], uidBuffer[i + 2]); } /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } @@ -627,11 +599,7 @@ int start(int argc, char **argv) uint16_t trb_address = 0; if (cmdLen != 4) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -649,25 +617,17 @@ int start(int argc, char **argv) } if (trb_set_address(uid, endpoint, trb_address) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("set_address failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "set_address failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } - + } else if (strncmp(cmd[0], "T", CMD_SIZE) == 0) { /*******************************************/ @@ -680,11 +640,7 @@ int start(int argc, char **argv) uint16_t number = 0; if (cmdLen != 5) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -712,22 +668,14 @@ int start(int argc, char **argv) } if (trb_send_trigger(type, info, random, number) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("send_trigger failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "send_trigger failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } @@ -738,11 +686,7 @@ int start(int argc, char **argv) /*******************************************/ if (cmdLen != 1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -752,10 +696,7 @@ int start(int argc, char **argv) } if (network_reset() == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("TRBNet RESET failed"); + logError(ERROR, "TRBNet RESET failed\n"); return -1; } @@ -766,11 +707,7 @@ int start(int argc, char **argv) /*******************************************/ if (cmdLen != 1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -780,10 +717,8 @@ int start(int argc, char **argv) } if (com_reset() == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("Etrax RESET failed"); + logError(ERROR, "Etrax RESET failed: %s\n", + trb_strerror(trb_errno)); return -1; } @@ -794,11 +729,7 @@ int start(int argc, char **argv) /*********************************************/ if (cmdLen != 2) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -811,25 +742,17 @@ int start(int argc, char **argv) } if (trb_register_write(trb_address, 0x0020, 0x8000) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("FPGA reload failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "FPGA reload failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } - + } else if (strncmp(cmd[0], "TR", CMD_SIZE) == 0) { /*********************************************/ @@ -843,11 +766,7 @@ int start(int argc, char **argv) uint16_t number = 0; if (cmdLen != 6) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -878,22 +797,14 @@ int start(int argc, char **argv) } if (trb_send_trigger_rich(input, type, info, random, number) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("send_trigger failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "send_trigger failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } @@ -912,11 +823,7 @@ int start(int argc, char **argv) int i; if (cmdLen != 5) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -950,26 +857,17 @@ int start(int argc, char **argv) status = trb_ipu_data_read(type, info, random, number, buffer, USER_BUFFER_SIZE); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("read_ipu_data failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "read_ipu_data failed: %s\n", + trb_strerror(trb_errno)); + return -1; } else { for (i = 0; i < status; i++) { fprintf(stdout, "0x%08x\n", buffer[i]); } - /* Check Status-Bits */ - if ((trb_term.status_common != 0x01) || - (trb_term.status_channel != 0)) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - fprintf(stderr, "WARNING Status-Bits:\n%s\n", - trb_strterm(trb_term)); + if (trb_errno == TRB_STATUS_WARNING) { + logError(WARNING, "Status-Bits are active:\n%s\n", + trb_strterm(trb_term)); } } @@ -984,11 +882,7 @@ int start(int argc, char **argv) uint8_t channel = 0; if (cmdLen != 2) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -998,10 +892,8 @@ int start(int argc, char **argv) } if (trb_fifo_flush(channel) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("trb_fifo_flush failed"); + logError(ERROR, "trb_fifo_flush failed: %s\n", + trb_strerror(trb_errno)); return -1; } @@ -1015,11 +907,7 @@ int start(int argc, char **argv) uint16_t reg_address = 0; if (cmdLen != 2) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -1032,10 +920,8 @@ int start(int argc, char **argv) } if (fpga_register_read(reg_address, &value) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("fpga_register_read failed"); + logError(ERROR, "fpga_register_read failed: %s\n", + trb_strerror(trb_errno)); return -1; } else { fprintf(stdout, "0x%04x 0x%08x\n", reg_address, value); @@ -1051,11 +937,7 @@ int start(int argc, char **argv) uint16_t reg_address = 0; if (cmdLen != 3) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -1070,10 +952,7 @@ int start(int argc, char **argv) } if (fpga_register_write(reg_address, value) == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("fpga_register_write failed"); + logError(ERROR, "fpga_register_write failed\n"); return -1; } @@ -1088,11 +967,7 @@ int start(int argc, char **argv) uint32_t bitMask; if (cmdLen != 4) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -1111,13 +986,9 @@ int start(int argc, char **argv) status = trb_register_modify(trb_address, reg_address, 1, bitMask, 0); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("setbit of register failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "setbit of register failed: %s\n", + trb_strerror(trb_errno)); + return -1; } } else if (strncmp(cmd[0], "clearbit", CMD_SIZE) == 0) { @@ -1131,11 +1002,7 @@ int start(int argc, char **argv) uint32_t bitMask; if (cmdLen != 4) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -1154,13 +1021,10 @@ int start(int argc, char **argv) status = trb_register_modify(trb_address, reg_address, 2, bitMask, 0); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("clearbit of register failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "clearbit of register failed: %s\n", + trb_strerror(trb_errno)); + + return -1; } } else if (strncmp(cmd[0], "loadbit", CMD_SIZE) == 0) { @@ -1175,11 +1039,7 @@ int start(int argc, char **argv) uint32_t bitValue; if (cmdLen != 5) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } @@ -1199,13 +1059,9 @@ int start(int argc, char **argv) status = trb_register_modify(trb_address, reg_address, 3, bitMask, bitValue); if (status == -1) { - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: ", lineCtr); - } - trb_error("loadbit of register failed"); - if (trb_errno != TRB_ENDPOINT_NOT_REACHED) { - return -1; - } + logError(ERROR, "loadbit of register failed: %s\n", + trb_strerror(trb_errno)); + return -1; } } else { @@ -1214,11 +1070,7 @@ int start(int argc, char **argv) /* Not a valid command */ /*******************************************/ - if (scriptFile != NULL) { - fprintf(stderr, "Line #%d: Invalid command\n", lineCtr); - } else { - usage(basename(argv[0])); - } + logError(ERROR, "Invalid command, try -h option\n"); return -1; } } /* End script-file-loop */ @@ -1381,8 +1233,6 @@ int main(int argc, char **argv) /* Enter an infinite loop to accept clients */ while (1) { socklen_t sin_size = sizeof(struct sockaddr_in); - ssize_t msgLen = 0; - char command[256]; if (tcp_debug > 0) { fprintf(stderr, "\n\nlisten...\n\n"); @@ -1420,6 +1270,12 @@ int main(int argc, char **argv) stderr = clientout; while (1) { + int start_argc = 0; + char *start_argv[256]; + int start_arg = 0; + char command[256] = ""; + ssize_t msgLen = 0; + msgLen = recv(myFd, (void *)command, 256, 0); if (msgLen == -1) { perror("Error recv"); @@ -1437,11 +1293,7 @@ int main(int argc, char **argv) } msgLen -= 2; command[msgLen] = '\0'; - - int start_argc = 0; - char *start_argv[256]; - int start_arg = 0; - + start_argv[start_argc++] = argv[0]; for (i = 0; i < (unsigned int)msgLen; i++) { if (isspace((int)command[i]) != 0) { diff --git a/libtrbnet/trberror.c b/libtrbnet/trberror.c index 1f90b99..ea3e518 100644 --- a/libtrbnet/trberror.c +++ b/libtrbnet/trberror.c @@ -52,13 +52,14 @@ const char* trb_strerror(int trberrno) "Invalid data-length give by Header", "FIFO Incomplete, missing", "SEMAPHORE Error", - "FIFO Shared Memory Error" + "FIFO Shared Memory Error", + "Termination Status Warning" }; - if (trberrno < 26) { + if (trberrno < 27) { return errorstring[trberrno]; } else { - return "Unknown Errno"; + return ">Unknown Errno"; } } @@ -71,19 +72,21 @@ const char* trb_strterm(TRB_TERM term) "COM_Checksum: checksum error", /* error */ "COM_DontUnderstand: endpoint doesn't understand data", /* error */ "COM_BufferMismatch: buffer numbers (EOB and ACK) mismatch", /* error */ - "COM_AnswerMissing: One2 endpoint didn't react", /* status */ - "", "", "", "", "", "", "", "", "" + "COM_AnswerMissing: One endpoint didn't react", /* status */ + "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", + "INVALID", "INVALID", "INVALID" }; static const char ch0StatusBits[16][64] = { "Ch0_TrigCtr: trigger counter mismatch", /* status */ "Ch0_TrigMissing: timing trigger missing", /* status */ - "", - "", + "INVALID", + "INVALID", "Ch0_BuffersHalfFull: data-buffers half full", /* status */ "Ch0_BuffersFull: data-buffers almost full", /* status */ "Ch0_NotConfigured: endpoint is not configured", /* status */ - "", "", "", "", "", "", "", "", "" + "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", + "INVALID", "INVALID", "INVALID" }; static const char ch1StatusBits[16][64] = { @@ -95,19 +98,23 @@ const char* trb_strterm(TRB_TERM term) "Ch1_DataMissing: parts of the data are missing",/* status */ "Ch1_Sync: serious sync problem detected", /* status */ "Ch1_EvtBroken: event data corrupted", /* status */ - "", "", "", "", "", "", "", "" + "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", + "INVALID", "INVALID", "INVALID" }; static const char ch2StatusBits[16][64] = { - "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "" + "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", + "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", + "INVALID", "INVALID", "INVALID", "INVALID" }; static const char ch3StatusBits[16][64] = { "Ch3_Address: unknown address", /* status */ "Ch3_Timeout: timeout error", /* error */ "Ch3_NoMoreData: no more data" /* status */ - "", "", "", "", "", "", "", "", "", "", "", "", "" + "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", + "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", + "INVALID" }; static const char *chStatusBits[4] = { @@ -121,19 +128,19 @@ const char* trb_strterm(TRB_TERM term) unsigned int i; if (term.channel >= 4) { - sprintf(buffer, "INVALID ChannelId %d", term.channel); + sprintf(buffer, ">INVALID ChannelId %d", term.channel); return buffer; } sprintf(buffer, - "CommonStatusBits: 0x%04x, Channel#%d StatusBits: 0x%04x", + ">CommonStatusBits: 0x%04x, Channel#%d StatusBits: 0x%04x", term.status_common, term.channel, term.status_channel); for (i = 0; i < 16; i++) { if ((term.status_common & (0x01 << i)) != (i != 0 ? 0 : 1)) { - strcat(buffer, "\n "); + strcat(buffer, "\n> "); strcat(buffer, commonStatusBits[i]); } } @@ -151,11 +158,11 @@ const char* trb_strerrorf() { static char buffer[4096] = ""; - if (trb_errno == TRB_STATUS_ERROR) { - snprintf(buffer, 4096, "%s\n%s", + if ((trb_errno == TRB_STATUS_ERROR) || (trb_errno == TRB_STATUS_WARNING)) { + snprintf(buffer, 4096, ">%s\n>%s", trb_strerror(trb_errno), trb_strterm(trb_term)); } else { - snprintf(buffer, 4096, "%s", trb_strerror(trb_errno)); + snprintf(buffer, 4096, ">%s", trb_strerror(trb_errno)); } return buffer; diff --git a/libtrbnet/trberror.h b/libtrbnet/trberror.h index 9b1a768..695b798 100644 --- a/libtrbnet/trberror.h +++ b/libtrbnet/trberror.h @@ -33,7 +33,8 @@ typedef enum { TRB_HDR_DLEN = 22, TRB_FIFO_INCOMPLETE = 23, TRB_SEMAPHORE = 24, - TRB_FIFO_SHARED_MEM = 25 + TRB_FIFO_SHARED_MEM = 25, + TRB_STATUS_WARNING = 26 } TRB_ERROR; extern int trb_errno; diff --git a/libtrbnet/trbnet.c b/libtrbnet/trbnet.c index c982f4f..f53fd35 100644 --- a/libtrbnet/trbnet.c +++ b/libtrbnet/trbnet.c @@ -1,4 +1,4 @@ -const char trbnet_version[] = "$Revision: 2.68 $"; +const char trbnet_version[] = "$Revision: 2.69 $"; #include #include @@ -912,21 +912,28 @@ static int trb_fifo_read(uint8_t channel, } /* Check StatusBits of TerminationPackage */ +#if 0 if ((trb_term.status_common == 0) && (trb_term.status_channel == 0)) { trb_errno = TRB_ENDPOINT_NOT_REACHED; return -1; } +#endif if ((trb_term.status_common & 0x0003e) != 0) { trb_errno = TRB_STATUS_ERROR; return -1; } - + if ((channel == 3) && ((trb_term.status_channel & 0x0002) != 0)) { trb_errno = TRB_STATUS_ERROR; return -1; } + if ((trb_term.status_common != 0x01) || + (trb_term.status_channel != 0)) { + trb_errno = TRB_STATUS_WARNING; + } + return dataCtr; }