summaryrefslogtreecommitdiff
path: root/cesar/maximus/channel/inc/ChannelComputer.h
diff options
context:
space:
mode:
authorsave2008-04-07 14:17:42 +0000
committersave2008-04-07 14:17:42 +0000
commit3d58a62727346b7ac1a6cb36fed1a06ed72228dd (patch)
treed7788c3cf9f76426aef0286d0202e2097f0fa0eb /cesar/maximus/channel/inc/ChannelComputer.h
parent095dca4b0a8d4924093bab424f71f588fdd84613 (diff)
Moved the complete svn base into the cesar directory.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1769 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/maximus/channel/inc/ChannelComputer.h')
-rw-r--r--cesar/maximus/channel/inc/ChannelComputer.h316
1 files changed, 316 insertions, 0 deletions
diff --git a/cesar/maximus/channel/inc/ChannelComputer.h b/cesar/maximus/channel/inc/ChannelComputer.h
new file mode 100644
index 0000000000..479ca5999d
--- /dev/null
+++ b/cesar/maximus/channel/inc/ChannelComputer.h
@@ -0,0 +1,316 @@
+/************************************************************************
+ ChannelComputer.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/channel/inc/ChannelComputer.h
+**************************************************************************/
+
+#ifndef CHANNELCOMPUTER_H
+#define CHANNELCOMPUTER_H
+
+#include "IChannel.h"
+#include "SystemManager.h" // for 'StationsList'
+
+#include "hal/phy/defs.h" // for 'PHY_CARRIER_NB'
+#include "channel_types.h" // for 'MAXIMUS_CHANNEL_MOD_NB'
+
+#include <map>
+#include <boost/random/mersenne_twister.hpp> // for random
+
+class IPhy;
+class PhySciMsgNoise;
+class ChannelSettings;
+class PhySciMsgMpdu;
+class ChannelPoint;
+
+struct Channel_Settings_Key
+{
+ Sci_Msg_Station_Id tx_station_id;
+ Sci_Msg_Station_Id rx_station_id;
+};
+struct ltkey
+{
+ bool operator()(const Channel_Settings_Key & key1, const Channel_Settings_Key & key2) const
+ {
+ if (key1.tx_station_id != key2.tx_station_id)
+ {
+ return key1.tx_station_id < key2.tx_station_id;
+ }
+ else
+ {
+ return key1.rx_station_id < key2.rx_station_id;
+ }
+ }
+};
+typedef std::map<const Channel_Settings_Key, ChannelSettings *, ltkey> ChannelSettingsList;
+
+
+/**
+ * class ChannelComputer
+ */
+
+class ChannelComputer : public IChannel
+{
+
+public:
+
+ // public attributes
+ //
+
+private:
+
+ // private attributes
+ //
+
+ boost::mt19937 mEngine; // for random
+
+ static unsigned short int mNumberOfCopiesArray[PHY_MOD_ROBO_NB];
+ static float mPowerScaleArray[MAXIMUS_CHANNEL_MOD_NB];
+ uint8_t * mpTonemask;
+ StationsList * mpListOfStations;
+ ChannelSettingsList mListOfChannelSettings;
+ unsigned int mBeaconPeriod;
+
+protected:
+
+ // protected attributes
+ //
+
+public:
+
+ // Constructors/Destructors
+ //
+
+ /**
+ * Constructor
+ */
+ ChannelComputer ( IPhy * p_phy, ISystem * p_system );
+
+ /**
+ * Empty Destructor
+ */
+ virtual ~ChannelComputer ( );
+
+ // public methods
+ //
+
+ /**
+ * Duplicate the MPDU payload.
+ * @param mpdu a PHY SCI message MPDU that contains the complete received MPDU payload
+ * @return bool
+ */
+ bool duplicateMpduPayload ( PhySciMsgMpdu & mpdu );
+
+ /**
+ * Compute PB measurement and NOISE.
+ * @param pb_measurement_array the PB measurement to fill in (for all PBs composing the MPDU)
+ * @param noise the PHY SCI message NOISE to fill in
+ * @param pb_header_array the PB header of each PB composing the MPDU
+ * @param mpdu a PHY SCI message MPDU that contains the duplicated MPDU payload
+ * @param tx_station_id the ID of the transmitting station
+ * @param rx_station_id the ID of the destination station
+ * @param current_tick the current Network Clock tick
+ * @return bool
+ */
+ bool addPerturbation ( uint32_t * pb_measurement_array,
+ PhySciMsgNoise & noise,
+ const uint32_t * pb_header_array,
+ const PhySciMsgMpdu & mpdu,
+ const Sci_Msg_Station_Id tx_station_id,
+ const Sci_Msg_Station_Id rx_station_id,
+ const Network_Clock_Tick current_tick );
+
+ /**
+ * Add Channel Settings to the list.
+ * Called when a station is created => create its associated Channel Settings.
+ * @return bool
+ */
+ bool addChannelSettings ( const Sci_Msg_Station_Id created_station_id );
+
+ /**
+ * Find Channel Settings.
+ * @param tx_station_id the ID of the transmitting station
+ * @param rx_station_id the ID of the destination station
+ * @return a list of Channel Settings
+ */
+ std::vector<ChannelSettings *> & findChannelSettings ( const Sci_Msg_Station_Id tx_station_id,
+ const Sci_Msg_Station_Id rx_station_id,
+ const bool both_directions );
+
+ /**
+ * Called when the PHY processor receives a preamble.
+ * @param current_tick the current Network Clock tick
+ * @param tx_station_id the ID of the transmitting station
+ * @return bool
+ */
+ bool receivePre ( const Sci_Msg_Station_Id tx_station_id, const Network_Clock_Tick current_tick );
+
+ /**
+ * Called when the PHY processor receives a frame control.
+ * @param current_tick the current Network Clock tick
+ * @param tx_station_id the ID of the transmitting station
+ * @return bool
+ */
+ bool receiveFc ( const Sci_Msg_Station_Id tx_station_id, const Network_Clock_Tick current_tick );
+
+ // public attribute accessor methods
+ //
+
+ // private attribute accessor methods
+ //
+
+ /**
+ * Sets the tonemask.
+ * @param p_tonemask the new value of mpTonemask
+ * @return bool
+ */
+ bool setTonemask ( const uint8_t * p_tonemask );
+
+ /**
+ * Sets the tonemap of the current transmission.
+ * @return bool
+ * @param tx_station_id the ID of the transmitting station
+ * @param length the tonemap length in octets
+ * @param p_tonemap the tonemap
+ */
+ bool setTonemap ( const Sci_Msg_Station_Id tx_station_id,
+ const unsigned long length,
+ const unsigned char * p_tonemap );
+
+ /**
+ * Sets the beacon period in ticks 25 MHz.
+ * @return bool
+ * @param frequency the power-line frequency
+ */
+ bool setBeaconPeriod ( const float frequency );
+
+ // protected attribute accessor methods
+ //
+
+private:
+
+ // private methods
+ //
+
+ /**
+ * Initializes the Channel Computer class attributes.
+ */
+ void initAttributes ( );
+
+ /**
+ * Gets a tonemask value.
+ * @param carrier_index
+ * @return a boolean value indicating if the requested carrier is enabled or not
+ */
+ const bool getTonemask ( const unsigned short int carrier_index ) const;
+
+ /**
+ * Update the list of Channel Settings.
+ * Called when channel perturbation has to be added.
+ * Check if stations have been removed => remove their associated Channel Settings.
+ */
+ void updateListOfChannelSettings ( );
+
+ /**
+ * Gets the beacon period in ticks 25 MHz.
+ * @return mBeaconPeriod
+ */
+ const unsigned int getBeaconPeriod ( ) const;
+
+protected:
+
+ // protected methods
+ // All following protected methods could be declared as private methods,
+ // but they are declared as protected methods to be unitarly tested.
+ //
+
+ /**
+ * Gets the sigma factor.
+ * @param modulation the tonemap modulation
+ * @param snr_in_db the SNR value in dB
+ * @return the sigma factor
+ */
+ const double getSigma ( const Channel_Mod modulation, const float snr_in_db ) const;
+
+ /**
+ * Gets the PowerScale.
+ * @param modulation the tonemap modulation
+ * @return 1 / (PowerScale^2)
+ */
+ const float getPowerScale ( const Channel_Mod modulation ) const;
+
+ /**
+ * Gets the linear SNR.
+ * @param snr_in_db the SNR value in dB
+ * @return the linear SNR value
+ */
+ const double getLinearSnr ( const float snr_in_db ) const;
+
+ /**
+ * Add noise.
+ * @param point the original point coordinates
+ * @param sigma the sigma factor
+ * @return the noise point coordinates
+ */
+ const ChannelPoint addNoise ( const ChannelPoint & point, const double sigma );
+
+ /**
+ * Compute the BER.
+ * @param codeA / codeB the 2 codes to compare
+ * @return the BER
+ */
+ const unsigned short int computeBer ( const unsigned short int codeA,
+ const unsigned short int codeB ) const;
+
+ /**
+ * Compute the noise.
+ * @param pointA / pointB the 2 points coordinates
+ * @return the (distance)^2 between the 2 points
+ */
+ const unsigned int computeNoise ( const ChannelPoint & pointA,
+ const ChannelPoint & pointB ) const;
+
+ /**
+ * Compute the FER.
+ * @param ber the BER of the current PB
+ * @param n the average number of bits coded per carrier on the current PB
+ * @param modulation the tonemap modulation
+ * @return the FER
+ */
+ const float computeFer ( const unsigned short int ber,
+ const unsigned int n,
+ const Channel_Mod modulation ) const;
+
+ /**
+ * Compute the CRC error.
+ * @param fer the FER of the current PB
+ * @return the CRC error
+ */
+ const bool computeCrcError ( const float fer );
+};
+
+
+#endif /* CHANNELCOMPUTER_H */