提交 5b3a598b authored 作者: blu's avatar blu

init

上级 afefb701
......@@ -71,16 +71,13 @@ class OTAClient:
return ''
def get_version(self):
if os.path.exists(VER_FILE):
with open(VER_FILE, 'r') as f:
while True:
sn = f.readline()
sn = sn.rstrip()
sn = sn.strip()
if len(sn) < 1:
continue
else:
return sn
try:
if os.path.exists(VER_FILE):
with open(VER_FILE, 'r') as f:
ver = json.load(f)
return ver.get('firmware', '')
except Exception as e:
logger.error("failed reading verisn file {}: {}", VER_FILE, str(e))
return ''
def get_sn(self):
......@@ -99,6 +96,18 @@ class OTAClient:
topic = '/device/ota/init/' + ud.sn
client.subscribe(topic, qos=1)
logger.info('subscribed to {} '.format(topic))
if ud.version is '':
ud.reply(-1, '', 'fail', 'no local version')
return
# check system status
# 1. is evdaemon ok?
sn = ud._get_sn_from_evdaemon()
if sn == '':
ud.reply(-1, ud.version, 'failed', 'evdaemon is down')
return
ud.reply()
@staticmethod
def on_message(client, ud, msg):
......@@ -253,7 +262,7 @@ class OTAClient:
return
# write version
with open(VER_FILE, 'w') as f:
f.writelines(self.version)
json.dump(req,f)
# report status
self.reply(batchId, ver, 'complete', 'OK')
os.system('systemctl restart evdaemon')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论