Skip to content
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
530 changes: 530 additions & 0 deletions src/infuse_iot/generated/rpc_definitions.py

Large diffs are not rendered by default.

27 changes: 2 additions & 25 deletions src/infuse_iot/rpc_wrappers/application_info.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
#!/usr/bin/env python3

import ctypes

from infuse_iot.commands import InfuseRpcCommand
from infuse_iot.generated.rpc_definitions import rpc_struct_mcuboot_img_sem_ver


class application_info(InfuseRpcCommand):
HELP = "Get the current application info"
DESCRIPTION = "Get the current application info"
COMMAND_ID = 9

class request(ctypes.LittleEndianStructure):
_fields_ = []
_pack_ = 1
import infuse_iot.generated.rpc_definitions as defs

class response(ctypes.LittleEndianStructure):
_fields_ = [
("application_id", ctypes.c_uint32),
("version", rpc_struct_mcuboot_img_sem_ver),
("network_id", ctypes.c_uint32),
("uptime", ctypes.c_uint32),
("reboots", ctypes.c_uint32),
("kv_crc", ctypes.c_uint32),
("data_blocks_internal", ctypes.c_uint32),
("data_blocks_external", ctypes.c_uint32),
]
_pack_ = 1

class application_info(InfuseRpcCommand, defs.application_info):
@classmethod
def add_parser(cls, _parser):
pass
Expand Down
25 changes: 2 additions & 23 deletions src/infuse_iot/rpc_wrappers/bt_connect_infuse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

import ctypes

from infuse_iot.commands import InfuseRpcCommand
from infuse_iot.generated.rpc_definitions import (
Expand All @@ -10,30 +9,10 @@
)
from infuse_iot.util.argparse import BtLeAddress
from infuse_iot.util.ctypes import bytes_to_uint8
import infuse_iot.generated.rpc_definitions as defs


class bt_connect_infuse(InfuseRpcCommand):
HELP = "Connect to an Infuse-IoT Bluetooth device"
DESCRIPTION = "Connect to an Infuse-IoT Bluetooth device"
COMMAND_ID = 50

class request(ctypes.LittleEndianStructure):
_fields_ = [
("peer", rpc_struct_bt_addr_le),
("conn_timeout_ms", ctypes.c_uint16),
("subscribe", ctypes.c_uint8),
("inactivity_timeout_ms", ctypes.c_uint16),
]
_pack_ = 1

class response(ctypes.LittleEndianStructure):
_fields_ = [
("cloud_public_key", 32 * ctypes.c_uint8),
("device_public_key", 32 * ctypes.c_uint8),
("network_id", ctypes.c_uint32),
]
_pack_ = 1

class bt_connect_infuse(InfuseRpcCommand, defs.bt_connect_infuse):
@classmethod
def add_parser(cls, parser):
parser.add_argument(
Expand Down
18 changes: 2 additions & 16 deletions src/infuse_iot/rpc_wrappers/bt_disconnect.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

import ctypes

from infuse_iot.commands import InfuseRpcCommand
from infuse_iot.generated.rpc_definitions import (
Expand All @@ -9,23 +8,10 @@
)
from infuse_iot.util.argparse import BtLeAddress
from infuse_iot.util.ctypes import bytes_to_uint8
import infuse_iot.generated.rpc_definitions as defs


class bt_disconnect(InfuseRpcCommand):
HELP = "Disconnect from a Bluetooth device"
DESCRIPTION = "Disconnect from a Bluetooth device"
COMMAND_ID = 51

class request(ctypes.LittleEndianStructure):
_fields_ = [
("peer", rpc_struct_bt_addr_le),
]
_pack_ = 1

class response(ctypes.LittleEndianStructure):
_fields_ = []
_pack_ = 1

class bt_disconnect(InfuseRpcCommand, defs.bt_disconnect):
@classmethod
def add_parser(cls, parser):
addr_group = parser.add_mutually_exclusive_group(required=True)
Expand Down
15 changes: 2 additions & 13 deletions src/infuse_iot/rpc_wrappers/coap_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@

from infuse_iot.commands import InfuseRpcCommand
from infuse_iot.generated.rpc_definitions import rpc_enum_file_action
import infuse_iot.generated.rpc_definitions as defs


class coap_download(InfuseRpcCommand):
HELP = "Download a file from a COAP server (Infuse-IoT DTLS protected)"
DESCRIPTION = "Download a file from a COAP server (Infuse-IoT DTLS protected)"
COMMAND_ID = 30

class response(ctypes.LittleEndianStructure):
_fields_ = [
("resource_len", ctypes.c_uint32),
("resource_crc", ctypes.c_uint32),
]
_pack_ = 1

class coap_download(InfuseRpcCommand, defs.coap_download):
@classmethod
def add_parser(cls, parser):
parser.add_argument(
Expand Down Expand Up @@ -69,7 +59,6 @@ def __init__(self, args):
self.action = args.action

def request_struct(self):

class request(ctypes.LittleEndianStructure):
_fields_ = [
("server_address", 48 * ctypes.c_char),
Expand Down
35 changes: 0 additions & 35 deletions src/infuse_iot/rpc_wrappers/epacket_udp_reconnect.py

This file was deleted.

20 changes: 2 additions & 18 deletions src/infuse_iot/rpc_wrappers/fault.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
#!/usr/bin/env python3

import ctypes

from infuse_iot.commands import InfuseRpcCommand
import infuse_iot.generated.rpc_definitions as defs


class fault(InfuseRpcCommand):
HELP = "Trigger a fault on the device"
DESCRIPTION = "Trigger a fault on the device"
COMMAND_ID = 2

class request(ctypes.LittleEndianStructure):
_fields_ = [
("fault", ctypes.c_uint8),
("zero", ctypes.c_uint32),
]
_pack_ = 1

class response(ctypes.LittleEndianStructure):
_fields_ = []
_pack_ = 1

class fault(InfuseRpcCommand, defs.fault):
@classmethod
def add_parser(cls, parser):
group = parser.add_mutually_exclusive_group(required=True)
Expand Down
23 changes: 2 additions & 21 deletions src/infuse_iot/rpc_wrappers/file_write_basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3

import binascii
import ctypes

from rich.progress import (
Progress,
Expand All @@ -11,29 +10,12 @@

from infuse_iot.commands import InfuseRpcCommand, Auth
from infuse_iot.generated.rpc_definitions import rpc_enum_file_action
import infuse_iot.generated.rpc_definitions as defs


class file_write_basic(InfuseRpcCommand):
HELP = "Write a file to a device"
DESCRIPTION = "Write a file to a device"
COMMAND_ID = 40
class file_write_basic(InfuseRpcCommand, defs.file_write_basic):
RPC_DATA = True

class request(ctypes.LittleEndianStructure):

_fields_ = [
("action", ctypes.c_uint8),
("crc", ctypes.c_uint32),
]
_pack_ = 1

class response(ctypes.LittleEndianStructure):
_fields_ = [
("recv_len", ctypes.c_uint32),
("recv_crc", ctypes.c_uint32),
]
_pack_ = 1

@classmethod
def add_parser(cls, parser):
parser.add_argument(
Expand Down Expand Up @@ -97,7 +79,6 @@ def auth_level(self):
return Auth.NETWORK

def request_struct(self):
print(f"FILE CRC {binascii.crc32(self.payload):08x}")
return self.request(self.action, binascii.crc32(self.payload))

def data_payload(self):
Expand Down
11 changes: 5 additions & 6 deletions src/infuse_iot/rpc_wrappers/kv_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import errno

from infuse_iot.commands import InfuseRpcCommand
import infuse_iot.generated.rpc_definitions as defs


class kv_read(InfuseRpcCommand):
HELP = "Read KV store values"
DESCRIPTION = "Read KV store values"
COMMAND_ID = 6

class kv_read(InfuseRpcCommand, defs.kv_read):
class request(ctypes.LittleEndianStructure):
_fields_ = [
("num", ctypes.c_uint8),
Expand Down Expand Up @@ -50,7 +47,9 @@ class kv_store_value(ctypes.LittleEndianStructure):

@classmethod
def add_parser(cls, parser):
parser.add_argument("--keys", "-k", type=int, nargs="+", help="Keys to read")
parser.add_argument(
"--keys", "-k", required=True, type=int, nargs="+", help="Keys to read"
)

def __init__(self, args):
self.keys = args.keys
Expand Down
35 changes: 35 additions & 0 deletions src/infuse_iot/rpc_wrappers/last_reboot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

from infuse_iot.commands import InfuseRpcCommand
import infuse_iot.generated.rpc_definitions as defs


class last_reboot(InfuseRpcCommand, defs.last_reboot):
@classmethod
def add_parser(cls, parser):
pass

def __init__(self, args):
pass

def request_struct(self):
return self.request()

def handle_response(self, return_code, response):
if return_code != 0:
print(f"Failed to query reboot info ({return_code})")
return

from infuse_iot.time import InfuseTime, InfuseTimeSource

t_remote = InfuseTime.unix_time_from_epoch(response.epoch_time)

print(f"\t Reason: {response.reason}")
print(f"\t Hardware: 0x{response.hardware_flags:08x}")
print(
f"\tReboot Time: {InfuseTime.utc_time_string(t_remote)} ({InfuseTimeSource(response.epoch_time_source)})"
)
print(f"\t Uptime: {response.uptime}")
print(f"\t Param 1: 0x{response.param_1:08x}")
print(f"\t Param 2: 0x{response.param_2:08x}")
print(f"\t Thread: {response.thread.decode('utf-8')}")
7 changes: 2 additions & 5 deletions src/infuse_iot/rpc_wrappers/lte_at_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import errno

from infuse_iot.commands import InfuseRpcCommand
import infuse_iot.generated.rpc_definitions as defs


class lte_at_cmd(InfuseRpcCommand):
HELP = "Run AT command on LTE modem"
DESCRIPTION = "Run AT command on LTE modem"
COMMAND_ID = 20

class lte_at_cmd(InfuseRpcCommand, defs.lte_at_cmd):
class request(ctypes.LittleEndianStructure):
_fields_ = []
_pack_ = 1
Expand Down
4 changes: 2 additions & 2 deletions src/infuse_iot/rpc_wrappers/lte_modem_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import ctypes

from infuse_iot.commands import InfuseRpcCommand
import infuse_iot.generated.rpc_definitions as defs

from . import kv_read, lte_pdp_ctx


class lte_modem_info(InfuseRpcCommand):
class lte_modem_info(InfuseRpcCommand, defs.kv_read):
HELP = "Get LTE modem information"
DESCRIPTION = "Get LTE modem information"
COMMAND_ID = 6

class request(kv_read.kv_read.request):
pass
Expand Down
4 changes: 2 additions & 2 deletions src/infuse_iot/rpc_wrappers/lte_pdp_ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import enum

from infuse_iot.commands import InfuseRpcCommand
import infuse_iot.generated.rpc_definitions as defs


class lte_pdp_ctx(InfuseRpcCommand):
class lte_pdp_ctx(InfuseRpcCommand, defs.kv_write):
HELP = "Set the WiFi network SSID and PSK"
DESCRIPTION = "Set the WiFi network SSID and PSK"
COMMAND_ID = 5

class request(ctypes.LittleEndianStructure):
_fields_ = [
Expand Down
11 changes: 2 additions & 9 deletions src/infuse_iot/rpc_wrappers/lte_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from infuse_iot.commands import InfuseRpcCommand
from infuse_iot.zephyr import net_if as z_nif
from infuse_iot.zephyr import lte as z_lte
import infuse_iot.generated.rpc_definitions as defs


class interface_state(ctypes.LittleEndianStructure):
Expand Down Expand Up @@ -60,15 +61,7 @@ def access_technology(self):
return z_lte.AccessTechnology(self._act)


class lte_state(InfuseRpcCommand):
HELP = "Get LTE state"
DESCRIPTION = "Get LTE state"
COMMAND_ID = 21

class request(ctypes.LittleEndianStructure):
_fields_ = []
_pack_ = 1

class lte_state(InfuseRpcCommand, defs.lte_state):
class response(ctypes.LittleEndianStructure):
_fields_ = [
("common", interface_state),
Expand Down
Loading