Skip to content

Commit

Permalink
error message with function name where the error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
meierb committed Aug 10, 2013
1 parent c03a036 commit 226c0f8
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions psi46test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -122,7 +122,7 @@ int main(int argc, char* argv[])

cmd();
}
catch (CRpcError e)
catch (CRpcError &e)
{
e.What();
}
Expand Down
10 changes: 5 additions & 5 deletions psi46test.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions psi46test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<ClCompile Include="psi46test.cpp" />
<ClCompile Include="rpc.cpp" />
<ClCompile Include="rpc_calls.cpp" />
<ClCompile Include="rpc_error.cpp" />
<ClCompile Include="test_dig.cpp" />
<ClCompile Include="usb.cpp">
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">All</AssemblerOutput>
Expand Down
3 changes: 3 additions & 0 deletions psi46test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<ClCompile Include="win32\rs232.cpp">
<Filter>Quellcodedateien</Filter>
</ClCompile>
<ClCompile Include="rpc_error.cpp">
<Filter>Quellcodedateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="command.h">
Expand Down
3 changes: 2 additions & 1 deletion rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
43 changes: 43 additions & 0 deletions rpc_error.cpp
Original file line number Diff line number Diff line change
@@ -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());
}
35 changes: 7 additions & 28 deletions rpc_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#pragma once

#include <stdio.h>
#include <string>


class CRpcError
{
Expand All @@ -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();
};
2 changes: 1 addition & 1 deletion rpcgen/datatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
9 changes: 7 additions & 2 deletions rpcgen/rpcgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,19 @@ 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;
plist.Read(parameter);

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"
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test_dig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}


Expand Down

0 comments on commit 226c0f8

Please sign in to comment.