Skip to content
aisbbnclass.py 44.7 KiB
Newer Older
developer8's avatar
developer8 committed
#!/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...