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!\n 11 ,22\n 33 ,44\n # Bye!" );
133+ std::string result = scaWriteSequence.write (" # Hello!\n abcdab11 ,22\n abcdab33 ,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\n 11,22\n 33,44\n AAAAAAAAaaaaa" );
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