Skip to content

Commit

Permalink
Add TimeStamp position packet
Browse files Browse the repository at this point in the history
  • Loading branch information
nakhonthai committed Nov 18, 2023
1 parent 2013973 commit 222e9bd
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 26 deletions.
3 changes: 3 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ typedef struct Config_Struct
//--Position
bool igate_bcn;
bool igate_gps;
bool igate_timestamp;
float igate_lat;
float igate_lon;
float igate_alt;
Expand All @@ -202,6 +203,7 @@ typedef struct Config_Struct
bool digi_en;
bool digi_loc2rf;
bool digi_loc2inet;
bool digi_timestamp;
uint8_t digi_ssid;
char digi_mycall[10];
char digi_path[72];
Expand All @@ -224,6 +226,7 @@ typedef struct Config_Struct
bool trk_en;
bool trk_loc2rf;
bool trk_loc2inet;
bool trk_timestamp;
uint8_t trk_ssid;
char trk_mycall[10];
char trk_path[72];
Expand Down
122 changes: 96 additions & 26 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ void defaultConfig()
config.igate_lon = 100.4930;
config.igate_alt = 0;
config.igate_interval = 600;
config.igate_timestamp = false;
sprintf(config.igate_symbol, "/&");
sprintf(config.igate_object, "");
sprintf(config.igate_phg, "");
Expand All @@ -585,6 +586,7 @@ void defaultConfig()
config.digi_loc2rf = true;
config.digi_loc2inet = false;
config.digi_ssid = 3;
config.digi_timestamp = false;
sprintf(config.digi_mycall, "NOCALL");
sprintf(config.digi_path, "WIDE1-1");
//--Position
Expand All @@ -607,6 +609,7 @@ void defaultConfig()
config.trk_sat = false;
config.trk_dx = false;
config.trk_ssid = 9;
config.trk_timestamp = false;
sprintf(config.trk_mycall, "NOCALL");
sprintf(config.trk_path, "WIDE1-1,WIDE2-1");

Expand Down Expand Up @@ -2265,6 +2268,16 @@ String compress_position(double nowLat, double nowLng, int alt_feed, double cour
return str_comp;
}

String getTimeStamp()
{
char strtmp[50];
time_t now;
time(&now);
struct tm *info = gmtime(&now);
sprintf(strtmp, "%02d%02d%02dz", info->tm_mday, info->tm_hour, info->tm_min);
return String(strtmp);
}

String trk_gps_postion(String comment)
{
String rawData = "";
Expand Down Expand Up @@ -2311,11 +2324,6 @@ String trk_gps_postion(String comment)
aprs_symbol = config.trk_symbol[1];
}

char object[10];
memset(object, 0, 10);
memcpy(object, config.trk_item, strlen(config.trk_item));
object[9] = 0;

if (gps.location.isValid() && (gps.hdop.hdop()<10.0))
{
nowLat = gps.location.lat();
Expand Down Expand Up @@ -2355,14 +2363,27 @@ String trk_gps_postion(String comment)

String compPosition = compress_position(nowLat, nowLng, gps.altitude.feet(), course, spdKnot, aprs_table, aprs_symbol, (gps.satellites.value()>3));
// ESP_LOGE("GPS", "Compress=%s", aprs_position);
if (strlen(object) >= 3)
if (strlen(config.trk_item) >= 3)
{
// sprintf(rawTNC, "%s-%d>APTWR1,%s:)%s!%c%s", config.aprs_mycall, config.aprs_ssid, Path.c_str(), object, aprs_table, aprs_position);
sprintf(rawTNC, ")%s!%s", object, compPosition.c_str());
char object[10];
memset(object, 0x20, 10);
memcpy(object, config.trk_item,strlen(config.trk_item));
object[9] = 0;
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(rawTNC, ";%s*%s%s", object, timeStamp, compPosition.c_str());
}else{
sprintf(rawTNC, ")%s!%s", config.trk_item, compPosition.c_str());
}
}
else
{
sprintf(rawTNC, "!%s", compPosition.c_str());
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(rawTNC, "/%s%s",timeStamp, compPosition.c_str());
}else{
sprintf(rawTNC, "!%s", compPosition.c_str());
}
}
}
else
Expand All @@ -2382,17 +2403,27 @@ String trk_gps_postion(String comment)
{
sprintf(csd_spd, "%03d/%03d", (int)gps.course.deg(), (int)gps.speed.knots());
}
if (strlen(object) >= 3)
if (strlen(config.trk_item) >= 3)
{
char object[10];
memset(object, 0, 10);
strcpy(object, config.trk_item);
memset(object, 0x20, 10);
memcpy(object, config.trk_item,strlen(config.trk_item));
object[9] = 0;
sprintf(rawTNC, ")%s!%02d%02d.%02d%c%c%03d%02d.%02d%c%c%s", object, lat_dd, lat_mm, lat_ss, lat_ns, aprs_table, lon_dd, lon_mm, lon_ss, lon_ew, aprs_symbol, csd_spd);
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(rawTNC, ";%s*%s%02d%02d.%02d%c%c%03d%02d.%02d%c%c%s", object,timeStamp, lat_dd, lat_mm, lat_ss, lat_ns, aprs_table, lon_dd, lon_mm, lon_ss, lon_ew, aprs_symbol, csd_spd);
}else{
sprintf(rawTNC, ")%s!%02d%02d.%02d%c%c%03d%02d.%02d%c%c%s", config.trk_item, lat_dd, lat_mm, lat_ss, lat_ns, aprs_table, lon_dd, lon_mm, lon_ss, lon_ew, aprs_symbol, csd_spd);
}
}
else
{
sprintf(rawTNC, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c%s", lat_dd, lat_mm, lat_ss, lat_ns, aprs_table, lon_dd, lon_mm, lon_ss, lon_ew, aprs_symbol, csd_spd);
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(rawTNC, "/%s%02d%02d.%02d%c%c%03d%02d.%02d%c%c%s",timeStamp, lat_dd, lat_mm, lat_ss, lat_ns, aprs_table, lon_dd, lon_mm, lon_ss, lon_ew, aprs_symbol, csd_spd);
}else{
sprintf(rawTNC, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c%s", lat_dd, lat_mm, lat_ss, lat_ns, aprs_table, lon_dd, lon_mm, lon_ss, lon_ew, aprs_symbol, csd_spd);
}
}
if (config.trk_altitude)
{
Expand All @@ -2409,7 +2440,7 @@ String trk_gps_postion(String comment)
}
else
{
sprintf(rawTNC, ">%s ", object);
sprintf(rawTNC, ">%s ", config.trk_item);
}

String tnc2Raw = "";
Expand Down Expand Up @@ -2443,11 +2474,25 @@ String trk_fix_position(String comment)
// ESP_LOGE("GPS", "Compress=%s", aprs_position);
if (strlen(config.trk_item) >= 3)
{
sprintf(loc, ")%s!%s", config.trk_item, compPosition.c_str());
char object[10];
memset(object, 0x20, 10);
memcpy(object, config.trk_item,strlen(config.trk_item));
object[9] = 0;
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(loc, ";%s*%s%s", object, timeStamp, compPosition.c_str());
}else{
sprintf(loc, ")%s!%s", config.trk_item, compPosition.c_str());
}
}
else
{
sprintf(loc, "!%s", compPosition.c_str());
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(loc, "/%s%s",timeStamp, compPosition.c_str());
}else{
sprintf(loc, "!%s", compPosition.c_str());
}
}
}
else
Expand All @@ -2467,14 +2512,24 @@ String trk_fix_position(String comment)
if (strlen(config.trk_item) >= 3)
{
char object[10];
memset(object, 0, 10);
strcpy(object, config.trk_item);
memset(object, 0x20, 10);
memcpy(object, config.trk_item,strlen(config.trk_item));
object[9] = 0;
sprintf(loc, ")%s!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", object, lat_dd, lat_mm, lat_ss, lat_ns, config.trk_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.trk_symbol[1]);
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(loc, ";%s*%s%02d%02d.%02d%c%c%03d%02d.%02d%c%c", object,timeStamp, lat_dd, lat_mm, lat_ss, lat_ns, config.trk_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.trk_symbol[1]);
}else{
sprintf(loc, ")%s!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", config.trk_item, lat_dd, lat_mm, lat_ss, lat_ns, config.trk_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.trk_symbol[1]);
}
}
else
{
sprintf(loc, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", lat_dd, lat_mm, lat_ss, lat_ns, config.trk_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.trk_symbol[1]);
if(config.trk_timestamp){
String timeStamp=getTimeStamp();
sprintf(loc, "/%s%02d%02d.%02d%c%c%03d%02d.%02d%c%c",timeStamp, lat_dd, lat_mm, lat_ss, lat_ns, config.trk_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.trk_symbol[1]);
}else{
sprintf(loc, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", lat_dd, lat_mm, lat_ss, lat_ns, config.trk_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.trk_symbol[1]);
}
}

if (config.trk_alt > 0)
Expand Down Expand Up @@ -2526,14 +2581,24 @@ String igate_position(double lat, double lon, double alt, String comment)
if (strlen(config.igate_object) >= 3)
{
char object[10];
memset(object, 0, 10);
strcpy(object, config.igate_object);
memset(object, 0x20, 10);
memcpy(object, config.igate_object,strlen(config.igate_object));
object[9] = 0;
sprintf(loc, ")%s!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", object, lat_dd, lat_mm, lat_ss, lat_ns, config.igate_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.igate_symbol[1]);
if(config.igate_timestamp){
String timeStamp=getTimeStamp();
sprintf(loc, ";%s*%s%02d%02d.%02d%c%c%03d%02d.%02d%c%c", object, timeStamp, lat_dd, lat_mm, lat_ss, lat_ns, config.igate_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.igate_symbol[1]);
}else{
sprintf(loc, ")%s!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", config.igate_object, lat_dd, lat_mm, lat_ss, lat_ns, config.igate_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.igate_symbol[1]);
}
}
else
{
sprintf(loc, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", lat_dd, lat_mm, lat_ss, lat_ns, config.igate_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.igate_symbol[1]);
if(config.igate_timestamp){
String timeStamp=getTimeStamp();
sprintf(loc, "/%s%02d%02d.%02d%c%c%03d%02d.%02d%c%c",timeStamp.c_str(), lat_dd, lat_mm, lat_ss, lat_ns, config.igate_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.igate_symbol[1]);
}else{
sprintf(loc, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", lat_dd, lat_mm, lat_ss, lat_ns, config.igate_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.igate_symbol[1]);
}
}
if (config.aprs_ssid == 0)
sprintf(strtmp, "%s>APTWR", config.aprs_mycall);
Expand Down Expand Up @@ -2573,7 +2638,12 @@ String digi_position(double lat, double lon, double alt, String comment)
{
sprintf(strAltitude, "/A=%06d", (int)(alt * 3.28F));
}
sprintf(loc, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", lat_dd, lat_mm, lat_ss, lat_ns, config.digi_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.digi_symbol[1]);
if(config.digi_timestamp){
String timeStamp=getTimeStamp();
sprintf(loc, "/%s%02d%02d.%02d%c%c%03d%02d.%02d%c%c",timeStamp, lat_dd, lat_mm, lat_ss, lat_ns, config.digi_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.digi_symbol[1]);
}else{
sprintf(loc, "!%02d%02d.%02d%c%c%03d%02d.%02d%c%c", lat_dd, lat_mm, lat_ss, lat_ns, config.digi_symbol[0], lon_dd, lon_mm, lon_ss, lon_ew, config.digi_symbol[1]);
}
if (config.digi_ssid == 0)
sprintf(strtmp, "%s>APTWR", config.digi_mycall);
else
Expand Down
52 changes: 52 additions & 0 deletions src/webservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,7 @@ void handle_igate()
bool bcnEN = false;
bool pos2RF = false;
bool pos2INET = false;
bool timeStamp = false;

if (server.hasArg("commitIGATE"))
{
Expand Down Expand Up @@ -2192,6 +2193,14 @@ void handle_igate()
bcnEN = true;
}
}
if (server.argName(i) == "igateTimeStamp")
{
if (server.arg(i) != "")
{
if (String(server.arg(i)) == "OK")
timeStamp = true;
}
}
}

config.igate_en = aprsEn;
Expand All @@ -2201,6 +2210,7 @@ void handle_igate()
config.igate_bcn = bcnEN;
config.igate_loc2rf = pos2RF;
config.igate_loc2inet = pos2INET;
config.igate_timestamp = timeStamp;

saveEEPROM();
initInterval=true;
Expand Down Expand Up @@ -2541,6 +2551,13 @@ void handle_igate()
if (config.inet2rf)
inet2rfEnFlag = "checked";
html += "<td style=\"text-align: left;\"><label class=\"switch\"><input type=\"checkbox\" id=\"inet2rfEnable\" name=\"inet2rfEnable\" onclick=\"onINET2RFCheck()\" value=\"OK\" " + inet2rfEnFlag + "><span class=\"slider round\"></span></label><label style=\"vertical-align: bottom;font-size: 8pt;\"><i> *Switch Internet to RF gateway</i></label></td>\n";
html += "</tr>\n";
html += "<tr>\n";
html += "<td align=\"right\"><b>Time Stamp:</b></td>\n";
String timeStampFlag = "";
if (config.igate_timestamp)
timeStampFlag = "checked";
html += "<td style=\"text-align: left;\"><label class=\"switch\"><input type=\"checkbox\" name=\"igateTimeStamp\" value=\"OK\" " + timeStampFlag + "><span class=\"slider round\"></span></label></td>\n";
html += "</tr>\n<tr>";

html += "<td align=\"right\"><b>POSITION:</b></td>\n";
Expand Down Expand Up @@ -2770,6 +2787,7 @@ void handle_digi()
bool bcnEN = false;
bool pos2RF = false;
bool pos2INET = false;
bool timeStamp = false;

if (server.hasArg("commitDIGI"))
{
Expand Down Expand Up @@ -2998,12 +3016,21 @@ void handle_digi()
config.digiFilter |= FILTER_POSITION;
}
}
if (server.argName(i) == "digiTimeStamp")
{
if (server.arg(i) != "")
{
if (String(server.arg(i)) == "OK")
timeStamp = true;
}
}
}
config.digi_en = digiEn;
config.digi_gps = posGPS;
config.digi_bcn = bcnEN;
config.digi_loc2rf = pos2RF;
config.digi_loc2inet = pos2INET;
config.digi_timestamp = timeStamp;

saveEEPROM();
initInterval=true;
Expand Down Expand Up @@ -3128,6 +3155,14 @@ void handle_digi()

html += "<tr><td style=\"text-align: right;\"><b>Repeat Delay:</b></td><td style=\"text-align: left;\"><input min=\"0\" max=\"10000\" step=\"100\" id=\"digiDelay\" name=\"digiDelay\" type=\"number\" value=\"" + String(config.digi_delay) + "\" /> mSec. <i>*0 is auto,Other random of delay time</i></td></tr>";

html += "<tr>\n";
html += "<td align=\"right\"><b>Time Stamp:</b></td>\n";
String timeStampFlag = "";
if (config.digi_timestamp)
timeStampFlag = "checked";
html += "<td style=\"text-align: left;\"><label class=\"switch\"><input type=\"checkbox\" name=\"digiTimeStamp\" value=\"OK\" " + timeStampFlag + "><span class=\"slider round\"></span></label></td>\n";
html += "</tr>\n";

html += "<tr><td align=\"right\"><b>POSITION:</b></td>\n";
html += "<td align=\"center\">\n";
html += "<table>";
Expand Down Expand Up @@ -3288,6 +3323,7 @@ void handle_tracker()
bool optAlt = false;
bool optBat = false;
bool optSat = false;
bool timeStamp = false;

if (server.hasArg("commitTRACKER"))
{
Expand Down Expand Up @@ -3545,6 +3581,14 @@ void handle_tracker()
pos2INET = true;
}
}
if (server.argName(i) == "trackerTimeStamp")
{
if (server.arg(i) != "")
{
if (String(server.arg(i)) == "OK")
timeStamp = true;
}
}
}
config.trk_en = trakerEn;
config.trk_smartbeacon = smartEn;
Expand All @@ -3558,6 +3602,7 @@ void handle_tracker()
config.trk_altitude = optAlt;
config.trk_bat = optBat;
config.trk_sat = optSat;
config.trk_timestamp = timeStamp;

saveEEPROM();
initInterval=true;
Expand Down Expand Up @@ -3712,6 +3757,13 @@ void handle_tracker()
compressEnFlag = "checked";
html += "<td style=\"text-align: left;\"><label class=\"switch\"><input type=\"checkbox\" name=\"compressEnable\" value=\"OK\" " + compressEnFlag + "><span class=\"slider round\"></span></label><label style=\"vertical-align: bottom;font-size: 8pt;\"><i> *Switch compress packet</i></label></td>\n";
html += "</tr>\n";
html += "<tr>\n";
html += "<td align=\"right\"><b>Time Stamp:</b></td>\n";
String timeStampFlag = "";
if (config.trk_timestamp)
timeStampFlag = "checked";
html += "<td style=\"text-align: left;\"><label class=\"switch\"><input type=\"checkbox\" name=\"trackerTimeStamp\" value=\"OK\" " + timeStampFlag + "><span class=\"slider round\"></span></label></td>\n";
html += "</tr>\n";
String trackerPos2RFFlag = "";
String trackerPos2INETFlag = "";
if (config.trk_loc2rf)
Expand Down

0 comments on commit 222e9bd

Please sign in to comment.