@ -27,6 +27,8 @@
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "dmr/DMRUtils.h"
# include "p25/P25Utils.h"
# include "host/setup/HostSetup.h"
# include "HostMain.h"
# include "Log.h"
@ -92,6 +94,7 @@ int HostSetup::run()
: : LogInfo ( " >> Modem Setup " ) ;
yaml : : Node systemConf = m_conf [ " system " ] ;
yaml : : Node modemConfig = systemConf [ " modem " ] ;
m_duplex = systemConf [ " duplex " ] . as < bool > ( true ) ;
// try to load bandplan identity table
@ -111,20 +114,7 @@ int HostSetup::run()
m_idenTable = new IdenTableLookup ( idenLookupFile , idenReloadTime ) ;
m_idenTable - > read ( ) ;
LogInfo ( " General Parameters " ) ;
std : : string identity = systemConf [ " identity " ] . as < std : : string > ( ) ;
: : LogInfo ( " Identity: %s " , identity . c_str ( ) ) ;
yaml : : Node cwId = systemConf [ " cwId " ] ;
bool cwEnabled = cwId [ " enable " ] . as < bool > ( false ) ;
uint32_t cwTime = cwId [ " time " ] . as < uint32_t > ( 10U ) ;
std : : string callsign = cwId [ " callsign " ] . as < std : : string > ( ) ;
LogInfo ( " CW Id Parameters " ) ;
LogInfo ( " Enabled: %s " , cwEnabled ? " enabled " : " disabled " ) ;
LogInfo ( " Time: %u mins " , cwTime ) ;
LogInfo ( " Callsign: %s " , callsign . c_str ( ) ) ;
yaml : : Node rfssConfig = systemConf [ " config " ] ;
m_channelId = ( uint8_t ) rfssConfig [ " channelId " ] . as < uint32_t > ( 0U ) ;
@ -150,12 +140,6 @@ int HostSetup::run()
return false ;
}
LogInfo ( " System Config Parameters " ) ;
LogInfo ( " RX Frequency: %uHz " , m_rxFrequency ) ;
LogInfo ( " TX Frequency: %uHz " , m_txFrequency ) ;
LogInfo ( " Base Frequency: %uHz " , entry . baseFrequency ( ) ) ;
LogInfo ( " TX Offset: %fMHz " , entry . txOffsetMhz ( ) ) ;
// open terminal console
ret = m_console . open ( ) ;
if ( ! ret ) {
@ -172,37 +156,75 @@ int HostSetup::run()
switch ( c ) {
/** Setup Commands */
case ' M ' :
{
modemConfig = m_conf [ " system " ] [ " modem " ] ;
m_conf [ " system " ] [ " modem " ] [ " protocol " ] [ " type " ] = std : : string ( " uart " ) ; // configuring modem, always sets type to UART
yaml : : Node uartConfig = modemConfig [ " protocol " ] [ " uart " ] ;
std : : string modemPort = uartConfig [ " port " ] . as < std : : string > ( " /dev/ttyUSB0 " ) ;
uint32_t portSpeed = uartConfig [ " speed " ] . as < uint32_t > ( 115200 ) ;
char value [ 21 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > Modem UART Port [%s] ? " , modemPort . c_str ( ) ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 21 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
modemPort = std : : string ( value ) ;
m_conf [ " system " ] [ " modem " ] [ " protocol " ] [ " uart " ] [ " port " ] = modemPort ;
}
: : fprintf ( stdout , " > Port Speed [%u] ? " , portSpeed ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 7 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
sscanf ( value , " %u " , & portSpeed ) ;
m_conf [ " system " ] [ " modem " ] [ " protocol " ] [ " uart " ] [ " speed " ] = __INT_STR ( portSpeed ) ;
}
printStatus ( ) ;
}
break ;
case ' I ' :
{
std : : string identity = m_conf [ " system " ] [ " identity " ] . as < std : : string > ( ) ;
char value [ 9 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > Identity ? " ) ;
: : fprintf ( stdout , " > Identity [%s] ? " , identity . c_str ( ) ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 9 , 0 ) ;
std : : string identity = std : : string ( value ) ;
identity = std : : string ( value ) ;
if ( identity . length ( ) > 0 ) {
m_conf [ " system " ] [ " identity " ] = identity ;
}
writeConfig ( ) ;
printStatus ( ) ;
}
break ;
case ' C ' :
{
cwId = m_conf [ " system " ] [ " cwId " ] ;
bool enabled = cwId [ " enable " ] . as < bool > ( false ) ;
uint32_t cwTime = cwId [ " time " ] . as < uint32_t > ( 10U ) ;
std : : string callsign = cwId [ " callsign " ] . as < std : : string > ( ) ;
char value [ 9 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > Callsign ? " ) ;
: : fprintf ( stdout , " > Callsign [%s] ? " , callsign . c_str ( ) ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 9 , 0 ) ;
std : : string callsign = std : : string ( value ) ;
callsign = std : : string ( value ) ;
if ( callsign . length ( ) > 0 ) {
m_conf [ " system " ] [ " cwId " ] [ " callsign " ] = callsign ;
}
: : fprintf ( stdout , " > CW Enabled (Y/N) ? " ) ;
: : fprintf ( stdout , " > CW Enabled [%u] (Y/N) ? " , enabled ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 2 , 0 ) ;
@ -212,7 +234,7 @@ int HostSetup::run()
m_conf [ " system " ] [ " cwId " ] [ " enable " ] = __BOOL_STR ( enabled ) ;
: : fprintf ( stdout , " > CW Interval (minutes) ? " ) ;
: : fprintf ( stdout , " > CW Interval [%u] (minutes) ? " , cwTime ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 4 , 0 ) ;
@ -222,18 +244,123 @@ int HostSetup::run()
m_conf [ " system " ] [ " cwId " ] [ " time " ] = __INT_STR ( time ) ;
}
writeConfig ( ) ;
printStatus ( ) ;
}
break ;
case ' N ' :
{
rfssConfig = m_conf [ " system " ] [ " config " ] ;
uint32_t siteId = ( uint8_t ) : : strtoul ( rfssConfig [ " siteId " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t dmrNetId = ( uint32_t ) : : strtoul ( rfssConfig [ " dmrNetId " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t p25NetId = ( uint32_t ) : : strtoul ( rfssConfig [ " netId " ] . as < std : : string > ( " BB800 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t p25SysId = ( uint32_t ) : : strtoul ( rfssConfig [ " sysId " ] . as < std : : string > ( " 001 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t p25RfssId = ( uint8_t ) : : strtoul ( rfssConfig [ " rfssId " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
char value [ 6 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > Site ID [$%02X] ? " , siteId ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 3 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
siteId = ( uint32_t ) : : strtoul ( std : : string ( value ) . c_str ( ) , NULL , 16 ) ;
siteId = p25 : : P25Utils : : siteId ( siteId ) ;
m_conf [ " system " ] [ " config " ] [ " siteId " ] = __INT_HEX_STR ( siteId ) ;
}
: : fprintf ( stdout , " > DMR Network ID [$%05X] ? " , dmrNetId ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 6 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
dmrNetId = ( uint32_t ) : : strtoul ( std : : string ( value ) . c_str ( ) , NULL , 16 ) ;
dmrNetId = dmr : : DMRUtils : : netId ( dmrNetId , dmr : : SITE_MODEL_TINY ) ;
m_conf [ " system " ] [ " config " ] [ " dmrNetId " ] = __INT_HEX_STR ( dmrNetId ) ;
}
: : fprintf ( stdout , " > P25 Network ID [$%05X] ? " , p25NetId ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 6 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
p25NetId = ( uint32_t ) : : strtoul ( std : : string ( value ) . c_str ( ) , NULL , 16 ) ;
p25NetId = p25 : : P25Utils : : netId ( p25NetId ) ;
m_conf [ " system " ] [ " config " ] [ " netId " ] = __INT_HEX_STR ( p25NetId ) ;
}
: : fprintf ( stdout , " > P25 System ID [$%03X] ? " , p25SysId ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 4 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
p25SysId = ( uint32_t ) : : strtoul ( std : : string ( value ) . c_str ( ) , NULL , 16 ) ;
p25SysId = p25 : : P25Utils : : sysId ( p25SysId ) ;
m_conf [ " system " ] [ " config " ] [ " sysId " ] = __INT_HEX_STR ( p25SysId ) ;
}
: : fprintf ( stdout , " > P25 RFSS ID [$%02X] ? " , p25RfssId ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 3 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
p25RfssId = ( uint8_t ) : : strtoul ( std : : string ( value ) . c_str ( ) , NULL , 16 ) ;
p25RfssId = p25 : : P25Utils : : rfssId ( p25RfssId ) ;
m_conf [ " system " ] [ " config " ] [ " rfssId " ] = __INT_HEX_STR ( p25RfssId ) ;
}
printStatus ( ) ;
}
break ;
case ' a ' :
{
rfssConfig = m_conf [ " system " ] [ " config " ] ;
uint32_t dmrColorCode = rfssConfig [ " colorCode " ] . as < uint32_t > ( 2U ) ;
uint32_t p25NAC = ( uint32_t ) : : strtoul ( rfssConfig [ " nac " ] . as < std : : string > ( " 293 " ) . c_str ( ) , NULL , 16 ) ;
char value [ 6 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > DMR Color Code [%u] ? " , dmrColorCode ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 2 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
sscanf ( value , " %u " , & dmrColorCode ) ;
dmrColorCode = dmr : : DMRUtils : : colorCode ( dmrColorCode ) ;
m_conf [ " system " ] [ " config " ] [ " colorCode " ] = __INT_STR ( dmrColorCode ) ;
}
: : fprintf ( stdout , " > P25 NAC [$%03X] ? " , p25NAC ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 4 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
p25NAC = ( uint32_t ) : : strtoul ( std : : string ( value ) . c_str ( ) , NULL , 16 ) ;
p25NAC = p25 : : P25Utils : : nac ( p25NAC ) ;
m_conf [ " system " ] [ " config " ] [ " nac " ] = __INT_HEX_STR ( p25NAC ) ;
}
printStatus ( ) ;
}
break ;
case ' i ' :
{
rfssConfig = m_conf [ " system " ] [ " config " ] ;
m_channelId = ( uint8_t ) rfssConfig [ " channelId " ] . as < uint32_t > ( 0U ) ;
char value [ 3 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > Channel ID ? " ) ;
: : fprintf ( stdout , " > Channel ID [%u] ? " , m_channelId ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 3 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
uint8_t prevChannelId = m_channelId ;
// bryanb: appease the compiler...
@ -248,18 +375,24 @@ int HostSetup::run()
m_channelId = prevChannelId ;
}
writeConfig ( ) ;
m_conf [ " system " ] [ " config " ] [ " channelId " ] = __INT_STR ( m_channelId ) ;
}
printStatus ( ) ;
}
break ;
case ' c ' :
{
rfssConfig = m_conf [ " system " ] [ " config " ] ;
m_channelNo = ( uint32_t ) : : strtoul ( rfssConfig [ " channelNo " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
char value [ 5 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > Channel No ? " ) ;
: : fprintf ( stdout , " > Channel No [%u] ? " , m_channelNo ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 5 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
uint8_t prevChannelNo = m_channelNo ;
sscanf ( value , " %u " , & m_channelNo ) ;
@ -268,18 +401,24 @@ int HostSetup::run()
m_channelNo = prevChannelNo ;
}
writeConfig ( ) ;
m_conf [ " system " ] [ " config " ] [ " channelNo " ] = __INT_HEX_STR ( m_channelNo ) ;
}
printStatus ( ) ;
}
break ;
case ' f ' :
{
rfssConfig = m_conf [ " system " ] [ " config " ] ;
m_channelNo = ( uint32_t ) : : strtoul ( rfssConfig [ " channelNo " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
char value [ 10 ] = { ' \0 ' } ;
: : fprintf ( stdout , " > Tx Frequency (Hz) ? " ) ;
: : fprintf ( stdout , " > Tx Frequency [%uHz] (Hz) ? " , m_txFrequency ) ;
: : fflush ( stdout ) ;
m_console . getLine ( value , 10 , 0 ) ;
if ( value [ 0 ] ! = ' \0 ' ) {
uint32_t txFrequency = m_txFrequency ;
sscanf ( value , " %u " , & txFrequency ) ;
@ -312,8 +451,17 @@ int HostSetup::run()
m_rxFrequency = prevRxFrequency ;
break ;
}
}
writeConfig ( ) ;
printStatus ( ) ;
}
break ;
case ' ! ' :
{
modemConfig = m_conf [ " system " ] [ " modem " ] ;
m_conf [ " system " ] [ " modem " ] [ " protocol " ] [ " type " ] = std : : string ( " null " ) ; // configuring modem, always sets type to UART
printStatus ( ) ;
}
break ;
@ -369,11 +517,15 @@ void HostSetup::displayHelp()
LogMessage ( LOG_SETUP , " ` Display current settings " ) ;
LogMessage ( LOG_SETUP , " V Display version of host " ) ;
LogMessage ( LOG_SETUP , " H/h Display help " ) ;
LogMessage ( LOG_SETUP , " ! Set \" null \" modem (disables modem communication) " ) ;
LogMessage ( LOG_SETUP , " S/s Save settings to configuration file " ) ;
LogMessage ( LOG_SETUP , " Q/q Quit " ) ;
LogMessage ( LOG_SETUP , " Setup Commands: " ) ;
LogMessage ( LOG_SETUP , " M Set modem port and speed " ) ;
LogMessage ( LOG_SETUP , " I Set identity (logical name) " ) ;
LogMessage ( LOG_SETUP , " C Set callsign and CW configuration " ) ;
LogMessage ( LOG_SETUP , " N Set site and network configuration " ) ;
LogMessage ( LOG_SETUP , " a Set NAC and Color Code " ) ;
LogMessage ( LOG_SETUP , " i Set logical channel ID " ) ;
LogMessage ( LOG_SETUP , " c Set logical channel number (by channel number) " ) ;
LogMessage ( LOG_SETUP , " f Set logical channel number (by Tx frequency) " ) ;
@ -419,19 +571,6 @@ bool HostSetup::calculateRxTxFreq()
return true ;
}
/// <summary>
/// Write configuration file.
/// </summary>
/// <returns>True, if configuration is written, otherwise false.</returns>
bool HostSetup : : writeConfig ( )
{
m_conf [ " system " ] [ " config " ] [ " channelId " ] = __INT_STR ( m_channelId ) ;
m_conf [ " system " ] [ " config " ] [ " channelNo " ] = __INT_STR ( m_channelNo ) ;
printStatus ( ) ;
return true ;
}
/// <summary>
/// Helper to sleep the thread.
/// </summary>
@ -451,6 +590,18 @@ void HostSetup::sleep(uint32_t ms)
void HostSetup : : printStatus ( )
{
yaml : : Node systemConf = m_conf [ " system " ] ;
{
yaml : : Node modemConfig = m_conf [ " system " ] [ " modem " ] ;
std : : string type = modemConfig [ " protocol " ] [ " type " ] . as < std : : string > ( ) ;
yaml : : Node uartConfig = modemConfig [ " protocol " ] [ " uart " ] ;
std : : string modemPort = uartConfig [ " port " ] . as < std : : string > ( ) ;
uint32_t portSpeed = uartConfig [ " speed " ] . as < uint32_t > ( 115200U ) ;
LogMessage ( LOG_SETUP , " - Port Type: %s, Modem Port: %s, Port Speed: %u " , type . c_str ( ) , modemPort . c_str ( ) , portSpeed ) ;
}
{
std : : string identity = systemConf [ " identity " ] . as < std : : string > ( ) ;
IdenTable entry = m_idenTable - > find ( m_channelId ) ;
@ -461,9 +612,10 @@ void HostSetup::printStatus()
calculateRxTxFreq ( ) ;
LogMessage ( LOG_SETUP , " - Identity: %s " , identity . c_str ( ) ) ;
LogMessage ( LOG_SETUP , " - Channel I D : %u, Channel No: %u" , m_channelId , m_channelNo ) ;
LogMessage ( LOG_SETUP , " - Channel I d : %u, Channel No: %u" , m_channelId , m_channelNo ) ;
LogMessage ( LOG_SETUP , " - Base Freq: %uHz, TX Offset: %fMHz, Bandwidth: %fKHz, Channel Spacing: %fKHz " , entry . baseFrequency ( ) , entry . txOffsetMhz ( ) , entry . chBandwidthKhz ( ) , entry . chSpaceKhz ( ) ) ;
LogMessage ( LOG_SETUP , " - Rx Freq: %uHz, Tx Freq: %uHz " , m_rxFrequency , m_txFrequency ) ;
}
{
yaml : : Node cwId = systemConf [ " cwId " ] ;
@ -473,4 +625,23 @@ void HostSetup::printStatus()
LogMessage ( LOG_SETUP , " - Callsign: %s, CW Interval: %u mins, CW Enabled: %u " , callsign . c_str ( ) , cwTime , enabled ) ;
}
{
yaml : : Node rfssConfig = systemConf [ " config " ] ;
uint32_t dmrColorCode = rfssConfig [ " colorCode " ] . as < uint32_t > ( 2U ) ;
uint32_t p25NAC = ( uint32_t ) : : strtoul ( rfssConfig [ " nac " ] . as < std : : string > ( " 293 " ) . c_str ( ) , NULL , 16 ) ;
LogMessage ( LOG_SETUP , " - DMR Color Code: %u, P25 NAC: $%03X " , dmrColorCode , p25NAC ) ;
}
{
yaml : : Node rfssConfig = systemConf [ " config " ] ;
uint32_t siteId = ( uint8_t ) : : strtoul ( rfssConfig [ " siteId " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t dmrNetId = ( uint32_t ) : : strtoul ( rfssConfig [ " dmrNetId " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t p25NetId = ( uint32_t ) : : strtoul ( rfssConfig [ " netId " ] . as < std : : string > ( " BB800 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t p25SysId = ( uint32_t ) : : strtoul ( rfssConfig [ " sysId " ] . as < std : : string > ( " 001 " ) . c_str ( ) , NULL , 16 ) ;
uint32_t p25RfssId = ( uint8_t ) : : strtoul ( rfssConfig [ " rfssId " ] . as < std : : string > ( " 1 " ) . c_str ( ) , NULL , 16 ) ;
LogMessage ( LOG_SETUP , " - Site Id: $%02X, DMR Network Id: $%05X, P25 Network Id: $%05X, P25 System Id: $%03X, P25 RFSS Id: $%02X " , siteId , dmrNetId , p25NetId , p25SysId , p25RfssId ) ;
}
}