-
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.
Merge pull request #1 from Wason1797/make-brs-forwarders
Refactor BR functionality and add SVM41 support
- Loading branch information
Showing
19 changed files
with
2,269 additions
and
2,313 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,6 @@ COPY . . | |
|
||
RUN poetry install --only main | ||
|
||
EXPOSE 5683/udp | ||
|
||
ENTRYPOINT ["bash", "runner.sh"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from .aiq_data import AiqDataResource # noqa | ||
from .aiq_management import AiqManagementSummaryResource, AiqManagementTruncateResource # noqa | ||
from .index import IndexResource | ||
from .station_data_storage import StationDataStorageResource # noqa | ||
from .index import IndexResource # noqa |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import asyncio | ||
from typing import Type, cast | ||
|
||
import aiocoap.resource as resource # type: ignore | ||
from aiocoap import CHANGED, INTERNAL_SERVER_ERROR, Message # type: ignore | ||
|
||
from app.log import log | ||
from app.managers.aiq_manager import AiqDataManager | ||
from app.repositories.aiq_coap.client import CoapClient | ||
from app.repositories.aiq_coap.managers import AiqDataCoapForwarder | ||
from app.security.payload_validator import PayloadValidator | ||
from app.serializers.request import AiqDataFromStation | ||
from app.types import AsyncSessionMaker | ||
|
||
|
||
class StationDataForwarderResource(resource.Resource): | ||
def __init__( | ||
self, | ||
backup_session: AsyncSessionMaker, | ||
payload_validator: Type[PayloadValidator], | ||
server_instance_id: int, | ||
coap_client: CoapClient, | ||
allow_backups: bool = False, | ||
): | ||
super().__init__() | ||
self.backup_session = backup_session | ||
self.payload_validator = payload_validator | ||
self.coap_client = coap_client | ||
self.server_instance_id = server_instance_id | ||
self.allow_backups = allow_backups | ||
|
||
async def render_put(self, request) -> Message: | ||
try: | ||
payload: str = request.payload.decode("ascii") | ||
log.info(f"[COAP] forwarder request {payload}") | ||
|
||
validated_payload = self.payload_validator.validate(payload, AiqDataFromStation) | ||
|
||
sensor_data = cast(AiqDataFromStation, validated_payload.data) | ||
border_router_id = validated_payload.border_router_id or self.server_instance_id | ||
|
||
AiqDataCoapForwarder.forward_aiq_data(self.coap_client, payload, border_router_id) | ||
|
||
if self.allow_backups: | ||
await AiqDataManager.save_sensor_data(self.backup_session, sensor_data, border_router_id) | ||
else: | ||
await asyncio.sleep(0.01) # Await something so the background task has time to schedule/run. | ||
|
||
except Exception: | ||
log.exception("Error in StationDataForwarderResource", exc_info=True) | ||
return Message(code=INTERNAL_SERVER_ERROR, payload="Error forwarding data") | ||
|
||
return Message(code=CHANGED, payload="") |
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
Oops, something went wrong.