コード例 #1
0
ファイル: d_log.py プロジェクト: zebra6/tux_2.0
def init():
    global g_sample_period
    thread_lcs = None

    #set up the logger first thing
    p_log.init(os.path.basename(__file__))

    # parse args
    args = __parse_args()

    # create datalog directory if it doesn't exist TODO nested paths
    if not os.path.exists(paths.datalog_directory):
        l(ll.info, "creating data_log directory\n")
        os.mkdir(paths.datalog_directory)

    # create new raw file w/ current date
    __new_raw_file()

    thread_lcs = threading.Thread(target = __thread_read_lcs, \
            name = "read_lc", \
            kwargs = {"sample_period": g_sample_period})

    #kick off the accessory thread
    thread_lcs.start()

    #main loop
    __run()

    #wait for the timestamp thread to finish
    thread_lcs.join()
コード例 #2
0
ファイル: d_log.py プロジェクト: zebra6/tux_2.0
def __new_raw_file():
    global g_current_raw_file

    g_current_raw_file = paths.datalog_directory + \
            "/" + \
            "data_log_" + \
            "[scale_id]_" + \
            str(datetime.datetime.now()) + \
            ".psl"

    #get rid of any spaces
    g_current_raw_file = g_current_raw_file.replace(" ", "_")
    l(ll.info, "creating new raw log file %s\n" % g_current_raw_file)
コード例 #3
0
ファイル: vadc_t.py プロジェクト: zebra6/tux_2.0
    def run(self):
        done = False

        while done != True:

            #only update if we are running
            if self.is_running == True:
                self.__tick()

            time.sleep(1 / 100)

            #process all our messages
            while self.msg_queue.empty() == False:
                msg = self.msg_queue.get()

                if msg.message == vadc_msg_type_e.start:
                    l(ll.info, "vadc: starting\n")
                    self.is_running = True

                elif msg.message == vadc_msg_type_e.pause:
                    l(ll.info, "vadc: pausing\n")
                    self.is_running = False

                elif msg.message == vadc_msg_type_e.stop:
                    l(ll.info, "vadc: shutting down\n")
                    self.is_running = False
                    done = True

                elif msg.message == vadc_msg_type_e.stop:
                    self.print()

                else:
                    l(ll.warn,
                      "vadc: got unknown message \"%i\"\n" % msg.message)
コード例 #4
0
ファイル: d_log.py プロジェクト: zebra6/tux_2.0
def __run():
    global g_done
    done = False

    l(ll.info, "starting execution, press \"q\" or \"x\" to exit\n")

    while done != True:
        tmp = g("$ ")

        if tmp == "q" or tmp == "x":
            g_done_lock.acquire()
            g_done = done = True
            g_done_lock.release()
        else:
            l(ll.warn, "unknown command \"%s\"\n" % tmp)
コード例 #5
0
def init():
    update_hz_signal = 100
    update_hz_output = 10
    vadc = None
    vadc_thread = None

    #set up the logger first thing
    p_log.init(os.path.basename(__file__))

    #parse args and override any defaults
    _parse_args()

    if os.path.exists(paths.virtual_mount_point):
        l(ll.fatal, \
                "unable to create mount point, directory '%s' already exists\n" \
                % paths.virtual_mount_point)
        quit()

    os.mkdir(paths.virtual_mount_point)

    #create the vadc
    l(ll.info, "creating virtual adc '%s'\n" % (paths.virtual_mount_point + "/" + paths.vadc_name))
    vadc = vadc_t.vadc_t(paths.vadc_name, paths.virtual_mount_point)
    l(ll.info, "vadc created successfully\n")
    vadc.print()

    l(ll.info, "starting vadc thread\n")
    vadc_thread = threading.Thread(target = vadc.run, name = "vadc")
    vadc_thread.start()

    #main loop
    run(vadc)

    #terminate the vadc thread
    vadc_thread.join()

    #clean up
    l(ll.info, "removing virtual mount points\n")
    shutil.rmtree(paths.virtual_mount_point)
    p_log.shutdown()

    print("done")
コード例 #6
0
def run(vadc):
    done = False

    l(ll.info, "starting execution, press \"q\" or \"x\" to exit\n")

    while done != True:
        tmp = g("$ ")
        if tmp == "q" or tmp == "x":
            vadc.stop()
            done = True
        elif tmp == "start":
            vadc.start()
        elif tmp == "pause":
            vadc.pause()
        elif tmp == "stop":
            vadc.stop()
        elif tmp == "print":
            vadc.print()
        else:
            l(ll.warn, "unknown command \"%s\"\n" % tmp)
コード例 #7
0
ファイル: vadc_t.py プロジェクト: zebra6/tux_2.0
    def print(self):
        i = 0

        l(ll.info, "vadc state:\n")
        l(ll.info, "name: %s\n" % self.name)
        l(ll.info, "path: %s\n" % self.path)
        l(ll.info, "num_ticks: %s\n" % self.num_ticks)
        l(ll.info, "child vlcs, path and name:\n")

        for vlc in self.vlc_list:
            l(ll.info, "%u: %s (%s)\n" % (i, vlc.path, vlc.name))
            i += 1
コード例 #8
0
ファイル: d_log.py プロジェクト: zebra6/tux_2.0
def __thread_read_lcs(sample_period):
    global g_current_raw_file
    global g_done
    done = False
    count = 0
    backup = sample_period
    latest_timestamp = None

    l(ll.info,
      "read_lc: starting with sample period of %lf seconds\n" % sample_period)

    #TODO mutex
    while done != True:

        g_done_lock.acquire()
        done = g_done
        g_done_lock.release()

        #update the timestamp
        latest_timestamp = str(datetime.datetime.now())

        fobj = open(g_current_raw_file, "a")

        # Iterate through each LBC and sample
        try:
            if count == 0:
                fobj.write("time: %s, " % latest_timestamp)
                fobj.write("sample_num: %u, " % count)
                fobj.write("starting with sample period %lf\n\n" %
                           sample_period)

            for i in range(0, NUM_LOAD_CELLS):
                vlc = open(paths.virtual_mount_point + \
                        '/' \
                        + paths.vlc_basename \
                        + str(i), \
                        "r" )

                line = (vlc.readline()).rstrip()
                vlc.close()

                if line == "":
                    line = NO_DATA_STR

                #write the timestamp and data
                fobj.write("time: %s, " % latest_timestamp)
                fobj.write("sample_num: %u, " % count)
                fobj.write("cell %i: %10s\n" % (i, line))

                #handle end of line
                if i == (NUM_LOAD_CELLS - 1):
                    fobj.write("\n")

                #we may have come in from an unmounted state, so always set this
                sample_period = backup

        except FileNotFoundError:
            l(
                ll.fatal, "vadcs unmounted, sleeping five seconds (%s)\n" %
                latest_timestamp)
            sample_period = 5.0

        count += 1
        fobj.close()
        time.sleep(sample_period)