Newer
Older
"""
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 shell.ais_shell import *
from constants import *
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 = mySO.sys_get_timezone()
DST = mySO.sys_get_daylight()
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
return myStr()
def AISEraseAllDevicesForCheck():
mySO.AIS_List_EraseAllDevicesForCheck()
def AISAddDeviceForCheck(devType,devId):
return mySO.AIS_List_AddDeviceForCheck(devType,devId)
def active_device():
pass
dev = DEV_HND
dev.idx = HND_LIST.index(dev.hnd)
res = "Active device [%d] | hnd= 0x%X" % (dev.idx + 1,dev.hnd)
return res
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 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]
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)
"""
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 GetListInformation():
hnd = c_void_p()
devSerial = c_char_p()
devType = c_int()
devID = c_int()
devFW_VER = c_int()
devCommSpeed = c_int()
devFTDI_Serial = c_char_p()
devOpened = c_int()
devStatus = c_int()
systemStatus = c_int()
dev = DEV_HND
print format_grid[0],'\n',format_grid[1],'\n',format_grid[2]
devCount = AISUpdateAndGetCount()
Loading full blame...