-
Notifications
You must be signed in to change notification settings - Fork 0
/
fm_rds.cpp
160 lines (122 loc) · 6.02 KB
/
fm_rds.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "fm_rds.h"
#include "globals.h"
//#include <QMutexLocker>
//bool g_mStop_rds;
FM_rds::FM_rds(QObject *parent) : QObject(parent),
mStop_rds(false)
{
}
void FM_rds::start_rds_reading()
{
//QMutexLocker locker(&lock);
mStop_rds = false;
//prog_chars = ""; //emit empty !!!
//rds_chars = ""; //emit empty !!!
qrds_text = "";
qprog_name = "";
emit rds_out(qrds_text); //emit empty !!!
emit rds_prog_out(qprog_name); //emit empty !!!
QThread::msleep(500);
rds();
//qDebug() << "mstop from function start: " << mStop_rds;
}
void FM_rds::stop_rds_reading()
{
mStop_rds = true;
//qDebug() << "mstop from function stop ...: " << mStop_rds;
}
int FM_rds::rds(){
int i;
//struct rds_data *rdsd;
struct fm_rds_data data;
if (strstr("/dev/radio0", "radio")) {
rdsfd = net_open(strdup("/dev/radio0"), O_RDWR);
if (rdsfd >= 0) {
uint8_t brkstat = 0;
uint8_t radiotext[150];
uint8_t program[9];
uint8_t print_program[9];
uint8_t rdsdata[8];
memset(radiotext, 0x0, 150);
memset(program, 0x0, 9);
memset(print_program, 0x0, 9);
int x=0;
while(1) {
QApplication::processEvents();
if(mStop_rds) break;
net_ioctl(rdsfd, FM_RDS_STATUS, &data);
if (data.rdssync) {
if (memcmp(rdsdata, data.data, 8)==0)
continue;
memcpy(rdsdata, data.data, 8);
if ((data.data[2]>>4) == 0) {
x = (data.data[3]&0x3)*2;
program[x++] = data.data[6]&0x7f;
program[x++] = data.data[7]&0x7f;
}
if ((data.data[2]>>4) == 2) {
x = (data.data[3]&0x0f)*4;
if ((data.data[3]&0x10) != brkstat) {
brkstat = data.data[3] & 0x10;
memset(radiotext, 0x0, 150);
}
radiotext[x++]=(data.data[4]&0x7f);
radiotext[x++]=(data.data[5]&0x7f);
radiotext[x++]=(data.data[6]&0x7f);
radiotext[x++]=(data.data[7]&0x7f);
}
usleep(10000);
if (isprint(program[0]) && isprint(program[1])) {
memcpy(print_program, program, 9);
c_prog_chars.clear();
//prog_chars.clear();
for(int i = 0; i < 9; i++){
//prog_chars = prog_chars.append(static_cast<char>(program[i]));
c_prog_chars.push_back(program[i]);
}
/*
if(prog_chars.contains('\0')){
prog_chars = prog_chars.replace('\0', "");
}
*/
}
if(c_prog_chars.size() > 0){
std::string c_prog_name = toUtf8StringUsingCharset(c_prog_chars.data(), (CharacterSet) 15, c_prog_chars.size());
qprog_name = QString::fromUtf8(c_prog_name.c_str());
}
//rds_chars.clear();
c_text_chars.clear();
for (i=0;i<64;i++) {
if(radiotext[i] != 0){
switch(radiotext[i]) {
case 0x19:
//printf("ue");
break;
default:
// char rds_single_char = 32; //init with space
// if(radiotext[i] != 127){ //remove white rectangles (ascii del)
// rds_single_char = static_cast<char>(radiotext[i]);
// }
c_text_chars.push_back(radiotext[i]);
// rds_chars.append(rds_single_char);
// if(rds_chars.contains('\0')){
// rds_chars = rds_chars.replace('\0', "");
// }
}
if(c_text_chars.size() > 0){
std::string c_rds_text = toUtf8StringUsingCharset(c_text_chars.data(), (CharacterSet) 15, c_text_chars.size());
qrds_text = QString::fromUtf8((c_rds_text.c_str()));
}
//end switch
} //end if
} //end for
emit rds_out(qrds_text);
emit rds_prog_out(qprog_name);
fflush(stdout);
} //end if
} //end while
}
}
net_close(rdsfd);
return 0;
}