def sts(adr, data_in, wen=1): ladr = (adr & 0xff) << 20 ldata = (data_in & 0xff) << 12 lwen = (wen & 0x01) << 7 data = (ladr & 0x0ff00000) + (ldata & 0x000ff000) + (lwen & 0x80) par_cnt = 0 for i in range(32): if (data >> i) & 0x01 == 0x01: par_cnt = par_cnt + 1 if par_cnt % 2 == 1: par_chk = 0 else: par_chk = 1 data = ((par_chk << 28) & 0x10000000) + data # print (hex(data)) # par = XOR B = UDP() B.write_reg(1, 2) time.sleep(1) B.write_reg(2, data + 0x01) print(hex(adr), hex(data_in), hex(B.read_reg(2))) B.write_reg(2, data + 0x00) # B.write_reg(1,0) # time.sleep(0.5)
def __init__(self): self.uart_flag = False self.udp = UDP() #self.adc_reg = ADC_REG() self.fpga_reg = FPGA_REG() self.bitop = Bit_Op() self.rf = config.subdir + "ADC_register_write_record.csv"
def setup(canvas): global headset global dimmer global images global samples global particles global attractor global ZOOM, ATTRACT, SPAWN, DIM, delay delay = 0 global BLOB BLOB = Image(abspath("g", "blob.png")) # See Attractor.draw_halo(). global MUTE # ---------------------------------------------------- #headset = Headset(host="169.254.132.243", port=12002) headset = Headset() # ---------------------------------------------------- #dimmer = None dimmer = UDP("10.0.1.2", 7000) # ---------------------------------------------------- # Blurred images: images = Images() for f in files(os.path.join("g", "cell", "*.png")): img = Image(abspath(f)) images.cache(img.id, img, kernel=15) images[os.path.basename(f)] = images[img.id] # Audio samples: samples = {} samples["attract"] = sample(abspath("audio", "attract.wav")) samples["repulse"] = sample(abspath("audio", "repulse.wav")) samples["ambient_lo"] = loop(sample(abspath("audio", "ambient_lo.wav"))) samples["ambient_hi"] = loop(sample(abspath("audio", "ambient_hi.wav"))) # Particles: particles = [] for i in range(40): particles.append( Particle(x=random(canvas.width), y=random(canvas.height), image=images["flower1.png"], radius=15 + random(20), bounds=(-65, -65, canvas.width + 65, canvas.height + 65), type=SLEEPIE)) # Attractor: attractor = Attractor(500, 250, radius=40, speed=1.0) attractor.bounds = (150, 100, canvas.width - 100, canvas.height - 100) # Canvas zoom (relative to attractor size): ZOOM = 1.25 # Spacebar toggles between ignore/receive input. MUTE = False # Value that drops to zero when relaxed. DIM = 1.0
parser.add_argument('--method', dest='method', action='store', type=str, default="svm", help='') args = parser.parse_args() print("Subject: %d Session: %d" % (args.subject, args.session)) pattern_num = 6 repetition_num = args.repeat block_num = pattern_num * repetition_num if args.online: receiver = UDP() else: receiver = Loadmat(args.subject, args.session, "train") for i in range(pattern_num * block_num): receiver.receive() receiver.group() erps = receiver.fetch() erps[0] = random.sample(erps[0], block_num) labels = sum([list(np.repeat(i, len(erps[i]))) for i in range(len(erps))], []) erps = sum(erps, []) if args.method == "svm":
def __init__(self, device): port = 9991 + device self.device = device self.shared = SharedData(self.device) self.wifi = UDP(self.shared, udp_port=port) self.alg = Algorithm(self.shared)
def __init__(self): self.uart_flag = False self.udp = UDP() #self.adc_reg = ADC_REG() self.fpga_reg = FPGA_REG() self.bitop = Bit_Op()
print(TAB_3 + 'RST: {}, SYN: {}, FIN:{}'.format( tcp.flag_rst, tcp.flag_syn, tcp.flag_fin)) if len(tcp.data) > 0: # HTTP if tcp.src_port == 80 or tcp.dest_port == 80: print(TAB_2 + 'HTTP Data:') try: http = HTTP(tcp.data) http_info = str(http.data).split('\n') for line in http_info: print(DATA_TAB_3 + str(line)) except: print(format_multi_line(DATA_TAB_3, tcp.data)) else: print(TAB_2 + 'TCP Data:') print(format_multi_line(DATA_TAB_3, tcp.data)) elif ipv4.proto == 17: udp = UDP(ipv4.data) print(TAB_1 + 'UDP Segment:') print(TAB_2 + 'Source Port: {}, Destination Port: {}, Length: {}'.format( udp.src_port, udp.dest_port, udp.size)) if count_pkt >= max_pkt: break else: count_pkt += 1 pcap.close()
def __init__(self, ip: str): # TODO: get ip from network auto self.ip = ip self.udp = UDP(ip) self.config = self.get_config()
class Light: def __init__(self, ip: str): # TODO: get ip from network auto self.ip = ip self.udp = UDP(ip) self.config = self.get_config() def send(self, message): result = self.udp.call(message) if message.params: self.update_config(message.params) return result def on(self): params = Params(state=True) message = self.message(params) self.send(message) def off(self): params = Params(state=False) message = self.message(params) self.send(message) def switch(self): if self.config.state: self.off() else: self.on() def color(self, **kwargs): params = Params() if HEXCODE in kwargs: params['r'] = int(kwargs[HEXCODE][:2], 16) params['g'] = int(kwargs[HEXCODE][2:4], 16) params['b'] = int(kwargs[HEXCODE][4:], 16) elif COLOR in kwargs: params['r'], params['g'], params['b'] = webcolors.name_to_rgb( kwargs[COLOR]) else: if RED in kwargs: params['r'] = kwargs[RED] if BLUE in kwargs: params['b'] = kwargs[BLUE] if GREEN in kwargs: params['g'] = kwargs[GREEN] message = self.message(params) self.send(message) def brightness(self, value: int): params = Params(dimming=value) message = self.message(params) self.send(message) def temp(self, value: int): params = Params(temp=value) message = self.message(params) self.send(message) def speed(self, value: int): params = Params(speed=value) message = self.message(params) self.send(message) def scene(self, scene_id=None, scene=None): if scene: if scene in SCENES: scene_id = SCENES[scene] if not scene_id: scene_id = input(self.get_prompt()) params = Params(sceneId=scene_id) message = self.message(params) self.send(message) def get_config(self): message = Request(GET_PILOT) result_json = self.send(message).decode('UTF-8') result = json.loads(result_json)['result'] config = Config(state=result['state'], scene=result['sceneId'], brightness=result['dimming']) if 'r' in result: config.red = result['r'] config.green = result['g'] config.blue = result['b'] return config def update_config(self, params): for key, value in params.items(): if key == 'sceneId': self.config.scene = params['sceneId'] if key == 'r': self.config.red = params['r'] elif key == 'g': self.config.green = params['g'] elif key == 'b': self.config.blue = params['b'] elif key == 'dimming': self.config.brightness = params['dimming'] elif key == 'state': self.config.state = params['state'] @staticmethod def message(params: Params): return Request(SET_PILOT, params) @staticmethod def get_prompt(): prompt = 'Select one of the following scenes:\n' for scene, scene_id in SCENES.items(): prompt += '{:>3} : {}\n'.format(scene_id, scene) return prompt
frame_header=protocol.FrameHeader(source=udp.source), frame_address=protocol.FrameAddress(target=target, ack_required=True, sequence=self.sequence), protocol_header=protocol.ProtocolHeader( _type=protocol.PacketType.LIGHT_SET_COLOR), payload=protocol.LightSetColor(color=protocol.LightHsbk( hue=int(round((hsbk[HSBK_HUE] % 360.) * (0xffff / 360.))), saturation=int(round(hsbk[HSBK_SAT] * 0xffff)), brightness=int(round(hsbk[HSBK_BR] * 0xffff)), kelvin=int(round(hsbk[HSBK_KELV]))))).serialize() if self.timeout is None: self.timeout = now udp = UDP() lights = { addr: Light(mac, addr) for mac, (addr, services) in udp.get_service(mac).items() # mac may be None if protocol.DeviceService.UDP in services } if hsbk is None: if len(lights): light = list(lights.values())[0] hsbk = udp.get_color(light.mac, light.addr) else: hsbk = numpy.array([0., 0., 1., 3500], numpy.double) assert sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) == 0