def main(): #Connecting to erg ergs = list(pyrow.find()) if len(ergs) == 0: exit("No ergs found.") print(ergs) erg = pyrow.PyRow(ergs[0]) print("Connected to erg.") #Create a dictionary of the different status states state = [ 'Error', 'Ready', 'Idle', 'Have ID', 'N/A', 'In Use', 'Pause', 'Finished', 'Manual', 'Offline' ] stroke = [ 'Wait for min speed', 'Wait for acceleration', 'Drive', 'Dwelling', 'Recovery' ] workout = [ 'Waiting begin', 'Workout row', 'Countdown pause', 'Interval rest', 'Work time inverval', 'Work distance interval', 'Rest end time', 'Rest end distance', 'Time end rest', 'Distance end rest', 'Workout end', 'Workout terminate', 'Workout logged', 'Workout rearm' ] command = [ 'CSAFE_GETSTATUS_CMD', 'CSAFE_PM_GET_STROKESTATE', 'CSAFE_PM_GET_WORKOUTSTATE' ] #prime status number cstate = -1 cstroke = -1 cworkout = -1 if state[erg.get_status()['status']] != 'Ready': print(state[erg.get_status()['status']]) print(erg.get_workout()) else: erg.set_workout(workout_time=[0, 30, 0], split=120) #Inf loop while 1: results = erg.send(command) print(results) if cstate != (results['CSAFE_GETSTATUS_CMD'][0] & 0xF): cstate = results['CSAFE_GETSTATUS_CMD'][0] & 0xF print("State " + str(cstate) + ": " + state[cstate]) if cstroke != results['CSAFE_PM_GET_STROKESTATE'][0]: cstroke = results['CSAFE_PM_GET_STROKESTATE'][0] print("Stroke " + str(cstroke) + ": " + stroke[cstroke]) if cworkout != results['CSAFE_PM_GET_WORKOUTSTATE'][0]: cworkout = results['CSAFE_PM_GET_WORKOUTSTATE'][0] print("Workout " + str(cworkout) + ": " + workout[cworkout]) time.sleep(1)
def ErgThread(): global cnt_erg ergs = list(pyrow.find()) erg = PyErg(ergs[0]) while run_thread: erg_dict = erg.get_monitor(forceplot=True) now = time() msg = "E, %f, %s" % (now, json.dumps(erg_dict)) all_data.append([now, msg]) cnt_erg += 1
def __init__(self): ergs = list(pyrow.find()) self._erg = PyErg(ergs[0]) self._erg_dict = {} self._stroke_dwelling_stamp = time.time() self.__last_stroke_state = -1 self._stroke_period = 5.0 self._erg_thread = threading.Thread( target=self._run_thread, daemon=True) self._erg_dict = self._erg.get_monitor(forceplot=True) # populate dict self._start_dist = self._erg_dict['distance'] self._erg_thread.start()
def get_rowers(): # Connecting to erg ergs = list(pyrow.find()) if len(ergs) == 0: print("No ergs found.") else: print("number of ergs found: " + str(len(ergs))) pm_list = [] for erg in ergs: pm = pyrow.PyErg(erg) pm_info = pm.get_erg() print("Connected to erg." + str(pm_info['serial'])) pm_list.append(pm) return pm_list
def main(): # handle command line options parser = OptionParser(usage="usage: %prog [options]", version="%prog 1.0") parser.add_option("--host", default='', type='string', action="store", dest="host", help="hostname (localhost)") parser.add_option("--port", default=8000, type='int', action="store", dest="port", help="port (8000)") (options, args) = parser.parse_args() print("Welcome to ErgServer!") # initialize connection to erg connected_ergs = pyrow.find() if len(connected_ergs) == 0: print("No ergs found.") else: print("{} erg(s) found. Starting ErgServer.".format(len(connected_ergs))) print("(NOTE: This will run forever. Press ctrl+c to quit)") try: message_queue = Queue(20) # connect to erg and monitor it using a new process erg = pyrow.pyrow(connected_ergs[0]) prc_monitor = Process(target=monitor_erg, args=(message_queue, erg)) prc_monitor.start() # start the websocket server to accept client connections erg_server = SimpleWebSocketServer(options.host, options.port, ErgSocket, message_queue) def close_sig_handler(signal, frame): erg_server.close() sys.exit(0) signal.signal(signal.SIGINT, close_sig_handler) erg_server.serveforever() except: pass print("Closing ErgServer. See you next time!") try: prc_monitor.terminate() except: pass sys.exit(0)
async def main(): while True: try: async with websockets.connect('ws://localhost:5000/erg/' + socket.gethostname()) as ws: erg = None while erg is None: ergs = [pyrow.PyErg(e) for e in pyrow.find()] erg = ergs[0] if len(ergs) > 0 else None await asyncio.sleep(1) while True: data = await asyncio.gather(*map(get_erg_update, ergs)) print(data) await ws.send(json.dumps(data)) await asyncio.sleep(1) except: pass await asyncio.sleep(5)
def __init__(self): with open("logging.json", "r") as f: logging.config.dictConfig(json.load(f)) self.logger = logging.getLogger("PySSConsole") self.cmd = dict() self.sio = socketio.Client() self.sio.on('read_from', self.handler) self.sio.on('connect', self.connect) self.sio.on('disconnect', self.disconnect) self.server_url = 'http://server.strokeside.ru:9090' self.sio.connect(self.server_url) self.ergs = pyrow.find() if self.ergs: self.pySS = PyStrokeSide(self.ergs[0]) self.pySS.restore_erg()
break status[_item['erg_num']] = _item['status'] status_q.task_done() for i in range(NUM_ERGS): fname = f'erg{i}.csv' import os.path if not os.path.isfile(fname): print("Generating CSV Files") with open(fname, 'w') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=LOG_FIELDNAMES) writer.writeheader() threads = [] ergs = list(pyrow.find()) if len(ergs) == 0: exit("No ergs found.") print(ergs) for i in range(NUM_ERGS): erg = pyrow.PyRow(ergs[i]) print("Connected to erg.") t = threading.Thread(target=erg_monitor, args=(i,erg)) t.start() threads.append(t) t = threading.Thread(target=stream_overlay) t.start() threads.append(t)
def main(): rowerFile = "defaultrower.txt" rower = rowingdata.getrower(rowerFile) #Connecting to erg ergs = list(pyrow.find()) if len(ergs) == 0: exit("No ergs found.") erg = pyrow.PyErg(ergs[0]) print("Connected to erg.") while True: print("Waiting to Start a New Workout...") wait_for_workout_start(erg=erg) # Now open and prepare csv file with current timestamp filename = "workout_" + str(time.time()) print("Starting a New Workout: " + filename) filename_csv = filename + ".csv" write_file = open(filename_csv, 'w') write_file_header(write_file=write_file) index = 0 rows_written = False # Get initial workout state workout = erg.get_workout() #Loop until workout ends while workout['state'] == 1: write_file_row(erg=erg, rowindex=index, write_file=write_file) # write out the row rows_written = True wait_for_stroke_start(erg=erg) wait_for_stroke_end(erg=erg) # Get workout state workout = erg.get_workout() index = index + 1 print("Ending Workout: " + filename) write_file.close() if rows_written == True: # Now use rowingdata to convert this to TCX res = rowingdata.rowingdata(filename_csv, rowtype="Indoor Rower", rower=rower) filename_tcx = filename + ".tcx" res.exporttotcx(filename_tcx) print("Workout TCX Export Complete: " + filename) else: print("Workout Empty!: " + filename)
import unittest from pyrow.tests.basetest_pyrow import * from pyrow import pyrow from usb.core import NoBackendError, USBError class TestFind(unittest.TestCase): def test_noerror(self): testfind_noerror(self, pyrow) valid_env = True try: ergs = pyrow.find() valid_env = len(list(pyrow.find())) > 0 except (NoBackendError, USBError): valid_env = False @unittest.skipIf(not valid_env, "Skipping tests, no ergs") class TestPyErg(unittest.TestCase): def setUp(self): testpyerg_setUp(self, pyrow) def test_get_monitor(self): testpyerg_get_monitor(self, pyrow) def test_get_forceplot(self): testpyerg_get_forceplot(self, pyrow) def test_get_workout(self):