예제 #1
0
 def check_schedule_task(self):
     # update group member list at 00:00 am every morning
     t = time.localtime()
     if t.tm_hour == 0 and t.tm_min <= 1:
         # update group member
         Log.debug('update group member list everyday')
         self.db.delete_table(Constant.TABLE_GROUP_LIST())
         self.db.delete_table(Constant.TABLE_GROUP_USER_LIST())
         self.db.create_table(Constant.TABLE_GROUP_LIST(),
                              Constant.TABLE_GROUP_LIST_COL)
         self.db.create_table(Constant.TABLE_GROUP_USER_LIST(),
                              Constant.TABLE_GROUP_USER_LIST_COL)
         self.wechat.fetch_group_contacts()
예제 #2
0
def group_list():
    """
    @brief      list groups
    """
    result = wechat.db.select(Constant.TABLE_GROUP_LIST())
    j = {'count': len(result), 'group': result}
    return flask.Response(json.dumps(j), mimetype='application/json')
예제 #3
0
 def clean_db(self):
     """
     @brief clean database, delete table & create table
     """
     self.db.delete_table(Constant.TABLE_GROUP_LIST())
     self.db.delete_table(Constant.TABLE_GROUP_USER_LIST())
     self.db.create_table(Constant.TABLE_GROUP_MSG_LOG,
                          Constant.TABLE_GROUP_MSG_LOG_COL)
     self.db.create_table(Constant.TABLE_GROUP_LIST(),
                          Constant.TABLE_GROUP_LIST_COL)
     self.db.create_table(Constant.TABLE_GROUP_USER_LIST(),
                          Constant.TABLE_GROUP_USER_LIST_COL)
     self.db.create_table(Constant.TABLE_RECORD_ENTER_GROUP,
                          Constant.TABLE_RECORD_ENTER_GROUP_COL)
     self.db.create_table(Constant.TABLE_RECORD_RENAME_GROUP,
                          Constant.TABLE_RECORD_RENAME_GROUP_COL)
예제 #4
0
def group_member_list(g_id):
    """
    @brief      list group member
    @param      g_id String
    """
    result = wechat.db.select(Constant.TABLE_GROUP_USER_LIST(), 'RoomID', g_id)
    return jsonify({'count': len(result), 'member': result})
예제 #5
0
def group_member_list(g_id):
    """
    @brief      list group member
    @param      g_id String
    """
    result = wechat.db.select(Constant.TABLE_GROUP_USER_LIST(), 'RoomID', g_id)
    j = {'count': len(result), 'member': result}
    return flask.Response(json.dumps(j), mimetype='application/json')
예제 #6
0
 def handle_group_member_change(self, group_id, member_list):
     """
     @brief      handle group member changes & saved in DB
     @param      group_id  Dict
     @param      member_list  Dict
     """
     self.db.delete(Constant.TABLE_GROUP_USER_LIST(), "RoomID", group_id)
     self.handle_group_member_list(group_id, member_list)
예제 #7
0
 def handle_group_member_list(self, group_id, member_list):
     """
     @brief      handle group member list & saved in DB
     @param      member_list  Array
     """
     fn = group_id + '.json'
     save_json(fn, member_list, self.data_dir)
     cols = [(group_id, m['UserName'], m['NickName'], m['DisplayName'],
              m['AttrStatus']) for m in member_list]
     self.db.insertmany(Constant.TABLE_GROUP_USER_LIST(), cols)
예제 #8
0
 def handle_group_list(self, group_list):
     """
     @brief      handle group list & saved in DB
     @param      group_list  Array
     """
     fn = Constant.LOG_MSG_GROUP_LIST_FILE
     save_json(fn, group_list, self.data_dir)
     cols = [(g['NickName'], g['UserName'], g['OwnerUin'], g['MemberCount'],
              g['HeadImgUrl']) for g in group_list]
     self.db.insertmany(Constant.TABLE_GROUP_LIST(), cols)
예제 #9
0
 def _rtd_switch(switch, fq_gpio):
     # name = "fq1_ctrl"
     rtd_gpio = Constant.fq1_ctrl
     if fq_gpio == Constant.get_val(Constant.fq2_ctrl_r):
         # name = "fq2_ctrl"
         rtd_gpio = Constant.fq2_ctrl
     if switch:
         # print("%s 打开" % name)
         PCM(rtd_gpio).pin_on()
     else:
         # print("%s 关闭" % name)
         PCM(rtd_gpio).pin_off()
예제 #10
0
    def send_fq2(self):
        fq2_dict = dict(self._fqm_rul)["fq2"]
        fq2_gpio = Constant.get_val(Constant.fq2_ctrl_r)
        fq2_switch = fq2_dict['switch']
        fq2_rate = fq2_dict['rate']
        fq2_rtd = fq2_dict['rtd']

        if fq2_switch:
            # 设置频率信号电阻
            self._rtd_switch(fq2_rtd, fq2_gpio)
            p = GPIO.PWM(fq2_gpio, fq2_rate)
            p.start(50)
            print("fq2 gpio=%s rate=%s" % (fq2_gpio, fq2_rate))

        while True:
            if not Common.pwm_is_run:
                break
예제 #11
0
def group_list():
    """
    @brief      list groups
    """
    result = wechat.db.select(Constant.TABLE_GROUP_LIST())
    return jsonify({'count': len(result), 'group': result})
예제 #12
0
 def __init__(self, gpio=None):
     self.gpio = Constant.get_val(gpio)
예제 #13
0
import spidev
import can
import json
import binascii
import uds_server
from convert import Convert
from config import Constant, Common, RuleConfig
from validate import Validate, ValidateDataOp
import RPi.GPIO as GPIO
import threading
import struct
import mysql_service

GPIO.setmode(GPIO.BCM)  # 使用BCM引还脚编号,此外有 GPIO.BOARD
GPIO.setwarnings(False)
GPIO.setup(Constant.get_val(Constant.vb), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.vb1), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.vb2), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.amp_5), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.amp_12), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.amp_19), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.fq1_ctrl), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.fq1_ctrl_r), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.fq2_ctrl), GPIO.OUT)
GPIO.setup(Constant.get_val(Constant.fq2_ctrl_r), GPIO.OUT)
GPIO.setup(19, GPIO.OUT)


# 日志
class Log:
    def __init__(self, serial_code=""):