Tools

Description

The CPU software makes use of the tools documented here throughout the software.

ConfigManager

class ConfigManager

class for configuring the instrument based on the configuration file provided

Public Functions

ConfigManager()

constructor initialise the file paths and configuration output

ConfigManager(const std::string&, const std::string&, const std::string&)

constructor

Parameters:
  • cfl – path to the local configuration file

  • cf – path to the configuration file to be copied over

void Configure()

reload and parse the configuration file

bool IsParsed()

check a configuration file has indeed been parsed, by checking output != -1

Parameters:

ConfigOut – the output to be checked

Public Members

std::string config_file_local

path to the local configuration file

std::string config_file_usb0

path to configuration file on USB0

std::string config_file_usb1

path to configuration file on USB1

std::shared_ptr<Config> ConfigOut

output of the configuration parsing is stored here

Private Functions

bool CopyFile(const char *SRC, const char *DEST)

copy a file

Parameters:
  • SRC – path to source

  • DEST – path to destination

void Parse(std::string)

parse the configuration file

InputParser

class InputParser

class to parse command line input to program

Public Functions

InputParser(int &argc, char **argv)

constructor.

Parameters:
  • argc – command line inputs

  • argv – command line inputs initalise the CmdLine struct

CmdLineInputs *ParseCmdLineInputs()

parse the command line options and store the result in CmdLine

int PrintVersionInfo()

print the version of the instrument (for use with mecontrol -ver)

inline const std::string getCmdOption(const std::string &option) const

get the command line options

Parameters:

option – flag to get option for

inline bool cmdOptionExists(const std::string &option) const

check if the command line option exists

Parameters:

option – check if this flag exists

Public Members

CmdLineInputs *CmdLine = new CmdLineInputs()

stores the command line inputs

Private Functions

int PrintHelpMsg()

print the help message detailing all accepted command line options (for use with mecontrol -help)

int CheckInputs()

Check that the inputs are part of the expected command line options.

Private Members

std::vector<std::string> tokens

vector containing all the passed command line options

std::vector<std::string> allowed_tokens

vector containting all allowed command line options

SynchonisedFile

class SynchronisedFile

handles asynchronous writing to file from multiple threads

Public Types

enum WriteType

file writing options

Values:

enumerator CONSTANT
enumerator VARIABLE_D1
enumerator VARIABLE_D2
enumerator VARIABLE_HV

Public Functions

SynchronisedFile(std::string path)

constructor.

Parameters:

path – path to the SynchronisedFile to be created

~SynchronisedFile()

destructor closes the SynchronisedFile

uint32_t Checksum()

calculate the CRC checksum and append to file

void Close()

close the SynchronisedFile

bool IsOpen()

Check if the SynchronisedFile is open.

template<class GenericType>
inline size_t Write(GenericType payload, WriteType write_type, std::shared_ptr<Config> ConfigOut = nullptr)

template to allow different objects to be passed for writing write a payload to the SynchronisedFile

Parameters:
  • payload – payload to be written to file

  • write_type – the way in which to write to file

  • ConfigOut – configuration output used to get number of packets for Zynq D1/D2 (optional)

Public Members

std::string path

stores the path to the file

Private Members

std::mutex _accessMutex

protection for file access

FILE *_ptr_to_file = nullptr

pointer to the SynchronisedFile

class Access

handles access to the SynchronisedFile

Public Functions

Access(std::shared_ptr<SynchronisedFile> sf)

constructor.

Parameters:

sf – pointer to the Synchronisedfile to be accessed

uint32_t GetChecksum()

get the checksum of the SynchronisedFile accessed

void CloseSynchFile()

close the SynchronisedFile accessed

template<class GenericType>
inline void WriteToSynchFile(GenericType payload, SynchronisedFile::WriteType write_type, std::shared_ptr<Config> ConfigOut = nullptr)

template to allow different objects to be passed for writing write a payload to the SynchronisedFile

Parameters:
  • payload – payload to be written to file

  • write_type – the way in which to write to file

  • ConfigOut – configuration output used to get number of packets for Zynq D1/D2 (optional)

Public Members

std::string path

path to the SynchronisedFile

Private Members

std::shared_ptr<SynchronisedFile> _sf

pointer to the SynchronisedFile

log

class logstream : public std::ostringstream

simple logging class with different output levels and timestamp

Public Types

enum log_level

log level optiions

Values:

enumerator quiet
enumerator error
enumerator warning
enumerator info
enumerator all
enumerator none
typedef logstream &(*logstream_manip)(logstream&)

stubs for manipulators

Public Functions

inline void flush()

print timestamp on flush

inline logstream &operator<<(const log_level &level)

overload the << operator

inline void set_level(log_level level)

sets the acceptable message level until next flush/endl

Private Members

log_level _m_log_level

stores the log level

log_level _m_current_level

stores the current log level until the next flush/endl

std::ostream &out

output stream

CpuTools

class CpuTools

class to provide useful functions to other parts of the software

Public Functions

CpuTools()

default constructor

Public Static Functions

static std::string CommandToStr(const char *cmd)

function to run command and pass stdout to a string

Parameters:

cmd – the command to send using popen NB: maximum size of returned string is limited to MAX_STR_LENGTH defined in CpuTools.h

static std::string IntToFixedLenStr(const int input, const int length)

function to convert int to a fixed length string

static void ClearFolder(const char *data_dir)

function to clear a directory

static std::string SpaceToUnderscore(std::string)

replaces spaces in a std::string with underscores

static bool PingConnect(const std::string &ip_address)

check if you can ping an IP address

Parameters:

ip_adress – the IP address as a string

static bool CheckFtp()

check if FTP server is up

static std::vector<int> DelimStrToVec(std::string input_string, char delim, uint8_t size, bool check_01)

convert comma delimited string of ints to vector of ints

Parameters:
  • input_string – string to convert

  • size – the number of ints expected

  • check_01 – set to 0 if input int is not 0 or 1

static std::string BuildStr(std::string stem, const std::string &sep, int val, int rep)

build strings with repetetive ints following a stem useful for ZynqManager telnet interface

Parameters:
  • stem – the start of the string

  • sep – the delimiter

  • val – the int value to be repeated

  • number – of times to repeat val

static std::string BuildStrFromVec(std::string stem, std::string sep, std::vector<int> values)

like BuildStr() but for a vector argument useful for ZynqManager telnet interface

Parameters:
  • stem – the start of the string

  • sep – the delimiter

  • values – vector of int values

static std::streampos FileSize(std::string file_path)

get the file size of an ifstream

Parameters:

file_path – path to the file

static uint32_t BuildCpuHeader(uint32_t type, uint32_t ver)

build the cpu file header

Parameters:
  • type – header tag of the file type

  • ver – header tag of the file type version

static uint32_t BuildCpuTimeStamp()

build the cpu timestamp simple UNIX timestamp

static std::vector<int> ReadMatrixDac10(std::string dac10_filename)

read the DAC10 matrix file into a vector