initial commit
This commit is contained in:
+197
-2
@@ -54,6 +54,7 @@ cKeyStoneCOMM::cKeyStoneCOMM(const QString& commPort, QObject *parent) :
|
||||
m_hardMute{false},
|
||||
m_initialized{false},
|
||||
m_totalProgram{0},
|
||||
m_currentProgram{0},
|
||||
m_mutePrevVolume{0}
|
||||
{
|
||||
}
|
||||
@@ -248,9 +249,17 @@ bool cKeyStoneCOMM::startStream(STREAM_MODE mode, uint16_t channel)
|
||||
if(!readSerialBytes(input, &dwBytes))
|
||||
return(false);
|
||||
|
||||
m_currentProgram = channel;
|
||||
m_currentMode = mode;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
int16_t cKeyStoneCOMM::channel()
|
||||
{
|
||||
return(m_currentProgram);
|
||||
}
|
||||
|
||||
bool cKeyStoneCOMM::stopStream()
|
||||
{
|
||||
uint16_t dwBytes;
|
||||
@@ -446,8 +455,21 @@ int8_t cKeyStoneCOMM::volume()
|
||||
|
||||
int8_t cKeyStoneCOMM::signalStrength()
|
||||
{
|
||||
int biterror;
|
||||
return(getSignalStrength(&biterror));
|
||||
int biterror;
|
||||
int8_t signalStrength = getSignalStrength(&biterror);
|
||||
if(signalStrength < 0)
|
||||
signalStrength = 0;
|
||||
return(signalStrength);
|
||||
}
|
||||
|
||||
QString cKeyStoneCOMM::programName()
|
||||
{
|
||||
return(getProgramName(m_currentMode, m_currentProgram, 1));
|
||||
}
|
||||
|
||||
QString cKeyStoneCOMM::programText()
|
||||
{
|
||||
return(getProgramText());
|
||||
}
|
||||
|
||||
bool cKeyStoneCOMM::hardMute()
|
||||
@@ -766,6 +788,179 @@ int8_t cKeyStoneCOMM::getSignalStrength(int* biterror)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
QString cKeyStoneCOMM::getProgramText()
|
||||
{
|
||||
uint16_t dwBytes;
|
||||
unsigned char input[TEXT_BUFFER_LEN] = {0};
|
||||
unsigned char output[] = {HEAD,0x01,0x2E,0x01,0x00,0x00,END};
|
||||
QString programText;
|
||||
|
||||
if(!writeSerialBytes(output, 7, &dwBytes))
|
||||
return(programText);
|
||||
|
||||
if(dwBytes != 7)
|
||||
return(programText);
|
||||
|
||||
if(!readSerialBytes(input, &dwBytes))
|
||||
return(programText);
|
||||
|
||||
if(dwBytes < 8)
|
||||
return(programText);
|
||||
|
||||
if(goodHeader(input, dwBytes))
|
||||
{
|
||||
if((input[1] == 0x01) && (input[2] == 0x2E))
|
||||
{
|
||||
int textLen = (0xFF & input[4]) << 8 |(0xFF & input[5]);
|
||||
|
||||
if(textLen > TEXT_BUFFER_LEN-1)
|
||||
return(programText); // buffer overrun
|
||||
|
||||
int unicodesize = textLen/2;
|
||||
char front;
|
||||
|
||||
for(int i = 0;i < textLen;i += 2) // WATCHOUT
|
||||
{
|
||||
front = input[6+i];
|
||||
input[6+i] = input[6+i+1];
|
||||
input[6+i+1] = front;
|
||||
}
|
||||
#ifdef WIN32
|
||||
programText = QString::fromWCharArray((wchar_t *)&input[6], unicodesize-1).trimmed();
|
||||
|
||||
#ifdef LABVIEW
|
||||
int asciilen=WideCharToMultiByte(CP_ACP, 0, programText, unicodesize-1, NULL,0,NULL,NULL);
|
||||
char *asciitext = new char[asciilen+1];
|
||||
WideCharToMultiByte(CP_ACP, 0, programText, unicodesize-1, asciitext, asciilen, NULL, NULL);
|
||||
asciitext[asciilen]=0;
|
||||
memset((char*)programText,0, asciilen+1);
|
||||
memcpy((char*)programText, asciitext, asciilen);
|
||||
delete asciitext;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
unsigned char tempBuffer[TEXT_BUFFER_LEN*4]={0};
|
||||
|
||||
for(int i=0; i< unicodesize;i++)
|
||||
{
|
||||
tempBuffer[i*4]=input[6+(i*2)];
|
||||
tempBuffer[(i*4)+1]=input[6+(i*2)+1];
|
||||
tempBuffer[(i*4)+2]=0;
|
||||
tempBuffer[(i*4)+3]=0;
|
||||
}
|
||||
|
||||
programText = QString::fromWCharArray((wchar_t *)&tempBuffer[0], unicodesize-1).trimmed();
|
||||
#endif
|
||||
return(0);
|
||||
|
||||
}
|
||||
else if((input[1] == 0x00) && (input[2] == 0x02))
|
||||
{
|
||||
if(input[6] == 0x01)
|
||||
return(programText);
|
||||
else
|
||||
return(programText);
|
||||
}
|
||||
else
|
||||
return(programText);
|
||||
}
|
||||
else
|
||||
return(programText);
|
||||
}
|
||||
|
||||
QString cKeyStoneCOMM::getProgramName(char mode, long dabIndex, char namemode)
|
||||
{
|
||||
uint16_t dwBytes;
|
||||
unsigned char input[50] = {0};
|
||||
unsigned char output[] = {HEAD,0x01,0x2D,0x01,0x00,0x05,0xFF,0xFF,0xFF,0xFF,0x01,END};
|
||||
unsigned char strChannel[4] = {0};
|
||||
QString programName;
|
||||
|
||||
if((mode != STREAM_MODE_DAB) && (mode != STREAM_MODE_FM))
|
||||
return(programName);
|
||||
|
||||
if(mode == STREAM_MODE_DAB)
|
||||
{
|
||||
memcpy(&strChannel[0], &dabIndex, sizeof(long));
|
||||
output[6] = strChannel[3];
|
||||
output[7] = strChannel[2];
|
||||
output[8] = strChannel[1];
|
||||
output[9] = strChannel[0];
|
||||
}
|
||||
|
||||
output[10] = namemode;
|
||||
|
||||
if(!writeSerialBytes(output, 12, &dwBytes))
|
||||
return(programName);
|
||||
|
||||
if(dwBytes != 12)
|
||||
return(programName);
|
||||
|
||||
if(!readSerialBytes(input, &dwBytes))
|
||||
return(programName);
|
||||
|
||||
if(dwBytes < 8)
|
||||
return(programName);
|
||||
|
||||
if(goodHeader(input, dwBytes))
|
||||
{
|
||||
if((input[1] == 0x01) && (input[2] == 0x2D))
|
||||
{
|
||||
int textLen = (int)input[5];
|
||||
|
||||
if(textLen > 50)
|
||||
return(programName); // prevent buffer overrun
|
||||
|
||||
int unicodesize = textLen/2;
|
||||
char front;
|
||||
|
||||
for(int i = 0;i < textLen;i += 2)
|
||||
{
|
||||
front = input[6+i];
|
||||
input[6+i] = input[6+i+1];
|
||||
input[6+i+1] = front;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
programName = QString::fromWCharArray((wchar_t*)&input[6], unicodesize-1).trimmed();
|
||||
|
||||
#ifdef LABVIEW
|
||||
int asciilen=WideCharToMultiByte(CP_ACP, 0, programName, unicodesize-1, NULL,0,NULL,NULL);
|
||||
char *asciitext = new char[asciilen+1];
|
||||
WideCharToMultiByte(CP_ACP, 0, programName, unicodesize-1, asciitext, asciilen, NULL, NULL);
|
||||
asciitext[asciilen]=0;
|
||||
memset((char*)programName,0, asciilen+1);
|
||||
memcpy((char*)programName, asciitext, asciilen);
|
||||
delete asciitext;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
unsigned char tempBuffer[TEXT_BUFFER_LEN*4]={0};
|
||||
|
||||
for(int i=0; i< unicodesize;i++)
|
||||
{
|
||||
tempBuffer[i*4]=input[6+(i*2)];
|
||||
tempBuffer[(i*4)+1]=input[6+(i*2)+1];
|
||||
tempBuffer[(i*4)+2]=0;
|
||||
tempBuffer[(i*4)+3]=0;
|
||||
}
|
||||
|
||||
programName = QString::fromWCharArray((wchar_t *)&tempBuffer[0], unicodesize-1).trimmed();
|
||||
#endif
|
||||
return(programName);
|
||||
|
||||
}
|
||||
else
|
||||
return(programName);
|
||||
}
|
||||
else
|
||||
return(programName);
|
||||
}
|
||||
|
||||
void cKeyStoneCOMM::serialReadReady()
|
||||
{
|
||||
m_readData.append(m_serialPort->readAll());
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include <QSerialPortInfo>
|
||||
|
||||
|
||||
#define TEXT_BUFFER_LEN 300
|
||||
|
||||
|
||||
class cKeyStoneCOMM : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -27,6 +30,7 @@ public:
|
||||
void close();
|
||||
|
||||
int16_t channelCount();
|
||||
int16_t channel();
|
||||
STREAM_MODE playMode();
|
||||
int16_t playIndex();
|
||||
bool setVolume(int8_t volume);
|
||||
@@ -39,6 +43,8 @@ public:
|
||||
void volumeMute();
|
||||
int8_t volume();
|
||||
int8_t signalStrength();
|
||||
QString programName();
|
||||
QString programText();
|
||||
signals:
|
||||
|
||||
private:
|
||||
@@ -54,6 +60,8 @@ private:
|
||||
int m_cntReadData;
|
||||
|
||||
uint16_t m_totalProgram;
|
||||
uint16_t m_currentProgram;
|
||||
STREAM_MODE m_currentMode;
|
||||
int8_t m_currentVolume;
|
||||
int8_t m_mutePrevVolume;
|
||||
|
||||
@@ -61,6 +69,9 @@ private:
|
||||
bool hardUnmute();
|
||||
bool hardResetRadio();
|
||||
|
||||
QString getProgramText();
|
||||
QString getProgramName(char mode, long dabIndex, char namemode);
|
||||
|
||||
bool readSerialBytes (unsigned char* buffer, uint16_t* bytesreadreturn);
|
||||
bool writeSerialBytes(unsigned char* buffer, uint16_t nNumberOfBytesToWrite, uint16_t* lpNumberOfBytesWritten);
|
||||
bool goodHeader(unsigned char* input, uint16_t dwBytes);
|
||||
|
||||
@@ -35,4 +35,33 @@ void cMainWindow::updateSignalStrength()
|
||||
{
|
||||
int8_t signalStrength = m_keystoneCOMM->signalStrength();
|
||||
ui->m_signalStrength->setText(QString("%1").arg(signalStrength));
|
||||
ui->m_sender->setText(m_keystoneCOMM->programName());
|
||||
ui->m_text->setText(m_keystoneCOMM->programText());
|
||||
int16_t channel = m_keystoneCOMM->channel();
|
||||
ui->m_channel->setText(QString("%1").arg(channel));
|
||||
int8_t volume = m_keystoneCOMM->volume();
|
||||
ui->m_volume->setText(QString("%1").arg(volume));
|
||||
}
|
||||
|
||||
void cMainWindow::on_m_channelDown_clicked()
|
||||
{
|
||||
m_keystoneCOMM->prevStream();
|
||||
}
|
||||
|
||||
|
||||
void cMainWindow::on_m_channelUp_clicked()
|
||||
{
|
||||
m_keystoneCOMM->nextStream();
|
||||
}
|
||||
|
||||
void cMainWindow::on_m_volumeDown_clicked()
|
||||
{
|
||||
m_keystoneCOMM->volumeMinus();
|
||||
}
|
||||
|
||||
|
||||
void cMainWindow::on_m_volumeUp_clicked()
|
||||
{
|
||||
m_keystoneCOMM->volumePlus();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,11 @@ private:
|
||||
|
||||
public slots:
|
||||
void updateSignalStrength();
|
||||
private slots:
|
||||
void on_m_channelDown_clicked();
|
||||
void on_m_channelUp_clicked();
|
||||
void on_m_volumeDown_clicked();
|
||||
void on_m_volumeUp_clicked();
|
||||
};
|
||||
|
||||
#endif // CMAINWINDOW_H
|
||||
|
||||
+130
-13
@@ -14,19 +14,136 @@
|
||||
<string>cMainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QLabel" name="m_signalStrength">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>49</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Text:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Sender:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Signal:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Colume:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="m_volume">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Channel:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QPushButton" name="m_channelDown">
|
||||
<property name="text">
|
||||
<string>channel -</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="m_channel">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="m_text">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="m_sender">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="m_signalStrength">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="m_channelUp">
|
||||
<property name="text">
|
||||
<string>channel +</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QPushButton" name="m_volumeDown">
|
||||
<property name="text">
|
||||
<string>volume -</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="m_volumeUp">
|
||||
<property name="text">
|
||||
<string>volume +</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
|
||||
Reference in New Issue
Block a user