Esempio n. 1
0
def FortiusAntChild(clv, conn):
    # --------------------------------------------------------------------------
    # Initialize the child process, create our own logfile
    # --------------------------------------------------------------------------
    debug.activate(clv.debug)
    if debug.on(debug.Any):
        logfile.Open('FortiusAntGUI')
        logfile.Console('FortiusAnt GUI started in child-process')

    FortiusAntBody.Initialize(clv)

    # --------------------------------------------------------------------------
    # Start the user-interface
    # --------------------------------------------------------------------------
    app = wx.App(0)
    frame = frmFortiusAntChild(None, conn, clv)
    app.SetTopWindow(frame)
    frame.Show()
    if clv.autostart:
        frame.Autostart()
    app.MainLoop()

    # --------------------------------------------------------------------------
    # Signal parent that we're done
    # --------------------------------------------------------------------------
    frame.GuiMessageToMain(cmd_EndExecution, False)
    if debug.on(debug.Any):
        logfile.Console('FortiusAnt GUI ended')
def g(name, fn, t, f, conn):
    debug.activate(debug.All)
    logfile.Open(fn, name)
    logfile.Write(fn)

    for i in range(0, 100):
        logfile.Write(name, i)

        # Communicate "results" to parent_conn
        # Then receive whether to proceed or to stop
        if i % f == 0:
            conn.send([i, None, 'hello', name])
            if conn.recv(): break

        # Wait, so we cycle once per second
        time.sleep(t)
Esempio n. 3
0
def mainProgram():
    global RestartApplication, clv

    # --------------------------------------------------------------------------
    # Initialize
    # --------------------------------------------------------------------------
    debug.deactivate()
    if not RestartApplication: clv = cmd.CommandLineVariables()
    debug.activate(clv.debug)
    FortiusAntBody.Initialize(clv)

    if debug.on(debug.Any):
        logfile.Open()
        logfile.Console("FortiusANT started")
        logfile.Write  ('    Restart=%s debug=%s' % (RestartApplication, clv.debug))
        clv.print()
        logfile.Console("------------------")

    RestartApplication = False

    #-------------------------------------------------------------------------------
    # Component info
    #-------------------------------------------------------------------------------
    if debug.on(debug.Any):
        # ----------------------------------------------------------------------
        if getattr(sys, 'frozen', False):
            logfile.Write('Windows executable started')
        else:
            logfile.Write('Python version started')
        # ----------------------------------------------------------------------
        logfile.Write('Version info for the components' )
        logfile.Write(githubWindowTitle())
        s = " %20s = %s"
        logfile.Write(s % ('FortiusAnt',                    __version__ ))
        logfile.Write(s % ('antDongle',                 ant.__version__ ))
        logfile.Write(s % ('antFE',                      fe.__version__ ))
        logfile.Write(s % ('antHRM',                    hrm.__version__ ))
        logfile.Write(s % ('antPWR',                    pwr.__version__ ))
        logfile.Write(s % ('antSCS',                    scs.__version__ ))
        logfile.Write(s % ('bleDongle',           bleDongle.__version__ ))
        logfile.Write(s % ('constants',           constants.__version__ ))
        logfile.Write(s % ('debug',                   debug.__version__ ))
        logfile.Write(s % ('FortiusAntBody', FortiusAntBody.__version__ ))
        logfile.Write(s % ('FortiusAntCommand',         cmd.__version__ ))
        if UseGui:
            logfile.Write(s % ('FortiusAntGui',         gui.__version__ ))
        logfile.Write(s % ('logfile',               logfile.__version__ ))
        if UseGui:
            logfile.Write(s % ('RadarGraph',     RadarGraph.__version__ ))
        logfile.Write(s % ('settings',             settings.__version__ ))
        logfile.Write(s % ('structConstants',            sc.__version__ ))
        logfile.Write(s % ('TCXexport',           TCXexport.__version__ ))
        logfile.Write(s % ('usbTrainer',         usbTrainer.__version__ ))

        logfile.Write(s % ('argparse',             argparse.__version__ ))
    #   logfile.Write(s % ('binascii',             binascii.__version__ ))
    #   logfile.Write(s % ('math',                     math.__version__ ))
        logfile.Write(s % ('numpy',                   numpy.__version__ ))
        logfile.Write(s % ('os',                         os.name        ))
        if os.name == 'nt':
            v = sys.getwindowsversion()
            logfile.Write((s + '.%s') %    ('windows',  v.major, v.minor))
        logfile.Write(s % ('pickle',                 pickle.format_version ))
        logfile.Write(s % ('platform',             platform.__version__ ))
    #   logfile.Write(s % ('glob',                     glob.__version__ ))
    #   logfile.Write(s % ('random',                 random.__version__ ))
        logfile.Write(s % ('sys (python)',              sys.version ))
    #   logfile.Write(s % ('struct',                 struct.__version__ ))
    #   logfile.Write(s % ('threading',           threading.__version__ ))
    #   logfile.Write(s % ('time',                     time.__version__ ))
        logfile.Write(s % ('usb',                       usb.__version__ ))
        if UseGui:
            logfile.Write(s % ('wx',                     wx.__version__ ))

        logfile.Write('FortiusANT code flags')
        logfile.Write(s % ('UseMultiProcessing',            UseMultiProcessing))
        logfile.Write(s % ('UseGui',                        UseGui))
        logfile.Write(s % ('UseBluetooth',                  UseBluetooth))
        logfile.Write("------------------")

    if not clv.gui:
        # --------------------------------------------------------------------------
        # Console only, no multiprocessing required to separate GUI
        # --------------------------------------------------------------------------
        Console = clsFortiusAntConsole()
        Console.Autostart()

    elif not UseMultiProcessing:
        # --------------------------------------------------------------------------
        # No multiprocessing wanted, start GUI immediatly
        # --------------------------------------------------------------------------
        clv.PedalStrokeAnalysis = False
        app = wx.App(0)
        frame = frmFortiusAnt(None, clv)
        app.SetTopWindow(frame)
        frame.Show()
        if clv.autostart:
            frame.Autostart()
        app.MainLoop()

    else:
        # --------------------------------------------------------------------------
        # Multiprocessing wanted, start GUI in it's own process
        # --------------------------------------------------------------------------
        # https://docs.python.org/3/library/multiprocessing.html
        # Create queue and sub-process
        # --------------------------------------------------------------------------
        app_conn, gui_conn = multiprocessing.Pipe(True)
        pChild = multiprocessing.Process(target=FortiusAntChild, args=(clv, gui_conn) )
        pChild.start()

        # --------------------------------------------------------------------------
        # Poll child-process untill done
        # --------------------------------------------------------------------------
        parent = clsFortiusAntParent(app_conn)  # The child process has the GUI
        parent.ListenToChild()

        # --------------------------------------------------------------------------
        # Wait for child-process to complete
        # --------------------------------------------------------------------------
        pChild.join()
    # ------------------------------------------------------------------------------
    # We're done
    # ------------------------------------------------------------------------------
    if debug.on(debug.Any):
        logfile.Console('FortiusAnt ended')
        logfile.Close()
Esempio n. 4
0
# And go!
# ------------------------------------------------------------------------------
# input:        command line
#
# Description:  Show all dongles available
#               Open defined dongle
#               Start listening what's going on in the air
#
# Output:       Console/logfile
#
# Returns:      None
# ------------------------------------------------------------------------------

debug.deactivate()
clv = cmd.CommandLineVariables()
debug.activate(clv.debug)

if True or debug.on(debug.Any):
    logfile.Open('ExplorANT')
    logfile.Console("ExplorANT started")

    s = " %17s = %s"
    logfile.Console(s % ('ExplorANT', __version__))
    logfile.Console(s % ('antDongle', ant.__version__))

    clv.print()
    logfile.Console("--------------------")

# ------------------------------------------------------------------------------
# First enumerate all dongles
# ------------------------------------------------------------------------------
Esempio n. 5
0
def HexSpaceL(list):
    rtn   = '['
    comma = ''
    for l in list:
        rtn += comma + HexSpace(l)
        comma = ', '
    rtn += ']'
    return rtn
#-------------------------------------------------------------------------------
# Main program to test the previous functions
#-------------------------------------------------------------------------------
if __name__ == "__main__":
    global LogfileJson
    print ("Test of wdLogfile")
    Write("This logrecord cannot be written")                 # Not open yet
    debug.activate()
    Open()                                                    # This is normal
    Write("This is a logrecord")                              # ..

    print ('json tests')
    LogfileJson.Close()

    Close()                                                   # ..
    print ("Test of wdLogfile done")
    print (HexSpace(binascii.unhexlify("203031")))
    print (HexSpace('False'))
    print (HexSpace(False))


else:
    pass                                # We're included so do not take action!
        logfile.Write(name, i)

        # Communicate "results" to parent_conn
        # Then receive whether to proceed or to stop
        if i % f == 0:
            conn.send([i, None, 'hello', name])
            if conn.recv(): break

        # Wait, so we cycle once per second
        time.sleep(t)


if __name__ == '__main__':
    pid = os.getpid()
    print('pid', pid)
    debug.activate(debug.All)
    fn = 'mp.' + str(pid)
    logfile.Open(fn)
    logfile.Console("Test Multiprocessing started")

    # https://docs.python.org/2/library/multiprocessing.html

    if False:
        print(1)
        # https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue
        q = Queue()

        b = Process(target=f, args=('bob', 1, q))
        m = Process(target=f, args=('michelle', 5, q))

        print(2)