Skip to content

Instantly share code, notes, and snippets.

@mosquito
Created November 21, 2014 11:26
Show Gist options
  • Select an option

  • Save mosquito/378d2ed604b0700b37d1 to your computer and use it in GitHub Desktop.

Select an option

Save mosquito/378d2ed604b0700b37d1 to your computer and use it in GitHub Desktop.
class SVPProto(object):
@staticmethod
def size_of_package(ctx):
print ctx
return 1
REQUEST = construct.Struct("SVPRequest",
construct.ULInt16("version"),
construct.ULInt16("serial"),
construct.Value(construct.ULInt16("size"), size_of_package),
construct.ULInt32("_reserved"),
construct.ULInt64("imei"),
construct.GreedyRange(
construct.Subconstruct(construct.Struct("Content",
construct.Enum(
construct.ULInt8("type"),
position1="\x01",
position2="\x02",
_default_="\x01"
),
construct.Switch("content", lambda ctx: ctx.type, {
"\x01": construct.Subconstruct(construct.Struct("Position",
construct.Const(construct.ULInt8("size"), 19),
construct.Enum(construct.ULInt8("is_valid"), valid=1, invalid=0, _default_=1),
construct.Value(construct.ULInt32("ts"), lambda ctx: int(time())),
construct.LFloat32("lat"),
construct.LFloat32("lon"),
construct.SLInt16("alt"),
construct.ULInt8("speed"),
CourseAdapter(construct.ULInt8("course")),
construct.ULInt8("satellites"),
)),
"\x02": construct.Subconstruct(construct.Struct("Position2",
construct.Const(construct.ULInt8("size"), 16),
construct.ULInt8("precision"),
construct.ULInt32("ts"),
construct.LFloat32("lat"),
construct.LFloat32("lon"),
construct.Bytes("_reserved", 3)
)),
"\xff": construct.Subconstruct(construct.Struct("SignatureContainer",
construct.Value("size", lambda ctx: ctx['']),
construct.Bytes("Signature", 255)
))
})
))
)
)
RESPONSE = construct.Struct("SVPResponse",
construct.Byte("type"),
construct.Byte("size"),
construct.Byte("cmd"),
construct.Bytes("args", 4),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment