1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 05:11:49 -05:00

CW Keyer: compiles

This commit is contained in:
f4exb 2016-12-10 06:16:13 +01:00
parent 808a8c85fd
commit d6c9b2f707

View File

@ -23,7 +23,7 @@
* 1: dash
* -1: end of sequence
*/
const char m_asciiToMorse[][128] = {
const char CWKeyer::m_asciiToMorse[][128] = {
{-1}, // 0
{-1}, // 1
{-1}, // 2
@ -313,7 +313,6 @@ void CWKeyer::nextStateIambic()
}
}
void CWKeyer::nextStateText()
{
// TODO...
@ -324,62 +323,39 @@ void CWKeyer::nextStateText()
m_elementPointer = 0;
m_textPointer = 0;
m_textState = TextStartChar;
nextStateText();
break;
case TextStartChar:
m_samplePointer = 0;
m_elementPointer = 0;
if (m_textPointer < m_text.length())
{
m_asciiChar = (m_text.at(m_textPointer)).toLatin1();
if (m_asciiChar < 0) { // non ASCII
m_asciiChar = 0;
}
if (m_asciiChar == ' ')
{
m_textState = TextWordSpace;
}
else
{
m_textState = TextStartElement;
}
m_textPointer++;
}
else // end of text
{
m_textState = TextEnd;
}
break;
case TextStartElement:
m_samplePointer = 0;
m_textState = TextElement;
break;
case TextElement:
nextStateIambic(); // dash or dot
if (m_samplePointer == 0) // done
if (m_asciiToMorse[m_elementPointer][m_asciiChar] == -1) // end of morse character
{
m_textState = TextStartElement; // next element
}
break;
case TextCharSpace:
if (m_samplePointer < 3*m_dotLength)
{
m_samplePointer++;
m_key = false;
}
else
{
m_samplePointer = 0;
m_textState = TextStartChar;
}
break;
case TextWordSpace:
if (m_samplePointer < 7*m_dotLength)
{
m_samplePointer++;
m_key = false;
}
else
{
m_samplePointer = 0;
m_textState = TextStartChar;
}
break;
case TextEnd:
default:
m_key = false;
break;
}
if (m_samplePointer == 0) // element not started or finished
{
if (m_asciiToMorse[m_elementPointer][m_asciiChar] == -1) // end of morse symbol
{
m_keyIambicState = KeyCharSpace;
m_samplePointer++;
m_key = false;
m_elementPointer = 0;
m_textState = TextCharSpace;
}
else
{
@ -393,39 +369,47 @@ void CWKeyer::nextStateText()
m_dot = false;
m_dash = true;
}
nextStateIambic();
m_textState = TextElement;
m_elementPointer++;
}
if (m_textPointer < m_text.length())
break;
case TextElement:
nextStateIambic(); // dash or dot
if (m_samplePointer == 0) // done
{
m_asciiChar = (m_text[m_textPointer]).toAscii();
if (m_asciiChar < 0) {
m_asciiChar = 0;
m_textState = TextStartElement; // next element
}
m_elementPointer = 0;
m_textPointer++;
}
else
{
// TODO: end of text
}
}
else
{
if ((m_keyIambicState == KeyDot) || (m_keyIambicState == KeyDash))
{
nextStateIambic();
}
else if (m_keyIambicState == KeyCharSpace)
{
if (m_samplePointer < 2*m_dotLength) // rest of a dash period (+2 dot periods)
break;
case TextCharSpace:
if (m_samplePointer < 2*m_dotLength) // 1 dot length space from element
{
m_samplePointer++;
m_key = false;
}
else
{
m_textState = TextStartChar;
}
break;
case TextWordSpace:
if (m_samplePointer < 7*m_dotLength)
{
m_samplePointer++;
m_key = false;
}
else
{
m_textState = TextStartChar;
}
break;
case TextEnd:
default:
m_key = false;
break;
}
}
bool CWKeyer::eom()
{
return !(m_textPointer < m_text.length());
}