forked from oandrew/ipod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispremote.go
422 lines (396 loc) · 8.86 KB
/
dispremote.go
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
package dispremote
import (
"bytes"
"encoding/binary"
"errors"
"github.com/teostofell/ipod"
)
func init() {
ipod.RegisterLingos(ipod.LingoDisplayRemoteID, Lingos)
}
var Lingos struct {
ACK `id:"0x00"`
GetCurrentEQProfileIndex `id:"0x01"`
RetCurrentEQProfileIndex `id:"0x02"`
SetCurrentEQProfileIndex `id:"0x03"`
GetNumEQProfiles `id:"0x04"`
RetNumEQProfiles `id:"0x05"`
GetIndexedEQProfileName `id:"0x06"`
RetIndexedEQProfileName `id:"0x07"`
SetRemoteEventNotification `id:"0x08"`
RemoteEventNotification `id:"0x09"`
GetRemoteEventStatus `id:"0x0A"`
RetRemoteEventStatus `id:"0x0B"`
GetiPodStateInfo `id:"0x0C"`
RetiPodStateInfo `id:"0x0D"`
SetiPodStateInfo `id:"0x0E"`
GetPlayStatus `id:"0x0F"`
RetPlayStatus `id:"0x10"`
SetCurrentPlayingTrack `id:"0x11"`
GetIndexedPlayingTrackInfo `id:"0x12"`
RetIndexedPlayingTrackInfo `id:"0x13"`
GetNumPlayingTracks `id:"0x14"`
RetNumPlayingTracks `id:"0x15"`
GetArtworkFormats `id:"0x16"`
RetArtworkFormats `id:"0x17"`
GetTrackArtworkData `id:"0x18"`
RetTrackArtworkData `id:"0x19"`
GetPowerBatteryState `id:"0x1A"`
RetPowerBatteryState `id:"0x1B"`
GetSoundCheckState `id:"0x1C"`
RetSoundCheckState `id:"0x1D"`
SetSoundCheckState `id:"0x1E"`
GetTrackArtworkTimes `id:"0x1F"`
RetTrackArtworkTimes `id:"0x20"`
}
type ACKStatus uint8
const (
ACKStatusSuccess ACKStatus = 0x00
ACKStatusPending ACKStatus = 0x06
)
type ACK struct {
Status ACKStatus
CmdID uint8
}
type GetCurrentEQProfileIndex struct {
}
type RetCurrentEQProfileIndex struct {
CurrentEQIndex uint32
}
type SetCurrentEQProfileIndex struct {
CurrentEQIndex uint32
RestoreOnExit bool
}
type GetNumEQProfiles struct {
}
type RetNumEQProfiles struct {
NumEQProfiles uint32
}
type GetIndexedEQProfileName struct {
EQProfileIndex uint32
}
type RetIndexedEQProfileName struct {
EQProfileName []byte
}
type SetRemoteEventNotification struct {
EventMask uint32
}
type RemoteEventNotification struct {
EventNum byte
EventData []byte
}
type GetRemoteEventStatus struct {
}
type RetRemoteEventStatus struct {
EventStatus uint32
}
//go:generate stringer -type=InfoType
type InfoType uint8
const (
InfoTypeTrackPositionMs InfoType = iota
InfoTypeTrackIndex
InfoTypeChapterIndex
InfoTypePlayStatus
InfoTypeVolume
InfoTypePower
InfoTypeEqualizer
InfoTypeShuffle
InfoTypeRepeat
InfoTypeDateTime
_ //InfoTypeAlarm
InfoTypeBacklight
InfoTypeHoldSwitch
InfoTypeSoundCheck
InfoTypeAudiobookSpeed
InfoTypeTrackPositionSec
InfoTypeVolume2
)
type InfoTrackPositionMs struct {
TrackPositionMs uint32
}
type InfoTrackIndex struct {
TrackIndex uint32
}
type InfoChapterIndex struct {
TrackIndex uint32
ChapterCount uint16
ChapterIndex uint16
}
//go:generate stringer -type=PlayStatusType
type PlayStatusType uint8
const (
PlayStatusStopped PlayStatusType = iota
PlayStatusPlaying
PlayStatusPaused
PlayStatusFF
PlayStatusREW
PlayStatusEndFFREW
)
type InfoPlayStatus struct {
PlayStatus PlayStatusType
}
type InfoVolume struct {
MuteState uint8
UIVolumeLevel uint8
}
type InfoPower struct {
PowerState uint8
BatteryLevel uint8
}
type InfoEqualizer struct {
EqIndex uint32
}
type InfoShuffle struct {
ShuffleState uint8
}
type InfoRepeat struct {
RepeatState uint8
}
type InfoDateTime struct {
Year uint16
Month uint8
Day uint8
Hour uint8
Minute uint8
}
type InfoBacklight struct {
BacklightLevel uint8
}
type InfoHoldSwitch struct {
HoldSwitchState uint8
}
type InfoSoundCheck struct {
SoundCheckState uint8
}
type InfoAudiobookSpeed struct {
PlaybackSpeed uint8
}
type InfoTrackPositionSec struct {
TrackPositionSec uint16
}
type InfoVolume2 struct {
MuteState uint8
UIVolumeLevel uint8
AbsoluteVolumeLevel uint8
}
type GetiPodStateInfo struct {
InfoType InfoType
}
type RetiPodStateInfo struct {
InfoType InfoType
InfoData interface{}
}
func (t *RetiPodStateInfo) MarshalBinary() ([]byte, error) {
buf := bytes.Buffer{}
binary.Write(&buf, binary.BigEndian, t.InfoType)
binary.Write(&buf, binary.BigEndian, t.InfoData)
return buf.Bytes(), nil
}
func (t *RetiPodStateInfo) UnmarshalBinary(data []byte) error {
r := bytes.NewReader(data)
binary.Read(r, binary.BigEndian, &t.InfoType)
switch t.InfoType {
case InfoTypeTrackPositionMs:
t.InfoData = &InfoTrackPositionMs{}
case InfoTypeTrackIndex:
t.InfoData = &InfoTrackIndex{}
case InfoTypeChapterIndex:
t.InfoData = &InfoChapterIndex{}
case InfoTypePlayStatus:
t.InfoData = &InfoPlayStatus{}
case InfoTypeVolume:
t.InfoData = &InfoVolume{}
case InfoTypePower:
t.InfoData = &InfoPower{}
case InfoTypeEqualizer:
t.InfoData = &InfoEqualizer{}
case InfoTypeShuffle:
t.InfoData = &InfoShuffle{}
case InfoTypeRepeat:
t.InfoData = &InfoRepeat{}
case InfoTypeDateTime:
t.InfoData = &InfoDateTime{}
case InfoTypeBacklight:
t.InfoData = &InfoBacklight{}
case InfoTypeHoldSwitch:
t.InfoData = &InfoHoldSwitch{}
case InfoTypeSoundCheck:
t.InfoData = &InfoSoundCheck{}
case InfoTypeAudiobookSpeed:
t.InfoData = &InfoAudiobookSpeed{}
case InfoTypeTrackPositionSec:
t.InfoData = &InfoTrackPositionSec{}
case InfoTypeVolume2:
t.InfoData = &InfoVolume2{}
default:
return errors.New("unknown info type")
}
return binary.Read(r, binary.BigEndian, t.InfoData)
}
type SetiPodStateInfo struct {
InfoType byte
InfoData byte // todo
}
type GetPlayStatus struct {
}
type RetPlayStatus struct {
PlayState byte
TrackIndex uint32
TrackLength uint32
TrackPos uint32
}
type SetCurrentPlayingTrack struct {
TrackIndex uint32
}
//go:generate stringer -type=TrackInfoType
type TrackInfoType uint8
const (
TrackInfoTypeCaps TrackInfoType = iota
TrackInfoTypeChapterTimeName
TrackInfoTypeArtist
TrackInfoTypeAlbum
TrackInfoTypeGenre
TrackInfoTypeTrack
TrackInfoTypeComposer
TrackInfoTypeLyrics
TrackInfoTypeArtworkCount
)
type GetIndexedPlayingTrackInfo struct {
InfoType TrackInfoType
TrackIndex uint32
ChapterIndex uint16
}
type TrackInfoCaps struct {
Caps uint32
TrackTotalMs uint32
ChapterCount uint16
}
type TrackInfoChapterTimeName struct {
ChapterTime uint32
ChapterName []byte
}
type TrackInfoArtist struct {
Name []byte
}
type TrackInfoAlbum struct {
Name []byte
}
type TrackInfoGenre struct {
Name []byte
}
type TrackInfoTrack struct {
Title []byte
}
type TrackInfoComposer struct {
Name []byte
}
type TrackInfoLyrics struct {
Flags uint8
PacketIndex uint16
Lyrics []byte
}
type TrackInfoArtworkCount struct {
None byte // empty = 0x08
}
type RetIndexedPlayingTrackInfo struct {
InfoType TrackInfoType
InfoData interface{}
}
func (t *RetIndexedPlayingTrackInfo) MarshalBinary() ([]byte, error) {
buf := bytes.Buffer{}
binary.Write(&buf, binary.BigEndian, t.InfoType)
binary.Write(&buf, binary.BigEndian, t.InfoData)
return buf.Bytes(), nil
}
func (t *RetIndexedPlayingTrackInfo) UnmarshalBinary(data []byte) error {
r := bytes.NewReader(data)
binary.Read(r, binary.BigEndian, &t.InfoType)
switch t.InfoType {
case TrackInfoTypeCaps:
t.InfoData = &TrackInfoCaps{}
case TrackInfoTypeChapterTimeName:
t.InfoData = &TrackInfoChapterTimeName{
ChapterTime: 0,
ChapterName: make([]byte, 0),
}
case TrackInfoTypeArtist:
t.InfoData = &TrackInfoArtist{
Name: make([]byte, 0),
}
case TrackInfoTypeAlbum:
t.InfoData = &TrackInfoAlbum{
Name: make([]byte, 0),
}
case TrackInfoTypeGenre:
t.InfoData = &TrackInfoGenre{
Name: make([]byte, 0),
}
case TrackInfoTypeTrack:
t.InfoData = &TrackInfoTrack{
Title: make([]byte, 0),
}
case TrackInfoTypeComposer:
t.InfoData = &TrackInfoComposer{
Name: make([]byte, 0),
}
case TrackInfoTypeLyrics:
t.InfoData = &TrackInfoLyrics{
Flags: 0x00,
PacketIndex: 0,
Lyrics: make([]byte, 0),
}
case TrackInfoTypeArtworkCount:
t.InfoData = &TrackInfoArtworkCount{}
default:
return errors.New("unknown info type")
}
return binary.Read(r, binary.BigEndian, t.InfoData)
}
type GetNumPlayingTracks struct {
}
type RetNumPlayingTracks struct {
NumPlayTracks uint32
}
type GetArtworkFormats struct {
}
type ArtworkFormat struct {
FormatID uint16
PixelFormat uint8
ImageWidth uint16
ImageHeight uint16
}
type RetArtworkFormats struct {
Formats []ArtworkFormat
}
type GetTrackArtworkData struct {
TrackIndex uint32
FormatID uint16
TimeOffset uint32
}
type RetTrackArtworkData struct {
//todo
}
type GetPowerBatteryState struct {
}
type RetPowerBatteryState struct {
PowerState byte
BatteryLevel uint8
}
type GetSoundCheckState struct {
}
type RetSoundCheckState struct {
Enabled bool
}
type SetSoundCheckState struct {
Enabled bool
RestoreOnExit bool
}
type GetTrackArtworkTimes struct {
TrackIndex uint32
FormatID uint16
ArtworkIndex uint16
ArtworkCount uint16
}
type RetTrackArtworkTimes struct {
TimeOffset []uint32
}