From 226c0f89b408f553dab9956db8fc9f8317df0f42 Mon Sep 17 00:00:00 2001 From: meierb Date: Sat, 10 Aug 2013 20:52:11 +0200 Subject: [PATCH] error message with function name where the error occurs --- Makefile | 2 +- psi46test.cpp | 4 ++-- psi46test.sln | 10 ++++----- psi46test.vcxproj | 1 + psi46test.vcxproj.filters | 3 +++ rpc.h | 3 ++- rpc_error.cpp | 43 +++++++++++++++++++++++++++++++++++++++ rpc_error.h | 35 +++++++------------------------ rpcgen/datatype.cpp | 2 +- rpcgen/rpcgen.cpp | 9 ++++++-- test_dig.cpp | 2 +- usb.cpp | 2 +- 12 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 rpc_error.cpp diff --git a/Makefile b/Makefile index 12c7651..ed8e06b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ UNAME := $(shell uname) -OBJS = cmd.o command.o pixel_dtb.o protocol.o psi46test.o rpc.o rpc_calls.o settings.o usb.o plot.o datastream.o analyzer.o chipdatabase.o defectlist.o pixelmap.o prober.o ps.o linux/rs232.o color.o error.o histo.o profiler.o scanner.o test_dig.o +OBJS = cmd.o command.o pixel_dtb.o protocol.o psi46test.o rpc.o rpc_calls.o settings.o usb.o plot.o datastream.o analyzer.o chipdatabase.o defectlist.o pixelmap.o prober.o ps.o linux/rs232.o color.o error.o histo.o profiler.o scanner.o test_dig.o rpc_error.o ifeq ($(UNAME), Darwin) CXXFLAGS = -g -Os -Wall -I/usr/local/include -Wno-logical-op-parentheses -I/usr/X11/include diff --git a/psi46test.cpp b/psi46test.cpp index 5780043..fbbf54d 100644 --- a/psi46test.cpp +++ b/psi46test.cpp @@ -89,7 +89,7 @@ int main(int argc, char* argv[]) tb.Welcome(); tb.Flush(); } - catch(CRpcError e) + catch(CRpcError &e) { e.What(); printf("ERROR: DTB software version could not be identified, please update it!\n"); @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) cmd(); } - catch (CRpcError e) + catch (CRpcError &e) { e.What(); } diff --git a/psi46test.sln b/psi46test.sln index a7dd232..feb81da 100644 --- a/psi46test.sln +++ b/psi46test.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "psi46test", "psi46test.vcxproj", "{C111528D-1041-29DE-0E8F-449670F1297A}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "psi46test", "psi46test.vcxproj", "{6F2009B6-583C-0C19-B3FF-CCB495403FBA}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rpcgen", "rpcgen\rpcgen.vcxproj", "{0E9701FB-B917-4198-86ED-7E29D670A201}" EndProject @@ -11,10 +11,10 @@ Global Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C111528D-1041-29DE-0E8F-449670F1297A}.Debug|Win32.ActiveCfg = Debug|Win32 - {C111528D-1041-29DE-0E8F-449670F1297A}.Debug|Win32.Build.0 = Debug|Win32 - {C111528D-1041-29DE-0E8F-449670F1297A}.Release|Win32.ActiveCfg = Release|Win32 - {C111528D-1041-29DE-0E8F-449670F1297A}.Release|Win32.Build.0 = Release|Win32 + {6F2009B6-583C-0C19-B3FF-CCB495403FBA}.Debug|Win32.ActiveCfg = Debug|Win32 + {6F2009B6-583C-0C19-B3FF-CCB495403FBA}.Debug|Win32.Build.0 = Debug|Win32 + {6F2009B6-583C-0C19-B3FF-CCB495403FBA}.Release|Win32.ActiveCfg = Release|Win32 + {6F2009B6-583C-0C19-B3FF-CCB495403FBA}.Release|Win32.Build.0 = Release|Win32 {0E9701FB-B917-4198-86ED-7E29D670A201}.Debug|Win32.ActiveCfg = Debug|Win32 {0E9701FB-B917-4198-86ED-7E29D670A201}.Debug|Win32.Build.0 = Debug|Win32 {0E9701FB-B917-4198-86ED-7E29D670A201}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/psi46test.vcxproj b/psi46test.vcxproj index c06214b..5604d26 100644 --- a/psi46test.vcxproj +++ b/psi46test.vcxproj @@ -161,6 +161,7 @@ + All diff --git a/psi46test.vcxproj.filters b/psi46test.vcxproj.filters index ed26b8a..0b582b8 100644 --- a/psi46test.vcxproj.filters +++ b/psi46test.vcxproj.filters @@ -90,6 +90,9 @@ Quellcodedateien + + Quellcodedateien + diff --git a/rpc.h b/rpc.h index 6e53252..1ad5906 100644 --- a/rpc.h +++ b/rpc.h @@ -48,7 +48,8 @@ extern const char rpc_timestamp[]; rpc_cmdId[x] = id = GetRpcCallId(name); \ if (id >= 0) return id; \ throw CRpcError(CRpcError::UNKNOWN_CMD); \ - } + } \ + friend class CRpcError; #define RPC_INIT rpc_io = &RpcIoNull; rpc_cmdId = new int[rpc_cmdListSize]; rpc_Clear(); diff --git a/rpc_error.cpp b/rpc_error.cpp new file mode 100644 index 0000000..f25cb87 --- /dev/null +++ b/rpc_error.cpp @@ -0,0 +1,43 @@ +// rpc_error.cpp + +#include "rpc_error.h" +#include "pixel_dtb.h" + + +const char *CRpcError::GetMsg() +{ + switch (error) + { + case OK: return "OK"; + case TIMEOUT: return "TIMEOUT"; + case WRITE_ERROR: return "WRITE_ERROR"; + case READ_ERROR: return "READ_ERROR"; + case READ_TIMEOUT: return "READ_TIMEOUT"; + case MSG_UNKNOWN: return "MSG_UNKNOWN"; + case WRONG_MSG_TYPE: return "WRONG_MSG_TYPE"; + case WRONG_DATA_SIZE: return "WRONG_DATA_SIZE"; + case ATB_MSG: return "ATB_MSG"; + case WRONG_CGRP: return "WRONG_CGRP"; + case WRONG_CMD: return "WRONG_CMD"; + case CMD_PAR_SIZE: return "CMD_PAR_SIZE"; + case NO_DATA_MSG: return "NO_DATA_MSG"; + case NO_CMD_MSG: return "NO_CMD_MSG"; + case UNKNOWN_CMD: return "UNKNOWN_CMD"; + case UNDEF: return "UNDEF"; + } + return "?"; +} + + +void CRpcError::What() +{ + if (functionId >= 0) + { + std::string fname(CTestboard::rpc_cmdName[functionId]); + std::string fname_pretty; + rpc_TranslateCallName(fname, fname_pretty); + printf("\n%s\nERROR: %s\n", fname_pretty.c_str(), GetMsg()); + } + else + printf("ERROR: %s\n", GetMsg()); +} diff --git a/rpc_error.h b/rpc_error.h index 7f3ed71..42b0a67 100644 --- a/rpc_error.h +++ b/rpc_error.h @@ -3,6 +3,8 @@ #pragma once #include +#include + class CRpcError { @@ -26,33 +28,10 @@ class CRpcError UNKNOWN_CMD, UNDEF } error; - CRpcError() : error(CRpcError::OK) {} + int functionId; + CRpcError() : error(CRpcError::OK), functionId(-1) {} CRpcError(errorId e) : error(e) {} - const char *GetMsg() - { - switch (error) - { - case OK: return "OK"; - case TIMEOUT: return "TIMEOUT"; - case WRITE_ERROR: return "WRITE_ERROR"; - case READ_ERROR: return "READ_ERROR"; - case READ_TIMEOUT: return "READ_TIMEOUT"; - case MSG_UNKNOWN: return "MSG_UNKNOWN"; - case WRONG_MSG_TYPE: return "WRONG_MSG_TYPE"; - case WRONG_DATA_SIZE: return "WRONG_DATA_SIZE"; - case ATB_MSG: return "ATB_MSG"; - case WRONG_CGRP: return "WRONG_CGRP"; - case WRONG_CMD: return "WRONG_CMD"; - case CMD_PAR_SIZE: return "CMD_PAR_SIZE"; - case NO_DATA_MSG: return "NO_DATA_MSG"; - case NO_CMD_MSG: return "NO_CMD_MSG"; - case UNKNOWN_CMD: return "UNKNOWN_CMD"; - case UNDEF: return "UNDEF"; - } - return "?"; - } - void What() - { - printf("ERROR: %s\n", GetMsg()); - } + void SetFunction(unsigned int cmdId) { functionId = cmdId; } + const char *GetMsg(); + void What(); }; diff --git a/rpcgen/datatype.cpp b/rpcgen/datatype.cpp index e38cff5..e612799 100644 --- a/rpcgen/datatype.cpp +++ b/rpcgen/datatype.cpp @@ -108,7 +108,7 @@ void CDataType::WriteRecvPar(FILE *f) if (retByteCount) { if (IsReturn()) - fprintf(f, "\t%s rpc_par0 = msg.Get_%s();\n", GetCTypeName(), GetTypeName()); + fprintf(f, "\trpc_par0 = msg.Get_%s();\n", GetTypeName()); else fprintf(f, "\trpc_par%u = msg.Get_%s();\n", id, GetTypeName()); } diff --git a/rpcgen/rpcgen.cpp b/rpcgen/rpcgen.cpp index f626e3c..1309942 100644 --- a/rpcgen/rpcgen.cpp +++ b/rpcgen/rpcgen.cpp @@ -162,7 +162,7 @@ void GenerateServerCodeTrailer(functList &fl, FILE *f) void GenerateClientEntry(FILE *f, unsigned int cmd, const char *fname, const char *parameter) { - string cmdId = string("rpc__") + fname + "$" + parameter; +// string cmdName = string(fname) + "$" + parameter; // read parameter list CParameterList plist; @@ -170,7 +170,11 @@ void GenerateClientEntry(FILE *f, unsigned int cmd, const char *fname, const cha plist.WriteCDeclaration(f, fname); fprintf(f, - "{ RPC_PROFILING\n" + "{ RPC_PROFILING\n"); + if (plist.begin()->HasRetValue()) + fprintf(f, "\t%s rpc_par0;\n", plist.begin()->GetCTypeName()); + fprintf(f, + "\ttry {\n" "\tuint16_t rpc_clientCallId = rpc_GetCallId(%u);\n" "\tRPC_THREAD_LOCK\n" "\trpcMessage msg;\n" @@ -192,6 +196,7 @@ void GenerateClientEntry(FILE *f, unsigned int cmd, const char *fname, const cha plist.WriteAllRecvDat(f); } fprintf(f, "\tRPC_THREAD_UNLOCK\n"); + fprintf(f, "\t} catch (CRpcError &e) { e.SetFunction(%u); throw; };\n", cmd); if (plist.begin()->HasRetValue()) fputs("\treturn rpc_par0;\n", f); fputs("}\n\n", f); diff --git a/test_dig.cpp b/test_dig.cpp index 22ed21f..4cf1a4f 100644 --- a/test_dig.cpp +++ b/test_dig.cpp @@ -825,7 +825,7 @@ void test_pulseheight() tb.Daq_Stop(); tb.Daq_Read(data, 4000); tb.Daq_Close(); - DumpData(data, 200); +// DumpData(data, 200); // --- plot data PixelReadoutData pix; diff --git a/usb.cpp b/usb.cpp index cad0eb9..7f4160e 100644 --- a/usb.cpp +++ b/usb.cpp @@ -130,7 +130,7 @@ void CUSB::Flush() ftStatus = FT_Write(ftHandle, m_bufferW, bytesToWrite, &bytesWritten); if (ftStatus != FT_OK) throw CRpcError(CRpcError::WRITE_ERROR); - if ((bytesWritten & 0xFFFFFFFF) != bytesToWrite) { ftStatus = FT_IO_ERROR; throw CRpcError(CRpcError::WRITE_ERROR); } + if (bytesWritten != bytesToWrite) { ftStatus = FT_IO_ERROR; throw CRpcError(CRpcError::WRITE_ERROR); } }