コード例 #1
0
 def vi_reset_button_monitor(self):
     # obtain irq count
     prev_irq_cnt = self.button_irq_cnt
     cmd = "cat /proc/interrupts | grep PB_RST | awk '{print $2'}"
     self.button_irq_cnt = int(subprocess.check_output(cmd, shell=True).strip())
     if self.debug:
         LOG.debug("Reset button monitor: irq=%s %s" % (prev_irq_cnt, self.button_irq_cnt))
     if (self.button_irq_cnt == (prev_irq_cnt + 1)):    # reset button was held 
         # Perform Firmware Reset 
         xcmodem_led.all_leds(3)                    # all leds slow blink
         LOG.info("Firmware Reset Button Activated !!!")
         ver, fname = subprocess.check_output("cat ../backup/factory/upgrade.ver", shell=True).split()
         LOG.info("Firmware Reset to %s ..." % ver)
         LOG.info("System will be reset after Firmware Reset ...")
         cmd = "rm -fr ../backup/current; cp -pr ../backup/factory ../backup/current; \
                cp -f ../backup/current/%s /tmp; \
                cd /tmp; tar xvf %s; ./xcmodem-upgrade.sh" % (fname, fname)
         # LOG.debug("issuing: " + cmd)
         if subprocess.call(cmd, shell=True):
             LOG.debug("firmware reset fail")
コード例 #2
0
def vi_cleanup():
    LOG.debug("Performing cleanup...")
    # Previous paired VI might incidently take over assigned mb/md
    # app ports; thus, we should clean up old paired devices

    # check if the device has already paired up
    cmd = "for d in `bluez-test-device list | grep -v %s | grep -v %s | awk '/OpenXC-VI-/ {print $1}'`; \
           do bluez-test-device remove $d; done" % (OPENXC_V2X_NAME_PREFIX, OPENXC_MODEM_NAME_PREFIX)
    # LOG.debug("issuing: " + cmd)
    if subprocess.call(cmd, shell=True):
        LOG.debug("clean up fail")

    # Remove lingering trace file
    cmd = "rm -f %s %s %s" % (XCMODEM_TRACE_RAW_FILE, XCMODEM_TRACE_RAW_BK_FILE, XCMODEM_TRACE_FILE)
    # LOG.debug("issuing: " + cmd)
    subprocess.call(cmd, shell=True)

    # clean up lingering pppd process if exist
    subprocess.call('if [ -r /var/run/ppp0.pid ]; then echo "cleanup pppd ..."; killall -q pppd; sleep 3; fi', shell=True)

    # turn off all led - needed to be after pppd cleaning up to free /tty/ACM3 for GSM Led if applicable
    xcmodem_led.all_leds(0)
コード例 #3
0
 def vi_auto_upgrade(self):
     ver_url = conf_options['web_scp_sw_latest_version_url']
     if ver_url is None or ver_url == 'None':
         return
     LOG.debug("OTA auto upgrade validation ...")
     # Use GSM if applicable 
     if conf_options['gsm_enable']:
         if not self.gsm_instance():
             LOG.error("OTA abort due to gsm_app instance fail")
             return
         if not self.gsm.start():
             LOG.error("OTA abort due to gsm_app start fail")
             # No need to move on without network connection
             return 
     # Obtain latest version info
     cmd = "rm -fr /tmp/upgrade.ver; \
            scp -o StrictHostKeyChecking=no -i %s %s@%s /tmp/upgrade.ver" % \
             (conf_options['web_scp_pem'], \
             conf_options['web_scp_userid'], \
             ver_url)
     # LOG.debug("issuing '%s'" % cmd)
     if subprocess.call(cmd, shell=True):
         LOG.error("fail to scp upgrade.ver from %s@%s" % (conf_options['web_scp_userid'], \
                                                      ver_url))
         LOG.error("OTA abort due to scp fail")
         return
     ver, fname = subprocess.check_output("cat /tmp/upgrade.ver", shell=True).split()
     cver = xcmodem_ver.get_version()
     LOG.debug("OTA latest=%s current=%s" % (ver, cver))
     if ver <= cver:
         return
     LOG.info("OTA auto upgrade for %s ..." % ver)
     # Obtain upgrading package
     if re.search(r'/', conf_options['web_scp_sw_latest_version_url'], re.M|re.I):
         delimiter = '/'
     else:
         delimiter = ':'
     pkg = "%s%s%s" % (conf_options['web_scp_sw_latest_version_url'].rsplit(delimiter, 1)[0], \
                       delimiter, fname)
     cmd = "scp -o StrictHostKeyChecking=no -i %s %s@%s /tmp" % \
            (conf_options['web_scp_pem'], \
             conf_options['web_scp_userid'], \
             pkg)
     # LOG.debug("issuing '%s'" % cmd)
     if subprocess.call(cmd, shell=True):
         LOG.error("fail to scp %s from %s@%s" % (fname, \
                                                  conf_options['web_scp_userid'], \
                                                  pkg))
         LOG.error("OTA abort due to scp fail")
         return
     # Use GSM if applicable 
     if conf_options['gsm_enable']:
         # Tear off gsm connection
         self.gsm.stop()
     # Perform SW upgrade  
     xcmodem_led.all_leds(3)                    # all leds slow blink
     LOG.info("OTA auto upgrading ...")
     LOG.info("System will be reset after software upgrade ...")
     # directory prep
     cmd = "rm -fr ../backup/previous; mv -f ../backup/current ../backup/previous; \
            mkdir -p ../backup/current; \
            cp -f /tmp/%s /tmp/upgrade.ver ../backup/current" % fname
     # LOG.debug("issuing: " + cmd)
     if subprocess.call(cmd, shell=True):
         LOG.error("OTA software upgrade fail to directory prep")
         cmd = "rm -fr ../backup/current; mv -f ../backup/previous ../backup/current"
         # LOG.debug("issuing: " + cmd)
         if subprocess.call(cmd, shell=True):
              LOG.error("Fail to restore directory !!!")
     # upgrade now
     cmd = "cd /tmp; tar xvf %s; ./xcmodem-upgrade.sh" % fname
     if subprocess.call(cmd, shell=True):
         LOG.info("OTA software upgrade fail")
         # Restore previous version
         ver, fname = subprocess.check_output("cat ../backup/previous/upgrade.ver", shell=True).split()
         LOG.info("Restoring previous software %s ..." % ver)
         cmd = "rm -fr ../backup/current; mv -f ../backup/previous ../backup/current; \
                cp -f ../backup/current/%s /tmp; \
                cd /tmp; tar xvf %s; ./xcmodem-upgrade.sh" % (fname, fname)
         # LOG.debug("issuing: " + cmd)
         if subprocess.call(cmd, shell=True):
             LOG.error("Fail to restore %s !!!" % ver)