Implementation of senssor application. More...
#include "ble-sensor-application.h"
Public Types | |
enum | BleApplicationState { CONNECTION_SLAVE, CONNECTION_MASTER, ADVERTISE, SCANNING, IDLE } |
Public Member Functions | |
BleSensorApplication (void) | |
Default Constructor. More... | |
virtual | ~BleSensorApplication (void) |
void | AnalyseResponsePacket (Ptr< Packet > p) |
Analyse Response Packet and send ACK. More... | |
void | AnalyseScanResponsePacket (Ptr< Packet > p) |
Analyse Scan Response Packet. More... | |
void | ChangeState (BleApplicationState s) |
Change state of application. More... | |
Ptr< BleLinkLayer > | GetLinkLayer (void) const |
Get LinkLayer. More... | |
Ptr< Node > | GetNode () const |
void | RxFromLinkLayer (Ptr< Packet > p, uint8_t int1, uint8_t int2) |
Received packet from LinkLayer. More... | |
void | SendAdvPacket (void) |
Create and Send AdvPacket. More... | |
void | SendRequestPacket (bool b) |
Send request packet to LinkLayer. More... | |
void | SendResponsePacket (Ptr< Packet > p) |
Send Response Packet to LinkLayer. More... | |
void | SendScanResponse (Ptr< Packet > p) |
Create and Send Scan Request. More... | |
void | SensingEvent (void) |
Called at every 1 hr. More... | |
void | SetLinkLayer (Ptr< BleLinkLayer > ll) |
Set LinkLayer. More... | |
void | SetNode (Ptr< Node > node) |
void | SetStartTime (Time start) |
Public Member Functions inherited from ns3::Application | |
Application () | |
virtual | ~Application () |
Ptr< Node > | GetNode () const |
void | SetNode (Ptr< Node > node) |
void | SetStartTime (Time start) |
Specify application start time. More... | |
void | SetStopTime (Time stop) |
Specify application stop time. More... | |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. More... | |
virtual | ~Object () |
Destructor. More... | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. More... | |
void | Dispose (void) |
Dispose of this Object. More... | |
AggregateIterator | GetAggregateIterator (void) const |
Get an iterator to the Objects aggregated to this one. More... | |
virtual TypeId | GetInstanceTypeId (void) const |
Implement the GetInstanceTypeId method defined in ObjectBase. More... | |
template<typename T > | |
Ptr< T > | GetObject (void) const |
Get a pointer to the requested aggregated Object. More... | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. More... | |
void | Initialize (void) |
Invoke DoInitialize on all Objects aggregated to this one. More... | |
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
SimpleRefCount () | |
Constructor. More... | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount (void) const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment. More... | |
void | Ref (void) const |
Increment the reference count. More... | |
void | Unref (void) const |
Decrement the reference count. More... | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. More... | |
void | GetAttribute (std::string name, AttributeValue &value) const |
Get the value of an attribute, raising fatal errors if unsuccessful. More... | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising erros. More... | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. More... | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. More... | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. More... | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. More... | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. More... | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. More... | |
Static Public Member Functions | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Application | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId (void) |
Register this type. More... | |
Static Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
static void | Cleanup (void) |
Noop. More... | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Protected Member Functions | |
void | PauseApplication (void) |
Call to pause the application. More... | |
virtual void | StartApplication (void) |
Call to start application by starting an advertisement. More... | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. More... | |
virtual void | NotifyNewAggregate (void) |
Notify all Objects aggregated to this one of a new Object being aggregated. More... | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. More... | |
virtual void | NotifyConstructionCompleted (void) |
Notifier called once the ObjectBase is fully constructed. More... | |
Private Member Functions | |
virtual void | DoDispose (void) |
Destructor implementation. More... | |
virtual void | DoInitialize (void) |
Initialize() implementation. More... | |
BleTimeStamp | TimetoTimeStamp (Time t) |
Time to TimeStamp Converter. More... | |
Private Attributes | |
bool | isMoreData |
MoreData remaining? More... | |
std::queue< std::pair < BleTimeStamp, bool > > | m_data |
ConnData. More... | |
bool | m_isOpen |
Open/Close. More... | |
Ptr< BleLinkLayer > | m_linkLayer |
LinkLayer connected to this application. More... | |
Ptr< Node > | m_node |
The node that this application is installed on. More... | |
Ptr< UniformRandomVariable > | m_random |
Random stream for sensing event – Number of sensing events per day. More... | |
uint64_t | m_senseCount |
Sensing count. More... | |
EventId | m_startEvent |
The event that will fire at m_startTime to start the application. More... | |
Time | m_startTime |
The simulation time that the application will start. More... | |
BleApplicationState | m_state |
Current state of Application. More... | |
EventId | m_stopEvent |
The event that will fire at m_stopTime to end the application. More... | |
Time | m_stopTime |
The simulation time that the application will end. More... | |
Additional Inherited Members | |
Protected Attributes inherited from ns3::Application | |
Ptr< Node > | m_node |
The node that this application is installed on. More... | |
EventId | m_startEvent |
The event that will fire at m_startTime to start the application. More... | |
Time | m_startTime |
The simulation time that the application will start. More... | |
EventId | m_stopEvent |
The event that will fire at m_stopTime to end the application. More... | |
Time | m_stopTime |
The simulation time that the application will end. More... | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid (void) |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
Implementation of senssor application.
Definition at line 45 of file ble-sensor-application.h.
Enumerator | |
---|---|
CONNECTION_SLAVE | |
CONNECTION_MASTER | |
ADVERTISE | |
SCANNING | |
IDLE |
Definition at line 49 of file ble-sensor-application.h.
ns3::BleSensorApplication::BleSensorApplication | ( | void | ) |
Default Constructor.
Definition at line 43 of file ble-sensor-application.cc.
References IDLE, m_isOpen, m_random, m_state, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), ns3::Seconds(), and SensingEvent().
|
virtual |
Definition at line 52 of file ble-sensor-application.cc.
References m_senseCount, NS_LOG_DEBUG, and NS_LOG_FUNCTION.
Analyse Response Packet and send ACK.
p | Recevied Response Packet |
Definition at line 269 of file ble-sensor-application.cc.
References ns3::Packet::CopyData(), ns3::Packet::CreateFragment(), data, ns3::Packet::GetSize(), m_linkLayer, NS_LOG_DEBUG, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Simulator::ScheduleNow(), and ns3::BleLinkLayer::TxToPhy().
Referenced by RxFromLinkLayer().
Analyse Scan Response Packet.
p | Recevied Scan Response Packet |
Definition at line 215 of file ble-sensor-application.cc.
References ns3::Packet::CopyData(), data, ns3::Packet::GetSize(), NS_LOG_DEBUG, NS_LOG_FUNCTION, and NS_LOG_INFO.
Referenced by RxFromLinkLayer().
void ns3::BleSensorApplication::ChangeState | ( | BleSensorApplication::BleApplicationState | newVal | ) |
Change state of application.
s | new state of application |
Definition at line 74 of file ble-sensor-application.cc.
References ADVERTISE, m_data, m_state, NS_LOG_FUNCTION, and SendAdvPacket().
Referenced by SensingEvent().
|
privatevirtual |
Destructor implementation.
This method is called by Dispose() or by the Object's destructor, whichever comes first.
Subclasses are expected to implement their real destruction code in an overriden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.
It is safe to call GetObject() from within this method.
Reimplemented from ns3::Application.
Definition at line 366 of file ble-sensor-application.cc.
References ns3::EventId::Cancel(), ns3::Object::DoDispose(), m_linkLayer, m_node, m_startEvent, m_stopEvent, and NS_LOG_FUNCTION.
|
privatevirtual |
Initialize() implementation.
This method is called only once by Initialize(). If the user calls Initialize() multiple times, DoInitialize() is called only the first time.
Subclasses are expected to override this method and chain up to their parent's implementation once they are done. It is safe to call GetObject() and AggregateObject() from within this method.
Reimplemented from ns3::Application.
Definition at line 358 of file ble-sensor-application.cc.
References ns3::Object::DoInitialize(), m_startEvent, m_startTime, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and StartApplication().
Ptr< BleLinkLayer > ns3::BleSensorApplication::GetLinkLayer | ( | void | ) | const |
Get LinkLayer.
Definition at line 67 of file ble-sensor-application.cc.
References m_linkLayer, and NS_LOG_FUNCTION.
|
static |
Get the type ID.
Definition at line 30 of file ble-sensor-application.cc.
References m_startTime, ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::Seconds(), and ns3::TypeId::SetParent().
|
protected |
Call to pause the application.
Received packet from LinkLayer.
p | Received packet |
int1 | Integer parameter 1 |
int2 | Integer parameter 2 |
When Application is in SCANNING mode, int1 = 0 => Connection request not Allowed int1 = 1 => Conenction request allowed int1 = 2 => Only Connection request is allowed
int2 = 0 => Scan Request not allowed int2 = 1 => Scan Request allowed
When Application is in ADVERTISE mode, int2 = 0 => Received packet is Connection Request int2 = 1 => Received packet is Scan Request
When Application is in CONNECTION_SLAVE mode, int1 = int2 = 1 => Connection is closed. Change state to Advertise
When Application is in CONNECTION_MASTER mode, int1 = int2 = 1 => Connection closed int1 = 1 and int2 = 0 => ConnectionEvent restart
Definition at line 94 of file ble-sensor-application.cc.
References ADVERTISE, AnalyseResponsePacket(), AnalyseScanResponsePacket(), ns3::BleLinkLayer::BleLLChangeState(), ns3::BleLinkLayer::CONN_REQ, ns3::BleLinkLayer::CONN_SLAVE, CONNECTION_MASTER, CONNECTION_SLAVE, ns3::BleLinkLayer::CreateConnection(), ns3::Packet::GetUid(), IDLE, ns3::BleLinkLayer::LL_ADV_RX_ON, ns3::BleLinkLayer::LL_CONN_RX_ON, m_data, m_linkLayer, m_state, ns3::Simulator::Now(), NS_LOG_FUNCTION, NS_LOG_INFO, SCANNING, ns3::Simulator::Schedule(), ns3::Simulator::ScheduleNow(), SendRequestPacket(), SendResponsePacket(), and SendScanResponse().
Referenced by SetLinkLayer().
void ns3::BleSensorApplication::SendAdvPacket | ( | void | ) |
Create and Send AdvPacket.
Definition at line 318 of file ble-sensor-application.cc.
References ns3::BleLinkLayer::ADVERTISER, data, IDLE, m_data, m_linkLayer, m_state, NS_LOG_FUNCTION, ns3::Simulator::ScheduleNow(), and ns3::BleLinkLayer::TxToPhy().
Referenced by ChangeState(), and StartApplication().
void ns3::BleSensorApplication::SendRequestPacket | ( | bool | b | ) |
Send request packet to LinkLayer.
b | Whether it is first request of connection |
Definition at line 377 of file ble-sensor-application.cc.
References CONNECTION_MASTER, data, m_linkLayer, m_state, NS_ASSERT, NS_LOG_FUNCTION, ns3::Simulator::ScheduleNow(), and ns3::BleLinkLayer::TxToPhy().
Referenced by RxFromLinkLayer().
Send Response Packet to LinkLayer.
p | Request packet |
Definition at line 237 of file ble-sensor-application.cc.
References ns3::Packet::CopyData(), data, ns3::BleTimeStamp::day, ns3::BleTimeStamp::hours, m_data, m_linkLayer, ns3::BleTimeStamp::minute, ns3::BleTimeStamp::month, NS_LOG_FUNCTION, ns3::Simulator::ScheduleNow(), ns3::BleTimeStamp::second, ns3::BleLinkLayer::TxToPhy(), and ns3::BleTimeStamp::year.
Referenced by RxFromLinkLayer().
Create and Send Scan Request.
Definition at line 194 of file ble-sensor-application.cc.
References data, ns3::BleTimeStamp::day, ns3::BleTimeStamp::hours, m_data, m_linkLayer, ns3::BleTimeStamp::minute, ns3::BleTimeStamp::month, NS_LOG_FUNCTION, ns3::BleLinkLayer::SCANNER_RESP, ns3::Simulator::ScheduleNow(), ns3::BleTimeStamp::second, ns3::BleLinkLayer::TxToPhy(), and ns3::BleTimeStamp::year.
Referenced by RxFromLinkLayer().
void ns3::BleSensorApplication::SensingEvent | ( | void | ) |
Called at every 1 hr.
If sensed then record time.
Definition at line 394 of file ble-sensor-application.cc.
References ADVERTISE, ChangeState(), CONNECTION_SLAVE, ns3::UniformRandomVariable::GetValue(), IDLE, m_data, m_isOpen, m_random, m_senseCount, m_state, ns3::Minutes(), ns3::Simulator::Now(), NS_LOG_FUNCTION, SCANNING, ns3::Simulator::Schedule(), and TimetoTimeStamp().
Referenced by BleSensorApplication().
void ns3::BleSensorApplication::SetLinkLayer | ( | Ptr< BleLinkLayer > | ll | ) |
Set LinkLayer.
ll | Pointer to BleLinkLayer |
Definition at line 59 of file ble-sensor-application.cc.
References m_linkLayer, ns3::MakeCallback(), NS_LOG_FUNCTION, and RxFromLinkLayer().
void ns3::BleSensorApplication::SetStartTime | ( | Time | start | ) |
Definition at line 86 of file ble-sensor-application.cc.
References m_startEvent, m_startTime, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), visualizer.core::start(), and StartApplication().
|
protectedvirtual |
Call to start application by starting an advertisement.
Reimplemented from ns3::Application.
Definition at line 304 of file ble-sensor-application.cc.
References ADVERTISE, ns3::BleLinkLayer::LL_ADV_RX_ON, m_linkLayer, m_state, NS_LOG_FUNCTION, SCANNING, and SendAdvPacket().
Referenced by DoInitialize(), and SetStartTime().
|
private |
Time to TimeStamp Converter.
Definition at line 415 of file ble-sensor-application.cc.
References ns3::BleTimeStamp::day, ns3::Time::GetDays(), ns3::Time::GetHours(), ns3::Time::GetMinutes(), ns3::Time::GetSeconds(), ns3::Time::GetYears(), ns3::BleTimeStamp::hours, ns3::BleTimeStamp::minute, ns3::BleTimeStamp::month, ns3::BleTimeStamp::second, and ns3::BleTimeStamp::year.
Referenced by SensingEvent().
|
private |
MoreData remaining?
Definition at line 172 of file ble-sensor-application.h.
|
private |
ConnData.
Definition at line 168 of file ble-sensor-application.h.
Referenced by ChangeState(), RxFromLinkLayer(), SendAdvPacket(), SendResponsePacket(), SendScanResponse(), and SensingEvent().
|
private |
Open/Close.
Definition at line 188 of file ble-sensor-application.h.
Referenced by BleSensorApplication(), and SensingEvent().
|
private |
LinkLayer connected to this application.
Definition at line 180 of file ble-sensor-application.h.
Referenced by AnalyseResponsePacket(), DoDispose(), GetLinkLayer(), RxFromLinkLayer(), SendAdvPacket(), SendRequestPacket(), SendResponsePacket(), SendScanResponse(), SetLinkLayer(), and StartApplication().
The node that this application is installed on.
Definition at line 197 of file ble-sensor-application.h.
Referenced by DoDispose().
|
private |
Random stream for sensing event – Number of sensing events per day.
Definition at line 184 of file ble-sensor-application.h.
Referenced by BleSensorApplication(), and SensingEvent().
|
private |
Sensing count.
Definition at line 192 of file ble-sensor-application.h.
Referenced by SensingEvent(), and ~BleSensorApplication().
|
private |
The event that will fire at m_startTime to start the application.
Definition at line 200 of file ble-sensor-application.h.
Referenced by DoDispose(), DoInitialize(), and SetStartTime().
|
private |
The simulation time that the application will start.
Definition at line 198 of file ble-sensor-application.h.
Referenced by DoInitialize(), GetTypeId(), and SetStartTime().
|
private |
Current state of Application.
Definition at line 176 of file ble-sensor-application.h.
Referenced by BleSensorApplication(), ChangeState(), RxFromLinkLayer(), SendAdvPacket(), SendRequestPacket(), SensingEvent(), and StartApplication().
|
private |
The event that will fire at m_stopTime to end the application.
Definition at line 201 of file ble-sensor-application.h.
Referenced by DoDispose().
|
private |
The simulation time that the application will end.
Definition at line 199 of file ble-sensor-application.h.