Skip to content

Commit 9e2ccc0

Browse files
Bugfixes
1 parent b8f99e3 commit 9e2ccc0

File tree

5 files changed

+240
-163
lines changed

5 files changed

+240
-163
lines changed

src/CommandLineUtilities/AliceLowlevelFrontend/AliceLowlevelFrontend.h

Lines changed: 43 additions & 49 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=%ul 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
}
@@ -319,32 +339,6 @@ class ScaWriteSequence: DimRpcInfoWrapper
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/ProgramAliceLowlevelFrontendClient.cxx

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class ProgramAliceLowlevelFrontendClient: public Program
6060
BOOST_THROW_EXCEPTION(Alf::AlfException() << Alf::ErrorInfo::Message("Environment variable 'DIM_DNS_NODE' not set"));
6161
}
6262

63+
cout << "Using serial=" << mSerialNumber << " link=" << mLink << '\n';
64+
6365
// Initialize DIM objects
6466
Alf::ServiceNames names(mSerialNumber, mLink);
6567
TemperatureInfo alfTestInt(names.temperature());
@@ -70,13 +72,12 @@ class ProgramAliceLowlevelFrontendClient: public Program
7072
Alf::ScaGpioReadRpc scaGpioReadRpc(names.scaGpioRead());
7173
Alf::ScaGpioWriteRpc scaGpioWriteRpc(names.scaGpioWrite());
7274
Alf::ScaWriteSequence scaWriteSequence(names.scaWriteSequence());
73-
Alf::PublishRpc publishRpc(names.publishStartCommandRpc());
74-
Alf::PublishScaRpc publishScaRpc(names.publishScaStartCommandRpc());
75-
76-
publishRpc.publish("ALF/TEST/1", 1.0, {0x1fc});
77-
publishRpc.publish("ALF/TEST/2", 3.0, {0x100, 0x104, 0x108});
75+
Alf::PublishRegistersStartRpc publishRpc(names.publishRegistersStart());
76+
Alf::PublishScaSequenceStartRpc publishScaRpc(names.publishScaSequenceStart());
7877

79-
publishScaRpc.publish("ALF/TEST/SCA_1", 1.0, {{0x0, 0x1}, {0x10, 0x11}});
78+
publishRpc.publish("TEST_1", 1.0, {0x1fc});
79+
publishRpc.publish("TEST_2", 3.0, {0x100, 0x104, 0x108});
80+
publishScaRpc.publish("TEST_3", 1.0, {{0x0, 0x1}, {0x10, 0x11}});
8081

8182
for (int i = 0; i < 10; ++i) {
8283
cout << "SCA GPIO write '" << i << "'" << endl;
@@ -115,32 +116,33 @@ class ProgramAliceLowlevelFrontendClient: public Program
115116
cout << " " << result << '\n';
116117
}
117118

118-
while (false)//!isSigInt())
119+
while (!isSigInt())
119120
{
120-
cout << "-------------------------------------\n";
121-
cout << "Temperature = " << gTemperature << endl;
122-
123-
int writes = 10; //std::rand() % 50;
124-
cout << "Write 0x1f8 = 0x1 times " << writes << endl;
125-
for (int i = 0; i < writes; ++i) {
126-
writeRpc.writeRegister(0x1f8, 0x1);
127-
}
128-
129-
cout << "Read 0x1fc = " << readRpc.readRegister(0x1fc) << endl;
130-
cout << "Read 0x1ec = " << readRpc.readRegister(0x1ec) << endl;
131-
cout << "Cmd 0x1f4 = 0x1" << endl;
132-
writeRpc.writeRegister(0x1f4, 0x1);
133-
cout << "Cmd 0x1f4 = 0x2" << endl;
134-
writeRpc.writeRegister(0x1f4, 0x1);
135-
cout << "Cmd 0x1f4 = 0x3" << endl;
136-
writeRpc.writeRegister(0x1f4, 0x1);
121+
// cout << "-------------------------------------\n";
122+
// cout << "Temperature = " << gTemperature << endl;
123+
//
124+
// int writes = 10; //std::rand() % 50;
125+
// cout << "Write 0x1f8 = 0x1 times " << writes << endl;
126+
// for (int i = 0; i < writes; ++i) {
127+
// writeRpc.writeRegister(0x1f8, 0x1);
128+
// }
129+
//
130+
// cout << "Read 0x1fc = " << readRpc.readRegister(0x1fc) << endl;
131+
// cout << "Read 0x1ec = " << readRpc.readRegister(0x1ec) << endl;
132+
// cout << "Cmd 0x1f4 = 0x1" << endl;
133+
// writeRpc.writeRegister(0x1f4, 0x1);
134+
// cout << "Cmd 0x1f4 = 0x2" << endl;
135+
// writeRpc.writeRegister(0x1f4, 0x1);
136+
// cout << "Cmd 0x1f4 = 0x3" << endl;
137+
// writeRpc.writeRegister(0x1f4, 0x1);
137138
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
138139
}
139140

140-
Alf::PublishStopRpc publishStopRpc(names.publishStopCommandRpc());
141-
publishStopRpc.stop("ALF/TEST/1");
142-
publishStopRpc.stop("ALF/TEST/2");
143-
publishStopRpc.stop("ALF/TEST/SCA_1");
141+
Alf::PublishRegistersStopRpc publishRegistersStopRpc(names.publishRegistersStop());
142+
Alf::PublishScaSequenceStopRpc publishScaSequenceStopRpc(names.publishScaSequenceStop());
143+
publishRegistersStopRpc.stop("TEST_1");
144+
publishScaSequenceStopRpc.stop("TEST_2");
145+
publishScaSequenceStopRpc.stop("TEST_3");
144146
}
145147

146148
int mSerialNumber;

0 commit comments

Comments
 (0)