// Setter functions return:// - true when value passed is not clamped, modified, or rejected// - false when value passed is clamped, modified, or rejectedclassWsprMessageTelemetryBasic{public://///////////////////////////////////////// Setters / Getters for Telemetry/////////////////////////////////////////// 'A' through 'X' for each charboolSetGrid56(constchar*grid56);constchar*GetGrid56()const;// 0 through 21,340, steps of 20boolSetAltitudeMeters(int32_taltitudeMeters);uint16_tGetAltitudeMeters()const;// -50 through 39boolSetTemperatureCelsius(int32_ttemperatureCelsius);int8_tGetTemperatureCelsius()const;// 3.0v through 4.95v, steps of 0.05vboolSetVoltageVolts(doublevoltageVolts);doubleGetVoltageVolts()const;// 0 through 82, steps of 2boolSetSpeedKnots(int32_tspeedKnots);uint8_tGetSpeedKnots()const;boolSetGpsIsValid(boolgpsValid);boolGetGpsIsValid()const;/////////////////////////////////////////// Setters / Getters for Encode / Decode/////////////////////////////////////////boolSetCallsign(constchar*callsign);constchar*GetCallsign()const;// 'A' through 'X' for chars 1 and 2// '0' through '9' for chars 3 and 4boolSetGrid4(constchar*grid4);constchar*GetGrid4()const;// 0, 3, 7, 10, 13, 17, 20, 23, 27, 30, 33, 37, 40, 43, 47, 50, 53, 57, 60boolSetPowerDbm(uint8_tpowerDbm);uint8_tGetPowerDbm()const;// Special Channel Map input into Encoding// 00 through 09, 10 through 19, Q0 through Q9boolSetId13(constchar*id13);constchar*GetId13()const;/////////////////////////////////////////// Encode / Decode/////////////////////////////////////////voidEncode();boolDecode();// return true on successful decode, false otherwise/////////////////////////////////////////// Reset the object to initial values/////////////////////////////////////////voidReset();};
#include<cstdint>#include<iostream>usingnamespacestd;#include"WsprEncoded.h"intmain(){// Create Basic Telemetry objectWsprMessageTelemetryBasictb;// Set telemetry fieldstb.SetGrid56("XS");tb.SetAltitudeMeters(12360);tb.SetTemperatureCelsius(-28);tb.SetVoltageVolts(3.35);tb.SetSpeedKnots(72);tb.SetGpsIsValid(true);// Configure band and channelconstchar*band="20m";uint16_tchannel=123;// Get channel detailsWsprChannelMap::ChannelDetailscd=WsprChannelMap::GetChannelDetails(band,channel);// Encode the datatb.SetId13(cd.id13);tb.Encode();// Extract the encoded WSPR fieldscout<<"Encoded data"<<endl;cout<<"------------"<<endl;cout<<"Callsign: "<<tb.GetCallsign()<<endl;cout<<"Grid4 : "<<tb.GetGrid4()<<endl;cout<<"PowerDbm: "<<(int)tb.GetPowerDbm()<<endl;return0;}
Output
Encoded data
------------
Callsign: 0Y6RLQ
Grid4 : EI27
PowerDbm: 33
structChannelDetails{charid13[3];// id13 column header value (null terminated c-string)uint8_tmin;// start minute (0, 2, 4, 6, 8)uint32_tfreq;// target frequency, in Hz};classWsprChannelMap{public:// For a given band and channel, get the channel detailsstaticChannelDetailsGetChannelDetails(constchar*band,uint16_tchannel);};
#include<cstdint>#include<iostream>usingnamespacestd;#include"WsprEncoded.h"intmain(){// Configure band and channelconstchar*band="20m";uint16_tchannel=123;// Get channel detailsWsprChannelMap::ChannelDetailscd=WsprChannelMap::GetChannelDetails(band,channel);// Examine the detailscout<<"Channel Details for band "<<band<<", channel "<<channel<<endl;cout<<"id13: "<<cd.id13<<endl;cout<<"min : "<<(int)cd.min<<endl;cout<<"freq: "<<cd.freq<<endl;return0;}
Output
Channel Details for band 20m, channel 123
id13: 06
min : 4
freq: 14097020
#include"WsprEncoded.h"/////////////////////////////////////////////////////////////////////// Testing Channel Detail Lookup/////////////////////////////////////////////////////////////////////voidReportChannelDetails(constchar*band,uint16_tchannel){// Report the requested band and channelSerial.print("[Channel details for band ");Serial.print(band);Serial.print(", channel ");Serial.print(channel);Serial.print("]");Serial.println();// Look up channel details by band and channelWsprChannelMap::ChannelDetailscd=WsprChannelMap::GetChannelDetails(band,channel);// Report the channel details for the given band and channel Serial.print("id1 : ");Serial.println(cd.id1);Serial.print("id3 : ");Serial.println(cd.id3);Serial.print("id13: ");Serial.println(cd.id13);Serial.print("min : ");Serial.println(cd.min);Serial.print("freq: ");Serial.println(cd.freq);Serial.println();}voidTestLookupChannelDetails(){constchar*band="20m";uint16_tchannel=368;ReportChannelDetails(band,channel);Serial.println();}/////////////////////////////////////////////////////////////////////// Testing Message Encoding/////////////////////////////////////////////////////////////////////voidReportEncodeBasicTelemetry(constchar*id13,constchar*grid56,int32_taltitudeMeters,int8_ttemperatureCelsius,doublevoltageVolts,uint8_tspeedKnots,boolgpsIsValid){// Create the message encoderWsprMessageTelemetryBasicmsg;// Set the telemetry fieldsmsg.SetGrid56(grid56);msg.SetAltitudeMeters(altitudeMeters);msg.SetTemperatureCelsius(temperatureCelsius);msg.SetVoltageVolts(voltageVolts);msg.SetSpeedKnots(speedKnots);msg.SetGpsIsValid(gpsIsValid);// Set Encoding parametermsg.SetId13(id13);// Report the parameters passed, and if they got automatically clampedSerial.println("Encoded WSPR BasicTelemetry Type1 Message for:");Serial.print("id13 : input as : ");Serial.println(id13);Serial.print(" : clamped to: ");Serial.println(msg.GetId13());Serial.print("grid56 : input as : ");Serial.println(grid56);Serial.print(" : clamped to: ");Serial.println(msg.GetGrid56());Serial.print("altM : input as : ");Serial.println(altitudeMeters);Serial.print(" : clamped to: ");Serial.println(msg.GetAltitudeMeters());Serial.print("tempC : input as : ");Serial.println(temperatureCelsius);Serial.print(" : clamped to: ");Serial.println(msg.GetTemperatureCelsius());Serial.print("voltage : input as : ");Serial.println(voltageVolts);Serial.print(" : clamped to: ");Serial.println(msg.GetVoltageVolts());Serial.print("speedKnots: input as : ");Serial.println(speedKnots);Serial.print(" : clamped to: ");Serial.println(msg.GetSpeedKnots());Serial.print("gpsValid : input as : ");Serial.println(gpsIsValid);Serial.print(" : clamped to: ");Serial.println(msg.GetGpsIsValid());Serial.println();// Do encodingmsg.Encode();// Extract the WSPR Type1 Message fields from the encoderconstchar*callsign=msg.GetCallsign();constchar*grid4=msg.GetGrid4();uint8_tpowerDbm=msg.GetPowerDbm();// Report what the Type1 Message fields areSerial.print("callsign: ");Serial.println(callsign);Serial.print("grid4 : ");Serial.println(grid4);Serial.print("pwrDbm : ");Serial.println(powerDbm);Serial.println();// Give a URL to check decoding atstd::stringurl="";url+="https://traquito.github.io/pro/decode/";url+="?decode=";url+=callsign;url+="%20";url+=grid4;url+="%20";url+=std::to_string(powerDbm);url+="&encode=";Serial.print("Check decoding at: ");Serial.println(url.c_str());Serial.println();}voidTestEncodeBasicTelemetry_NonClampedValues(){constchar*id13="Q5";constchar*grid56="JM";int32_taltitudeMeters=5120;int8_ttemperatureCelsius=-5;doublevoltageVolts=3.25;uint8_tspeedKnots=25;boolgpsIsValid=true;Serial.println("[Testing Non-Clamped Encoded Values]");ReportEncodeBasicTelemetry(id13,grid56,altitudeMeters,temperatureCelsius,voltageVolts,speedKnots,gpsIsValid);}voidTestEncodeBasicTelemetry_ClampedValues(){constchar*id13="Q5";constchar*grid56="JM";int32_taltitudeMeters=25000;int8_ttemperatureCelsius=45;doublevoltageVolts=5.6;uint8_tspeedKnots=96;boolgpsIsValid=true;Serial.println("[Testing Clamped Encoded Values]");ReportEncodeBasicTelemetry(id13,grid56,altitudeMeters,temperatureCelsius,voltageVolts,speedKnots,gpsIsValid);}voidTestEncodeBasicTelemetry(){TestEncodeBasicTelemetry_NonClampedValues();Serial.println();TestEncodeBasicTelemetry_ClampedValues();Serial.println();}/////////////////////////////////////////////////////////////////////// Setup and Loop logic/////////////////////////////////////////////////////////////////////voidsetup(){Serial.begin(9600);}voidloop(){Serial.println("--------------");Serial.println("Start of tests");Serial.println("--------------");Serial.println();TestLookupChannelDetails();TestEncodeBasicTelemetry();Serial.println();delay(5000);}
Output
--------------
Start of tests
--------------
[Channel details for band 20m, channel 368]
id1 : 1
id3 : 8
id13: 18
min : 4
freq: 14097060
[Testing Non-Clamped Encoded Values]
Encoded WSPR BasicTelemetry Type1 Message for:
id13 : input as : Q5
: clamped to: Q5
grid56 : input as : JM
: clamped to: JM
altM : input as : 5120
: clamped to: 5120
tempC : input as : -5
: clamped to: -5
voltage : input as : 3.25
: clamped to: 3.25
speedKnots: input as : 25
: clamped to: 25
gpsValid : input as : 1
: clamped to: 1
callsign: QD5WPK
grid4 : IR39
pwrDbm : 47
Check decoding at: https://traquito.github.io/pro/decode/?decode=QD5WPK%20IR39%2047&encode=
[Testing Clamped Encoded Values]
Encoded WSPR BasicTelemetry Type1 Message for:
id13 : input as : Q5
: clamped to: Q5
grid56 : input as : JM
: clamped to: JM
altM : input as : 25000
: clamped to: 21340
tempC : input as : 45
: clamped to: 39
voltage : input as : 5.60
: clamped to: 4.95
speedKnots: input as : 96
: clamped to: 82
gpsValid : input as : 1
: clamped to: 1
callsign: QD5XUP
grid4 : RK54
pwrDbm : 43
Check decoding at: https://traquito.github.io/pro/decode/?decode=QD5XUP%20RK54%2043&encode=