Beispiel #1
0
 def save_instruction(cls, bt_arr: list):
     cls.instruction = bt_arr
     b = Bus()
     print(str(bt_arr[1]))
     if re.match(r'0x(\w+)', bt_arr[1].decode('utf-8')):
         address = bt_arr[1].decode('utf-8')
     else:
         address = random.choice(string.ascii_uppercase) + str(
             random.randint(0, 9))
     print('address: ', address)
     b.set_address_bus(address, cls.control)
     b.set_data_bus(cls.instruction, cls.control)
     b.send_to_ram(cls.control)
     b.send_interruption(address, cls.control)
     cls.control += 1
 def setUp(self):
     self.bus = Bus(22, "Ocean Terminal")
Beispiel #3
0
from typing import Optional, List
import asyncio

from fastapi import FastAPI
from pydantic import BaseModel
from starlette.websockets import WebSocket

from src.bus import Bus
from src.redis_app import get_subscriber, redis_send

CHANNEL = "main"
app = FastAPI()
websockets: List[WebSocket] = []
bus = Bus()


class Item(BaseModel):
    name: str
    price: float
    is_offer: Optional[bool] = None


# in-memory
@app.post("/ws/write")
async def post_ws(item: Item):
    global websockets
    for ws in websockets:
        await ws.send_text(item.json())
    return {"item": item}