Skip to content

Commit

Permalink
figured out meter mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Efpophis committed Apr 15, 2019
1 parent 2798d82 commit 1070435
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
*.out
*.app
tunerctl
ampctl
tunermon

16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
%.o:%.c
g++ -c -o $@ $<

tunerctl : tuner.o serial.o
tunermon : tunermon.o serial.o
g++ -o $@ $^

tunerctl: tunerctl.o serial.o
g++ -o $@ $^

ampctl: ampctl.o serial.o
g++ -o $@ $^



clean:
rm -f *.o
rm -f tunerctl

rm -f tunermon
rm -f ampctl

all: tunerctl ampctl tunermon

52 changes: 52 additions & 0 deletions ampctl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
#include <string>
#include <unistd.h>
#include "serial.h"


using namespace std;

int main( int argc, char* argv[] )
{
const unsigned char off_cmd[] = { 0xff, 0x01, 0x00 };
const unsigned char on_cmd[] = { 0xff, 0x01, 0x01 };

SerialPort port;

if ( port.init( "/dev/ttyUSB2" ) != -1 )
{
if ( argc == 2 )
{
string status = argv[1];

if ( status == "on" )
{
port.write( on_cmd, sizeof( on_cmd ) );
}
else if ( status == "reset" )
{
port.write( off_cmd, sizeof(off_cmd) );
sleep(1);
port.write( on_cmd, sizeof( on_cmd ) );
}
else if ( status == "off" )
{
port.write( off_cmd, sizeof( off_cmd ) );
}
else
{
cout << "invalid command: " << status << endl;
}

}
else
{
cout << "invalid argument" << endl;
}
}
else
{
cout << "Error initializing port" << endl;
}
return 0;
}
139 changes: 139 additions & 0 deletions tunerctl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <math.h>
#include <arpa/inet.h> // for ntohs
#include <unistd.h>
#include "serial.h"

using namespace std;

void tuneResponse( char r )
{
switch (r)
{
case 'T':
cout << "Good tune!" << endl;
break;

case 'M':
cout << "OK tune.." << endl;
break;

case 'F':
cout << "BAD tune :(" << endl;
break;
}
}

int main( int argc, char* argv[] )
{
const char toggleAntCmd = 'A';
const char memTuneCmd = 'M';
const char fullTuneCmd = 'F';
const char bypassCmd = 'P';
const char autoCmd = 'C';
const char manualCmd = 'M';
const char syncCmd = 'Z';
const char meterCmd = 'S';
const char ctlCmd = 'X';
const char wakeCmd = ' ';

if ( argc == 2 )
{
SerialPort port;

if ( port.init( "/dev/ttyUSB1", B38400) != -1 )
{
string cmd = argv[1];
const string syncResp = "000000000000000AzAz";
char resp[20];

memset( resp, 0x00, sizeof(resp) );

if ( cmd == "toggle" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &toggleAntCmd, sizeof(toggleAntCmd) );
port.readFully( resp, 1 );
cout << "Antenna " << resp << " selected." << endl;
}
else if ( cmd == "mem" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &memTuneCmd, sizeof(memTuneCmd));
port.readFully( resp, 1 );
tuneResponse( resp[0] );
}
else if ( cmd == "full" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &fullTuneCmd, sizeof(fullTuneCmd) );
port.readFully( resp, 1 );
tuneResponse( resp[0] );
}
else if ( cmd == "bypass" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &bypassCmd, sizeof(bypassCmd) );
port.readFully( resp, 1 );
cout << "bypass response: " << resp[0] << endl;
}
else if ( cmd == "auto" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &autoCmd, sizeof(autoCmd) );
port.readFully( resp, 1 );
cout << "auto response: " << resp[0] << endl;
}
else if ( cmd == "manual" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &manualCmd, sizeof(manualCmd) );
port.readFully( resp, 1 );
cout << "Manual response: " << resp[0] << endl;
}
else if ( cmd == "sync" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &syncCmd, sizeof(syncCmd) );
port.readFully( resp, 19 );
cout << "Sync Response: " << resp << endl;
}
else if ( cmd == "meter" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &meterCmd, sizeof(meterCmd) );
}
else if ( cmd == "ctl" )
{
port.write( &wakeCmd, sizeof(wakeCmd) );
usleep( 1000 );
port.write( &ctlCmd, sizeof(ctlCmd));
}
else
{
cout << "invalid command: " << cmd << endl;
}
}
else
{
cout << "problem opening port" << endl;
}

}
else
{
cout << "incorrect number of args" << endl;
}
exit(0);
}
File renamed without changes.

0 comments on commit 1070435

Please sign in to comment.