コード例 #1
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def update_info_all(power, rs):
    sql = 'call update_id_manage_infoall(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\")' % (power.monitor, power.bmonitor,
                                                                                      1, rs['shock_state'],
                                                                                      rs['temperature_state'],
                                                                                      rs['distance_state'], power.ip,
                                                                                      rs['gateway_id'])
    mysql.mdb_call(sql)
コード例 #2
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def confirm_id(power):  # 验证是否需要往id_manage中插入数据
    rs = find_id(power.monitor)
    if rs is not None:
        update_info_all(power, rs)
    else:
        sql = 'call insert_id_to_id_manage(\'%s\',\'%s\',\'%s\')' % (power.monitor, power.bmonitor, power.ip)
        mysql.mdb_call(sql)
        print('%s 创建ID:%s' % (GetNowTime(),power.monitor))
        read_id_manage()
    return
コード例 #3
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def read_id_manage():  # 读取id_manage信息
    lock.acquire()
    globalval.id_list = []
    rs, row = mysql.mdb_call('call select_table_id_manage()')
    for i in range(0, row):
        globalval.id_list.append(rs[i])
    lock.release()
コード例 #4
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def save_pic(pic_name,uid):
    fpic_path = ("%s\%s\%s" % (os.path.abspath('.'),"pic",uid))
    pic_path= ("%s\%s.jpg" % (fpic_path,make_time()))
    if os.path.exists(fpic_path) == False:
        os.makedirs(fpic_path)
    with open(pic_name, 'rb') as f:
        img = f.read()
        f.close()
    with open(pic_path, 'wb') as fp:
        fp.write(img)
        fp.close()

    path=pic_path.replace('\\','\\\\')
    insert_pic =(("call insert_pic(\"%s\",\"%s\")") % (uid,path))
    rs, row = mysql.mdb_call(insert_pic)
    print("%s 创建图片记录%d,id:%s" % (GetNowTime(),rs[0]['LAST_INSERT_ID()'], uid))
コード例 #5
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def distance(power, buf):#激光测距
    index = 0
    for i in range(0, 17):
        power.bmonitor += dec2hex_str(buf[i])
    index += 17
    power.collect_time = buf[index] + (buf[index + 1] << 8) + (buf[index + 2] << 16) + (buf[index + 3] << 24)
    index += 4
    power.alarm = buf[index]
    index += 2

    f1 = ("%02x" % (buf[index]))
    index += 1
    f2 = ("%02x" % (buf[index]))
    index += 1
    f3 = ("%02x" % (buf[index]))
    index += 1
    f4 = ("%02x" % (buf[index]))
    index += 1
    s = ("%s%s%s%s" % (f4, f3, f2, f1))

    power.distance = convert(s)
    confirm_id(power)
    rse = find_id(power.monitor)
    insert_distance = (
        "call insert_distance(\"%s\",%d,%.2f,%d)" % (power.monitor, power.alarm,
                                                      power.distance, power.collect_time))
    rs, row = mysql.mdb_call(insert_distance)
    if rse['distance_state'] != power.alarm:
        if power.alarm == 1:
            rse['distance_state'] = 1
            print("%s 创建距离报警记录%d,id:%s;距离:%s" % (GetNowTime(),rs[0]['LAST_INSERT_ID()'], power.monitor, power.distance))
        else:
            rse['distance_state'] = 0
            print("%s 取消距离报警记录,id:%s;距离:%s" % (GetNowTime(),power.monitor,power.distance))
    else:
        if power.alarm == 1:
            rse['distance_state'] = 1
            print("%s 创建距离报警记录%d,id:%s;距离:%s" % (GetNowTime(),
                rs[0]['LAST_INSERT_ID()'], power.monitor,power.distance))
    return
コード例 #6
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def shock(power, buf):#震动报警
    index = 0
    for i in range(0, 17):
        power.bmonitor += dec2hex_str(buf[i])
    index += 17
    power.collect_time = buf[index] + (buf[index + 1] << 8) + (buf[index + 2] << 16) + (buf[index + 3] << 24)
    index += 4
    power.alarm = buf[index]
    index += 2
    thresh_tap = buf[index]
    index+=1
    dur= buf[index]
    index+=1
    confirm_id(power)
    rse = find_id(power.monitor)
    rse['shock_state'] = power.alarm
    insert_shock = (("call insert_shock(\"%s\",%d,%d)") % (power.monitor, power.alarm, power.collect_time))
    rs, row = mysql.mdb_call(insert_shock)
    if power.alarm == 1:
        print("%s 创建震动报警记录%d,id:%s,(%d,%d)" % (GetNowTime(),rs[0]['LAST_INSERT_ID()'], power.monitor, thresh_tap, dur))
    else:
        print("%s 取消震动报警记录,id:%s" % (GetNowTime(),power.monitor,power.monitor, thresh_tap, dur))
    return
コード例 #7
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def acceleration(power, buf):#加速度
    index = 0
    for i in range(0, 17):
        power.bmonitor += dec2hex_str(buf[i])
    index += 17
    power.collect_time = buf[index] + (buf[index + 1] << 8) + (buf[index + 2] << 16) + (buf[index + 3] << 24)
    index += 4
    power.alarm = buf[index]
    index += 2

    acce = acce_t()
    acce.x = float(("%s.%s" % (int(buf[index+1]),int(buf[index]))))
    index +=2
    acce.y = float(("%s.%s" % (int(buf[index+1]),int(buf[index]))))
    index +=2
    acce.z = float(("%s.%s" % (int(buf[index+1]),int(buf[index]))))

    confirm_id(power)
    rse = find_id(power.monitor)
    insert_acceleration =  ("call insert_acceleration(\"%s\",%d,%f,%f,%f)" % (power.monitor,power.collect_time,
                                                         acce.x, acce.y,acce.z))
    rs, row = mysql.mdb_call(insert_acceleration)
    print("%s 创建加速度记录%d,id:%s;加速度:[%s  %s  %s]" % (GetNowTime(),rs[0]['LAST_INSERT_ID()'], power.monitor,acce.x, acce.y,acce.z))
    return
コード例 #8
0
ファイル: main.py プロジェクト: utopiaprince/esn
def maintain_online_event():#维护设备在线状态
    mysql.mdb_call('call maintain_online()')
コード例 #9
0
ファイル: powerdatadeal.py プロジェクト: utopiaprince/esn
def atmo(power, buf):#气象
    index = 0
    for i in range(0, 17):
        power.bmonitor += dec2hex_str(buf[i])
    index += 17
    power.collect_time = buf[index] + (buf[index + 1] << 8) + (buf[index + 2] << 16) + (buf[index + 3] << 24)
    index += 4
    power.alarm = buf[index]
    index += 2

    atmos = atmos_t()
    atmos.driver_state_temperature = buf[index] & 1
    atmos.driver_state_wind_direction_speed = buf[index] & 2
    atmos.driver_state_pressure = buf[index] & 4
    atmos.driver_state_compass = buf[index] & 8
    atmos.driver_state_hyetometer = buf[index] & 16

    if(atmos.driver_state_temperature >0 ):atmos.driver_state_temperature=1
    if(atmos.driver_state_wind_direction_speed >0 ):atmos.driver_state_wind_direction_speed=1
    if(atmos.driver_state_pressure >0 ):atmos.driver_state_pressure=1
    if(atmos.driver_state_compass >0 ):atmos.driver_state_compass=1
    if(atmos.driver_state_hyetometer >0 ):atmos.driver_state_hyetometer=1
    index += 2

    atmos.wind_direction = buf[index] + (buf[index+1]<<8)
    index += 2
    #风速
    f1 = ("%02x" % (buf[index]))
    index += 1
    f2 = ("%02x" % (buf[index]))
    index += 1
    f3 = ("%02x" % (buf[index]))
    index += 1
    f4 = ("%02x" % (buf[index]))
    index += 1
    s = ("%s%s%s%s" % (f4, f3, f2, f1))
    atmos.wind_speed = convert(s)
    #温度
    f1 = ("%02x" % (buf[index]))
    index += 1
    f2 = ("%02x" % (buf[index]))
    index += 1
    f3 = ("%02x" % (buf[index]))
    index += 1
    f4 = ("%02x" % (buf[index]))
    index += 1
    s = ("%s%s%s%s" % (f4, f3, f2, f1))
    atmos.temperature = convert(s)
    #湿度
    f1 = ("%02x" % (buf[index]))
    index += 1
    f2 = ("%02x" % (buf[index]))
    index += 1
    f3 = ("%02x" % (buf[index]))
    index += 1
    f4 = ("%02x" % (buf[index]))
    index += 1
    s = ("%s%s%s%s" % (f4, f3, f2, f1))
    atmos.humidity = convert(s)
    #气压
    f1 = ("%02x" % (buf[index]))
    index += 1
    f2 = ("%02x" % (buf[index]))
    index += 1
    f3 = ("%02x" % (buf[index]))
    index += 1
    f4 = ("%02x" % (buf[index]))
    index += 1
    s = ("%s%s%s%s" % (f4, f3, f2, f1))
    atmos.pressure = convert(s)
    #电子罗盘
    atmos.compass = buf[index] + (buf[index+1]<<8)
    index += 2
    #降雨状态
    atmos.rainfall_state = buf[index] + (buf[index+1]<<8)
    index += 2
    #降雨强度
    f1 = ("%02x" % (buf[index]))
    index += 1
    f2 = ("%02x" % (buf[index]))
    index += 1
    f3 = ("%02x" % (buf[index]))
    index += 1
    f4 = ("%02x" % (buf[index]))
    index += 1
    s = ("%s%s%s%s" % (f4, f3, f2, f1))
    atmos.rainfall_streng = convert(s)
    #累积降雨量
    f1 = ("%02x" % (buf[index]))
    index += 1
    f2 = ("%02x" % (buf[index]))
    index += 1
    f3 = ("%02x" % (buf[index]))
    index += 1
    f4 = ("%02x" % (buf[index]))
    index += 1
    s = ("%s%s%s%s" % (f4, f3, f2, f1))
    atmos.rainfall_total = convert(s)

    atmos.rainfall_streng_unit = buf[index+1] & 7
    if atmos.rainfall_streng_unit == 1:
        atmos.rainfall_streng_unit = "mm/s"
    elif atmos.rainfall_streng_unit == 2:
        atmos.rainfall_streng_unit = "mm/m"
    else:
        atmos.rainfall_streng_unit = "mm/h"

    state = ("\"%d,%d,%d,%d,%d\"" % (atmos.driver_state_temperature,atmos.driver_state_wind_direction_speed,atmos.driver_state_pressure,
                                 atmos.driver_state_compass,atmos.driver_state_hyetometer))
    val = ("\"%d,%.2f,%.2f,%.2f,%.2f,%d,%d,%.2f,%.2f,%s\"" % (atmos.wind_direction,atmos.wind_speed,atmos.temperature,
                                              atmos.humidity,atmos.pressure,atmos.compass,
                                              atmos.rainfall_state,atmos.rainfall_streng,atmos.rainfall_total,
                                              atmos.rainfall_streng_unit))
    confirm_id(power)
    rse = find_id(power.monitor)
    insert_atmos =  ("call insert_atmo(\"%s\",%d,%s,%s)" % (power.monitor,power.collect_time,state,val))
    rs, row = mysql.mdb_call(insert_atmos)
    print("%s 创建气象记录%d,id:%s;  [%s   %s]" % (GetNowTime(),rs[0]['LAST_INSERT_ID()'], power.monitor,state,val))

    return