kopia lustrzana https://github.com/Hamlib/Hamlib
Added implementation for pbsToHz() and hzToPBS() helper functions.
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2808 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.11
rodzic
ba2e011bee
commit
708bb709a9
|
@ -1046,7 +1046,7 @@ freq_t ddsToHz( const unsigned int steps )
|
|||
{
|
||||
freq_t rc = 0.0;
|
||||
|
||||
rc = ( (double) steps * 44545000.0 / 16777216.0 );
|
||||
rc = ( (freq_t) steps * 44545000.0 / 16777216.0 );
|
||||
|
||||
return( rc );
|
||||
}
|
||||
|
@ -1087,6 +1087,76 @@ unsigned int hzToDDS( const freq_t freq )
|
|||
return( rc );
|
||||
}
|
||||
|
||||
/*
|
||||
* /brief Convert PBS/BFO steps to frequency in Hz
|
||||
*
|
||||
* /param steps PBS/BFO offset steps
|
||||
*
|
||||
* /return Frequency in Hz or 0 on failure
|
||||
*
|
||||
* Max +ve offset is 127, max -ve offset is 128
|
||||
* Min -ve offset is 255
|
||||
*/
|
||||
float pbsToHz( const unsigned char steps )
|
||||
{
|
||||
freq_t rc = 0.0;
|
||||
|
||||
/* treat steps as a 1's complement signed 8-bit number */
|
||||
if ( 128 > steps )
|
||||
{
|
||||
rc = ( ( (float) steps * 12.5 * 44545000.0 ) / 16777216.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = ( ( (float) (~steps & 0x7f) * -12.5 * 44545000.0 ) / 16777216.0 );
|
||||
}
|
||||
|
||||
rig_debug( RIG_DEBUG_VERBOSE, "%s: raw %d hz %f\n", __func__, steps, rc );
|
||||
|
||||
return( rc );
|
||||
}
|
||||
|
||||
/*
|
||||
* /brief Convert PBS/BFO offset frequency in Hz to steps
|
||||
*
|
||||
* /param freq Offset frequency in Hz
|
||||
*
|
||||
* /return steps (8 bits) or 0 on failure
|
||||
*/
|
||||
unsigned char hzToPBS( const float freq )
|
||||
{
|
||||
unsigned char rc;
|
||||
int steps;
|
||||
|
||||
if ( 0 < freq )
|
||||
{
|
||||
steps = ( ( (freq + 0.5) * 16777216.0 ) / ( 44545000.0 * 12.5 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
steps = ( ( (freq - 0.5) * 16777216.0 ) / ( 44545000.0 * 12.5 ) );
|
||||
}
|
||||
|
||||
rig_debug( RIG_DEBUG_VERBOSE, "%s: steps %d\n", __func__, steps );
|
||||
|
||||
if ( 0 <= steps )
|
||||
{
|
||||
rc = (unsigned char) (steps & 0x7f);
|
||||
}
|
||||
else if ( -128 < steps )
|
||||
{
|
||||
rc = (unsigned char) (steps + 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = (unsigned char) 0;
|
||||
}
|
||||
|
||||
rig_debug( RIG_DEBUG_VERBOSE, "%s: hz %f rc %d\n", __func__, freq, rc );
|
||||
|
||||
return( rc );
|
||||
}
|
||||
|
||||
/*
|
||||
* /brief Convert native Mode to Hamlib mode
|
||||
*
|
||||
|
|
Ładowanie…
Reference in New Issue