-
Notifications
You must be signed in to change notification settings - Fork 0
/
scevents.h
394 lines (368 loc) · 9.56 KB
/
scevents.h
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/**
* $DateTime: 2015/08/23 13:00:12 $
* $Id: //depot/sircond/scevents.h#1 $
* $Change: 2154 $
*
* Copyright (C) 2015 Swarga Research (http://www.swarga-research.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _SCEVENTS_H_
#define _SCEVENTS_H_
//!
//! \file scevents.h
//! \brief Declarations for SiriusConnect event classes
//!
#include <iostream>
#include "scp.h"
//!
//! \brief Event (virtual) base class.
//!
//! All SiriusConnect event classes are derived from this base class.
//! These objects are simple wrappers for the details of each event.
//!
struct SCEvent
{
virtual size_t deserialize(uint8_t* data, size_t len) { return 0u; };
friend std::ostream& operator<< (std::ostream& out, SCEvent e)
{
out << "INVALID";
return out;
}
};
//!
//! \brief Startup event
//!
struct SCEStartup : public SCEvent
{
friend std::ostream& operator<< (std::ostream& out, SCEStartup e)
{
out << "STARTUP";
return out;
}
};
//!
//! \brief Result code from a GET request
//!
struct SCEGetResult : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEGetResult e)
{
out << "GET," << static_cast<unsigned>(e.result);
return out;
}
uint16_t result;
};
//!
//! \brief Result code from a SET request
//!
struct SCESetResult : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCESetResult e)
{
out << "SET," << static_cast<unsigned>(e.result);
return out;
}
uint16_t result;
};
//!
//! \brief Sirius Radio ID
//!
//! Each Sirius radio has a unique identifier (Sirius ID, or SID).
//! The SID is a string of numeric ASCII characters which is used
//! for subscription purposes. This event contains the attached
//! radio's SID string.
//!
struct SCESiriusID : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCESiriusID e)
{
out << "SID," << e.sid;
return out;
}
string sid;
};
//!
//! \brief Gain value
//!
struct SCEGain : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEGain e)
{
out << "GAIN," << static_cast<int>(e.gain);
return out;
}
int8_t gain;
};
//!
//! \brief Mute value
//!
struct SCEMute : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEMute e)
{
out << "MUTE," << static_cast<unsigned>(e.mute);
return out;
}
uint8_t mute;
};
//!
//! \brief Song ID
//!
//! Sirius provides a unique identifier for each song or program on
//! their service. This identifier consists of a short string of
//! printable ASCII characters.
//!
struct SCESongID : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCESongID e)
{
out << "SONGID," << "\"" << e.songid << "\"";
return out;
}
string songid;
};
//!
//! \brief Song info
//!
struct SCESongInfo : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCESongInfo e)
{
out << "SONGINFO,";
out << static_cast<unsigned>(e.channel) << ",";
out << "\"" << e.song_id << "\",";
out << "\"" << e.artist_id << "\",";
out << "\"" << e.title << "\",";
out << "\"" << e.artist << "\",";
out << "\"" << e.composer << "\"";
return out;
}
SCP_CHANNEL_INDEX channel; //!< The channel where this song is playing
string title; //!< Song title
string artist; //!< Artist's name
string album; //!< Album name
string composer; //!< Composer's name
string song_id; //!< Sirius song ID string
string artist_id; //!< Sirius artist ID string
};
//!
//! \brief Current channel number
//!
//! This event indicates the channel to which the radio is currently
//! tuned.
//!
struct SCEChannel : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEChannel e)
{
out << "CHANNEL," << static_cast<unsigned>(e.channel);
return out;
}
SCP_CHANNEL_INDEX channel;
};
//!
//! \brief Info for a channel
//!
struct SCEChannelInfo : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEChannelInfo e)
{
out << "CHANNELINFO,";
out << static_cast<unsigned>(e.channel) << ",";
out << static_cast<unsigned>(e.genre) << ",";
out << "\"" << e.lname << "\",";
out << "\"" << e.sname << "\",";
out << "\"" << e.lgenre << "\",";
out << "\"" << e.sgenre << "\"";
return out;
}
SCP_CHANNEL_INDEX channel; //!< Sirius channel number
uint8_t genre; //!< Sirius genre code
string sname; //!< Short channel name
string lname; //!< Long channel name
string sgenre; //!< Short genre name
string lgenre; //!< Long genre name
};
//!
//! \brief Channel Map update event
//!
//! The Channel Map is a bitmap containing a single bit flag for
//! each of the 224 Sirius channels. A '1' bit indicates that the
//! corresponding channel is valid and tunable; a '0' bit indicates
//! an invalid channel. The bitmap is stored as a byte array in big-
//! endian order, i.e. the most significant bit of first byte corresponds
//! to Sirius channel 223, and the least significant bit of the last byte
//! corresponds to Sirius channel 0.
//!
struct SCEChannelMap : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEChannelMap e)
{
out << "CHANNELMAP";
return out;
}
uint8_t channel_map[SCP_CHANNEL_BITMAP_SIZE]; //!< Bitmap of valid channels
};
//!
//! \brief Status
//!
struct SCEStatus : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEStatus e)
{
out << "STATUS,";
out << static_cast<unsigned>(e.type) << ",";
out << static_cast<unsigned>(e.status1) << ",";
out << static_cast<unsigned>(e.status2);
return out;
}
uint8_t type; //!< Type of status
uint8_t status1; //!< Primary status code
uint8_t status2; //!< Secondary status
};
//!
//! \brief RSSI event
//!
struct SCERSSI : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCERSSI e)
{
out << "RSSI,";
out << static_cast<unsigned>(e.composite) << ",";
out << static_cast<unsigned>(e.satellite) << ",";
out << static_cast<unsigned>(e.terrestrial);
return out;
}
uint8_t composite;
uint8_t satellite;
uint8_t terrestrial;
};
//!
//! \brief Signal acquired/lost event
//!
struct SCESignal : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCESignal e)
{
out << "SIGNAL," << static_cast<unsigned>(e.signal);
return out;
}
uint8_t signal;
};
//!
//! \brief Antenna connected/disconnected event
//!
struct SCEAntenna : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEAntenna e)
{
out << "ANTENNA," << static_cast<unsigned>(e.antenna);
return out;
}
uint8_t antenna;
};
//!
//! \brief Reset event
//!
struct SCEReset : public SCEvent
{
friend std::ostream& operator<< (std::ostream& out, SCEReset e)
{
out << "RESET";
return out;
}
};
//!
//! \brief Current power setting
//!
struct SCEPower : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCEPower e)
{
out << "POWER," << static_cast<unsigned>(e.power);
return out;
}
uint8_t power;
};
//!
//! \brief Time Zone settings
//!
struct SCETimeZoneInfo : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCETimeZoneInfo e)
{
out << "TZINFO," << static_cast<int>(e.offset) << "," << static_cast<unsigned>(e.dst);
return out;
}
int16_t offset; //!< Offset in minutes from UTC
uint8_t dst; //!< Daylight savings time flag (Boolean)
};
//!
//! \brief Time event
//!
struct SCETime : public SCEvent
{
size_t deserialize(uint8_t* data, size_t len);
friend std::ostream& operator<< (std::ostream& out, SCETime e)
{
out << "TIME,";
out << static_cast<unsigned>(e.year) << ",";
out << static_cast<unsigned>(e.mon) << ",";
out << static_cast<unsigned>(e.day) << ",";
out << static_cast<unsigned>(e.hour) << ",";
out << static_cast<unsigned>(e.min) << ",";
out << static_cast<unsigned>(e.sec) << ",";
out << static_cast<unsigned>(e.dow) << ",";
out << static_cast<unsigned>(e.dst);
return out;
}
uint16_t year; //!< Year
uint8_t mon; //!< Month
uint8_t day; //!< Day of the month
uint8_t hour; //!< Hour
uint8_t min; //!< Minute
uint8_t sec; //!< Second
uint8_t dow; //!< Day of the week (0 == Sunday)
uint8_t dst; //!< Daylight savings time active flag (Boolean)
};
//!
//! \brief Shutdown event
//!
struct SCEShutdown : public SCEvent
{
friend std::ostream& operator<< (std::ostream& out, SCEShutdown e)
{
out << "SHUTDOWN";
return out;
}
};
#endif