Esempio n. 1
0
    def get_qmp_args(self):
        """
        Get chardev hotplug requried args by backend type

        :return dict: dict include chardev-add requried args.
        """
        args = {
            "id": self.get_qid(),
            "backend": {
                "type": self.params.get("backend"),
                "data": {}
            }
        }
        if self.params.get("backend") == "socket":
            if self.get_param("port"):
                addr_type = "inet"
                host = self.get_param("host") or "0.0.0.0"
                addr_data = {"host": host, "port": self.get_param("port")}
            else:
                addr_type = "unix"
                addr_data = {"path": self.get_param("path")}
            args["backend"]["data"]["addr"] = {
                "type": addr_type,
                "data": addr_data
            }
            if addr_type == "inet":
                sock_params = ["telnet", "ipv4", "ipv6", "nodelay"]
            else:
                sock_params = ["server", "nowait"]

            for param in sock_params:
                if self.get_param(param) is None:
                    continue
                value = True if self.get_param(param) else False
                if param == "nowait":
                    value = not value
                    param = "wait"
                args["backend"]["data"][param] = value
            return args

        if self.params.get("backend") == "file":
            args["backend"]["data"] = {"out": self.get_param("path")}
            return args

        if self.params.get("backend") in ["null", "pty"]:
            return args

        if self.params.get("backend") in ["serial", "parallel"]:
            args["backend"]["data"] = {"device": self.get_param("path")}
            return args

        raise DeviceError("chardev '%s' not support hotplug" %
                          self.params.get("backend"))
Esempio n. 2
0
    def open_proxmark(self):
        """ open proxmark3 device and get read/write endpoints """

        # check for connected proxmark
        self.dev = usb.core.find(idVendor=0x9ac4, idProduct=0x4b8f)
        if not self.dev:
            raise DeviceError('Proxmark not Found', ERR_NOT_FOUND)

        # get configuration and interface
        self.cfg = self.dev.get_active_configuration()
        self.iface = self.cfg[(0, 0)]

        # get reading and writing endoint
        self.ep_out = usb.util.find_descriptor(
            self.dev.get_interface_altsetting(),
            custom_match=lambda e: usb.util.endpoint_direction(
                e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
        self.ep_in = usb.util.find_descriptor(
            self.dev.get_interface_altsetting(),
            custom_match=lambda e: usb.util.endpoint_direction(
                e.bEndpointAddress) == usb.util.ENDPOINT_IN)
        if not self.ep_in or not self.ep_out:
            raise DeviceError("Unable to get read/write endpoints",
                              ERR_NO_ENDPOINT)

        # try to detach kernel driver
        if self.dev.is_kernel_driver_active(self.iface.bInterfaceNumber):
            self.dev.detach_kernel_driver(self.iface.bInterfaceNumber)

        # set configuration
        self.dev.set_configuration(self.cfg)

        # set alternate setting
        self.dev.set_interface_altsetting(self.iface)

        return (self.ep_out.bEndpointAddress, self.ep_in.bEndpointAddress)
Esempio n. 3
0
 def verify_supported_backend(self, backend):
     if backend not in self.backends:
         raise DeviceError("Unknow chardev backend '%s'" % backend)
Esempio n. 4
0
 def verify_hotplug(self, out, monitor):
     raise DeviceError("'verify_hotplug' function unimplemented")
Esempio n. 5
0
 def unplug_qmp(self):
     """ :return: the unplug monitor command """
     if self.get_qid():
         return "object-del", {'id': self.get_qid()}
     else:
         raise DeviceError("Device has no qemu_id.")
Esempio n. 6
0
 def unplug_hmp(self):
     """ :return: the unplug monitor command """
     if self.get_qid():
         return "object_del %s" % self.get_qid()
     else:
         raise DeviceError("Device has no qemu_id.")
Esempio n. 7
0
 def unplug_qmp(self):
     """ :return: the unplug monitor command """
     if self.get_qid() is None:
         raise DeviceError("qid not set; device %s can't be unplugged" %
                           self)
     return "__com.redhat_drive_del", {'id': self.get_qid()}
Esempio n. 8
0
 def unplug_hmp(self):
     """ :return: the unplug monitor command """
     if self.get_qid() is None:
         raise DeviceError("qid not set; device %s can't be unplugged" %
                           self)
     return "drive_del %s" % self.get_qid()
Esempio n. 9
0
 def unplug_qmp(self):
     """ :return: tuple(unplug qemu command, arguments)"""
     raise DeviceError("Unplug is not supported by this device %s", self)
Esempio n. 10
0
 def unplug_hmp(self):
     """ :return: the unplug monitor command """
     raise DeviceError("Unplug is not supported by this device %s", self)
Esempio n. 11
0
                    type=str, help='path where state_dict saved in after training')

parser.add_argument('--max_steps', default=12001, type=int,
                    help='max steps')
args = parser.parse_args()


# find GPU
if torch.cuda.is_available():

    
    torch.cuda.empty_cache()
    device = torch.device('cuda:0')
    # print(device)
else:
    raise DeviceError('Master: there must be at least one GPU!')


# get dataset
dataset = Data_batch('training')
train_loader = DataLoader(dataset=dataset, shuffle=True, batch_size=args.batch_size)
train_iterator = iter(train_loader)
#initialzie network and parameters
net = FRE()
net.to(device)
net.train()
if args.fine_tune:
    net.load_state_dict(torch.load(args.pth_path))
else:
    # first, use pretrained vgg16.pth initialze backbone(vgg part)
    pre_trained = torch.load(args.vgg_pth_path)
Esempio n. 12
0
 def unplug_qmp(self):
     """ :return: the unplug monitor command """
     if self.get_qid():
         return "device_del", self.get_qid()
     else:
         raise DeviceError("Device has no qemu_id.")