-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement camera to controller comms
- Loading branch information
Showing
9 changed files
with
67 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
from os import mkfifo | ||
import os | ||
import unittest | ||
from os import mkfifo | ||
from typing import BinaryIO | ||
|
||
|
||
class IPC: | ||
def __init__(self, io: BinaryIO): | ||
self.io = io | ||
|
||
def send_data(self, data: bytes): | ||
size = len(data) | ||
self.io.write(size.to_bytes(4, 'little')) # 4 bytes = 32 bits | ||
self.io.write(data) | ||
self.io.flush() | ||
|
||
def receive_data(self) -> bytes: | ||
size = int.from_bytes(self.io.read(2), byteorder='little') | ||
return self.io.read(size) | ||
def __init__(self, io: BinaryIO): | ||
self.io = io | ||
|
||
def send_data(self, data: bytes): | ||
size = len(data) | ||
self.io.write(size.to_bytes(4, "little")) # 4 bytes = 32 bits | ||
self.io.write(data) | ||
self.io.flush() | ||
|
||
def receive_data(self) -> bytes: | ||
size = int.from_bytes(self.io.read(2), byteorder="little") | ||
return self.io.read(size) | ||
|
||
|
||
def new_fifo_ipc(path: str): | ||
mkfifo(path, 0o660) | ||
reader = open(path, 'wb') | ||
return IPC(reader) | ||
writer = open(path, "rb+", 0) | ||
print("c") | ||
return IPC(writer) | ||
|
||
|
||
class TestIPC(unittest.TestCase): | ||
def test_serialize(self): | ||
test_path = "camerastream" | ||
try: | ||
os.remove(test_path) | ||
except OSError: | ||
pass | ||
comms = new_fifo_ipc(test_path) | ||
comms.send_data(b"hello uwu") | ||
print("done") | ||
def test_serialize(self): | ||
test_path = "camerastream" | ||
try: | ||
os.remove(test_path) | ||
except OSError: | ||
pass | ||
comms = new_fifo_ipc(test_path) | ||
comms.send_data(b"hello uwu") | ||
print("done") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
unittest.main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters