예제 #1
0
def build_command(iid, buf_id, offset, size):
    return Request(target_category=0x0c,
                   target_id=1,
                   command_id=0x0c,
                   instance_id=iid,
                   flags=libssam.REQUEST_HAS_RESPONSE,
                   payload=pack_block_data(buf_id, offset, size, 0))
예제 #2
0
    def _get_device_descriptor_part(self, entry, offset, length):
        payload = struct.pack("<BIIB", entry, offset, length, 0)

        rqst = Request(self.target_categorty, self.target_id, 0x04,
                       self.instance_id, libssam.REQUEST_HAS_RESPONSE, payload)
        resp = self.ctrl.request(rqst)

        head, data = resp[:10], resp[10:]
        _, _, _, done = struct.unpack("<BIIB", head)

        return done, data
예제 #3
0
파일: ctrl.py 프로젝트: imDiver/BigSurface
def main():
    cmd_name = sys.argv[1]

    if cmd_name == 'help':
        print(f'Usage:')
        print(f'  {sys.argv[0]} <command> [args...]')
        print(f'')
        print(f'Commands:')
        print(f'  help')
        print(f'    display this help message')
        print(f'')
        print(f'  request <tc> <tid> <cid> <iid> <flags> [payload...]')
        print(f'    basic command with optional payload')
        print(f'')
        print(f'Arguments:')
        print(f'  <tc>:          command target category')
        print(f'  <tid>:         command target ID')
        print(f'  <cid>:         command ID')
        print(f'  <iid>:         command instance ID')
        print(f'  <flags>:       request flags')
        print(
            f'  [payload...]:  optional payload bytes, separated by whitespace'
        )

    elif cmd_name == 'request':
        tc = int(sys.argv[2], 0)
        tid = int(sys.argv[3], 0)
        cid = int(sys.argv[4], 0)
        iid = int(sys.argv[5], 0)
        flg = int(sys.argv[6], 0)
        pld = [int(x, 0) for x in sys.argv[7:]]

        rqst = Request(tc, tid, cid, iid, flg, pld)

        with Controller() as ctrl:
            rsp = ctrl.request(rqst)
            if rsp:
                print(' '.join(['{:02x}'.format(x) for x in rsp]))
예제 #4
0
파일: dtx.py 프로젝트: imDiver/BigSurface
#!/usr/bin/env python3
import sys

import libssam
from libssam import Controller, Request, REQUEST_HAS_RESPONSE

COMMANDS = {
    "lock": Request(0x11, 0x01, 0x06, 0x00),
    "unlock": Request(0x11, 0x01, 0x07, 0x00),
    "request": Request(0x11, 0x01, 0x08, 0x00),
    "confirm": Request(0x11, 0x01, 0x09, 0x00),
    "heartbeat": Request(0x11, 0x01, 0x0a, 0x00),
    "cancel": Request(0x11, 0x01, 0x0b, 0x00),
    "get-state": Request(0x11, 0x01, 0x0c, 0x00, REQUEST_HAS_RESPONSE),
    "get-opmode": Request(0x11, 0x01, 0x0d, 0x00, REQUEST_HAS_RESPONSE),
    "get-status": Request(0x11, 0x01, 0x11, 0x00, REQUEST_HAS_RESPONSE),
}


def print_usage_and_exit():
    print(f"Usage:")
    print(f"  {sys.argv[0]} help")
    print(f"  {sys.argv[0]} <command>")
    exit(1)


def print_help_and_exit():
    print(f"Usage:")
    print(f"  {sys.argv[0]} help")
    print(f"  {sys.argv[0]} <command>")
    print(f"")
예제 #5
0
def query_buffer_part(ctrl, tc, tid, cid, iid, bufid, offset, length):
    payload = [bufid] + u32le_to_buf(offset) + u32le_to_buf(length) + [0x00]
    command = Request(tc, tid, cid, iid, libssam.REQUEST_HAS_RESPONSE, payload,
                      128)

    return ctrl.request(command)
예제 #6
0
 def set_capslock_led(self, state):
     state_byte = 0x01 if state else 0x00
     rqst = Request(0x08, 0x02, 0x01, 0x00, 0, bytes([state_byte]))
     self.ctrl.request(rqst)
예제 #7
0
 def get_hid_feature_report(self, num):
     flags = libssam.REQUEST_HAS_RESPONSE
     rqst = Request(0x08, 0x02, 0x0b, 0x00, flags, bytes([num]))
     return self.ctrl.request(rqst)
예제 #8
0
 def get_device_descriptor(self, entry):
     flags = libssam.REQUEST_HAS_RESPONSE
     rqst = Request(0x08, 0x02, 0x00, 0x00, flags, bytes([entry]))
     return self.ctrl.request(rqst)
예제 #9
0
def command(tc, tid, cid, iid, snc, payload):
    return Request(tc, tid, cid, iid, snc, payload, 8)