summaryrefslogtreecommitdiff
path: root/cesar/maximus/phy/inc/PhyProcessor.h
blob: 27531f2e917672f5f70afa05e7f7360bed0c6360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
/************************************************************************
                        PhyProcessor.h - Copyright buret

Here you can write a license for your code, some comments or any other
information you want to have in your generated code. To to this simply
configure the "headings" directory in uml to point to a directory
where you have your heading files.

or you can just replace the contents of this file with your own.
If you want to do this, this file is located at

/usr/share/apps/umbrello/headings/heading.h

-->Code Generators searches for heading files based on the file extension
   i.e. it will look for a file name ending in ".h" to include in C++ header
   files, and for a file name ending in ".java" to include in all generated
   java code.
   If you name the file "heading.<extension>", Code Generator will always
   choose this file even if there are other files with the same extension in the
   directory. If you name the file something else, it must be the only one with that
   extension in the directory to guarantee that Code Generator will choose it.

you can use variables in your heading files which are replaced at generation
time. possible variables are : author, date, time, filename and filepath.
just write %variable_name%

This file was generated on %date% at %time%
The original location of this file is /home/buret/eclipse/maximus/phy/inc/PhyProcessor.h
**************************************************************************/

#ifndef PHYPROCESSOR_H
#define PHYPROCESSOR_H

#include "IPhy.h"

#include "phy_types.h"

#include <map> // for 'map' and 'multimap'

class ISci;
class PhySciMsgNoise;
class PhySciMsgPre;

struct Expected_Tx
{
  Phy_Tx_Id src_tx_id; // expected transmission ID
  Sci_Msg_Station_Id src_station_id; // expected transmitting station ID
};
struct lttx
{
  bool operator() ( const Expected_Tx tx1, const Expected_Tx tx2 ) const
  {
    if (tx1.src_tx_id != tx2.src_tx_id)
    {
      return tx1.src_tx_id < tx2.src_tx_id;
    }
    else
    {
      return tx1.src_station_id < tx2.src_station_id;
    }
  }
};
typedef std::multimap<const Expected_Tx, const Sci_Msg_Station_Id, lttx> RxStationsList; // list of destination stations
struct Frame_Control
{
  uint32_t fc_10;
  uint32_t fc_av[4];
};
typedef std::map<const Expected_Tx, Frame_Control, lttx> RxFcList; // list of received Frame Control
struct Mpdu_Payload
{
  unsigned short int msg_nb; // number of PHY SCI messages MPDU that have been received
  unsigned long data_length;
  unsigned char * p_data;
  uint32_t pb_header[MAC_MAX_PB_PER_MPDU];
};
typedef std::map<const Expected_Tx, Mpdu_Payload, lttx> RxMpduList; // list of received MPDU


/**
  * class PhyProcessor
  * Simulates the real HomePlugAV physical interface and data bus.
  */

class PhyProcessor : public IPhy
{

public:
  
  // public attributes
  //  

private:

  // private attributes
  //
  ISci * mpSciServer;
  INetworkClock * mpNetworkClock;
  IChannel * mpChannel;

  bool mIsChannelEnabled;

  unsigned int mNbOfCarriers;
  uint8_t * mpTonemask;

  Phy_Tx_Id mTxId; // unique ID incremented for each transmission
                   // (PREAMBLE, FC, MPDU, and NOISE if enabled).
  RxStationsList mListOfRxStations;

  PhyMpduCb mInterfaceCb;
  RxFcList mListOfRxFc;
  RxMpduList mListOfRxMpdu;

  float mFrequency;
  Network_Clock_Tick mZeroCrossDelay;
  PhySciMsg * mpZeroCross;

  // For the wrong preambles transmission feature
  bool mIsFalseAlarmActivated;
  PhySciMsgPre * mpWrongPre;
  Network_Clock_Tick mAverageDuration;
  float mStdDeviation;

protected:
  
  // protected attributes
  //  
  
public:

  // Constructors/Destructors
  //  

  /**
   * Constructor
   */
  PhyProcessor ( ISci * p_sci_server );

  /**
   * Empty Destructor
   */
  virtual ~PhyProcessor ( );

  // public methods
  //  

  /**
   * @param  interface_cb
   * Initialize PHY with an interface callback function for PHY SCI message MPDU reception.
   */
  bool init ( PhyMpduCb interface_cb );

  /**
   * Initialize PHY with the PLC frequency for PHY SCI message of type ZERO_CROSS.
   * @param  frequency
   * @return bool
   */
  bool init ( const float frequency );

  /**
   * @return PhySciMsg *
   */
  PhySciMsg * createMsg ( );

  /**
   * Creates a PHY SCI message MPDU.
   * @return PhySciMsgMpdu *
   */
  PhySciMsgMpdu * createMpdu ( );

  /**
   * Sends a PHY SCI message MPDU.
   * This message has to be configured before transmission.
   * @param  p_mpdu
   * @return bool
   */
  bool sendMpdu ( PhySciMsgMpdu * p_mpdu );

  /**
   * Sends the PHY SCI message associated to the received Network Clock event.
   * @return bool
   * @param  received_evt
   */
  bool receiveEvt ( NetworkClockEvt & received_evt );

  /**
   * Processes the received PHY SCI message of type NONE or NOISE.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receiveInvalid ( PhySciMsg & received_phy_sci_msg );

  /**
   * Processes the received PHY SCI message of type PREAMBLE.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receivePre ( PhySciMsg & received_phy_sci_msg );

  /**
   * Processes the received PHY SCI message of type FC_HYBRID_MODE or FC_AV_ONLY_MODE.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receiveFc ( PhySciMsg & received_phy_sci_msg );

  /**
   * Processes the received PHY SCI message of type PRS.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receivePrs ( PhySciMsg & received_phy_sci_msg );

  /**
   * Processes the received PHY SCI message of type MPDU_PAYLOAD.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receiveMpdu ( PhySciMsg & received_phy_sci_msg );

  /**
   * Processes the received PHY SCI message of type TONEMASK.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receiveTonemask ( PhySciMsg & received_phy_sci_msg );

  /**
   * Processes the received PHY SCI message of type TONEMAP.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receiveTonemap ( PhySciMsg & received_phy_sci_msg );

  /**
   * Processes the received PHY SCI message of type RX.
   * @return bool
   * @param  received_phy_sci_msg
   */
  bool receiveRx ( PhySciMsg & received_phy_sci_msg );

  /**
   * @return bool
   * @param  phy_sci_msg_to_send
   */
  bool sendMsgToAllStations ( PhySciMsg & phy_sci_msg_to_send ) const;

  /**
   * Activate the wrong preambles transmission feature.
   * @param  average_duration  average number of ticks 25 MHz between two consecutive wrong preambles
   * @param  std_deviation  the standard deviation
   * @return bool
   */
  bool activateFalseAlarm ( const Network_Clock_Tick average_duration, const float std_deviation );

  /**
   * Deactivate the wrong preambles transmission feature.
   * @return bool
   */
  bool deactivateFalseAlarm ( );

  // public attribute accessor methods
  //  

  // private attribute accessor methods
  //  

  /**
   * @return bool
   * @param  p_network_clock the new value of mpNetworkClock
   */
  bool setNetworkClock ( INetworkClock * p_network_clock );

  /**
   * @return bool
   * @param  p_channel the new value of mpChannel
   */
  bool setChannel ( IChannel * p_channel );

  /**
   * Sets the channel perturbation.
   * @param  is_channel_enabled the new value of mIsChannelEnabled
   */
  bool setIsChannelEnabled ( const bool is_channel_enabled );

  /**
   * Gets the TX ID.
   * @return mTxId
   */
  Phy_Tx_Id getTxId ( ) const;

  /**
   * Gets the tonemask.
   * @return mpTonemask
   */
  const uint8_t * getTonemask ( ) const;

  /**
   * Check if the channel perturbation is enabled.
   * @return mIsChannelEnabled
   */
  bool isChannelEnabled ( ) const;

  /**
   * Sets the power line frequency.
   * @param  frequency  the new value of mFrequency
   * @return bool
   */
  bool setFrequency ( const float frequency );

  /**
   * Gets the power line frequency.
   * @return mFrequency
   */
  float getFrequency ( ) const;

  // protected attribute accessor methods
  //  

private:

  // private methods
  //  

  /**
   * Initializes the PHY processor class attributes.
   */
  void initAttributes ( );

  /**
   * Registers the PHY SCI message creation function to the SCI server.
   */
  void registerPhySciMsg ( );

  /**
   * Computes PREAMBLE transmission duration.
   * @return preamble delay in ticks
   */
  Network_Clock_Tick calculatePreDelay ( ) const;

  /**
   * Computes Frame Control transmission duration.
   * @return Frame Control delay in ticks
   */
  Network_Clock_Tick calculateFcDelay ( Phy_Fc_Mode fc_mode ) const;

  /**
   * Computes MPDU payload transission duration.
   * @return MPDU payload delay in ticks
   */
  Network_Clock_Tick calculateMpduDelay ( Phy_Mod mod,
                                          Phy_Fecrate fecrate,
                                          unsigned short int pb_size,
                                          Phy_Nb_Of_Pbs pb_nb,
                                          Phy_Gil gil ) const;

  /**
   * @return bool
   * @param  phy_sci_msg_to_send
   */
  bool fillMsg ( PhySciMsg & phy_sci_msg_to_send ) const;

  /**
   * @return a pointer to SCI server
   */
  ISci * getSciServer ( ) const;

  /**
   * @return a pointer to Network Clock Processor
   */
  INetworkClock * getNetworkClock ( ) const;

  /**
   * Gets a pointer to Channel.
   * @return mpChannel
   */
  IChannel * getChannel ( ) const;

  /**
   * Gets the number of carriers.
   * @return mNbOfCarriers
   */
  unsigned int getNbOfCarriers ( ) const;

  /**
   * Sets the number of carriers.
   * @return bool
   * @param  nb_of_carriers the new value of mNbOfCarriers
   */
  bool setNbOfCarriers ( const unsigned int nb_of_carriers );

  /**
   * Sets the tonemask.
   * @return bool
   * @param  length the tonemask length in octets
   * @param  p_tonemask the new value of mpTonemask
   */
  bool setTonemask ( const unsigned int length, const uint8_t * p_tonemask );

  /**
   * Increments the TX ID.
   * @return bool
   */
  bool incrementTxId ( );

  /**
   * Gets the interface callback function for PHY SCI message MPDU reception.
   * @return mInterfaceCb
   */
  PhyMpduCb getInterfaceCb ( ) const;

  /**
   * Gets the zero-cross delay for PHY SCI message of type ZERO_CROSS transmission.
   * @return mZeroCrossDelay
   */
  Network_Clock_Tick getZeroCrossDelay ( ) const;

  /**
   * Sets the zero-cross delay for PHY SCI message of type ZERO_CROSS transmission.
   * @param  zero_cross_delay the new value of mZeroCrossDelay
   * @return bool
   */
  bool setZeroCrossDelay ( const Network_Clock_Tick zero_cross_delay );

  /**
   * Gets a pointer to the PHY SCI message of type ZERO_CROSS.
   * @return mpZeroCross
   */
  PhySciMsg * getZeroCross ( ) const;

  /**
   * Schedules an event for next PHY SCI message of type ZERO_CROSS transmission.
   * @return bool
   */
  bool scheduleZeroCross ( );

  /**
   * Sends a PHY SCI message of type MPDU to destination stations.
   * @param  mpdu  the PHY SCI message MPDU to send
   * @return bool
   */
  bool sendMpduToDestStations ( PhySciMsgMpdu & mpdu );

  /**
   * Sends an empty PHY SCI message of type NOISE to destination stations.
   * @param  noise  the empty PHY SCI message NOISE to send
   * @return bool
   */
  bool sendEmptyNoiseToDestStations ( PhySciMsgNoise & noise );

  /**
   * Sends PHY SCI message(s) of type MPDU
   * and a PHY SCI message of type NOISE
   * to destination stations.
   * @param  mpdu  the PHY SCI message of type MPDU
   * @return  bool
   */
  bool sendMpduAndNoiseToDestStations ( PhySciMsgMpdu & mpdu );

  /**
   * Update the list of destination stations.
   * Once a PHY SCI message MPDU has been sent to the destination stations,
   * remove the destination stations from the reception list.
   */
  void updateListOfRxStations ( PhySciMsgMpdu & mpdu );

  /**
   * Check if the wrong preambles transmission is enabled or not.
   * @return mIsFalseAlarmActivated
   */
  bool isFalseAlarmActivated ( ) const;

  /**
   * Gets a pointer to the PHY SCI message of type PREAMBLE with the flag PHY_FLAG_WRONG_PREAMBLE set.
   * @return mpWrongPre
   */
  PhySciMsgPre * getWrongPre ( ) const;

  /**
   * Gets the average number of ticks 25 MHz between 2 consecutive wrong preambles transmissions.
   * @return mAverageDuration
   */
  Network_Clock_Tick getAverageDuration ( ) const;

  /**
   * Gets the standard deviation (used to calculate date of the next wrong preamble transmission).
   * @return mStdDeviation
   */
  float getStdDeviation ( ) const;

  /**
   * Calculate date of next wrong preamble transmission.
   * @return the calculated date in ticks 25 MHz
   */
  Network_Clock_Tick calculateNextWrongPreDate ( ) const;

  /**
   * Schedules an event for next wrong preamble transmission.
   * @param  tick_wrong_pre  the next wrong preamble should be transmitted at current date + tick_wrong_pre (in 25 MHz)
   * @return bool
   */
  bool scheduleNextWrongPre ( const Network_Clock_Tick tick_wrong_pre ) const;

protected:
  
  // protected methods
  //  

};


#endif // PHYPROCESSOR_H