diff options
author | Qiu Tingting <qiutt@fujitsu.com> | 2021-04-28 05:42:44 +0800 |
---|---|---|
committer | Jan-Simon Möller <jsmoeller@linuxfoundation.org> | 2021-11-03 15:11:21 +0100 |
commit | f1ba6e0b1bada4dfff863fb9f10ab59eb243cedf (patch) | |
tree | 927b63bf7a8db8257ca3bece47f66fa9e225894b | |
parent | d05f0e7cdf63756847f5543c1479a9b2e9207ca0 (diff) |
Add CLI functionality for radio
Bug-AGL: SPEC-3946
Signed-off-by: Qiu Tingting <qiutt@fujitsu.com>
Change-Id: I48a042f65a8274f069e8ee01dc8a06f7487c5777
-rw-r--r-- | pyagl/services/radio.py | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/pyagl/services/radio.py b/pyagl/services/radio.py index a509526..d5b09c3 100644 --- a/pyagl/services/radio.py +++ b/pyagl/services/radio.py @@ -32,14 +32,22 @@ class AFBRadioResponse(AFBResponse): self.type = data.type self.data = data.data +verbs = ['subscribe', 'unsubscribe', 'frequency', 'band', 'band_supported', 'frequency_range', 'frequency_step', 'start', 'stop', 'scan_start', 'scan_stop', 'stereo_mode', 'rds', 'quality', 'alternative_frequency'] +events = ['frequency', 'station_found', 'status', 'rds'] class RadioService(AGLBaseService): service = 'agl-service-radio' parser = AGLBaseService.getparser() - parser.add_argument('--start', help='Start radio playback') - parser.add_argument('--stop', help='Stop radio playback') - parser.add_argument('--scan-start', help='Start radio scanning') - parser.add_argument('--scan-stop', help='Stop radio scanning') + parser.add_argument('--start', help='Start radio playback', action='store_true') + parser.add_argument('--stop', help='Stop radio playback', action='store_true') + parser.add_argument('--scan-start', help='Start radio scanning(e.g. forward, backward)') + parser.add_argument('--scan-stop', help='Stop radio scanning', action='store_true') + parser.add_argument('--frequency', help='get/set tuned radio frequency(e.g. 101100000)') + parser.add_argument('--band', help='get/set current band type(e.g. AM, FM)') + parser.add_argument('--band_supported', help='check if a certain band is supported(e.g. AM, FM)') + parser.add_argument('--frequency_range', help='get frequency range for band type(e.g. AM, FM)') + parser.add_argument('--frequency_step', help='get frequency step/spacing for band type(e.g. AM, FM)') + parser.add_argument('--stereo_mode', help='get/set stereo or mono mode(e.g. stereo, mono)') # FIXME: Add rest of verb arguments... def __await__(self): @@ -105,7 +113,6 @@ class RadioService(AGLBaseService): async def unsubscribe(self, event=None): return await super().unsubscribe(event=event) - async def main(loop): args = RadioService.parser.parse_args() RS = await RadioService(ip=args.ipaddr) @@ -116,7 +123,17 @@ async def main(loop): print(r) if args.stop: - msgid = await RS.start() + msgid = await RS.stop() + r = await RS.afbresponse() + print(r) + + if args.scan_start: + msgid = await RS.scan_start(args.scan_start) + r = await RS.afbresponse() + print(r) + + if args.scan_stop: + msgid = await RS.scan_stop() r = await RS.afbresponse() print(r) @@ -127,10 +144,46 @@ async def main(loop): r = await RS.afbresponse() print(r) + if args.unsubscribe: + for event in args.unsubscribe: + msgid = await RS.unsubscribe(event) + print(f"Unsubscribed for event {event} with messageid {msgid}") + r = await RS.afbresponse() + print(r) + if args.listener: async for response in RS.listener(): print(response) + if args.frequency: + msgid = await RS.frequency(args.frequency) + r = await RS.afbresponse() + print(r) + + if args.band: + msgid = await RS.band(args.band) + r = await RS.afbresponse() + print(r) + + if args.band_supported: + msgid = await RS.band_supported(args.band_supported) + r = await RS.afbresponse() + print(r) + + if args.frequency_range: + msgid = await RS.frequency_range(args.frequency_range) + r = await RS.afbresponse() + print(r) + + if args.frequency_step: + msgid = await RS.frequency_step(args.frequency_step) + r = await RS.afbresponse() + print(r) + + if args.stereo_mode: + msgid = await RS.stereo_mode(args.stereo_mode) + r = await RS.afbresponse() + print(r) if __name__ == '__main__': loop = asyncio.get_event_loop() |