Example #1
0
	def write(self, address, value):
		scp = '$WRI,%04X,%02X' % (address, value)
		
		if self.waiting_for_ack:
			debug("write() already waiting for ack")
			return SHAKE_ERROR
		
		self.write_to_port(scp)
		debug("+++ SENT: " + scp)
		
		self.waiting_for_ack_signal = True
		self.waiting_for_ack = True
		
		timeout = 250
		while timeout != 0 and self.waiting_for_ack_signal:
			ssleep(0.001)
			timeout -= 1
			
		debug("+++ ACK WAIT OVER timeout = " + str(timeout))
			
		self.waiting_for_ack = False
		if not self.lastack:
			debug("write() failed to get ACK")
			return SHAKE_ERROR
		
		self.lastack = False

		return SHAKE_SUCCESS
Example #2
0
def handle_exit(sleepDuration=0):
    print("\n[Shutdown]: closing tasks")
    try:
        client.loop.run_until_complete(client.close())
    except:
        pass
    for t in all_tasks(loop=client.loop):
        if t.done():
            try:
                t.exception()
            except InvalidStateError:
                pass
            except TimeoutError:
                pass
            except CancelledError:
                pass
            continue
        t.cancel()
        try:
            client.loop.run_until_complete(wait_for(t, 5, loop=client.loop))
            t.exception()
        except InvalidStateError:
            pass
        except TimeoutError:
            pass
        except CancelledError:
            pass
    from time import sleep as ssleep
    ssleep(sleepDuration)
Example #3
0
	def read(self, address):
		scp = '$REA,%04X,00' % (address)

		if self.waiting_for_ack:
			return SHAKE_ERROR

		self.write_to_port(scp)
		debug("SENT: " + scp)
		
		self.waiting_for_ack_signal = True
		self.waiting_for_ack = True
		
		timeout = 250
		while self.waiting_for_ack_signal:
			ssleep(0.001)
			timeout -= 1
			if timeout == 0:
				break
			
		self.waiting_for_ack = False
		
		if not self.lastack:
			return (SHAKE_ERROR, 0)
		
		self.lastack = False

		return (SHAKE_SUCCESS, self.lastval)
Example #4
0
	def info_retrieve(self):
		if self.fwrev == None:
			if self.write_data_request(1) == SHAKE_ERROR:
				return SHAKE_ERROR
			count = 0
			
			while count < 1000 and self.fwrev == None:
				count+=1
				ssleep(0.001)
		return SHAKE_SUCCESS
Example #5
0
	def connect(self, addr):
		if not self.thread_done or addr == None:
			return False

		self.thread_done = False
		self.thread_exit = False
		self.device_address = addr
		thread.start_new_thread(self.run, ())
		#self.run()

		elapsed = 0
		while elapsed < 10.0 and not self.synced:
			ssleep(0.01)
			elapsed += 0.01

		if self.thread_done:
			return False

		return self.synced
Example #6
0
	def upload_vib_sample_extended(self, profile, samples, mode, freq, duty):
		if profile < 0 or profile > SHAKE_VIB_PROFILE_MAX:
			return SHAKE_ERROR

		if len(samples) < 2 or (len(samples) % 2 != 0):
			return SHAKE_ERROR

		debug("uploading to location " + str(profile))

		svp = '$VIB,%02X,%02X,%02X,%02X' % (profile, mode, freq, duty)

		i = 0
		while i < len(samples):
			s = ',%02X,%02X' % (samples[i], samples[i+1])
			svp += s
			i += 2

		svp += '~'
		debug("sending upload: " + svp + "\n")

		self.waiting_for_ack = True
		self.lastaddr = -1

		self.write_to_port(svp)
		
		elapsed = 0
		while self.waiting_for_ack and elapsed < 2000:
			ssleep(0.01)
			elapsed += 10 
							
		self.waiting_for_ack = False
	
		if not self.lastack or self.lastaddr == -1:
			return SHAKE_ERROR

		return SHAKE_SUCCESS
Example #7
0
def kill_p(c):
    os.kill(os.getpid(), signal.SIGINT)
    return ssleep(1)