PHY

Parsing PHY messages

When processing PHY messages sent to a compatible interface, the whad::phy::PhyMsg::getType() function returns the corresponding message type (whad::phy::MessageType). This message type is then used to process and parse the incoming message.

The following example code shows a message processing function defined for a compatible interface that only supports PHY packet sniffing. The supported commands must also be indicated in the interface’s capabilities as described in Discovery of interface characteristics.

void process_phy_message(Message *p_message)
{
    NanoPbMsg *response = NULL;

    /* Wrap our NanoPbMsg into a PhyMsg. */
    whad::phy::PhyMsg phy_msg(message);

    switch (phy_msg.getType())
    {
        case whad::phy::MessageType::SetGfskModMsg:
        {
            /* Configure PHY to GFSK mod/demod ... (custom code) */
            /* ... */

            /* Return a success message. */
            response = new whad::generic::Success();
        }
        break;

        case whad::phy::MessageType::SetSniffModeMsg:
        {
            /* Configure our interface in sniffing mode ... (custom code) */
            /* ... */

            /* Return a success message. */
            response = new whad::generic::Success();
        }
        break;

        case whad::phy::MessageType::StartMsg:
        {
            /* Start current mode. */
            /* ... */

            /* Return a success message. */
            response = new whad::generic::Success();
        }
        break;

        case whad::phy::MessageType::StopMsg:
        {
            /* Stop current mode. */
            /* ... */

            /* Return a success message. */
            response = new whad::generic::Success();
        }
        break;

        default:
        {
            /* Return an error message. */
            whad_generic_cmd_result(&response, WHAD_RESULT_ERROR);
        }
        break;
    }

    /* Send the response to the host. */
    whad::send(*response);
    delete response;
}

PHY API reference

namespace phy

Typedefs

typedef whad::Packet<255> Packet

Enums

enum ModulationType

Modulation type.

Values:

enumerator ModulationASK

Amplitude-Shift Keying modulation.

enumerator ModulationFSK

Frequency Shift Keying modulation.

enumerator Modulation4FSK

Quadrature Frequency-Shift Keying modulation.

enumerator ModulationGFSK

Gaussian Frequency Shift Keying modulation.

enumerator ModulationMSK

Minimum-Shift Keying modulation.

enumerator ModulationBPSK

Binary Phase-Shift Keying modulation.

enumerator ModulationQPSK

Quadrature Phase-Shift Keying modulation.

enumerator ModulationLora

LoRa modulation.

enum Endianness

PHY endianness.

Values:

enumerator PhyLittleEndian

Little-endian.

enumerator PhyBigEndian
enum MessageType

PHY message type.

Values:

enumerator UnknownMsg

Unknown message.

enumerator SetAskModMsg

Set ASK modulation.

enumerator SetFskModMsg

Set FSK modulation.

enumerator SetGfskModMsg

Set GFSK modulation.

enumerator SetBpskModMsg

Set BPSK modulation.

enumerator SetQpskModMsg

Set QPSK modulation.

enumerator Set4FskModMsg

Set 4FSK modulation.

enumerator SetMskModMsg

Set MSK modulation.

enumerator SetLoRaModMsg

Set LoRa modulation.

enumerator GetSupportedFreqsMsg

Get supported frequency ranges.

enumerator SetFreqMsg

Set interface frequency.

enumerator SetDatarateMsg

Set interface datarate.

enumerator SetEndiannessMsg

Set packet endianness.

enumerator SetTxPowerMsg

Set transmitting power.

enumerator SetPacketSizeMsg

Set packet size.

enumerator SetSyncWordMsg

Set synchronization word.

enumerator SetSniffModeMsg

Set interface in sniffing mode.

enumerator SendMsg

Send PDU.

enumerator SendRawMsg

Send raw PDU.

enumerator StartMsg

Start current mode.

enumerator StopMsg

Stop current mode.

enumerator SetJamModeMsg

Set interface in jamming mode.

enumerator SetMonitorModeMsg

Set interface in monitoring mode.

enumerator PacketReceivedMsg

PDU received notification.

enumerator RawPacketReceivedMsg

Raw PDU received notification.

enumerator JammedMsg

Jamming result notification.

enumerator MonitorReportMsg

Monitoring report.

enumerator SupportedFreqsMsg

Supported frequency ranges.

enumerator SendSchedPacketMsg

Schedule a PDU for transmission.

enumerator SchedPacketRespMsg

Schedule response.

enumerator SchedPacketSentMsg

Scheduled PDU sent notification.

enum JammingMode

Values:

enumerator PhyContinuousJamming
enumerator PhyReactiveJamming
enum LoRaSpreadingFactor

LoRa spreading factor.

Values:

enumerator LoraSfError
enumerator LoraSf7

spreading factor: 7

enumerator LoraSf8

spreading factor: 8

enumerator LoraSf9

spreading factor: 9

enumerator LoraSf10

spreading factor: 10

enumerator LoraSf11

spreading factor: 11

enumerator LoraSf12

spreading factor: 12

enum LoRaCodingRate

LoRa coding rate

Values:

enumerator LoraCrError
enumerator LoraCr45

coding rate: 4/5

enumerator LoraCr46

coding rate: 4/6

enumerator LoraCr47

coding rate: 4/7

enumerator LoraCr48

coding rate: 4/8

enum TxPower

Values:

enumerator PhyTxPowerLow
enumerator PhyTxPowerMedium
enumerator PhyTxPowerHigh
class PhyMsg : public whad::NanoPbMsg
#include <base.hpp>

Subclassed by whad::phy::JamMode, whad::phy::Jammed, whad::phy::MonitorMode, whad::phy::PacketReceived, whad::phy::PacketScheduled, whad::phy::SchedulePacket, whad::phy::ScheduledPacketSent, whad::phy::SendPacket, whad::phy::Set4FskMod, whad::phy::SetAskMod, whad::phy::SetBpskMod, whad::phy::SetDatarate, whad::phy::SetEndianness, whad::phy::SetFreq, whad::phy::SetFskMod, whad::phy::SetGfskMod, whad::phy::SetLoraMod, whad::phy::SetMskMod, whad::phy::SetPacketSize, whad::phy::SetQpskMod, whad::phy::SetSyncWord, whad::phy::SetTxPower, whad::phy::SniffMode, whad::phy::Start, whad::phy::Stop, whad::phy::SupportedFreqsResp

Public Functions

PhyMsg()

PHY message base class.

PhyMsg(NanoPbMsg &pMessage)

PHY message base class.

Parameters:

pMessage[in] NanoPbMsg object containing a PHY domain message

~PhyMsg()

PHY message base class destructor.

whad::phy::MessageType getType(void)

Identify the underlying discovery message.

This method can be used when parsing incoming PHY domain message to identify the type of message it contains and process it later.

Returns:

PHY message type.

class FskMod
#include <fskmod.hpp>

Subclassed by whad::phy::Set4FskMod, whad::phy::SetFskMod, whad::phy::SetGfskMod, whad::phy::SetMskMod

Public Functions

FskMod()

Default constructor.

FskMod(uint32_t deviation)

Constructor.

Parameters:

deviation[in] FSK deviation in Hz

uint32_t getDeviation()

Get deviation.

Return values:

Deviation – in Hz

class JamMode : public whad::phy::PhyMsg
#include <jam.hpp>

Public Functions

JamMode(PhyMsg &message)

Create a JamMode message based on raw PHY message.

Parameters:

message[in] Base PhyMsg message to use.

JamMode(JammingMode)

Create a JamMode message with specified mode.

Parameters:

mode[in] Jamming mode to use

JammingMode getMode()

Get the specified jamming mode.

class Jammed : public whad::phy::PhyMsg
#include <jam.hpp>

Public Functions

Jammed(PhyMsg &message)

Create a Jammed message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

Jammed(Timestamp &timestamp)

Create a Jammed message with its associated timestamp.

Parameters:

timestamp[in] Timestamp at which the target has been successfully jammed

Timestamp getTimestamp()

Get message timestamp.

Parameters:

timestamp[in] Timestamp at which the target has been successfully jammed

class MonitorMode : public whad::phy::PhyMsg
#include <monitor.hpp>

Public Functions

MonitorMode(PhyMsg &message)

Create a MonitorMode message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

MonitorMode()

Create a MonitorMode message.

Parameters:

message[in] Base NanoPb message to use.

class PacketReceived : public whad::phy::PhyMsg
#include <packetrx.hpp>

Public Functions

PacketReceived(NanoPbMsg &message)

Create a PacketReceived message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

PacketReceived(uint32_t frequency, int32_t rssi, Timestamp &ts, Packet &packet, SyncWord &syncword, Endianness endian, uint32_t datarate, uint32_t deviation, ModulationType modulation)

Create a PacketReceived message with corresponding parameters.

Parameters:
  • frequency[in] Frequency on which this packet has been received

  • rssi[in] Received signal strength indicator

  • ts[in] Timestamp at which the packet has been received

  • packet[in] Packet received

  • syncword[in] Synchronization word

  • endian[in] Current packet endianness

  • datarate[in] Current datarate

  • deviation[in] Current frequency deviation

  • modulation[in] Current modulation type

uint32_t getFrequency()

Get the frequency parameter.

Return values:

Frequency – in Hz

int32_t getRssi()

Get the RSSI parameter.

Return values:

Received – signal strength indicator

Timestamp &getTimestamp()

Get the timetamp parameter.

Return values:

Timestamp – at which the packet has been received

Packet &getPacket()

Get the received packet.

Return values:

Instance – of Packet representing the received packet

class SchedulePacket : public whad::phy::PhyMsg
#include <schedpkt.hpp>

Public Functions

SchedulePacket(PhyMsg &message)

Create a SchedulePacket message based on raw PHY message.

Schedule Packet

Parameters:

message[in] Base NanoPb message to use.

SchedulePacket(Packet &packet, Timestamp &timestamp)

Create a SchedulePacket message from timestamp and packet.

Parameters:
  • packet[in] Packet to schedule

  • timestamp[in] Timerstamp at which the provided packet must be sent

Packet &getPacket()

Get the scheduled packet object.

Return values:

Scheduled – packet

Timestamp &getTimestamp()

Get the scheduled packet timestamp object.

Return values:

Scheduled – packet timestamp

class PacketScheduled : public whad::phy::PhyMsg
#include <schedpkt.hpp>

Public Functions

PacketScheduled(PhyMsg &message)

Create a PacketScheduled message based on raw PHY message.

Scheduled packet notification

Parameters:

message[in] Base NanoPb message to use.

PacketScheduled(uint8_t packetId, bool full)

Create a PacketScheduled message with specific packet ID.

Parameters:
  • packetId[in] Packet identifier

  • full[in] Set to true to indicate the scheduled packets list is full.

uint8_t getPacketId()

Get the packet identifier.

Return values:

Packet – identifier

bool isFull()

Determine if the scheduled packets list is full.

Return values:

True – if list is full, false otherwise.

class ScheduledPacketSent : public whad::phy::PhyMsg
#include <schedpkt.hpp>

Public Functions

ScheduledPacketSent(PhyMsg &message)

Create a ScheduledPacketSent message based on raw PHY message.

Scheduled packet sent notification

Parameters:

message[in] Base NanoPb message to use.

ScheduledPacketSent(uint32_t packetId)

Create a ScheduledPacketSent message with a specific packet ID.

Parameters:

packetId[in] Packet identifier.

uint32_t getPacketId()

Get message packet ID.

Return values:

Packet – ID

class SendPacket : public whad::phy::PhyMsg
#include <sendpkt.hpp>

Public Functions

SendPacket(PhyMsg &message)

Create a SendPacket message based on raw PHY message.

Send Packet

Parameters:

message[in] Base NanoPb message to use.

SendPacket(Packet &packet)

Create a SendPacket message from a packet.

Parameters:

packet[in] Packet to send

Packet &getPacket()

Get the packet to send.

Return values:

Packet – object to send

class Set4FskMod : public whad::phy::PhyMsg, public whad::phy::FskMod
#include <set4fskmod.hpp>

Public Functions

Set4FskMod(PhyMsg &message)

Create a Set4FskMod message from a NanoPbMsg.

Parameters:

message[in] NanoPb message

Set4FskMod(uint32_t deviation)

Create a Set4FskMod message with a specific deviation.

Parameters:

deviation[in] Deviation in Hz

class SetAskMod : public whad::phy::PhyMsg
#include <setaskmod.hpp>

Public Functions

SetAskMod(PhyMsg &message)

Create a SetAskMod message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

SetAskMod(bool ook)

Create a SetAskMod message.

Parameters:

ook[in] On/Off keying is enabled if set to true, disabled otherwise.

bool isOok()

Determine if OnOff keying is enabled or not.

Return values:

OOK – is enabled if true, disabled otherwise.

class SetBpskMod : public whad::phy::PhyMsg
#include <setbpskmod.hpp>

Public Functions

SetBpskMod(PhyMsg &message)

Create a SetBpskMod message from a NanoPbMsg message.

Parameters:

message[in] NanoPbMsg instance

SetBpskMod()

Create a SetBpskMod message.

class SetDatarate : public whad::phy::PhyMsg
#include <setdatarate.hpp>

Public Functions

SetDatarate(PhyMsg &message)

Create a SetDatarate message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

SetDatarate(uint32_t datarate)

Create a SetDatarate message with specific data rate.

Parameters:

datarate[in] Data rate to use in bits/second

uint32_t getDatarate()

Get the data rate specified in this message.

Return values:

Datarate – in bits/second

class SetEndianness : public whad::phy::PhyMsg
#include <setendian.hpp>

Public Functions

SetEndianness(PhyMsg &message)

Create a SetEndianness message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

SetEndianness(Endianness endian)

Create a SetEndianness message with specific endianness.

Parameters:

endian[in] Endianness to use

Endianness getEndianness()

Get the endianness specified in this message.

Return values:

Endianness – to use

class SetFreq : public whad::phy::PhyMsg
#include <setfreq.hpp>

Public Functions

SetFreq(NanoPbMsg &message)

Create a SetFreq message from a NanoPbMsg message.

Parameters:

message[in] NanoPbMsg instance

SetFreq(uint32_t frequency)

Create a SetFreq message with a specific frequency.

Parameters:

frequency[in] Frequency in Hz

uint32_t getFrequency()

Get the frequency specified in this message.

Return values:

Frequency – in Hz

class SetFskMod : public whad::phy::PhyMsg, public whad::phy::FskMod
#include <setfskmod.hpp>

Public Functions

SetFskMod(PhyMsg &message)

Create a SetFskMod message from a NanoPbMsg.

FSK modulation

Parameters:

message[in] NanoPb message

SetFskMod(uint32_t deviation)

Create a SetFskMod message with a specific deviation.

Parameters:

deviation[in] Deviation in Hz

class SetGfskMod : public whad::phy::PhyMsg, public whad::phy::FskMod
#include <setgfskmod.hpp>

Public Functions

SetGfskMod(PhyMsg &message)

Create a SetGfskMod message from a NanoPbMsg message.

Parameters:

message[in] NanoPbMsg instance

SetGfskMod(uint32_t deviation)

Create a SetGfskMod message with a specific deviation.

Parameters:

deviation[in] Deviation in Hz

class SetLoraMod : public whad::phy::PhyMsg
#include <setloramod.hpp>

Public Functions

SetLoraMod(PhyMsg &message)

Create a SetLoraMod message from a NanoPbMsg message.

Parameters:

message[in] PhyMsg instance

SetLoraMod(uint32_t bandwidth, LoRaSpreadingFactor sf, LoRaCodingRate cr, uint32_t preambleLength, bool enableCrc, bool explicitMode, bool invertIq)

Create a SetLoraMod message with specific parameters.

Parameters:
  • bandwidth[in] Modulation bandwidth in Hz

  • sf[in] Spreading factor

  • cr[in] Coding rate

  • enableCrc[in] If true, CRC will be enabled and checked by the hardware

  • preambleLength[in] Length of preamble, in number of symbols

  • explicitMode[in] If true, set explicit mode

  • invertIq[in] If true, invert I/Q (used in downstream channels)

uint32_t getBandwidth()

Get the message bandwidth modulation parameter.

Return values:

Bandwidth – in Hz.

uint32_t getPreambleLength()

Get the message preamble length parameter.

Return values:

Preamble – length in number of symbols.

LoRaSpreadingFactor getSpreadingFactor()

Get the message spreading factor parameter.

Return values:

Spreading – factor

LoRaCodingRate getCodingRate()

Get the message coding rate parameter.

Return values:

Coding – rate

bool isCrcEnabled()

Determine if CRC is enabled.

Return values:

True – if CRC should be enabled, false otherwise.

bool isExplicitMode()

Determine if explicit mode is enabled.

Return values:

True – if explicit mode should be enabled, false otherwise.

bool isIqInverted()

Determine if IQ inversion is enabled.

Return values:

True – if IQ inversion should be enabled, false otherwise.

class SetMskMod : public whad::phy::PhyMsg, public whad::phy::FskMod
#include <setmskmod.hpp>

Public Functions

SetMskMod(PhyMsg &message)

Create a SetMskMod message from a NanoPbMsg message.

Parameters:

message[in] NanoPbMsg instance

SetMskMod(uint32_t deviation)

Create a SetMskMod message with a specific deviation.

Parameters:

deviation[in] Deviation in Hz

class SetPacketSize : public whad::phy::PhyMsg
#include <setpktsize.hpp>

Public Functions

SetPacketSize(PhyMsg &message)

Create a SetPacketSize message based on raw PHY message.

Set Packet size

Parameters:

message[in] Base PhyMsg message to use.

SetPacketSize(uint32_t size)

Create a SetPacketSize message with a specific size.

Parameters:

size[in] Packet size to use, in bytes

uint32_t getSize()

Get the specified packet size.

Return values:

Packet – size specified, in bytes

class SetQpskMod : public whad::phy::PhyMsg
#include <setqpskmod.hpp>

Public Functions

SetQpskMod(PhyMsg &message)

Create a SetQpskMod message from a NanoPbMsg message.

Parameters:

message[in] NanoPbMsg instance

SetQpskMod(bool offset)

Create a SetQpskMod message with a specific offset.

Parameters:

offset[in] Modulation offset

bool getOffset()

Get modulation offset.

Return values:

Modulation – offset

class SetSyncWord : public whad::phy::PhyMsg
#include <setsyncword.hpp>

Public Functions

SetSyncWord(PhyMsg &message)

Create a SetSyncWord message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

SetSyncWord(SyncWord &syncWord)

Create a SetSyncWord message from a specified synchronization word.

Parameters:

syncWord[in] Synchronization word to use

SyncWord &get()

Get the specified synchronization word.

Return values:

Synchronization – word in use

class SetTxPower : public whad::phy::PhyMsg
#include <settxpower.hpp>

Public Functions

SetTxPower(PhyMsg &message)

Create a SetTxPower message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

SetTxPower(TxPower power)

Create a SetTxPower message with a specific power level.

Parameters:

power[in] Power level to use

TxPower getPower()

Get the specified power level.

Return values:

Power – level specified in this message

class SniffMode : public whad::phy::PhyMsg
#include <sniff.hpp>

Public Functions

SniffMode(PhyMsg &message)

Create a SniffMode message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

SniffMode(bool iqMode)

Create a SniffMode message.

Parameters:

iqMode[in] If set to true, will sniff IQ samples otherwise will sniff packets.

bool isIqModeEnabled()

Determine if IQ sniffing mode is enabled.

Return values:

True – if IQ sniffing is enabled, false otherwise.

class Start : public whad::phy::PhyMsg
#include <start.hpp>

Public Functions

Start(PhyMsg &message)

Create a Start message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

Start()

Default constructor.

class Stop : public whad::phy::PhyMsg
#include <stop.hpp>

Public Functions

Stop(PhyMsg &message)

Create a Stop message based on raw PHY message.

Parameters:

message[in] Base NanoPb message to use.

Stop()

Create a Stop message.

class SupportedFreqsResp : public whad::phy::PhyMsg
#include <suppfreq.hpp>

Public Functions

SupportedFreqsResp(PhyMsg &message)

parse a supported frequency ranges message

Parameters:

message[in] Base PhyMsg message to use.

SupportedFreqsResp(const whad_phy_frequency_range_t *pFreqRanges)

Create a SupportedFreqs message with the provided frequency ranges.

Parameters:

pFreqRanges[in] Pointer to an array containing the supported frequency ranges

class SyncWord
#include <syncword.hpp>
class Timestamp
#include <timestamp.hpp>

Public Functions

Timestamp()

Create a null timestamp.

Timestamp(uint32_t sec, uint32_t usec)

Create a timestamp with a precision to the microsecond.

Parameters:
  • sec[in] Number of seconds

  • usec[in] Number of microseconds

void set(uint32_t sec, uint32_t usec)

Set the timestamp value.

Parameters:
  • sec[in] Number of seconds

  • usec[in] Number of microseconds

uint32_t getSeconds()

Get the number of seconds from a timestamp.

Return values:

Number – of seconds

void setSeconds(uint32_t seconds)

Set the number of seconds.

Parameters:

seconds[in] Number of seconds

uint32_t getMicroseconds()

Get the number of microseconds from a timestamp.

Return values:

Number – of microseconds

void setMicroseconds(uint32_t microseconds)

Set the number of microseconds.

Parameters:

microseconds[in] Number of microseconds