From 60f8ea15bae406837320a20d62d793263cf4c264 Mon Sep 17 00:00:00 2001 From: mungewell Date: Tue, 28 Nov 2017 14:42:14 -0700 Subject: [PATCH] Add new commands 'stream' and 'wifi' to configure camera settings. (#53) New commands 'stream' and 'wifi' allow control of the Streaming and WiFi functions of the attached camera. These settings can also be written to and read from files. For Streaming settings, the official tools should be used to allocate the appropriate crypto-tokens, the other values can be changed at will. Ustream documentation explains how to obtain the OAuth2 tokens, the others are available from user's profile. --- pmca-console.py | 13 ++++ pmca/commands/usb.py | 181 +++++++++++++++++++++++++++++++++++++++++++ pmca/usb/sony.py | 16 ++++ 3 files changed, 210 insertions(+) diff --git a/pmca-console.py b/pmca-console.py index b5f2f32..675df56 100644 --- a/pmca-console.py +++ b/pmca-console.py @@ -46,6 +46,15 @@ def main(): gps = subparsers.add_parser('gps', description='Update GPS assist data') gps.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver') gps.add_argument('-f', dest='file', type=argparse.FileType('rb'), help='assistme.dat file') + stream = subparsers.add_parser('stream', description='Update Streaming configuration') + stream.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver') + stream.add_argument('-f', dest='file', type=argparse.FileType('w'), help='store current settings to file') + stream.add_argument('-w', dest='write', type=argparse.FileType('r'), help='program camera settings from file') + wifi = subparsers.add_parser('wifi', description='Update WiFi configuration') + wifi.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver') + wifi.add_argument('-m', dest='multi', action='store_true', help='Read/Write "Multi-WiFi" settings') + wifi.add_argument('-f', dest='file', type=argparse.FileType('w'), help='store current settings to file') + wifi.add_argument('-w', dest='write', type=argparse.FileType('r'), help='program camera settings from file') args = parser.parse_args() if args.command == 'info': @@ -70,6 +79,10 @@ def main(): updaterShellCommand(args.model, args.fdatFile, args.driver) elif args.command == 'gps': gpsUpdateCommand(args.file, args.driver) + elif args.command == 'stream': + streamingCommand(args.write, args.file, args.driver) + elif args.command == 'wifi': + wifiCommand(args.write, args.file, args.multi, args.driver) else: parser.print_usage() diff --git a/pmca/commands/usb.py b/pmca/commands/usb.py index 2c81bdb..45fc4a3 100644 --- a/pmca/commands/usb.py +++ b/pmca/commands/usb.py @@ -4,6 +4,7 @@ import os import sys import time +import struct if sys.version_info < (3,): # Python 2 @@ -392,3 +393,183 @@ def gpsUpdateCommand(file=None, driverName=None): print('Writing GPS data') SonyExtCmdCamera(device).writeGpsData(file) print('Done') + + +def streamingCommand(write=None, file=None, driverName=None): + """Read/Write Streaming information for the camera connected via usb""" + with importDriver(driverName) as driver: + device = getDevice(driver) + if device: + if isinstance(device, SonyMtpAppInstaller): + print('Error: Cannot configure camera in app install mode. Please restart the device.') + else: + dev = SonyExtCmdCamera(device) + + if write: + incoming = json.load(write) + + # assemble Social (first 9 items in file) + mydict = {} + for key in incoming[:9]: + if key[0] in ['twitterEnabled', 'facebookEnabled']: + mydict[key[0]] = key[1] # Integer + else: + mydict[key[0]] = key[1].encode('ascii') + + data = SonyExtCmdCamera.LiveStreamingSNSInfo.pack( + twitterEnabled = mydict['twitterEnabled'], + twitterConsumerKey = mydict['twitterConsumerKey'].ljust(1025, b'\x00'), + twitterConsumerSecret = mydict['twitterConsumerSecret'].ljust(1025, b'\x00'), + twitterAccessToken1 = mydict['twitterAccessToken1'].ljust(1025, b'\x00'), + twitterAccessTokenSecret = mydict['twitterAccessTokenSecret'].ljust(1025, b'\x00'), + twitterMessage = mydict['twitterMessage'].ljust(401, b'\x00'), + facebookEnabled = mydict['facebookEnabled'], + facebookAccessToken = mydict['facebookAccessToken'].ljust(1025, b'\x00'), + facebookMessage = mydict['facebookMessage'].ljust(401, b'\x00'), + ) + dev.setLiveStreamingSocialInfo(data) + + # assemble Streaming, file may contain multiple sets (of 14 items) + data = b'\x01\x00\x00\x00' + data += struct.pack('