本文整理匯總了Python中transport.Transport.nfcEncodePrefix方法的典型用法代碼示例。如果您正苦於以下問題:Python Transport.nfcEncodePrefix方法的具體用法?Python Transport.nfcEncodePrefix怎麽用?Python Transport.nfcEncodePrefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類transport.Transport
的用法示例。
在下文中一共展示了Transport.nfcEncodePrefix方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MicroNFCBoard
# 需要導入模塊: from transport import Transport [as 別名]
# 或者: from transport.Transport import nfcEncodePrefix [as 別名]
#.........這裏部分代碼省略.........
return spRecordNumber
def _generateTextRecord(self, recordNumber, record, spRecordNumber):
languageCodeBuf = array("B")
languageCodeBuf.fromstring(record.language)
textBuf = array("B")
textBuf.fromstring(record.text)
self._transport.nfcSetRecordInfo(recordNumber, 2, [{v: k for k, v in TEXT_ENCODING.items()}[record.encoding], len(languageCodeBuf), len(textBuf)])
return spRecordNumber
def _generateSmartPosterRecord(self, recordNumber, record, recordsStart):
self._transport.nfcSetRecordInfo(recordNumber, 3, [recordsStart, len(record.records)])
spRecordNumber = recordsStart
for spRecord in record.records:
self._addNdefRecord(spRecordNumber, spRecord, 0, False) #No sub records
spRecordNumber += 1
return spRecordNumber
def _generateMIMERecord(self, recordNumber, record, spRecordNumber):
mimeTypeBuf = array("B")
mimeTypeBuf.fromstring(record.mimeType)
dataBuf = array("B", record.data)
self._transport.nfcSetRecordInfo(recordNumber, 4, [len(mimeTypeBuf), len(dataBuf)])
return spRecordNumber
def _setNdefRecord(self, recordNumber, record, recordsStart, spAllowed = True):
funcs = { URIRecord : self._setURIRecord,
TextRecord : self._setTextRecord,
SmartPosterRecord : self._setSmartPosterRecord,
MIMERecord : self._setMIMERecord,
}
if( not spAllowed and type(record) == SmartPosterRecord ):
raise SmartPosterNestingException()
return funcs[type(record)](recordNumber, record, recordsStart)
def _setURIRecord(self, recordNumber, record, spRecordNumber):
#Try to get prefix
buf = array("B")
buf.fromstring(record.uri)
prefix, length = self._encodePrefix(buf[0:36])
self._setRecordData(recordNumber, 0, buf[length:])
return spRecordNumber
def _setTextRecord(self, recordNumber, record, spRecordNumber):
languageCodeBuf = array("B")
languageCodeBuf.fromstring(record.language)
textBuf = array("B")
textBuf.fromstring(record.text)
self._setRecordData(recordNumber, 0, languageCodeBuf)
self._setRecordData(recordNumber, 1, textBuf)
return spRecordNumber
def _setSmartPosterRecord(self, recordNumber, record, recordsStart):
spRecordNumber = recordsStart
for spRecord in record.records:
self._setNdefRecord(spRecordNumber, spRecord, 0, False) #No sub records
spRecordNumber += 1
return spRecordNumber
def _setMIMERecord(self, recordNumber, record, spRecordNumber):
mimeTypeBuf = array("B")
mimeTypeBuf.fromstring(record.mimeType)
dataBuf = array("B", record.data)
self._setRecordData(recordNumber, 0, mimeTypeBuf)
self._setRecordData(recordNumber, 1, dataBuf)
return spRecordNumber
def _encodePrefix(self, uri):
prefix, length = self._transport.nfcEncodePrefix(uri)
return prefix, length
def _setRecordData(self, recordNumber, item, itemData):
itemLength = len(itemData)
itemOff = 0
while itemOff < itemLength:
chunkLength = min(CHUNK_SIZE, itemLength - itemOff)
buf = array("B", itemData[itemOff:itemOff+chunkLength])
self._transport.nfcSetRecordData(recordNumber, item, itemOff, buf)
itemOff += chunkLength