• 记录飞天程序库调用


    FeiTian.py

    # coding=utf-8
    # 添加消息
    from ctypes import *
    import ctypes
    import json
    import time
    
    hinst = ctypes.cdll.LoadLibrary('/opt/Rockey3_SDK_LINUX_V1.10/api/api64/libRockey3.so.0.3')
    RY3_Find = hinst.RY3_Find
    RY3_Open = hinst.RY3_Open
    RY3_GetHardID = hinst.RY3_GetHardID
    RY3_GenRandom = hinst.RY3_GenRandom
    RY3_Read = hinst.RY3_Read
    RY3_Write = hinst.RY3_Write
    RY3_Close = hinst.RY3_Close
    handle = c_longlong(0)
    print('ROCKEY3 Sample INIT')
    
    def init():
        VendorID = c_char_p(b"92799461")
        count = c_int(0)
        handle = c_longlong(0)
        hardwareid = c_char_p(b'00000000')
        arr = c_byte * 16
        rand = arr()
        arr2 = c_byte * 10240
        rand2 = arr2()
        harduuid = b""
        ret = RY3_Find(VendorID, byref(count))
        if ret == 0:
            print('Find ROCKEY3 Success.')
        else:
            print('Find ROCKEY3 Failed.')
    
    
    def writeData():
        VendorID = c_char_p(b"92799461")
        count = c_int(0)
        handle = c_longlong(0)
        hardwareid = c_char_p(b'00000000')
        arr = c_byte * 16
        rand = arr()
        arr2 = c_byte * 10240
        rand2 = arr2()
        harduuid = b""
        ret = RY3_Find(VendorID, byref(count))
        if ret == 0:
            print('Find ROCKEY3 Success.')
        else:
            print('Find ROCKEY3 Failed.')
        ret = RY3_Open(byref(handle), 1)
        if ret == 0:
            print('Open ROCKEY3 Success.')
        else:
            print('Open Open Failed')
        start_time = time.strftime('%Y-%m-%d %H:%I:%S', time.localtime(time.time()))
        data={"a": "11", "b": "22", "c": "33", "uuid": "1C697B5AD7071026k", "expireDate": "2019-10-01", "expire": "yes","start_time":start_time}
        rand_content =json.dumps(data)
        #rand_content = b'{"a":"11", "b":"22", "c":"33","uuid":"1C697B5AD7071026","expireDate":"null","expire":"no"}'
        rand_content=rand_content.encode(encoding="utf-8")
        sizeLength = len(rand_content)
        ret = RY3_Write(handle, 0, pointer(c_int(sizeLength)), 4)
        ret = RY3_Write(handle, 4, rand_content, sizeLength)
        if ret == 0:
            print('Generate Write success')
        else:
            print('Generate Write failed')
        ret = RY3_Close(handle, 0)
        if ret == 0:
            print('Generate Close success')
        else:
            print('Generate Close failed')
    
    
    def readData():
        VendorID = c_char_p(b"92799461")
        count = c_int(0)
        handle = c_longlong(0)
        hardwareid = c_char_p(b'00000000')
        arr = c_byte * 16
        rand = arr()
        arr2 = c_byte * 10240
        rand2 = arr2()
        harduuid = b""
        ret = RY3_Find(VendorID, byref(count))
        if ret == 0:
            print('Find ROCKEY3 Success.')
        else:
            print('Find ROCKEY3 Failed.')
        ret = RY3_Open(byref(handle), 1)
        if ret == 0:
            print('Open ROCKEY3 Success.')
        else:
            print('Open Open Failed')
        pkgLen = c_int(0)
        ret = RY3_Read(handle, 0, pointer(pkgLen), 4)
        ret = RY3_Read(handle, 4, rand2, pkgLen)
        if ret == 0:
            print(string_at(rand2, pkgLen))
            hh = string_at(rand2, pkgLen)
            hhstring = str(hh, 'utf-8')
            print(hhstring)
            print(rand2[0], rand2[1], rand2[2], rand2[3], rand2[4], rand2[5], rand2[6], rand2[7])
            print(c_char(rand2[0]), c_char(rand2[1]), c_char(rand2[2]), c_char(rand2[3]), c_char(rand2[4]),
                  c_char(rand2[5]), rand2[6], rand2[7])
            print(json.loads(hhstring))
            object = json.loads(hhstring)
            print(object.get("a"))
            print('Generate Read success')
        else:
            print('Generate Read failed')
        return object
    
    
    
    def getHardID():
        VendorID = c_char_p(b"92799461")
        count = c_int(0)
        handle = c_longlong(0)
        hardwareid = c_char_p(b'00000000')
        arr = c_byte * 16
        rand = arr()
        arr2 = c_byte * 10240
        rand2 = arr2()
        harduuid = b""
        ret = RY3_Find(VendorID, byref(count))
        if ret == 0:
            print('Find ROCKEY3 Success.')
        else:
            print('Find ROCKEY3 Failed.')
        ret = RY3_Open(byref(handle), 1)
        if ret == 0:
            print('Open ROCKEY3 Success.')
        else:
            print('Open Open Failed')
        ret = RY3_GetHardID(handle, hardwareid)
        if ret == 0:
            print('Get ROCKEY3 Hardware ID success.')
            harduuid = string_at(hardwareid)
            uuidstring = str(harduuid, 'utf-8', 'ignore')
            print(uuidstring)
            uid = readData()
            print('Get ROCKEY3 Read 000.')
            print(uid.get("uuid"))
            print('Get ROCKEY3 Read success.')
        else:
            print('Get ROCKEY3 Hardware ID failed')
        return uuidstring
  • 相关阅读:
    JavaScript中split() 使用方法
    解决elementui中table表格rowstyle改变当前行样式
    vue项目中使用$.once(‘hook:beforeDestory‘,() => {})清理定时器问题
    js中split()方法和join()方法
    前端报各种提示错误400 等
    Linux 网络编程Socket
    C 语言数组名
    Checksum
    Gcc 编译过程
    Nodejs爬取壁纸接口数据
  • 原文地址:https://www.cnblogs.com/xmyfsj/p/15231875.html
Copyright © 2020-2023  润新知