Skip to content

Commit

Permalink
Nifty console status screen, will probably become default console int…
Browse files Browse the repository at this point in the history
…erface
  • Loading branch information
ab0tj committed May 12, 2015
1 parent 2805de6 commit d757908
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ all: picrumbs
picrumbs: $(OBJS)
$(C) $(OBJS) -lpthread -lhamlib -lhamlib++ -lwiringPi -lcurl -lgps -o picrumbs

beacon.o: beacon.cpp beacon.h hamlib.h pi.h http.h predict.h tnc.h
beacon.o: beacon.cpp beacon.h hamlib.h pi.h http.h predict.h tnc.h console.h version.h
$(C) $(CFLAGS) -o beacon.o beacon.cpp

console.o: console.cpp console.h version.h stringfuncs.h beacon.h hamlib.h
$(C) $(CFLAGS) -o console.o console.cpp

gps.o: gps.cpp gps.h
gps.o: gps.cpp gps.h console.h
$(C) $(CFLAGS) -o gps.o gps.cpp

hamlib.o: hamlib.cpp hamlib.h beacon.h
Expand All @@ -37,7 +37,7 @@ predict.o: predict.cpp predict.h beacon.h
stringfuncs.o: stringfuncs.cpp stringfuncs.h
$(C) $(CFLAGS) -o stringfuncs.o stringfuncs.cpp

tnc.o: tnc.cpp tnc.h beacon.h stringfuncs.h
tnc.o: tnc.cpp tnc.h beacon.h stringfuncs.h console.h
$(C) $(CFLAGS) -o tnc.o tnc.cpp

INIReader.o: INIReader.cpp INIReader.h ini.c ini.h
Expand Down
5 changes: 5 additions & 0 deletions beacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "http.h"
#include "predict.h"
#include "tnc.h"
#include "console.h"
#include "version.h"

// GLOBAL VARS
extern float pos_lat; // current latitude
Expand All @@ -18,6 +20,8 @@ extern short int gps_hdg; // heading from gps
extern string temp_file; // file to get 1-wire temp info from, blank to disable
extern bool temp_f; // temp units: false for C, true for F
extern bool fh_debug; // frequency hopping debug
extern bool console_disp; // print smartbeaconing params to console
extern int console_iface; // console serial port fd

// LOCAL VARS
string mycall; // callsign we're operating under, excluding ssid
Expand Down Expand Up @@ -146,5 +150,6 @@ int beacon() {
if (path != 0) tune_radio(0); // retune if we're not back to the main vhf frequency
if (path != -1) aprs_paths[path].success++; // update stats

if (console_disp) show_pathstats();
return path;
}
3 changes: 0 additions & 3 deletions beacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ using namespace std;
#include <rigclass.h>
#include <vector>

// MACROS
#define PACKET_DEST "APRS" // packet tocall

// STRUCTS
struct aprspath {
freq_t freq; // frequency in hz
Expand Down
56 changes: 34 additions & 22 deletions console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern string beacon_comment; // comment to send along with aprs packets

// VARS
int console_iface; // console serial port fd
bool console_sb; // print smartbeaconing params to console
bool console_disp; // print smartbeaconing params to console

int console_print(string s) {
return write(console_iface, s.c_str(), s.length());
Expand All @@ -31,6 +31,26 @@ string build_prompt() {
return ss.str();
}

void show_pathstats() {
console_print("\x1B[9;0H");

stringstream buff_out;

for (unsigned int i=0; i < aprs_paths.size(); i++) { // loop thru all paths
buff_out << i + 1 << ": " << aprs_paths[i].attempt;

if (aprs_paths[i].attempt > 0) {
buff_out << ", " << aprs_paths[i].success;
buff_out << " (" << (int)(((float)aprs_paths[i].success / (float)aprs_paths[i].attempt) * 100) << "%)";
}

console_print("\x1B[K" + buff_out.str() + "\r\n");

buff_out.str(string()); // clear output buffer
buff_out.clear();
}
}

void* console_thread(void*) { // handle console interaction
stringstream buff_in;
stringstream buff_out;
Expand Down Expand Up @@ -71,7 +91,7 @@ void* console_thread(void*) { // handle console interaction
console_print("comment <new comment>: Set or get current beacon comment.\r\n");
console_print("symbol <c or tc>: Set or get current symbol table, character.\r\n");
console_print("stats: Get path usage statistics.\r\n");
console_print("sbinfo: Show SmartBeaconing info.\r\n");
console_print("info: Show tracker info.\r\n");
} else if (param.compare("bcnnow") == 0) {
console_print("Sending beacon...\r\n");

Expand Down Expand Up @@ -132,27 +152,19 @@ void* console_thread(void*) { // handle console interaction
console_print("comment: " + beacon_comment + "\r\n");
}
} else if (param.compare("stats") == 0) {
console_print("Path: Attempts, successes (success%) - last attempt\r\n\n");

for (unsigned int i=0; i < aprs_paths.size(); i++) { // loop thru all paths
buff_out << i + 1 << ": " << aprs_paths[i].attempt;

if (aprs_paths[i].attempt > 0) {
buff_out << ", " << aprs_paths[i].success;
buff_out << " (" << (int)(((float)aprs_paths[i].success / (float)aprs_paths[i].attempt) * 100) << "%) - ";
buff_out << secs_to_str((int)difftime(time(NULL), aprs_paths[i].lastused));
}

console_print(buff_out.str() + "\r\n");

buff_out.str(string()); // clear output buffer
buff_out.clear();
}
} else if (param.compare("sbinfo") == 0) {
console_print("Press any key to stop.\r\n");
console_sb = true;
console_print("Path: Attempts, successes (success%)\r\n\n");
show_pathstats();
} else if (param.compare("info") == 0) {
console_print("\x1B[2JPiCrumbs <" + prompt + "\r\n");
console_print("Press any key to quit.\r\n\n");
console_print("GPS: \r\n");
console_print("SB: \r\n");
console_print("TNC: \r\n\n");
console_print("Path: Attempts, successes (success%)");
show_pathstats();
console_disp = true;
read(console_iface, data, 1);
console_sb = false;
console_disp = false;
console_print("\r\n");
} else {
console_print("Error: Unrecognized command: " + param + "\r\n");
Expand Down
1 change: 1 addition & 0 deletions console.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ using namespace std;
// FUNCTIONS
int console_print(string);
void* console_thread(void*);
void show_pathstats();
#endif
6 changes: 6 additions & 0 deletions gps.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "gps.h"
#include "console.h"
#include <pthread.h>
#include <libgpsmm.h>

// GLOBAL VARS
extern bool verbose;
extern bool gps_debug;
extern bool console_disp; // print smartbeaconing params to console
extern int console_iface; // console serial port fd

// LOCAL VARS
int gps_iface; // gps serial port fd
Expand All @@ -31,6 +34,7 @@ void* gps_thread(void*) {
if (!gps_rec.waiting(5000000)) {
gps_valid = false;
if (gps_debug) printf("GPS_DEBUG: GPSd timeout.\n");
if (console_disp) console_print("\x1B[4;6H\x1B[KGPSd timeout.");
continue;
}

Expand All @@ -48,9 +52,11 @@ void* gps_thread(void*) {
if (newdata->set & ALTITUDE_SET) pos_alt = newdata->fix.altitude;

if (gps_debug) printf("GPS_DEBUG: Lat:%f Lon:%f Alt:%i MPH:%.2f Hdg:%i Mode:%iD\n", pos_lat, pos_lon, pos_alt, gps_speed, gps_hdg, newdata->fix.mode);
if (console_disp) dprintf(console_iface, "\x1B[4;6H\x1B[KLat:%f Lon:%f Alt:%i MPH:%.2f Hdg:%i Mode:%iD\n", pos_lat, pos_lon, pos_alt, gps_speed, gps_hdg, newdata->fix.mode);
} else {
gps_valid = false; // no fix
if (gps_debug) printf("GPS_DEBUG: No fix.\n");
if (console_disp) console_print("\x1B[4;6H\x1B[KNo Fix.");
}

}
Expand Down
7 changes: 4 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern Rig* radio; // radio control interface reference
extern bool verbose; // verbose interface?
extern bool sb_debug; // smartbeaconing debug
extern unsigned int last_heard; // time since we heard our call on vhf
extern bool console_sb; // print smartbeaconing params to console
extern bool console_disp; // print smartbeaconing params to console

// VARS
unsigned short int sb_low_speed; // SmartBeaconing low threshold, in mph
Expand Down Expand Up @@ -110,14 +110,15 @@ int main(int argc, char* argv[]) {
hdg_change = 360 - abs(hdg_diff);
}

if (abs(hdg_change) > turn_threshold && beacon_timer > sb_turn_time) beacon_timer = beacon_rate;
if (abs(hdg_change) > turn_threshold && beacon_timer > sb_turn_time) beacon_timer = beacon_rate; // SmartBeaconing spec says CornerPegging is "ALWAYS" enabled, but GPS speed doesn't seem to be accurate enough to keep this from being triggered while stopped.
}

if (sb_debug) printf("SB_DEBUG: Speed:%.2f Rate:%i Timer:%i LstHdg:%i Hdg:%i HdgChg:%i Thres:%.0f\n", gps_speed, beacon_rate, beacon_timer, hdg_last, hdg_curr, hdg_change, turn_threshold);
if (console_sb) dprintf(console_iface, "\rSpeed:%.2f Rate:%i Timer:%i LstHdg:%i Hdg:%i HdgChg:%i Thres:%.0f ", gps_speed, beacon_rate, beacon_timer, hdg_last, hdg_curr, hdg_change, turn_threshold);
if (console_disp) dprintf(console_iface, "\x1B[5;6H\x1B[KRate:%i Timer:%i LstHdg:%i Hdg:%i HdgChg:%i Thres:%.0f LstHrd:%i", beacon_rate, beacon_timer, hdg_last, hdg_curr, hdg_change, turn_threshold, last_heard);
}

if (sb_debug && !gps_valid && gps_enable) printf("SB_DEBUG: GPS data invalid. Rate:%i Timer:%i\n", beacon_rate, beacon_timer);
if (console_disp && !gps_valid && gps_enable) dprintf(console_iface, "\x1B[5;6H\x1B[KGPS data invalid. Rate:%i Timer:%i\n ", beacon_rate, beacon_timer);

beacon_timer++;
last_heard++; // this will overflow if not reset for 136 years. then again maybe it's not a problem.
Expand Down
2 changes: 1 addition & 1 deletion stringfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ string secs_to_str(int in) {
if (days > 0) buff << days << "d ";
if (hours > 0) buff << hours << "h ";
if (mins > 0) buff << mins << "m ";
if (secs > 0) buff << secs << 's';
buff << secs << 's';

return buff.str();
}
Expand Down
34 changes: 21 additions & 13 deletions tnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
#include <cstdio>
#include <unistd.h>
#include <fcntl.h>
#include <sstream>
#include "beacon.h"
#include "stringfuncs.h"
#include "console.h"

// GLOBAL VARS
extern bool tnc_debug; // rf debugging
extern string mycall; // callsign we're operating under, excluding ssid
extern unsigned char myssid; // ssid of this station (stored as a number, not ascii)
extern unsigned int last_heard; // time since we heard a station on vhf
extern bool console_disp; // print smartbeaconing params to console
extern int console_iface; // console serial port fd

// VARS
int vhf_tnc_iface; // vhf tnc serial port fd
Expand Down Expand Up @@ -143,10 +147,10 @@ void process_ax25_frame(string data) { // listen for our own packets and update
source.ssid = data[13];
source.decode();

if (tnc_debug) { // process the rest of the frame and print it out
if (tnc_debug || console_disp) { // process the rest of the frame and print it out
ax25address destination;
vector<ax25address> via;
string payload;
stringstream tnc2;

destination.callsign = data.substr(0,6);
destination.ssid = data[6];
Expand All @@ -165,18 +169,22 @@ void process_ax25_frame(string data) { // listen for our own packets and update
index += 7;
} while (!thisone.last);
}
if (index < data.length() - 3) payload = data.substr(index+2); // all the way to the end of the frame, but skip control bytes

printf("TNC_IN: %s", StripNonAscii(source.callsign).c_str());
if (source.ssid != 0) printf("-%i", source.ssid);
printf(">%s", StripNonAscii(destination.callsign).c_str());
if (destination.ssid != 0) printf("-%i", destination.ssid);
for (int i=0;i<viacalls;i++) {
printf(",%s", StripNonAscii(via[i].callsign).c_str());
if (via[i].ssid != 0) printf("-%i", via[i].ssid);
if (via[i].hbit) printf("*");

tnc2 << StripNonAscii(source.callsign);
if (source.ssid != 0) tnc2 << '-' << (int)source.ssid;
tnc2 << '>' << StripNonAscii(destination.callsign);
if (destination.ssid != 0) tnc2 << '-' << (int)destination.ssid;

for (int i = 0; i < viacalls; i++) {
tnc2 << ',' << StripNonAscii(via[i].callsign);
if (via[i].ssid != 0) tnc2 << '-' << (int)via[i].ssid;
if (via[i].hbit) tnc2 << '*';
}
printf(":%s\n", StripNonAscii(payload).c_str());

if (index < data.length() - 3) tnc2 << ':' << StripNonAscii(data.substr(index+2));

if (tnc_debug) printf("%s\n", tnc2.str().c_str());
if (console_disp) console_print("\x1B[6;6H\x1B[K" + tnc2.str());
}

if ((source.callsign.compare(mycall) == 0) && source.ssid == myssid) {
Expand Down
1 change: 1 addition & 0 deletions version.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef VERSION
#define VERSION "0.2" // program version for messages, etc
#define PACKET_DEST "APMG02" // packet tocall
#endif

0 comments on commit d757908

Please sign in to comment.