Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions esp32/frozen/LTE/sqnsbr.py

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions esp32/frozen/LTE/sqnscodec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- python -*-
#################################################################
#
# Module : CODEC
# Purpose: Base encoders/decoders
#
#################################################################
#
# Copyright (c) 2011 SEQUANS Communications.
# All rights reserved.
#
# This is confidential and proprietary source code of SEQUANS
# Communications. The use of the present source code and all
# its derived forms is exclusively governed by the restricted
# terms and conditions set forth in the SEQUANS
# Communications' EARLY ADOPTER AGREEMENT and/or LICENCE
# AGREEMENT. The present source code and all its derived
# forms can ONLY and EXCLUSIVELY be used with SEQUANS
# Communications' products. The distribution/sale of the
# present source code and all its derived forms is EXCLUSIVELY
# RESERVED to regular LICENCE holder and otherwise STRICTLY
# PROHIBITED.
#
#################################################################
import struct, array

LITTLE_ENDIAN = "<"
NATIVE_ENDIAN = "="
BIG_ENDIAN = ">"

# -------------------------------------------------// Utility /__________________________________
class encode:
@staticmethod
def u32 (value, endian = BIG_ENDIAN):
return array.array("c", struct.pack(endian + "I", value))

@staticmethod
def s32 (value, endian = BIG_ENDIAN):
if value < 0:
value = 0x100000000 + value
return encode.u32(value, endian)

@staticmethod
def u16 (value, endian = BIG_ENDIAN):
return array.array("c", struct.pack(endian + "H", value))

@staticmethod
def u8 (value, endian = None):
return array.array("c", chr(value))

@staticmethod
def string (value, endian = None):
return array.array("c", value + "\x00")

class decode:
@staticmethod
def u32 (value, endian = BIG_ENDIAN):
return struct.unpack(endian + "I", value)[0]

@staticmethod
def s32 (value, endian = BIG_ENDIAN):
v = decode.u32(value, endian)
if v & (1 << 31):
return v - 0x100000000
return v

@staticmethod
def u16 (value, endian = BIG_ENDIAN):
return struct.unpack(endian + "H", value)[0]

@staticmethod
def u8 (value, endian = None):
return ord(value)

@staticmethod
def string (value, endian = None):
offset = 0
str = ""
c = value[offset]
while c != '\x00':
offset += 1
str += c
c = value[offset]

return str

58 changes: 58 additions & 0 deletions esp32/frozen/LTE/sqnscrc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- python -*-
#################################################################
#
# Module : CRC
# Purpose: CRC calculation
#
#################################################################
#
# Copyright (c) 2011 SEQUANS Communications.
# All rights reserved.
#
# This is confidential and proprietary source code of SEQUANS
# Communications. The use of the present source code and all
# its derived forms is exclusively governed by the restricted
# terms and conditions set forth in the SEQUANS
# Communications' EARLY ADOPTER AGREEMENT and/or LICENCE
# AGREEMENT. The present source code and all its derived
# forms can ONLY and EXCLUSIVELY be used with SEQUANS
# Communications' products. The distribution/sale of the
# present source code and all its derived forms is EXCLUSIVELY
# RESERVED to regular LICENCE holder and otherwise STRICTLY
# PROHIBITED.
#
#################################################################
import sqnscodec as codec

# -------------------------------------------------// Fletcher /_________________________________
def fletcher32 (data):
l = len(data)

index = 0
s1 = s2 = 0xFFFF
while l > 1:
qty = 720 if l > 720 else (l & ~1)
l -= qty

qty += index
while index < qty:
word = codec.decode.u16(data[index:index+2])
s1 += word
s2 += s1

index += 2

s1 = (s1 & 0xFFFF) + (s1 >> 16)
s2 = (s2 & 0xFFFF) + (s2 >> 16)

if (l & 1):
s1 += ord(data[index]) << 8
s2 += s1

s1 = (s1 & 0xFFFF) + (s1 >> 16)
s2 = (s2 & 0xFFFF) + (s2 >> 16)

s1 = (s1 & 0xFFFF) + (s1 >> 16)
s2 = (s2 & 0xFFFF) + (s2 >> 16)

return (s2 << 16) | s1
Loading