Newer
Older
1
2
3
4
5
6
7
8
9
10
11
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python
"""
@author: Vladan S
@version: 2.0.1.3 (build) (lib:4.8.0)
"""
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_ARMHF) #CARM
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()
offset = c_int()
dev.status = mySO.AIS_GetTime(dev.hnd,byref(currTime),byref(timezone),byref(DST),byref(offset))
res = "AIS_GetTime(dev= 0x%X)> {%d(%s):%s} = (tz= %d | dst= %d | offset= %d) %d | %s\n" % (dev.hnd,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
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
myStr.restype = c_char_p
print 'GetDevicesForCheck: %s' % myStr()
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:
aop = mySO.AIS_Open(hnd)
#res = "AIS_Open():{%d(0x%X):%s} hnd[0x%X]" % (aop,aop,E_ERROR_CODES[aop],hnd)
dev.hnd = HND_LIST[0] #default
print "DEFAULT DEVICE hnd[0x%X] \n" % 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 PrintLOG():
# logIndex = c_int()
# logAction = c_int()
# logReaderId = c_int()
# logCardId = c_int()
# logSystemId = c_int()
# logNfcUid = (c_uint8 * NFC_UID_MAX_LEN)()
# logNfcUidLen = c_int()
# logTimeStamp = c_uint64()
# nfcuid = str()
# dev = DEV_HND
# print rte_list_header[0],'\n', \
# rte_list_header[1],'\n', \
# rte_list_header[2]
# while True:
# dev.status = mySO.AIS_ReadLog(dev.hnd,byref(logIndex),
# byref(logAction),
# byref(logReaderId),
# byref(logCardId),
# byref(logSystemId),
# logNfcUid,
# byref(logNfcUidLen),
# byref(logTimeStamp)
# )
Loading full blame...