Newer
Older
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import MySQLdb as mdb
import os
import sys
import cgi
import threading
import time
import traceback
import requests
import urllib2,urllib
from platform import platform
from urlparse import urlparse, parse_qs
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
from ctypes import *
from socket import *
from constants import *
from dl_status import *
from ais_readers_list import *
import device_list
HND_LIST = []
devCount = c_long()
DEV_HND = device_list .S_DEVICE()
log_t = device_list .S_LOG()
def GetPlatformLib():
if sys.platform.startswith("win32"):
return windll.LoadLibrary(os.getcwd() + LIB_PATH + WIN_PATH + LIB_WIN32)
elif sys.platform.startswith("linux"):
return cdll.LoadLibrary(os.getcwd() + LIB_PATH + LINUX_PATH + LIB_LINUX) #ARMHF_PATH + LIB_ARMHF (for BeagleBoneBlack)
elif platform().lower().find('armv7l-with-debian') > -1:
return cdll.LoadLibrary(os.getcwd() + LIB_PATH + LINUX_PATH + LIB_ARM) #ARM
def AISGetVersion():
hardware_type = c_int()
firmware_version = c_int()
dev = DEV_HND
DL_STATUS = mySO.AIS_GetVersion(dev.hnd,byref(hardware_type),byref(firmware_version))
res = "AIS_GetVersion() hw = %d | fw = %d\n" % (hardware_type.value,firmware_version.value)
return res
def AISUpdateAndGetCount():
return mySO.AIS_List_UpdateAndGetCount()
def AISGetTime():
dev = DEV_HND
currTime = c_uint64()
timezone = c_int()
DST = c_int()
dev.status = mySO.AIS_GetTime(dev.hnd,byref(currTime),byref(timezone),byref(DST),byref(offset))
if dev.status:
res = wr_status("AIS_GetTime",dev.status)
return res
res = "AIS_GetTime()> {%d(%s):%s} = (tz= %d | dst= %d | offset= %d) %d | %s\n" % (dev.status,hex(dev.status),E_ERROR_CODES[dev.status],timezone.value,DST.value,offset.value,currTime.value, time.ctime(currTime.value))
return res
def AISSetTime():
currTime = c_uint64
timez = c_int
DST = c_int
offset = c_int
dev = DEV_HND
currTime = int(time.time())
# timez = time.timezone
# DST = time.daylight
# offset = -3600
timez = mySO.sys_get_timezone()
DST = mySO.sys_get_daylight()
offset = mySO.sys_get_dstbias()
ais_set_time = mySO.AIS_SetTime
ais_set_time.argtypes = (c_void_p,c_char_p,c_uint64,c_int,c_int,c_int)
ais_set_time.restype = c_int
result = ais_set_time(dev.hnd,PASS,currTime,timez,DST,offset)
res = "AIS_SetTime(pass:%s)> timezone=%d | DST=%d |offset=%d {%d(%s)%s}|%s\n" % \
(PASS,timez,DST,offset,result,hex(result),E_ERROR_CODES[result],time.ctime(currTime))
return res
def AISGetDevicesForCheck():
myStr = mySO.AIS_List_GetDevicesForCheck
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
return myStr()
def AISEraseAllDevicesForCheck():
mySO.AIS_List_EraseAllDevicesForCheck()
def AISAddDeviceForCheck(devType,devId):
return mySO.AIS_List_AddDeviceForCheck(devType,devId)
def blacklist_write(black_list_write):
dev = DEV_HND
dev.status = mySO.AIS_Blacklist_Write(dev.hnd,PASS,black_list_write)
res = 'AIS_Blacklist_Write(pass:%s):b_list= %s > %s\n' % (PASS,black_list_write,dl_status2str(dev.status))
return res
def whitelist_write(white_list_write):
dev = DEV_HND
dev.status = mySO.AIS_Whitelist_Write(dev.hnd,PASS,white_list_write)
res = '\nAIS_Whitelist_Write(pass:%s):w_list= %s > %s\n' % (PASS,white_list_write,dl_status2str(dev.status))
return res
def print_percent_hdr():
i = c_int
sys.stdout.write("%")
for i in range(0,101):
sys.stdout.write(str(i % 10))
sys.stdout.write("\n%=")
def AISOpen():
dev = DEV_HND
for hnd in HND_LIST:
print "DEFAULT DEVICE:dev[%d] | hnd[0x%X] \n" % ((HND_LIST.index(dev.hnd) + 1),dev.hnd)
def dev_list():
list_init = c_bool
list_init = False
if not list_init:
ListDevices() #prepare device list
list_init = True
devCount = AISUpdateAndGetCount()
res = "AIS_List_UpdateAndGetCount()= [%d]\n" % devCount
if devCount:
GetListInformation()
AISOpen()
else:
res = "NO DEVICE FOUND"
print res
return res
def http_request(path, post_attrib):
try:
req = urllib2.Request(path, post_attrib)
req.add_header("Content-type", "application/x-www-form-urlencoded")
page = urllib2.urlopen(req).read()
except Exception as e:
print e
def AIS_GetLog_Set():
dev = DEV_HND
DL_STATUS = mySO.AIS_GetLog_Set(dev.hnd, PASS)
res = DL_STATUS,hex( DL_STATUS),E_ERROR_CODES[ DL_STATUS]
return res
# def GetInfoAndDeviceCount():
# print AISUpdateAndGetCount()
deviceType = E_KNOWN_DEVICE_TYPES['DL_AIS_BASE_HD_SDK']
AISEraseAllDevicesForCheck()
deviceId = 1
DL_STATUS = AISAddDeviceForCheck(deviceType, deviceId)
deviceId = 3
DL_STATUS = AISAddDeviceForCheck(deviceType, deviceId)
Loading full blame...