Skip to content

Commit

Permalink
From Kivy to Textual & fix docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Krisjanis Veinbahs committed Mar 12, 2022
1 parent 76ab43b commit 4ad991f
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 298 deletions.
3 changes: 1 addition & 2 deletions client/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ name = "pypi"
[packages]
websockets = "*"
mypy = "*"
coloredlogs = "*"
pylint = "*"
result = "*"
click = "*"
requests = "*"
rich = "*"
pyserial = "*"
kivy = { version = "*", platform_machine = "!= 'aarch64'" }
bitstring = "*"
pyyaml = "*"
appdirs = "*"
aiohttp = "*"
textual = "*"

[dev-packages]
pyinstaller = "*"
Expand Down
158 changes: 53 additions & 105 deletions client/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
- Run `./dist/dip_client --help` to print built client CLI usage definition

### File tree
- `dip_client.py` is just an entrypoint for the CLI interface from `cli.py`
- `cli.py` defines a CLI interface for all possible DIP client commands:
- Generic one-off client commands are defined in `backend_util.py`
- Microcontroller agent commands are defined in `agent_entrypoints.py`
- `main.py` is just an entrypoint for the CLI interface from `service/click.py`
- `service/click.py` and `service/cli.py` define a CLI interface for all possible DIP client commands:
- Generic one-off client commands are defined mostly in `service/backend.py`
- Persistent event engine agent commands are defined in `agent/*`, `monitor/*`, `engine/*`
- `agent_entrypoints.py` prepare and run a configured agent `agent.py`
- `agent.py` runs using an `AgentConfig`, `Engine`, serialization `Encoder`/`Decoder`
- `agent_util.py` defines a base `AgentConfig`
- `engine.py` defines a base `Engine`
- `agent_*.py` define custom `Engine`s and `AgentConfig`s
- `agent/agent.py` runs using an `AgentConfig` i.e. an `Engine` attached to `SocketInterface` with the help of message `Codec`s
- `engine/engine.py` defines a base `Engine` which starts, stops, receives messages, processes events, executes side-effects
- `engine/board/*` define engines to handle hardware board lifecycle - heartbeats, firmware uploads, monitoring
- `engine/video/*` define video streaming engines using VLC
- `monitor/*` define serial monitoring interfaces
- Agents use `ws.py` to exchange WebSocket messages
- Agents use `s11n_*.py` to serialize messages
- Agents use `Engine` for stateful actions & resulting messages
- Agents more specifically SocketInterfaces use `protocol/*` to encode/decode messages
17 changes: 5 additions & 12 deletions client/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@ cd "${SCRIPT_DIR}"
rm -rf docker/
rm -rf dist/

# Build amd64 locally (supposing that we're building on amd64)
pipenv install && pipenv run ./build.sh &
LOCAL_INSTALL_PID="$!"

## Build amd64 & arm64 in docker w/ buildx i.e. moby/buildkit i.e. QEMU
## Multi-platform docs: https://github.com/moby/buildkit/blob/master/docs/multi-platform.md
export TARGET_PLATFORMS=linux/arm64 #,linux/amd64 # Currently Kivy (used in amd64) doesn't comply with docker builds
export TARGET_PLATFORMS=linux/arm64,linux/amd64
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --name multiarch --driver docker-container --use || true
docker buildx build \
--platform "${TARGET_PLATFORMS}" \
-o type=local,dest=docker \
.

# Wait for local stuff to finish
wait "${LOCAL_INSTALL_PID}"

# Clean up dist
mv dist/dip_client dist/dip_client_amd64
#mv docker/linux_arm64/app/dist/dip_client dist/dip_client_arm64
mv docker/app/dist/dip_client dist/dip_client_arm64
# Create dist
mkdir dist
mv docker/linux_arm64/app/dist/dip_client dist/dip_client_arm64
mv docker/linux_amd64/app/dist/dip_client dist/dip_client_amd64
36 changes: 36 additions & 0 deletions client/src/domain/fancy_byte.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import math
from dataclasses import dataclass
from typing import Iterable
from result import Result, Err, Ok


@dataclass
class FancyByte:
value: int

@staticmethod
def fromBytes(b: bytes) -> Result['FancyByte', str]:
if len(b) > 1:
return Err("Only one byte allowed")
try:
return Ok(FancyByte(int.from_bytes(b, "little")))
except Exception as e:
return Err(f"Can't build byte: {e}")

@staticmethod
def fromInt(n: int) -> Result['FancyByte', str]:
if n < 0:
return Err("Byte too small")
elif n >= math.pow(2, 8):
return Err("Byte too large")
return Ok(FancyByte(n))

def to_binary_bits(self) -> Iterable[bool]:
str_bits_8 = bin(self.value)[2:].zfill(8)
return list(map(lambda x: x == "1", str_bits_8))

def to_hex_str(self) -> str:
return str(hex(self.value))

def to_char(self) -> str:
return chr(self.value)
Loading

0 comments on commit 4ad991f

Please sign in to comment.