10 Star 43 Fork 16

lantsang / smart-dtu

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bluestone_common.py 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
lantsang 提交于 2021-04-27 19:13 . 优化串口逻辑,添加公共方法
'''
File: bluestone_common.py
Project: bluestone
Author: daniel dong
Email: dongzhenguo@lantsang.cn
Copyright 2021 - 2021 bluestone tech
'''
import uos
import ure
import modem
import log
import ujson
import _thread
log.basicConfig(level = log.INFO)
_common_log = log.getLogger("COMMON")
class BluestoneCommon(object):
inst = None
_network_state = 1
_lock = _thread.allocate_lock()
def __init__(self):
BluestoneCommon.inst = self
@staticmethod
def get_network_state():
return BluestoneCommon._network_state
@staticmethod
def set_network_state(state = 1):
BluestoneCommon._lock.acquire()
BluestoneCommon._network_state = state
BluestoneCommon._lock.release()
@staticmethod
def get_imei():
return modem.getDevImei()
@staticmethod
def get_sn():
return modem.getDevSN()
@staticmethod
def generate_random_str():
random_str = ''.join([('0' + hex(ord(uos.urandom(1)))[2:])[-2:] for x in range(8)])
return random_str
@staticmethod
def check_file_exist(file_name):
if not file_name:
return False
file_list = uos.listdir('usr')
if file_name in file_list:
return True
else:
return False
@staticmethod
def is_url(url):
#pattern = ure.compile('http[s]://.+')
return ure.match('https?://.+', url)
@staticmethod
def is_json(content):
if not content:
return False
try:
ujson.loads(content)
return True
except Exception as err:
return False
@staticmethod
def get_range(start, end, step = 1):
result = []
index = start
while True:
if start < end:
if index <= end:
result.push(index)
else:
break
index = index + step
else:
if index >= end:
result.push(index)
else:
break
index = index - step
return result
Python
1
https://gitee.com/lantsang/smart-dtu.git
git@gitee.com:lantsang/smart-dtu.git
lantsang
smart-dtu
smart-dtu
master

搜索帮助