Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

requestverification.test.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AmptekHardwareInterface.cpp 30.09 KiB
    #include "AmptekHardwareInterface.h"
    #include "packet.h"
    #include <iostream>
    #include <iomanip>
    #include <cstring>
    #include "AmptekUdpConnectionHandler.h"
    #include "AmptekUsbConnectionHandler.h"
    #include "AmptekSimulatorConnectionHandler.h"
    
    AmptekHardwareInterface::AmptekHardwareInterface(){
    
    }
    
    AmptekHardwareInterface::~AmptekHardwareInterface(){
        std::cout << "in AmptekHardwareInterface::~AmptekHardwareInterface()" << std::endl;
        if (connection_handler != nullptr){
            std::cout << "delete connection_handler" << std::endl;
            delete connection_handler;
        }
    }
    
    
    /**
     * @brief Connect via UDP to the detector
     * 
     * @param hostname host of the detector, can be IP address
     * @param port port on which the amptek is listening. Should be 10001
     * @param timeout connection timeout in seconds
     */
    void AmptekHardwareInterface::connectUDP(std::string hostname, int port, double timeout){
    
        if (connection_handler != nullptr){
            throw AmptekException("Amptek is already connected");
        }
        else{
            connection_handler = new AmptekUdpConnectionHandler(hostname, port, timeout);
            current_state = ON;
        }
    }
    
    /**
     * @brief Connect via USB to the detector
     * 
     * @param serialNb the serial number of the detector to connect with
     */
    void AmptekHardwareInterface::connectUSB(int serialNb){
    if (connection_handler != nullptr){
            throw AmptekException("Amptek is already connected");
        }
        else{
            connection_handler = new AmptekUsbConnectionHandler(serialNb);
            current_state = ON;
        }
    }
    
    /**
     * @brief Connect to a simulator interface
     * This allows debugging of interface logic without an available hardware to connect to
     * 
     */
    void AmptekHardwareInterface::connectSimulator(){
    
        if (connection_handler != nullptr){
            throw AmptekException("Amptek is already connected");
        }
        else{
            connection_handler = new AmptekSimulatorConnectionHandler();
            current_state = ON;
        }
    }