|
| 1 | +#// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// \file example.cxx |
| 12 | +/// \brief An example on the use of ALF as a library |
| 13 | +/// |
| 14 | +/// \author Kostas Alexopoulos ([email protected]) |
| 15 | + |
| 16 | +#include <chrono> |
| 17 | +#include <thread> |
| 18 | +#include <vector> |
| 19 | + |
| 20 | +#include "Alf/Alf.h" |
| 21 | + |
| 22 | +using namespace o2::alf; |
| 23 | + |
| 24 | +int main() |
| 25 | +{ |
| 26 | + |
| 27 | + std::cout << "Running SWT test" << std::endl; |
| 28 | + std::string cardId("#2"); |
| 29 | + auto swt = Swt(cardId, 0); // Get an SWT handle for card #2 on channel 0 |
| 30 | + |
| 31 | + std::cout << "Running simple SWT operations" << std::endl; |
| 32 | + try { |
| 33 | + swt.reset(); |
| 34 | + swt.write({ 0xcafe, 0x41d, 0x0 }); |
| 35 | + swt.write({ 0xb00f, 0x42, 0x88 }); |
| 36 | + swt.write({ 0xb00f, 0x42, 0x88 }); |
| 37 | + swt.write({ 0xbe0f, 0x0, 0x0, SwtWord::Size::High }); |
| 38 | + swt.write({ 0xb00f, 0x42, 0x21, SwtWord::Size::Low }); |
| 39 | + auto wordsRead = swt.read(SwtWord::Size::Medium, 10); |
| 40 | + for (const auto& word : wordsRead) { |
| 41 | + std::cout << word << std::endl; |
| 42 | + } |
| 43 | + } catch (const SwtException& e) { |
| 44 | + std::cerr << e.what() << std::endl; |
| 45 | + } |
| 46 | + |
| 47 | + std::cout << "Running an SWT sequence" << std::endl; |
| 48 | + std::vector<std::pair<Swt::Operation, Swt::Data>> ops; |
| 49 | + swt.setChannel(1); // Change the channel to 1 |
| 50 | + ops.push_back({ Swt::Operation::Reset, {} }); |
| 51 | + ops.push_back({ Swt::Operation::Write, SwtWord{ 0xcafe, 0x41d, 0x0 } }); |
| 52 | + ops.push_back({ Swt::Operation::Write, SwtWord{ 0xb00f, 0x42, 0x88, SwtWord::Size::High } }); |
| 53 | + ops.push_back({ Swt::Operation::Write, SwtWord{ 0xb00f, 0x42, 0x88 } }); |
| 54 | + ops.push_back({ Swt::Operation::Read, { 50 } }); |
| 55 | + ops.push_back({ Swt::Operation::Error, {} }); // inject error |
| 56 | + auto output = swt.executeSequence(ops, true); // execute the sequence atomically |
| 57 | + for (const auto& out : output) { |
| 58 | + if (out.first == Swt::Operation::Write) { |
| 59 | + std::cout << "Write | " << boost::get<SwtWord>(out.second) << std::endl; |
| 60 | + } else if (out.first == Swt::Operation::Read) { |
| 61 | + std::cout << "Read | " << boost::get<SwtWord>(out.second) << std::endl; |
| 62 | + } else if (out.first == Swt::Operation::Reset) { |
| 63 | + std::cout << "Reset |" << std::endl; |
| 64 | + } else if (out.first == Swt::Operation::Error) { |
| 65 | + std::cout << "Error | " << boost::get<std::string>(out.second) << std::endl; |
| 66 | + } else { |
| 67 | + std::cout << "Unknown operation" << std::endl; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + return 0; |
| 72 | +} |
0 commit comments