Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
scIGPMessage.h
Go to the documentation of this file.
1 /* @author János Végh (jvegh)
2 * @bug No known bugs.
3 */
9 #ifndef scIGPMessage_h
10 #define scIGPMessage_h
11 
12 //#include "scGridPoint.h"
13 #include <cstring>
14 #include "GridPoint.h"
15 class scGridPoint;
16 using namespace sc_core; using namespace std;
17 
21 typedef enum {msg_Reg,
27 
29 
32 typedef struct {
33  uint32_t Time : (32-4-4-4-4);
34  uint32_t SubKey: 4;
35  uint32_t ReplyLength : 4;
37  uint32_t Length : 4;
38  uint32_t Type: 4;
39  int &ToInt() { return *reinterpret_cast<int *>(this);}
41 
98 {
99 // friend class scGridPoint; /*!< The messages are handled directly by scGridPoint */
100 // friend class scProcessor; /*!< and by scProcessor */
101 // friend class scClusterBusMemorySlow; /*!< and may go directly to the bus */
102 
103  public:
114  scIGPMessage(void);
115  ~scIGPMessage(void);
116  void
118  BufferContent_Set(int index, int32_t C)
119  { assert(!(index<0 || index >= MAX_IGPCBUFFER_SIZE)); // wrong index
120  mBuffer[4+index] = C;
121  }
123  int32_t
124  BufferContent_Get(int index)
125  { assert(!(index<0 || index >= MAX_IGPCBUFFER_SIZE)); // wrong index
126  return mBuffer[4+index];
127  }
129  string
131  {
132  ostringstream oss;
133  oss << "0x" << hex << BufferContent_Get(index) << dec ;
134  return oss.str();
135  }
141  {
142  MessageFeatures_t MsgType;
143  static_assert( sizeof(MsgType) <= sizeof(mBuffer[1]), "!");
144  memcpy( &MsgType ,&mBuffer[1], sizeof(mBuffer[1]));
145  return MsgType;
146  }
151  void
153  {
154  static_assert( sizeof(F) <= sizeof(mBuffer[1]), "!");
155  memcpy(&mBuffer[1], &F, sizeof(mBuffer[1]));
156  }
159  Type_Get(void)
160  {
161  MessageFeatures_t MsgType;
162  static_assert( sizeof(MsgType) <= sizeof(mBuffer[1]), "!");
163  memcpy( &MsgType ,&mBuffer[1], sizeof(mBuffer[1]));
164  return (IGPMessageType)MsgType.Type;
165  }
167  void
169  {
170  MessageFeatures_t MsgType;
171  static_assert( sizeof(T) <= sizeof(mBuffer[1]), "!");
172  memcpy( &MsgType ,&mBuffer[1], sizeof(mBuffer[1]));
173  MsgType.Type = T;
174  memcpy(&mBuffer[1], &MsgType, sizeof(mBuffer[1]));
175  }
177  int
179  {
180  MessageFeatures_t MsgType;
181  static_assert( sizeof(MsgType) <= sizeof(mBuffer[1]), "!");
182  memcpy( &MsgType ,&mBuffer[1], sizeof(mBuffer[1]));
183  return MsgType.Length;
184  }
189  int
191  {
192  MessageFeatures_t MsgType;
193  static_assert( sizeof(MsgType) <= sizeof(mBuffer[1]), "!");
194  memcpy( &MsgType ,&mBuffer[1], sizeof(mBuffer[1]));
195  return MsgType.ReplyLength;
196  }
200  {
201  ClusterAddress_t CA;
202  memcpy(&CA, &mBuffer[0], sizeof(CA));
203  return CA;
204  }
206  void
208  {
209  memcpy(&mBuffer[0], &CA, sizeof(CA));
210  return;
211  }
213  void
215  {
216  memcpy(&mBuffer[2], &CA, sizeof(CA));
217  return;
218  }
222  {
223  ClusterAddress_t CA;
224  memcpy(&CA, &mBuffer[2], sizeof(CA));
225  return CA;
226  }
227 
229  uint32_t
231  {
232  uint32_t A;
233  memcpy(&A, &mBuffer[3], sizeof(A));
234  return A;
235  }
237  void
238  Header3Address_Set(uint32_t A)
239  {
240  memcpy(&mBuffer[3], &A, sizeof(A));
241  return;
242  }
244  void
245  DelayTime_Set(int16_t T)
246  {
247  MessageFeatures_t MsgType;
248  static_assert( sizeof(T) <= sizeof(mBuffer[1]), "!");
249  memcpy( &MsgType ,&mBuffer[1], sizeof(mBuffer[1]));
250  MsgType.Time = T;
251  memcpy(&mBuffer[1], &MsgType, sizeof(mBuffer[1]));
252  }
254  int16_t
256  {
257  MessageFeatures_t MsgType;
258  static_assert( sizeof(MsgType) <= sizeof(mBuffer[1]), "!");
259  memcpy( &MsgType ,&mBuffer[1], sizeof(mBuffer[1]));
260  return MsgType.Time;
261  }
262 private:
263  int32_t mBuffer[4+MAX_IGPCBUFFER_SIZE];
264 
265 }; // of scIGPMessage
266 
267 #endif // scIGPMessage_h
MessageFeatures_t::Length
uint32_t Length
Definition: scIGPMessage.h:37
msg_Coop
@ msg_Coop
Cooperation-type messages.
Definition: scIGPMessage.h:24
scIGPMessage::ReplyLength_Get
int ReplyLength_Get(void)
Get from the 'memory read' message the requested reply length MessageFeatures_t::ReplyLength.
Definition: scIGPMessage.h:190
MessageFeatures_t::ReplyLength
uint32_t ReplyLength
Definition: scIGPMessage.h:35
GridPoint.h
Topology information for the electronic modules arranged in a grid.
scIGPMessage::BufferContent_Get
int32_t BufferContent_Get(int index)
Returns the index-th element in the buffer.
Definition: scIGPMessage.h:124
scIGPMessage
The scIGPMessage class.
Definition: scIGPMessage.h:97
MessageFeatures_t::Time
uint32_t Time
Definition: scIGPMessage.h:33
scIGPMessage::DestinationAddress_Get
ClusterAddress_t DestinationAddress_Get(void)
Return the ClusterAddress_t address of the destination in the message.
Definition: scIGPMessage.h:199
scIGPMessage::DelayTime_Get
int16_t DelayTime_Get(void)
Return MessageFeatures_t::Length of the message (Total, including the header)
Definition: scIGPMessage.h:255
msg_Qt
@ msg_Qt
QT-type messages.
Definition: scIGPMessage.h:22
scIGPMessage::DestinationAddress_Set
void DestinationAddress_Set(ClusterAddress_t CA)
Set the destination address to ClusterAddress_t address CA.
Definition: scIGPMessage.h:207
scIGPMessage::Header3Address_Set
void Header3Address_Set(uint32_t A)
Set the Header3 address to ClusterAddress_t address CA.
Definition: scIGPMessage.h:238
scIGPMessage::FeatureWord_Get
MessageFeatures_t FeatureWord_Get(void)
Returns the features word of the message.
Definition: scIGPMessage.h:140
MessageFeatures_t::SubKey
uint32_t SubKey
Definition: scIGPMessage.h:34
scGridPoint
This class implements the autonomous grid point functionality: it is a communicating GridPoint....
Definition: scGridPoint.h:127
ClusterAddress_t
A GridPoint can be addressed also by its cluster address of type ClusterAddress_t....
Definition: Clustering.h:58
scIGPMessage::Length_Get
int Length_Get(void)
Return MessageFeatures_t::Length of the message (Total, including the header)
Definition: scIGPMessage.h:178
scIGPMessage::ReplyToAddress_Get
ClusterAddress_t ReplyToAddress_Get(void)
Return the ClusterAddress_t ReplyTo (or source) address.
Definition: scIGPMessage.h:221
scIGPMessage::BufferContent_Set
void BufferContent_Set(int index, int32_t C)
Sets the index-th element of the buffer to C.
Definition: scIGPMessage.h:118
scIGPMessage::FeatureWord_Set
void FeatureWord_Set(MessageFeatures_t &F)
Sets the features word to F.
Definition: scIGPMessage.h:152
msg_Neur
@ msg_Neur
Neuron-type messages.
Definition: scIGPMessage.h:25
scIGPMessage::ReplyToAddress_Set
void ReplyToAddress_Set(ClusterAddress_t CA)
Set the ReplyTo address to ClusterAddress_t address CA.
Definition: scIGPMessage.h:214
IGPMessageType
The basic message types of scIGPMessage messages.
msg_Reg
@ msg_Reg
Register-type messages.
Definition: scIGPMessage.h:21
scIGPMessage::DelayTime_Set
void DelayTime_Set(int16_t T)
Set the type of the message in the buffer to MessageFeatures_t::Type T.
Definition: scIGPMessage.h:245
scIGPMessage::StringOfBufferContent_Get
string StringOfBufferContent_Get(int index)
return content of the index-th element in hexadecimal string form
Definition: scIGPMessage.h:130
MessageFeatures_t
The messages may use this feature word in different ways.
Definition: scIGPMessage.h:32
scIGPMessage::Header3Address_Get
uint32_t Header3Address_Get(void)
Set the ReplyTo (or source) address to ClusterAddress_t CA.
Definition: scIGPMessage.h:230
MessageFeatures_t::Type
uint32_t Type
Definition: scIGPMessage.h:38
IGPMessageType
IGPMessageType
Definition: scIGPMessage.h:21
scIGPMessage::Type_Get
IGPMessageType Type_Get(void)
Returns MessageFeatures_t::Type.
Definition: scIGPMessage.h:159
scIGPMessage::Type_Set
void Type_Set(IGPMessageType &T)
Set the type of the message in the buffer to MessageFeatures_t::Type T.
Definition: scIGPMessage.h:168
msg_Mem
@ msg_Mem
Memory-type messages.
Definition: scIGPMessage.h:23