Skip to content

Commit 694743f

Browse files
authored
SWT and client changes
* [swt] Update interface * [alf-client] Add option for ALF server hostname * [swt] Always truncate word to 76bits
1 parent 5be0804 commit 694743f

File tree

6 files changed

+65
-33
lines changed

6 files changed

+65
-33
lines changed

apps/ProgramAlfClient.cxx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,17 @@ class ProgramAlfClient : public AliceO2::Common::Program
5959
options.add_options()("link",
6060
po::value<int>(&mOptions.link),
6161
"Link number");
62+
options.add_options()("alf-id",
63+
po::value<std::string>(&mOptions.alfId)->default_value(""),
64+
"Hostname of node running the ALF server(required)");
6265
}
6366

6467
virtual void run(const po::variables_map&) override
6568
{
69+
if (mOptions.alfId == "") {
70+
getErrorLogger() << "Parameter alf-id is required." << endm;
71+
return;
72+
}
6673

6774
getLogger() << "ALF client initializations..." << endm;
6875

@@ -77,7 +84,7 @@ class ProgramAlfClient : public AliceO2::Common::Program
7784
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("DIM_DNS_NODE env variable not set, and no relevant argument provided.")); // InfoLogger and errors?
7885
}
7986

80-
std::string alfId = ip::host_name();
87+
std::string alfId = mOptions.alfId; //TODO: change to hostname argument
8188
boost::to_upper(alfId);
8289

8390
getLogger() << "Starting the DIM Client using ALF ID=" << alfId << ", serial=" << mOptions.serial << " and link=" << mOptions.link << endm;
@@ -100,9 +107,10 @@ class ProgramAlfClient : public AliceO2::Common::Program
100107
uint32_t rValue = registerReadRpc.readRegister(rAddress);
101108
getWarningLogger() << "Wrote: " << Util::formatValue(wValue) << " Read: " << Util::formatValue(rValue) << endm;
102109

103-
auto swtOut = swtSequence.write({ std::make_pair("0x00000000000000000000", "write"),
110+
auto swtOut = swtSequence.write({ std::make_pair("0x0000000000000000000", "write"),
111+
std::make_pair("", "reset"),
104112
std::make_pair("0x000000001234", "write"),
105-
std::make_pair("0x0", "read") });
113+
std::make_pair("", "read") });
106114
getWarningLogger() << "swtSequence output: " << swtOut << endm;
107115

108116
auto scaOut = scaSequence.write({ std::make_pair("0x00010002", "0xff000000"),
@@ -134,6 +142,7 @@ class ProgramAlfClient : public AliceO2::Common::Program
134142
std::string dimDnsNode = "";
135143
int serial = -1;
136144
int link = -1;
145+
std::string alfId = "";
137146
} mOptions;
138147
};
139148

src/AlfClient.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ class SwtSequenceRpc : DimRpcInfoWrapper
136136
{
137137
std::stringstream buffer;
138138
for (size_t i = 0; i < sequence.size(); ++i) {
139-
buffer << sequence[i].first << pairSeparator() << sequence[i].second;
139+
if (sequence[i].first != "") {
140+
buffer << sequence[i].first << pairSeparator() << sequence[i].second;
141+
} else {
142+
buffer << sequence[i].second;
143+
}
140144
if (i + 1 < sequence.size()) {
141145
buffer << argumentSeparator();
142146
}

src/AlfServer.cxx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,39 +116,55 @@ Sca::CommandData AlfServer::stringToScaPair(std::string stringPair)
116116
std::pair<SwtWord, Swt::Operation> AlfServer::stringToSwtPair(const std::string stringPair)
117117
{
118118
std::vector<std::string> swtPair = Util::split(stringPair, pairSeparator());
119-
if (swtPair.size() != 2) {
119+
if (swtPair.size() != 1 && swtPair.size() != 2) {
120120
BOOST_THROW_EXCEPTION(
121121
AlfException() << ErrorInfo::Message("SWT word pair not formatted correctly"));
122122
}
123123

124-
std::string hexString = swtPair[0];
125-
std::string leadingHex = "0x";
124+
Swt::Operation operation;
126125

127-
std::string::size_type i = hexString.find(leadingHex);
128-
if (i != std::string::npos) {
129-
hexString.erase(i, leadingHex.size());
126+
if (swtPair[swtPair.size() - 1] == "read") {
127+
operation = Swt::Operation::Read;
128+
if (swtPair.size() == 2) {
129+
BOOST_THROW_EXCEPTION(
130+
AlfException() << ErrorInfo::Message("Too many arguments for READ operation"));
131+
}
132+
} else if (swtPair[swtPair.size() - 1] == "write") {
133+
operation = Swt::Operation::Write;
134+
if (swtPair.size() == 1) {
135+
BOOST_THROW_EXCEPTION(
136+
AlfException() << ErrorInfo::Message("Too few arguments for WRITE operation"));
137+
}
138+
} else if (swtPair[swtPair.size() - 1] == "reset") {
139+
operation = Swt::Operation::Reset;
140+
if (swtPair.size() == 2) {
141+
BOOST_THROW_EXCEPTION(
142+
AlfException() << ErrorInfo::Message("Too many arguments for RESET operation"));
143+
}
144+
} else {
145+
BOOST_THROW_EXCEPTION(std::out_of_range("Parameter for SWT operation unkown"));
130146
}
131147

132-
if (hexString.length() > 19) {
133-
BOOST_THROW_EXCEPTION(std::out_of_range("Parameter does not fit in 76-bit unsigned int"));
134-
}
148+
SwtWord word;
149+
if (operation == Swt::Operation::Write) {
150+
std::string hexString = swtPair[0];
151+
std::string leadingHex = "0x";
135152

136-
std::stringstream ss;
137-
ss << std::setw(19) << std::setfill('0') << hexString;
153+
std::string::size_type i = hexString.find(leadingHex);
154+
if (i != std::string::npos) {
155+
hexString.erase(i, leadingHex.size());
156+
}
138157

139-
SwtWord word;
140-
word.setHigh(std::stoul(ss.str().substr(0, 3), NULL, 16));
141-
word.setMed(std::stoul(ss.str().substr(3, 8), NULL, 16));
142-
word.setLow(std::stoul(ss.str().substr(11, 8), NULL, 16));
158+
if (hexString.length() > 19) {
159+
BOOST_THROW_EXCEPTION(std::out_of_range("Parameter does not fit in 76-bit unsigned int"));
160+
}
143161

144-
Swt::Operation operation;
162+
std::stringstream ss;
163+
ss << std::setw(19) << std::setfill('0') << hexString;
145164

146-
if (swtPair[1] == "read") {
147-
operation = Swt::Operation::Read;
148-
} else if (swtPair[1] == "write") {
149-
operation = Swt::Operation::Write;
150-
} else {
151-
BOOST_THROW_EXCEPTION(std::out_of_range("Parameter for SWT operation unkown"));
165+
word.setHigh(std::stoul(ss.str().substr(0, 3), NULL, 16));
166+
word.setMed(std::stoul(ss.str().substr(3, 8), NULL, 16));
167+
word.setLow(std::stoul(ss.str().substr(11, 8), NULL, 16));
152168
}
153169

154170
return std::make_pair(word, operation);

src/Swt/Swt.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ namespace sc_regs = AliceO2::roc::Cru::ScRegisters;
4141

4242
Swt::Swt(AlfLink link) : mBar2(*link.bar2), mLink(link)
4343
{
44-
reset();
4544
setChannel(mLink.linkId);
4645
}
4746

@@ -128,12 +127,15 @@ std::string Swt::writeSequence(std::vector<std::pair<SwtWord, Operation>> words)
128127
if (it.second == Operation::Read) {
129128
std::vector<SwtWord> results;
130129
read(results);
131-
for (const auto& word : results) {
132-
resultBuffer << word << "\n";
130+
for (const auto& result : results) {
131+
resultBuffer << result << "\n";
133132
}
134133
} else if (it.second == Operation::Write) {
135134
write(word);
136-
resultBuffer << word << "\n";
135+
resultBuffer << "0"
136+
<< "\n";
137+
} else if (it.second == Operation::Reset) {
138+
reset();
137139
} else {
138140
BOOST_THROW_EXCEPTION(SwtException() << ErrorInfo::Message("SWT operation type unknown"));
139141
}

src/Swt/Swt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class Swt
5050
void read(std::vector<SwtWord>& words, SwtWord::Size wordSize = SwtWord::Size::High);
5151

5252
enum Operation { Read,
53-
Write };
53+
Write,
54+
Reset };
5455

5556
std::string writeSequence(std::vector<std::pair<SwtWord, Operation>> words);
5657

src/Swt/SwtWord.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void SwtWord::setMed(uint32_t med)
7575

7676
void SwtWord::setHigh(uint16_t high)
7777
{
78-
mHigh = high;
78+
mHigh = high & 0xfff;
7979
}
8080

8181
uint32_t SwtWord::getLow() const
@@ -90,7 +90,7 @@ uint32_t SwtWord::getMed() const
9090

9191
uint16_t SwtWord::getHigh() const
9292
{
93-
return mHigh;
93+
return mHigh & 0xfff;
9494
}
9595

9696
std::ostream& operator<<(std::ostream& output, const SwtWord& swtWord)

0 commit comments

Comments
 (0)