Skip to content
This repository has been archived by the owner on Jan 31, 2022. It is now read-only.

Adding RPC manager initial structure #15

Merged
merged 6 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ OBJS_TEST = $(SRCS_TEST:.cpp=.o)
SRCS_RPC_SA = $(shell echo src/common/rpc_standalone_client/*.cpp)
OBJS_RPC_SA = $(SRCS_RPC_SA:.cpp=.o)

SRCS_RPC_MAN = $(shell echo src/common/rpc_manager/*.cc)
OBJS_RPC_MAN = $(SRCS_RPC_MAN:.cc=.o)


TARGET_LIB=${XHAL_ROOT}/lib/x86_64/libxhal.so
TARGET_TEST=${XHAL_ROOT}/test/bin/test
RPC_SA_LIB=${XHAL_ROOT}/lib/x86_64/librwreg.so
RPC_MAN_LIB=${XHAL_ROOT}/lib/x86_64/librpcman.so

all:${TARGET_LIB} ${RPC_SA_LIB}

all:${TARGET_LIB} ${TARGET_TEST} ${RPC_SA_LIB}
rpc:${RPC_MAN_LIB}

test:${TARGET_TEST}

utils:${TARGET_LIB}

Expand Down Expand Up @@ -57,9 +66,16 @@ $(RPC_SA_LIB): $(OBJS_RPC_SA)
$(OBJS_RPC_SA):$(SRCS_RPC_SA)
$(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) -L${XHAL_ROOT}/lib/x86_64 -lwiscrpcsvc -c -o $@ $<

$(RPC_MAN_LIB): $(OBJS_RPC_MAN)
$(CC) $(CCFLAGS) $(ADDFLAGS) ${LDFLAGS} $(INC) -L${XHAL_ROOT}/lib/x86_64/ -lwiscrpcsvc -o $@ $^

$(OBJS_RPC_MAN):$(SRCS_RPC_MAN)
$(CC) $(CCFLAGS) $(ADDFLAGS) $(INC) -L${XHAL_ROOT}/lib/x86_64 -lwiscrpcsvc -c $(@:%.o=%.cc) -o $@


.PHONY: clean
clean:
-${RM} ${TARGET_LIB} ${OBJS} ${OBJS_XHAL} ${TARGET_TEST} ${OBJS_TEST} ${RPC_SA_LIB} ${OBJS_RPC_SA}
-${RM} ${TARGET_LIB} ${OBJS} ${OBJS_XHAL} ${TARGET_TEST} ${OBJS_TEST} ${RPC_SA_LIB} ${OBJS_RPC_SA} ${RPC_MAN_LIB} ${OBJS_RPC_MAN}



2,001 changes: 2,001 additions & 0 deletions etc/gem_amc_v3_1_4_GBT.xml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions include/xhal/rpc/calibration_routines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CALIBRATION_ROUTINES_H
#define CALIBRATION_ROUTINES_H

#include "xhal/rpc/utils.h"

DLLEXPORT uint32_t ttcGenConf(uint32_t L1Ainterval, uint32_t pulseDelay);
DLLEXPORT uint32_t genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t enCal, uint32_t mask, char * scanReg);

#endif
13 changes: 13 additions & 0 deletions include/xhal/rpc/daq_monitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef DAQ_MONITOR_H
#define DAQ_MONITOR_H

#include "xhal/rpc/utils.h"

DLLEXPORT uint32_t getmonTTCmain(uint32_t* result);
DLLEXPORT uint32_t getmonTRIGGERmain(uint32_t* result, uint32_t noh = 12);
DLLEXPORT uint32_t getmonTRIGGEROHmain(uint32_t* result, uint32_t noh = 12);
DLLEXPORT uint32_t getmonDAQmain(uint32_t* result);
DLLEXPORT uint32_t getmonDAQOHmain(uint32_t* result, uint32_t noh = 12);
DLLEXPORT uint32_t getmonOHmain(uint32_t* result, uint32_t noh = 12);

#endif
49 changes: 49 additions & 0 deletions include/xhal/rpc/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef UTILS_H
#define UTILS_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory>
#include "xhal/rpc/wiscrpcsvc.h"

#define DLLEXPORT extern "C"

#define STANDARD_CATCH \
catch (wisc::RPCSvc::NotConnectedException &e) { \
printf("Caught NotConnectedException: %s\n", e.message.c_str()); \
return 1; \
} \
catch (wisc::RPCSvc::RPCErrorException &e) { \
printf("Caught RPCErrorException: %s\n", e.message.c_str()); \
return 1; \
} \
catch (wisc::RPCSvc::RPCException &e) { \
printf("Caught exception: %s\n", e.message.c_str()); \
return 1; \
} \
catch (wisc::RPCMsg::BadKeyException &e) { \
printf("Caught exception: %s\n", e.key.c_str()); \
return 0xdeaddead; \
}

#define ASSERT(x) do { \
if (!(x)) { \
printf("Assertion Failed on line %u: %s\n", __LINE__, #x); \
return 1; \
} \
} while (0)

static wisc::RPCSvc rpc;
static wisc::RPCMsg req, rsp;

wisc::RPCSvc* getRPCptr();
DLLEXPORT uint32_t init(char * hostname);
DLLEXPORT uint32_t getReg(uint32_t address);
DLLEXPORT uint32_t putReg(uint32_t address, uint32_t value);
DLLEXPORT uint32_t getList(uint32_t* addresses, uint32_t* result, ssize_t size);
DLLEXPORT uint32_t getBlock(uint32_t address, uint32_t* result, ssize_t size);
DLLEXPORT uint32_t update_atdb(char * xmlfilename);
DLLEXPORT uint32_t getRegInfoDB(char * regName);

#endif
8 changes: 8 additions & 0 deletions include/xhal/rpc/vfat3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef VFAT3_H
#define VFAT3_H

#include "xhal/rpc/utils.h"

DLLEXPORT uint32_t configureVFAT3s(uint32_t ohN, uint32_t vfatMask);

#endif
3 changes: 2 additions & 1 deletion python/reg_interface/rw_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#import uhal
from ctypes import *

lib = CDLL(os.getenv("XHAL_ROOT")+"/lib/x86_64/librwreg.so")
#lib = CDLL(os.getenv("XHAL_ROOT")+"/lib/x86_64/librwreg.so")
lib = CDLL(os.getenv("XHAL_ROOT")+"/lib/x86_64/librpcman.so")
rReg = lib.getReg
rReg.restype = c_uint
rReg.argtypes=[c_uint]
Expand Down
97 changes: 69 additions & 28 deletions python/reg_interface/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from ctypes import *
import timeit

lib = CDLL(os.getenv("XHAL_ROOT")+"/lib/x86_64/librwreg.so")
#lib = CDLL(os.getenv("XHAL_ROOT")+"/lib/x86_64/librwreg.so")
lib = CDLL(os.getenv("XHAL_ROOT")+"/lib/x86_64/librpcman.so")
rReg = lib.getReg
rReg.restype = c_uint
rReg.argtypes=[c_uint]
Expand All @@ -19,15 +20,15 @@
getRegInfo = lib.getRegInfoDB
getRegInfo.argtypes = [c_char_p]
getRegInfo.restype = c_uint
confTRIMDAC = lib.configureTRIMDAC
confTRIMDAC.argtypes = [c_char_p, c_char_p]
confTRIMDAC.restype = c_uint
confVT1 = lib.configureVT1
confVT1.argtypes = [c_char_p, c_char_p, c_uint]
confVT1.restype = c_uint
confVFATs = lib.configureVFATs
confVFATs.argtypes = [c_char_p, c_char_p, c_char_p, c_uint, c_uint]
confVFATs.restype = c_uint
#confTRIMDAC = lib.configureTRIMDAC
#confTRIMDAC.argtypes = [c_char_p, c_char_p]
#confTRIMDAC.restype = c_uint
#confVT1 = lib.configureVT1
#confVT1.argtypes = [c_char_p, c_char_p, c_uint]
#confVT1.restype = c_uint
#confVFATs = lib.configureVFATs
#confVFATs.argtypes = [c_char_p, c_char_p, c_char_p, c_uint, c_uint]
#confVFATs.restype = c_uint
getTTCmain = lib.getmonTTCmain
getTTCmain.argtypes = [POINTER(c_uint32)]
getTTCmain.restype = c_uint
Expand All @@ -42,32 +43,72 @@
rList.restype = c_uint
rList.argtypes=[POINTER(c_uint32),POINTER(c_uint32)]

ttcGenConf = lib.ttcGenConf
ttcGenConf.restype = c_uint
ttcGenConf.argtypes = [c_uint, c_uint]

genScan = lib.genScan
genScan.restype = c_uint
genScan.argtypes = [c_uint, c_uint, c_uint, c_uint, c_uint, c_uint, c_uint, c_uint, c_char_p]

confVFAT = lib.configureVFAT3s
confVFAT.restype = c_uint
confVFAT.argtypes = [c_uint, c_uint]

DEBUG = True

def main():
print "Start testing"
start_time_ = timeit.default_timer()
rpc_connect("eagle34")
rpc_connect("eagle60")
elapsed_ = timeit.default_timer() - start_time
print "Connect time %s" %(elapsed_)
print "Connection to eagle34 successful"
print "Connection to eagle60 successful"
getRegInfo("GEM_AMC.GEM_SYSTEM.BOARD_ID")
res = (c_uint32 * 5)()
res_code = getTTCmain(res)
print "\ngetTTCmain result code: %s" %(res_code)
if res_code == 0:
print "getTTCmain result: %s" %(res)
for c in res:
print c
noh = 2
res2 = (c_uint32 * (noh+1))()
res_code = getTRIGGERmain(res2,noh)
if res_code == 0:
print "getTRIGGERmain result: %s" %(res2)
for c in res2:
print c
update_atdb("/mnt/persistent/texas/gem_amc_top.xml")
print "Address table updated"
ohN = 0
mask = 0xF65F7E
confVFAT(ohN,mask)
print "Configure TTC"
L1Ainterval = 0x200
pulseDelay = 50
res=ttcGenConf(L1Ainterval, pulseDelay)
if res==0:
print "TTC configured successfully"
else:
print "TTC configuration failed"
sys.exit()

print "Starting scan"
nevts = 1000
ohN = 0
dacMin = 0
dacMax = 255
dacStep = 1
ch = 69
enCal = 1
mask = 0xF65F7E
scanReg = "LATENCY"
confVFAT(ohN,mask)
genScan(nevts, ohN, dacMin, dacMax, dacStep, ch, enCal, mask, scanReg)

#getRegInfo("GEM_AMC.GEM_SYSTEM.BOARD_ID")
#res = (c_uint32 * 5)()
#res_code = getTTCmain(res)
#print "\ngetTTCmain result code: %s" %(res_code)
#if res_code == 0:
# print "getTTCmain result: %s" %(res)
# for c in res:
# print c
#noh = 2
#res2 = (c_uint32 * (noh+1))()
#res_code = getTRIGGERmain(res2,noh)
#if res_code == 0:
# print "getTRIGGERmain result: %s" %(res2)
# for c in res2:
# print c
#update_atdb("/mnt/persistent/gemdaq/xml/gem_amc_top.xml")
#update_atdb("/mnt/persistent/texas/gem_amc_top_v1_7_3_2oh.xml")
#print "Address table updated"
#getRegInfo("GEM_AMC.GEM_SYSTEM.BOARD_ID")
#start_time_ = timeit.default_timer()
#res = confTRIMDAC('2','/mnt/persistent/texas/test/chConfig_GEMINIm01L1.txt')
Expand Down
79 changes: 79 additions & 0 deletions src/common/rpc_manager/calibration_routines.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "xhal/rpc/calibration_routines.h"

/***
* @brief configure TTC generator
*/
DLLEXPORT uint32_t ttcGenConf(uint32_t L1Ainterval, uint32_t pulseDelay)
{
wisc::RPCSvc* rpc_loc = getRPCptr();
//wisc::RPCMsg req_loc, rsp_loc;
//req_loc = wisc::RPCMsg("calibration_routines.ttcGenConf");
req = wisc::RPCMsg("calibration_routines.ttcGenConf");
req.set_word("L1Ainterval", L1Ainterval);
req.set_word("pulseDelay", pulseDelay);
try {
rsp = rpc_loc->call_method(req);
}
STANDARD_CATCH;

if (rsp.get_key_exists("error")) {
return 1;
}
return 0;
}

/***
* @brief run a generic scan routine
*/
DLLEXPORT uint32_t genScan(uint32_t nevts, uint32_t ohN, uint32_t dacMin, uint32_t dacMax, uint32_t dacStep, uint32_t ch, uint32_t enCal, uint32_t mask, char * scanReg)
{
req = wisc::RPCMsg("calibration_routines.genScan");

req.set_word("nevts", nevts);
req.set_word("ohN", ohN);
req.set_word("dacMin", dacMin);
req.set_word("dacMax", dacMax);
req.set_word("dacStep", dacStep);
req.set_word("ch", ch);
req.set_word("enCal", enCal);
req.set_word("mask", mask);
req.set_string("scanReg", std::string(scanReg));

//std::shared_ptr<wisc::RPCSvc> rpc_loc = getRPCptr();
wisc::RPCSvc* rpc_loc = getRPCptr();

try {
rsp = rpc_loc->call_method(req);
}
STANDARD_CATCH;

if (rsp.get_key_exists("error")) {
printf("Caught an error: %s\n", (rsp.get_string("error")).c_str());
return 1;
}
const uint32_t size = (dacMax - dacMin+1)*24/dacStep;
uint32_t* result = new uint32_t[size];
if (rsp.get_key_exists("data")) {
ASSERT(rsp.get_word_array_size("data") == size);
rsp.get_word_array("data", result);
} else {
printf("No data key found");
return 1;
}
FILE *f = fopen("file.txt", "w");
if (f == NULL)
{
printf("Error opening file!\n");
exit(1);
}
fprintf(f, "vfatN/I:nEvents/I:dacVal/I:nHits/I\n");
uint32_t vfatSize = (dacMax-dacMin+1)/dacStep;
for (unsigned int i = 0; i<24; i++)
{
for (unsigned int j = 0; j<vfatSize; j++)
{
fprintf(f,"%d %d %d %d\n",i,result[i*vfatSize+j]&0xFFFF,dacMin+j*dacStep,(result[i*vfatSize+j]>>16)&0xFFFF);
}
}
return 0;
}
Loading