Skip to content

Commit

Permalink
Merge pull request #36 from M1cha/state-write
Browse files Browse the repository at this point in the history
feat: add `image state-write`
  • Loading branch information
JPHutchins authored Dec 9, 2024
2 parents 9284a1f + 838e8ec commit d7cf405
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion smpmgr/image_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from smpclient import SMPClient
from smpclient.generics import error, success
from smpclient.mcuboot import ImageInfo
from smpclient.requests.image_management import ImageStatesRead
from smpclient.requests.image_management import ImageStatesRead, ImageStatesWrite
from typing_extensions import Annotated

from smpmgr.common import Options, connect_with_spinner, get_smpclient, smp_request
Expand Down Expand Up @@ -56,6 +56,33 @@ async def f() -> None:
asyncio.run(f())


@app.command()
def state_write(
ctx: typer.Context,
hash: Annotated[str, typer.Argument(help="SHA256 hash of the image header and body.")],
confirm: Annotated[bool, typer.Argument(help="Confirm the image given by hash.")],
) -> None:
"""Request to write the state of FW images on the SMP Server."""

options = cast(Options, ctx.obj)
smpclient = get_smpclient(options)
hash_bytes = bytes.fromhex(hash)

async def f() -> None:
await connect_with_spinner(smpclient, options.timeout)

r = await smp_request(smpclient, options, ImageStatesWrite(hash=hash_bytes, confirm=confirm), "Waiting for image state write...") # type: ignore # noqa

if error(r):
print(r)
elif success(r):
pass
else:
raise Exception("Unreachable")

asyncio.run(f())


async def upload_with_progress_bar(
smpclient: SMPClient, file: typer.FileBinaryRead | BufferedReader, slot: int = 0
) -> None:
Expand Down

0 comments on commit d7cf405

Please # to comment.