mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 21:37:13 +02:00
new separate receiver
This commit is contained in:
261
slsReceiverSoftware/includes/circularFifo.h
Normal file
261
slsReceiverSoftware/includes/circularFifo.h
Normal file
@ -0,0 +1,261 @@
|
||||
/* CircularFifo.h
|
||||
* Not any company's property but Public-Domain
|
||||
* Do with source-code as you will. No requirement to keep this
|
||||
* header if need to use it/change it/ or do whatever with it
|
||||
*
|
||||
* Note that there is No guarantee that this code will work
|
||||
* and I take no responsibility for this code and any problems you
|
||||
* might get if using it. The code is highly platform dependent!
|
||||
*
|
||||
* Code & platform dependent issues with it was originally
|
||||
* published at http://www.kjellkod.cc/threadsafecircularqueue
|
||||
* 2009-11-02
|
||||
* @author Kjell Hedstr<74>m, hedstrom@kjellkod.cc */
|
||||
|
||||
#ifndef CIRCULARFIFO_H_
|
||||
#define CIRCULARFIFO_H_
|
||||
|
||||
//#include "sls_receiver_defs.h"
|
||||
#include <semaphore.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
typedef double double32_t;
|
||||
typedef float float32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
|
||||
|
||||
/** Circular Fifo (a.k.a. Circular Buffer)
|
||||
* Thread safe for one reader, and one writer */
|
||||
template<typename Element>
|
||||
class CircularFifo {
|
||||
public:
|
||||
|
||||
CircularFifo(unsigned int Size) : tail(0), head(0){
|
||||
Capacity = Size + 1;
|
||||
array.resize(Capacity);
|
||||
sem_init(&free_mutex,0,0);
|
||||
}
|
||||
virtual ~CircularFifo() {}
|
||||
|
||||
bool push(Element*& item_);
|
||||
bool pop(Element*& item_);
|
||||
|
||||
bool isEmpty() const;
|
||||
bool isFull() const;
|
||||
|
||||
int getSemValue();
|
||||
|
||||
private:
|
||||
volatile unsigned int tail; // input index
|
||||
vector <Element*> array;
|
||||
volatile unsigned int head; // output index
|
||||
unsigned int Capacity;
|
||||
sem_t free_mutex;
|
||||
|
||||
unsigned int increment(unsigned int idx_) const;
|
||||
};
|
||||
|
||||
template<typename Element>
|
||||
int CircularFifo<Element>::getSemValue()
|
||||
{
|
||||
int value;
|
||||
sem_getvalue(&free_mutex, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/** Producer only: Adds item to the circular queue.
|
||||
* If queue is full at 'push' operation no update/overwrite
|
||||
* will happen, it is up to the caller to handle this case
|
||||
*
|
||||
* \param item_ copy by reference the input item
|
||||
* \return whether operation was successful or not */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::push(Element*& item_)
|
||||
{
|
||||
|
||||
int nextTail = increment(tail);
|
||||
if(nextTail != head)
|
||||
{
|
||||
array[tail] = item_;
|
||||
tail = nextTail;
|
||||
sem_post(&free_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// queue was full
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Consumer only: Removes and returns item from the queue
|
||||
* If queue is empty at 'pop' operation no retrieve will happen
|
||||
* It is up to the caller to handle this case
|
||||
*
|
||||
* \param item_ return by reference the wanted item
|
||||
* \return whether operation was successful or not */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::pop(Element*& item_)
|
||||
{
|
||||
// if(head == tail)
|
||||
// return false; // empty queue
|
||||
sem_wait(&free_mutex);
|
||||
|
||||
item_ = array[head];
|
||||
head = increment(head);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Useful for testinng and Consumer check of status
|
||||
* Remember that the 'empty' status can change quickly
|
||||
* as the Procuder adds more items.
|
||||
*
|
||||
* \return true if circular buffer is empty */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::isEmpty() const
|
||||
{
|
||||
return (head == tail);
|
||||
}
|
||||
|
||||
/** Useful for testing and Producer check of status
|
||||
* Remember that the 'full' status can change quickly
|
||||
* as the Consumer catches up.
|
||||
*
|
||||
* \return true if circular buffer is full. */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::isFull() const
|
||||
{
|
||||
int tailCheck = (tail+1) % Capacity;
|
||||
return (tailCheck == head);
|
||||
}
|
||||
|
||||
/** Increment helper function for index of the circular queue
|
||||
* index is inremented or wrapped
|
||||
*
|
||||
* \param idx_ the index to the incremented/wrapped
|
||||
* \return new value for the index */
|
||||
template<typename Element>
|
||||
unsigned int CircularFifo<Element>::increment(unsigned int idx_) const
|
||||
{
|
||||
// increment or wrap
|
||||
// =================
|
||||
// index++;
|
||||
// if(index == array.lenght) -> index = 0;
|
||||
//
|
||||
//or as written below:
|
||||
// index = (index+1) % array.length
|
||||
idx_ = (idx_+1) % Capacity;
|
||||
return idx_;
|
||||
}
|
||||
|
||||
#endif /* CIRCULARFIFO_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#ifndef CIRCULARFIFO_H_
|
||||
#define CIRCULARFIFO_H_
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
|
||||
#include "/usr/include/alsa/atomic.h"
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
template<typename Element>
|
||||
class CircularFifo {
|
||||
public:
|
||||
|
||||
CircularFifo(unsigned int Size) : tail(0), head(0){
|
||||
Capacity = Size + 1;
|
||||
array.resize(Capacity);
|
||||
}
|
||||
virtual ~CircularFifo() {}
|
||||
|
||||
bool push(Element*& item_);
|
||||
bool pop(Element*& item_);
|
||||
|
||||
bool wasEmpty() const;
|
||||
bool wasFull() const;
|
||||
bool isLockFree() const;
|
||||
|
||||
private:
|
||||
vector <Element*> array;
|
||||
unsigned int Capacity;
|
||||
|
||||
std::atomic<unsigned int> tail; // input index
|
||||
std::atomic<unsigned int> head; // output index
|
||||
|
||||
unsigned int increment(unsigned int idx_) const;
|
||||
};
|
||||
|
||||
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::push(Element*& item_)
|
||||
{
|
||||
auto currentTail = tail.load();
|
||||
auto nextTail = increment(currentTail);
|
||||
if(nextTail != head.load())
|
||||
{
|
||||
array[currentTail] = item_;
|
||||
tail.store(nextTail);
|
||||
return true;
|
||||
}
|
||||
|
||||
// queue was full
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::pop(Element*& item_)
|
||||
{
|
||||
const auto currentHead = head.load();
|
||||
if(currentHead == tail.load())
|
||||
return false; // empty queue
|
||||
|
||||
item_ = array[currentHead];
|
||||
head.store(increment(currentHead));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::wasEmpty() const
|
||||
{
|
||||
return (head.load() == tail.load());
|
||||
}
|
||||
|
||||
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::wasFull() const
|
||||
{
|
||||
const auto nextTail = increment(tail.load());
|
||||
return (nextTail == head.load());
|
||||
}
|
||||
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::isLockFree() const
|
||||
{
|
||||
return (tail.is_lock_free() && head.is_lock_free());
|
||||
}
|
||||
|
||||
|
||||
template<typename Element>
|
||||
unsigned int CircularFifo<Element>::increment(unsigned int idx_) const
|
||||
{
|
||||
// increment or wrap
|
||||
// =================
|
||||
// index++;
|
||||
// if(index == array.lenght) -> index = 0;
|
||||
//
|
||||
//or as written below:
|
||||
// index = (index+1) % array.length
|
||||
return (idx_ + 1) % Capacity;
|
||||
}
|
||||
|
||||
#endif */
|
72
slsReceiverSoftware/includes/receiver_defs.h
Executable file
72
slsReceiverSoftware/includes/receiver_defs.h
Executable file
@ -0,0 +1,72 @@
|
||||
#ifndef RECEIVER_DEFS_H
|
||||
#define RECEIVER_DEFS_H
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define GOODBYE -200
|
||||
|
||||
#define DO_NOTHING 0
|
||||
#define CREATE_FILES 1
|
||||
#define DO_EVERYTHING 2
|
||||
|
||||
#define BUF_SIZE (16*1024*1024) //16mb
|
||||
#define SAMPLE_TIME_IN_NS 100000000//100ms
|
||||
#define MAX_JOBS_PER_THREAD 1000
|
||||
#define HEADER_SIZE_NUM_TOT_PACKETS 2
|
||||
#define HEADER_SIZE_NUM_FRAMES 2
|
||||
#define HEADER_SIZE_NUM_PACKETS 1
|
||||
|
||||
|
||||
//all max frames defined in sls_receiver_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench
|
||||
|
||||
|
||||
#define GOTTHARD_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000
|
||||
/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/
|
||||
#define GOTTHARD_PACKETS_PER_FRAME 2
|
||||
#define GOTTHARD_ONE_PACKET_SIZE 1286
|
||||
#define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2
|
||||
#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2
|
||||
|
||||
#define GOTTHARD_SHORT_PACKETS_PER_FRAME 1
|
||||
#define GOTTHARD_SHORT_BUFFER_SIZE 518
|
||||
#define GOTTHARD_SHORT_DATABYTES 512
|
||||
#define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF
|
||||
#define GOTTHARD_SHORT_FRAME_INDEX_OFFSET 0
|
||||
#define GOTTHARD_SHORT_PACKET_INDEX_MASK 0
|
||||
#define GOTTHARD_SHORT_PIXELS_IN_ROW 256
|
||||
#define GOTTHARD_SHORT_PIXELS_IN_COL 1
|
||||
|
||||
|
||||
#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE
|
||||
#define GOTTHARD_FRAME_INDEX_OFFSET 1
|
||||
#define GOTTHARD_PACKET_INDEX_MASK 0x1
|
||||
|
||||
#define GOTTHARD_PIXELS_IN_ROW 1280
|
||||
#define GOTTHARD_PIXELS_IN_COL 1
|
||||
|
||||
|
||||
|
||||
#define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000
|
||||
/*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/
|
||||
#define MOENCH_PACKETS_PER_FRAME 40
|
||||
#define MOENCH_ONE_PACKET_SIZE 1286
|
||||
#define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40
|
||||
#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40
|
||||
|
||||
#define MOENCH_BYTES_PER_ADC (40*2)
|
||||
#define MOENCH_PIXELS_IN_ONE_ROW 160
|
||||
#define MOENCH_BYTES_IN_ONE_ROW (MOENCH_PIXELS_IN_ONE_ROW*2)
|
||||
|
||||
|
||||
#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00
|
||||
#define MOENCH_FRAME_INDEX_OFFSET 8
|
||||
#define MOENCH_PACKET_INDEX_MASK 0xFF
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//#define THIS_SOFTWARE_VERSION 0x20120919
|
||||
#endif
|
118
slsReceiverSoftware/includes/sls_receiver_defs.h
Executable file
118
slsReceiverSoftware/includes/sls_receiver_defs.h
Executable file
@ -0,0 +1,118 @@
|
||||
#ifndef SLS_RECEIVER_DEFS_H
|
||||
#define SLS_RECEIVER_DEFS_H
|
||||
|
||||
|
||||
#ifdef __CINT__
|
||||
#define MYROOT
|
||||
#define __cplusplus
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
typedef double double32_t;
|
||||
typedef float float32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
/** default maximum string length */
|
||||
#define MAX_STR_LENGTH 1000
|
||||
#define MAX_FRAMES_PER_FILE 20000
|
||||
#define SHORT_MAX_FRAMES_PER_FILE 100000
|
||||
#define MOENCH_MAX_FRAMES_PER_FILE 1000
|
||||
|
||||
|
||||
/**
|
||||
\file sls_receiver_defs.h
|
||||
This file contains all the basic definitions common to the slsReceiver class
|
||||
and to the server programs running on the receiver
|
||||
* @author Anna Bergamaschi
|
||||
* @version 0.1alpha (any string)
|
||||
* @see slsDetector
|
||||
$Revision: 809 $
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/** @short class containing all the constants and enum definitions */
|
||||
class slsReceiverDefs {
|
||||
public:
|
||||
|
||||
slsReceiverDefs(){};
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Type of the detector
|
||||
*/
|
||||
enum detectorType {
|
||||
GET_DETECTOR_TYPE=-1, /**< the detector will return its type */
|
||||
GENERIC, /**< generic sls detector */
|
||||
MYTHEN, /**< mythen */
|
||||
PILATUS, /**< pilatus */
|
||||
EIGER, /**< eiger */
|
||||
GOTTHARD, /**< gotthard */
|
||||
PICASSO, /**< picasso */
|
||||
AGIPD, /**< agipd */
|
||||
MOENCH /**< moench */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
return values
|
||||
*/
|
||||
enum {
|
||||
OK, /**< function succeeded */
|
||||
FAIL, /**< function failed */
|
||||
FINISHED, /**< acquisition finished */
|
||||
FORCE_UPDATE
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
indexes for the acquisition timers
|
||||
*/
|
||||
enum timerIndex {
|
||||
FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */
|
||||
ACQUISITION_TIME, /**< exposure time */
|
||||
FRAME_PERIOD, /**< period between exposures */
|
||||
DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */
|
||||
GATES_NUMBER, /**< number of gates per frame (in gated mode) */
|
||||
PROBES_NUMBER, /**< number of probe types in pump-probe mode */
|
||||
CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */
|
||||
ACTUAL_TIME, /**< Actual time of the detector's internal timer */
|
||||
MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */
|
||||
|
||||
PROGRESS, /**< fraction of measurement elapsed - only get! */
|
||||
MEASUREMENTS_NUMBER
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
staus mask
|
||||
*/
|
||||
enum runStatus {
|
||||
IDLE, /**< detector ready to start acquisition - no data in memory */
|
||||
ERROR, /**< error i.e. normally fifo full */
|
||||
WAITING, /**< waiting for trigger or gate signal */
|
||||
RUN_FINISHED, /**< acquisition not running but data in memory */
|
||||
TRANSMITTING, /**< acquisition running and data in memory */
|
||||
RUNNING /**< acquisition running, no data in memory */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
protected:
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT
|
||||
#include "sls_receiver_funcs.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
;
|
55
slsReceiverSoftware/includes/sls_receiver_funcs.h
Normal file
55
slsReceiverSoftware/includes/sls_receiver_funcs.h
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
@internal
|
||||
function indexes to call on the server
|
||||
All set functions with argument -1 work as get, when possible
|
||||
*/
|
||||
#ifndef SLS_RECEIVER_FUNCS_H
|
||||
#define SLS_RECEIVER_FUNCS_H
|
||||
|
||||
enum {
|
||||
//General functions
|
||||
F_EXEC_RECEIVER_COMMAND=0, /**< command is executed */
|
||||
F_EXIT_RECEIVER, /**< turn off receiver server */
|
||||
F_LOCK_RECEIVER, /**< Locks/Unlocks server communication to the given client */
|
||||
F_GET_LAST_RECEIVER_CLIENT_IP, /**< returns the IP of the client last connected to the receiver */
|
||||
F_SET_RECEIVER_PORT, /**< Changes communication port of the receiver */
|
||||
F_UPDATE_RECEIVER_CLIENT, /**< Returns all the important parameters to update the shared memory of the client */
|
||||
|
||||
// Identification
|
||||
F_GET_RECEIVER_ID, /**< get receiver id of version */
|
||||
F_GET_RECEIVER_TYPE, /**< return receiver type */
|
||||
F_SEND_RECEIVER_DETHOSTNAME, /**< set detector hostname to receiver */
|
||||
|
||||
//network functions
|
||||
F_RECEIVER_SHORT_FRAME, /**< Sets receiver to receive short frames */
|
||||
F_SETUP_RECEIVER_UDP, /**< sets the receiver udp connection and returns receiver mac address */
|
||||
|
||||
//Acquisition setup functions
|
||||
F_SET_RECEIVER_TIMER, /**< set/get timer value */
|
||||
F_SET_RECEIVER_DYNAMIC_RANGE, /**< set/get detector dynamic range */
|
||||
F_READ_RECEIVER_FREQUENCY, /**< sets the frequency of receiver sending frames to gui */
|
||||
|
||||
// Acquisition functions
|
||||
F_GET_RECEIVER_STATUS, /**< gets the status of receiver listening mode */
|
||||
F_START_RECEIVER, /**< starts the receiver listening mode */
|
||||
F_STOP_RECEIVER, /**< stops the receiver listening mode */
|
||||
F_START_RECEIVER_READOUT, /**< acquisition has stopped. start remaining readout in receiver */
|
||||
F_READ_RECEIVER_FRAME, /**< read one frame to gui*/
|
||||
|
||||
//file functions
|
||||
F_SET_RECEIVER_FILE_PATH, /**< sets receiver file directory */
|
||||
F_SET_RECEIVER_FILE_NAME, /**< sets receiver file name */
|
||||
F_SET_RECEIVER_FILE_INDEX, /**< sets receiver file index */
|
||||
F_SET_RECEIVER_FRAME_INDEX, /**< sets the receiver frame index */
|
||||
F_GET_RECEIVER_FRAME_INDEX, /**< gets the receiver frame index */
|
||||
F_GET_RECEIVER_FRAMES_CAUGHT, /**< gets the number of frames caught by receiver */
|
||||
F_RESET_RECEIVER_FRAMES_CAUGHT, /**< resets the frames caught by receiver */
|
||||
F_ENABLE_RECEIVER_FILE_WRITE, /**< sets the receiver file write */
|
||||
F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */
|
||||
F_ENABLE_RECEIVER_OVERWRITE /**< set overwrite flag in receiver */
|
||||
|
||||
/* Always append functions hereafter!!! */
|
||||
};
|
||||
|
||||
#endif
|
||||
/** @endinternal */
|
11
slsReceiverSoftware/includes/svnInfoReceiver.h
Normal file
11
slsReceiverSoftware/includes/svnInfoReceiver.h
Normal file
@ -0,0 +1,11 @@
|
||||
//#define SVNPATH ""
|
||||
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsReceiverSoftware/includes"
|
||||
//#define SVNREPPATH ""
|
||||
#define SVNREPUUID "5644e8d6-1a0c-4dbd-ab0e-45e7522ac187"
|
||||
//#define SVNREV 0x5
|
||||
//#define SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTH "l_maliakal_d"
|
||||
#define SVNREV 0x5
|
||||
#define SVNDATE 0x20140515
|
||||
//
|
11
slsReceiverSoftware/includes/svnInfoReceiverTmp.h
Normal file
11
slsReceiverSoftware/includes/svnInfoReceiverTmp.h
Normal file
@ -0,0 +1,11 @@
|
||||
//#define SVNPATH ""
|
||||
#define SVNURL ""
|
||||
//#define SVNREPPATH ""
|
||||
#define SVNREPUUID ""
|
||||
//#define SVNREV ""
|
||||
//#define SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTH ""
|
||||
#define SVNREV ""
|
||||
#define SVNDATE ""
|
||||
//
|
Reference in New Issue
Block a user