Skip to content

Commit 0d551dd

Browse files
Merge branch 'devel-alf'
2 parents a01180b + 0e1d910 commit 0d551dd

File tree

10 files changed

+678
-510
lines changed

10 files changed

+678
-510
lines changed

src/CommandLineUtilities/AliceLowlevelFrontend/AliceLowlevelFrontend.h

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,24 @@ inline void setDataBuffer(std::vector<char>& buffer, DimObject& dimObject)
5959
dimObject.setData(buffer.data(), buffer.size());
6060
}
6161

62+
inline std::string argumentSeparator()
63+
{
64+
return "\n";
65+
}
66+
67+
inline std::string scaPairSeparator()
68+
{
69+
return ",";
70+
}
71+
6272
inline std::string successPrefix()
6373
{
64-
return "success:";
74+
return "success" + argumentSeparator();
6575
}
6676

6777
inline std::string failPrefix()
6878
{
69-
return "failure:";
79+
return "failure" + argumentSeparator();
7080
}
7181

7282
inline std::string makeSuccessString(const std::string& string)
@@ -92,6 +102,7 @@ inline bool isFail(const std::string& string)
92102
inline std::string stripPrefix(const std::string& string)
93103
{
94104
if (string.length() < PREFIX_LENGTH) {
105+
printf("len=%lu str=%s\n", string.length(), string.c_str());
95106
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("string too short to contain prefix"));
96107
}
97108
return string.substr(PREFIX_LENGTH);
@@ -115,7 +126,7 @@ class DimRpcInfoWrapper
115126
auto string = std::string(mRpcInfo->getString());
116127
if (isFail(string)) {
117128
BOOST_THROW_EXCEPTION(
118-
AlfException() << ErrorInfo::Message("ALF server failure" + string));
129+
AlfException() << ErrorInfo::Message("ALF server failure: " + string));
119130
}
120131
return string;
121132
}
@@ -137,60 +148,69 @@ class DimRpcInfoWrapper
137148
std::unique_ptr<DimRpcInfo> mRpcInfo;
138149
};
139150

140-
class PublishRpc : DimRpcInfoWrapper
151+
class PublishRegistersStartRpc : DimRpcInfoWrapper
141152
{
142153
public:
143-
PublishRpc(const std::string& serviceName)
154+
PublishRegistersStartRpc(const std::string& serviceName)
144155
: DimRpcInfoWrapper(serviceName)
145156
{
146157
}
147158

148-
void publish(std::string dnsName, double frequency, std::vector<size_t> addresses)
159+
void publish(std::string dnsName, double interval, std::vector<size_t> addresses)
149160
{
150161
std::ostringstream stream;
151-
stream << dnsName << ';';
162+
auto sep = argumentSeparator();
163+
stream << dnsName << sep << interval;
152164
for (size_t i = 0; i < addresses.size(); ++i) {
153-
stream << addresses[i];
154-
if ((i + 1) < addresses.size()) {
155-
stream << ',';
156-
}
165+
stream << sep << addresses[i];
157166
}
158-
stream << ';' << frequency;
159167
printf("Publish: %s\n", stream.str().c_str());
160168
setString(stream.str());
161169
getString();
162170
}
163171
};
164172

165-
class PublishScaRpc : DimRpcInfoWrapper
173+
class PublishScaSequenceStartRpc : DimRpcInfoWrapper
166174
{
167175
public:
168-
PublishScaRpc(const std::string& serviceName)
176+
PublishScaSequenceStartRpc(const std::string& serviceName)
169177
: DimRpcInfoWrapper(serviceName)
170178
{
171179
}
172180

173-
void publish(std::string dnsName, double frequency, const std::vector<Sca::CommandData>& commandDataPairs)
181+
void publish(std::string dnsName, double interval, const std::vector<Sca::CommandData>& commandDataPairs)
174182
{
175183
std::ostringstream stream;
176-
stream << dnsName << ';';
184+
auto sep = argumentSeparator();
185+
stream << dnsName << sep << interval;
177186
for (size_t i = 0; i < commandDataPairs.size(); ++i) {
178-
stream << commandDataPairs[i].command << ',' << commandDataPairs[i].data;
179-
if ((i + 1) < commandDataPairs.size()) {
180-
stream << '\n';
181-
}
187+
stream << sep << commandDataPairs[i].command << scaPairSeparator() << commandDataPairs[i].data;
182188
}
183-
stream << ';' << frequency;
184189
printf("Publish SCA: %s\n", stream.str().c_str());
185190
setString(stream.str());
186191
getString();
187192
}
188193
};
189194

190-
class PublishStopRpc: DimRpcInfoWrapper
195+
class PublishRegistersStopRpc: DimRpcInfoWrapper
196+
{
197+
public:
198+
PublishRegistersStopRpc(const std::string &serviceName)
199+
: DimRpcInfoWrapper(serviceName)
200+
{
201+
}
202+
203+
void stop(std::string dnsName)
204+
{
205+
setString(dnsName);
206+
getString();
207+
}
208+
};
209+
210+
class PublishScaSequenceStopRpc: DimRpcInfoWrapper
191211
{
192212
public:
193-
PublishStopRpc(const std::string &serviceName)
213+
PublishScaSequenceStopRpc(const std::string &serviceName)
194214
: DimRpcInfoWrapper(serviceName)
195215
{
196216
}
@@ -227,7 +247,7 @@ class RegisterWriteRpc: DimRpcInfoWrapper
227247

228248
void writeRegister(uint64_t registerAddress, uint32_t registerValue)
229249
{
230-
setString((boost::format("0x%x,0x%x") % registerAddress % registerValue).str());
250+
setString((boost::format("0x%x%s0x%x") % registerAddress % argumentSeparator() % registerValue).str());
231251
getString();
232252
}
233253
};
@@ -257,7 +277,7 @@ class ScaWriteRpc: DimRpcInfoWrapper
257277

258278
std::string write(uint32_t command, uint32_t data)
259279
{
260-
setString((boost::format("0x%x,0x%x") % command % data).str());
280+
setString((boost::format("0x%x%s0x%x") % command % scaPairSeparator() % data).str());
261281
return stripPrefix(getString());
262282
}
263283
};
@@ -310,41 +330,15 @@ class ScaWriteSequence: DimRpcInfoWrapper
310330
{
311331
std::stringstream buffer;
312332
for (size_t i = 0; i < sequence.size(); ++i) {
313-
buffer << sequence[i].first << ',' << sequence[i].second;
333+
buffer << sequence[i].first << scaPairSeparator() << sequence[i].second;
314334
if (i + 1 < sequence.size()) {
315-
buffer << '\n';
335+
buffer << argumentSeparator();
316336
}
317337
}
318338
return write(buffer.str());
319339
}
320340
};
321341

322-
class StringRpcServer: public DimRpc
323-
{
324-
public:
325-
using Callback = std::function<std::string(const std::string&)>;
326-
327-
StringRpcServer(const std::string& serviceName, Callback callback)
328-
: DimRpc(serviceName.c_str(), "C", "C"), callback(callback)
329-
{
330-
}
331-
332-
StringRpcServer(const StringRpcServer& b) = delete;
333-
StringRpcServer(StringRpcServer&& b) = delete;
334-
335-
private:
336-
void rpcHandler() override
337-
{
338-
try {
339-
auto returnValue = callback(std::string(getString()));
340-
Alf::setDataString(Alf::makeSuccessString(returnValue), *this);
341-
} catch (const std::exception& e) {
342-
Alf::setDataString(Alf::makeFailString(e.what()), *this);
343-
}
344-
}
345-
346-
Callback callback;
347-
};
348342

349343
} // namespace Alf
350344
} // namespace CommandLineUtilities

src/CommandLineUtilities/AliceLowlevelFrontend/ProgramAlfScaWriteSequence.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ProgramAlfScaWriteSequence: public Program
3636
options.add_options()
3737
("serial", boost::program_options::value<int>(&mSerialNumber),
3838
"Card serial number")
39+
("link", boost::program_options::value<int>(&mLink),
40+
"Link")
3941
("file", boost::program_options::value<std::string>(&mFilePath)->required(),
4042
"Path to command sequence file")
4143
("out", boost::program_options::value<std::string>(&mOutFilePath),
@@ -51,8 +53,8 @@ class ProgramAlfScaWriteSequence: public Program
5153
}
5254

5355
// Initialize DIM objects
54-
Alf::ServiceNames names(mSerialNumber);
55-
Alf::ScaWriteSequence scaWriteSequence(names.scaWriteSequence());
56+
Alf::ServiceNames names(mSerialNumber, mLink);
57+
Alf::ScaWriteSequence scaWriteSequence(names.scaSequence());
5658

5759
// Read file
5860
std::ifstream file(mFilePath);
@@ -76,6 +78,7 @@ class ProgramAlfScaWriteSequence: public Program
7678
std::string mFilePath;
7779
std::string mOutFilePath;
7880
int mSerialNumber;
81+
int mLink;
7982
};
8083
} // Anonymous namespace
8184

src/CommandLineUtilities/AliceLowlevelFrontend/ProgramAliceLowlevelFrontendClient.cxx

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// \author Pascal Boeschoten ([email protected])
55

66
#include "CommandLineUtilities/Program.h"
7+
#include "Common/GuardFunction.h"
78
#include <iostream>
89
#include <thread>
910
#include <dim/dic.hxx>
@@ -43,49 +44,71 @@ class ProgramAliceLowlevelFrontendClient: public Program
4344
virtual Description getDescription() override
4445
{
4546
return {"ALF DIM Client example", "ALICE low-level front-end DIM Client example",
46-
"roc-alf-client --serial=12345"};
47+
"roc-alf-client --serial=12345 --link=42"};
4748
}
4849

4950
virtual void addOptions(boost::program_options::options_description& options) override
5051
{
51-
options.add_options()("serial", boost::program_options::value<int>(&mSerialNumber), "Card serial number");
52+
options.add_options()
53+
("serial", boost::program_options::value<int>(&mSerialNumber), "Card serial number")
54+
("link", boost::program_options::value<int>(&mLink), "Link");
5255
}
5356

5457
virtual void run(const boost::program_options::variables_map&) override
5558
{
5659
// Get DIM DNS node from environment
5760
if (getenv(std::string("DIM_DNS_NODE").c_str()) == nullptr) {
58-
BOOST_THROW_EXCEPTION(Alf::AlfException() << Alf::ErrorInfo::Message("Environment variable 'DIM_DNS_NODE' not set"));
61+
BOOST_THROW_EXCEPTION(
62+
Alf::AlfException() << Alf::ErrorInfo::Message("Environment variable 'DIM_DNS_NODE' not set"));
5963
}
6064

65+
cout << "Using serial=" << mSerialNumber << " link=" << mLink << '\n';
66+
6167
// Initialize DIM objects
62-
Alf::ServiceNames names(mSerialNumber);
68+
Alf::ServiceNames names(mSerialNumber, mLink);
6369
TemperatureInfo alfTestInt(names.temperature());
6470
Alf::RegisterReadRpc readRpc(names.registerReadRpc());
6571
Alf::RegisterWriteRpc writeRpc(names.registerWriteRpc());
6672
Alf::ScaReadRpc scaReadRpc(names.scaRead());
6773
Alf::ScaWriteRpc scaWriteRpc(names.scaWrite());
6874
Alf::ScaGpioReadRpc scaGpioReadRpc(names.scaGpioRead());
6975
Alf::ScaGpioWriteRpc scaGpioWriteRpc(names.scaGpioWrite());
70-
Alf::ScaWriteSequence scaWriteSequence(names.scaWriteSequence());
71-
Alf::PublishRpc publishRpc(names.publishStartCommandRpc());
72-
Alf::PublishScaRpc publishScaRpc(names.publishScaStartCommandRpc());
73-
74-
publishRpc.publish("ALF/TEST/1", 1.0, {0x1fc});
75-
publishRpc.publish("ALF/TEST/2", 3.0, {0x100, 0x104, 0x108});
76+
Alf::ScaWriteSequence scaWriteSequence(names.scaSequence());
77+
Alf::PublishRegistersStartRpc publishRegistersStartRpc(names.publishRegistersStart());
78+
Alf::PublishRegistersStopRpc publishRegistersStopRpc(names.publishRegistersStop());
79+
Alf::PublishScaSequenceStartRpc publishScaSequenceStartRpc(names.publishScaSequenceStart());
80+
Alf::PublishScaSequenceStopRpc publishScaSequenceStopRpc(names.publishScaSequenceStop());
81+
82+
publishRegistersStartRpc.publish("TEST_1", 5.0, {0x1fc});
83+
publishRegistersStartRpc.publish("TEST_2", 5.0, {0x100, 0x104});
84+
publishScaSequenceStartRpc.publish("TEST_3", 2.5, {{0x0, 0x1}, {0x10, 0x11}});
85+
86+
AliceO2::Common::GuardFunction publishStopper{
87+
[&]() {
88+
publishRegistersStopRpc.stop("TEST_1");
89+
publishRegistersStopRpc.stop("TEST_2");
90+
publishScaSequenceStopRpc.stop("TEST_3");
91+
}
92+
};
7693

77-
publishScaRpc.publish("ALF/TEST/SCA_1", 1.0, {{0x0, 0x1}, {0x10, 0x11}});
94+
for (int i = 0; i < 3; ++i) {
95+
cout << "SCA write '" << i << "'" << endl;
96+
cout << " result: " << scaWriteRpc.write(0xabcdabcd, i) << endl;
97+
cout << "SCA read" << endl;
98+
cout << " result: " << scaReadRpc.read() << endl;
99+
}
78100

79-
for (int i = 0; i < 10; ++i) {
101+
for (int i = 0; i < 3; ++i) {
80102
cout << "SCA GPIO write '" << i << "'" << endl;
81103
cout << " result: " << scaGpioWriteRpc.write(i) << endl;
82104
cout << "SCA GPIO read" << endl;
83105
cout << " result: " << scaGpioReadRpc.read() << endl;
84106
}
85107

86108
{
87-
cout << "1k writes to 0x1fc..." << endl;
88-
for (int i = 0; i < 1000; ++i) {
109+
cout << "Reads & writes to 0x1fc..." << endl;
110+
for (int i = 0; i < 3; ++i) {
111+
writeRpc.writeRegister(0x1fc, 0x123);
89112
readRpc.readRegister(0x1fc);
90113
}
91114
cout << "Done!" << endl;
@@ -96,7 +119,7 @@ class ProgramAliceLowlevelFrontendClient: public Program
96119
cout << "Writing blob of " << numInts << " pairs of 32-bit ints..." << endl;
97120
std::vector<std::pair<uint32_t, uint32_t>> buffer(numInts);
98121
for (size_t i = 0; i < buffer.size(); ++i) {
99-
buffer[i] = {i * 2, i * 2 + 1};
122+
buffer[i] = {0xabcdab + i * 2, 0xabcdab + i * 2 + 1};
100123
}
101124

102125
std::string result = scaWriteSequence.write(buffer);
@@ -107,41 +130,27 @@ class ProgramAliceLowlevelFrontendClient: public Program
107130

108131
{
109132
cout << "Writing blob with comments..." << endl;
110-
std::string result = scaWriteSequence.write("# Hello!\n11,22\n33,44\n# Bye!");
133+
std::string result = scaWriteSequence.write("# Hello!\nabcdab11,22\nabcdab33,44\n# Bye!");
111134
cout << "Done!" << endl;
112135
cout << "Got result: \n";
113136
cout << " " << result << '\n';
114137
}
115138

116-
while (false)//!isSigInt())
117-
{
118-
cout << "-------------------------------------\n";
119-
cout << "Temperature = " << gTemperature << endl;
120-
121-
int writes = 10; //std::rand() % 50;
122-
cout << "Write 0x1f8 = 0x1 times " << writes << endl;
123-
for (int i = 0; i < writes; ++i) {
124-
writeRpc.writeRegister(0x1f8, 0x1);
125-
}
139+
try {
140+
cout << "Writing bad blob..." << endl;
141+
std::string result = scaWriteSequence.write("I AM BAD\n11,22\n33,44\nAAAAAAAAaaaaa");
142+
} catch (const Alf::AlfException& e) {
143+
cout << "Successfully broke the server!\n";
144+
}
126145

127-
cout << "Read 0x1fc = " << readRpc.readRegister(0x1fc) << endl;
128-
cout << "Read 0x1ec = " << readRpc.readRegister(0x1ec) << endl;
129-
cout << "Cmd 0x1f4 = 0x1" << endl;
130-
writeRpc.writeRegister(0x1f4, 0x1);
131-
cout << "Cmd 0x1f4 = 0x2" << endl;
132-
writeRpc.writeRegister(0x1f4, 0x1);
133-
cout << "Cmd 0x1f4 = 0x3" << endl;
134-
writeRpc.writeRegister(0x1f4, 0x1);
146+
while (!isSigInt())
147+
{
135148
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
136149
}
137-
138-
Alf::PublishStopRpc publishStopRpc(names.publishStopCommandRpc());
139-
publishStopRpc.stop("ALF/TEST/1");
140-
publishStopRpc.stop("ALF/TEST/2");
141-
publishStopRpc.stop("ALF/TEST/SCA_1");
142150
}
143151

144152
int mSerialNumber;
153+
int mLink;
145154
};
146155
} // Anonymous namespace
147156

0 commit comments

Comments
 (0)