DispatcherCmd.h
Go to the documentation of this file.
1 #ifndef DISPATCHERCMD_H
2 #define DISPATCHERCMD_H
3 
4 #include <sys/types.h>
5 #include <stdint.h>
6 #include <vector>
7 
8 // namespace EventDispatcher {
9 
10 // #define USE_MAGIC_NO
11 
13 
14  public:
15 
16 
17  // Magic numbers used as sanity checks
19  DSPCMD_BYTECOUNTMAGIC1 = 0xBBADBEEF,
20  DSPCMD_BYTECOUNTMAGIC2 = 0xBEEFBBAD,
25 
30 
31  };
32 
36  DSPCMD_IDENT = 'I',
48  DSPCMD_END = 'E',
50  };
51 
55  DEFAULT_TRIGGER_MASK = 0xFFFFFFFF,
56  DEFAULT_PRESCALE_MASK = 0xFFFFFFFF,
58  };
59 
60  struct DspCmd {
62  std::vector<int32_t> data;
63  };
64 
65 
66  DispatcherCMD( void* output_buff, bool ack=false);
67  DispatcherCMD(DispatcherCommands cmd, void* output_buff, bool ack=false);
68  DispatcherCMD(DispatcherCommands cmd, int32_t value, void* output_buff, bool ack=false);
69  DispatcherCMD(DispatcherCommands cmd, int32_t value1, int32_t value2, void* output_buff, bool ack=false);
70  DispatcherCMD(DispatcherCommands cmd, std::vector<int32_t> values, void* output_buff, bool ack=false);
71 
72  // Constructor for deserialization of a received command
73  DispatcherCMD(uint8_t* input_buffer);
74 
76 
77  void addCommand(DispatcherCommands cmd, int32_t value);
78  void addCommand(DispatcherCommands cmd, std::vector<int32_t> values);
79 
80  void reset();
81  ssize_t write();
82  //bool sendList();
83 
84  static uint8_t* InsertByteCountMagic(uint8_t* insertion_pointer); //! Function to insert magic numbers into the buffer
85 
87  std::vector<int32_t> getCommandData(){return aCommand.data;};
88 
90 
91 
93 
94  switch( cmd ){
95  // Commands that need Acknowledgement
96  case DSPCMD_IDENT :
98  return true;
99  break;
100  // Commands that do NOT need Acknowledgement
101  case DSPCMD_DATA_VERSION :
102  case DSPCMD_SET_PRESCALE :
108  case DSPCMD_START_DATAFLOW :
109  case DSPCMD_STOP_DATAFLOW :
110  case DSPCMD_NEXT_EVENT :
111  case DSPCMD_END :
113  case DSPCMD_NOT_SET :
114  case DSPCMD_ACK :
115  return false;
116  break;
117  default:
118  return false;
119  }
120  }
121 
122  static bool cmdNeedsAck( DispatcherCMD& cmd){ return cmdNeedsAck(cmd.getCommand()); }
123 
124  protected:
125 
126 
127  private:
128 
129  void Init(void* output_buff);
131  void serializeCmd();
132  bool deserializeCmd(void* input_buffer);
133 
134  DspCmd aCommand; //! A command
136 
137  void* external_buff; //! Pointer to the external output buffer
138  uint8_t internal_buff[256]; //! 256byte internal buffer for serialization
139 
140  // Base address of the buffer we write to
141  union {
142  void* buff_base;
143  uint8_t* buff8_base;
144  uint16_t* buff16_base;
145  uint32_t* buff32_base;
146  };
147 
148  union {
149  uint32_t magicNumberWord[2];
150  uint8_t magicNumberBytes[8];
151  };
152 
153  // Current address of insertion point in the buffer we write to
154  union {
155  void* buff;
156  uint8_t* buff8;
157  uint16_t* buff16;
158  uint32_t* buff32;
159  };
160 
161 };
162 
163 //} // endnamespace
164 
165 #endif /* DISPATCHERCMD_H */
uint8_t magicNumberBytes[8]
static uint8_t * InsertByteCountMagic(uint8_t *insertion_pointer)
static bool cmdNeedsAck(DispatcherCommands cmd)
Definition: DispatcherCmd.h:92
bool deserializeCmd(void *input_buffer)
bool Acknowledge_flag
A command.
void * getExternalBuffer()
Definition: DispatcherCmd.h:89
DispatcherCommands cmd
Definition: DispatcherCmd.h:61
uint8_t * buff8_base
uint32_t magicNumberWord[2]
std::vector< int32_t > data
Definition: DispatcherCmd.h:62
void Init(void *output_buff)
const XML_Char int const XML_Char * value
Definition: expat.h:331
uint32_t * buff32_base
uint8_t * buff8
DispatcherCommands getCommand()
Function to insert magic numbers into the buffer.
Definition: DispatcherCmd.h:86
static bool cmdNeedsAck(DispatcherCMD &cmd)
uint8_t internal_buff[256]
Pointer to the external output buffer.
void addCommand(DispatcherCommands cmd, int32_t value)
void setCommandDefault(DispatcherCommands cmd)
uint32_t * buff32
uint16_t * buff16
DispatcherCMD(void *output_buff, bool ack=false)
std::vector< int32_t > getCommandData()
Definition: DispatcherCmd.h:87
uint16_t * buff16_base
void * external_buff