def __init__(self,
                 board_manager_stub: departure_pb2_grpc.BoardManagerStub):
        super().__init__()
        self.board_manager_stub = board_manager_stub

        self.next_mission_tracker = [
            departure_pb2.Movement(static_content=departure_pb2.StaticContent(
                total_duration=2000)),
            departure_pb2.Movement(
                scrolling_content=departure_pb2.ScrollingContent(
                    step_duration=100,
                    total_steps=11,
                    delta_x_per_step=0,
                    delta_y_per_step=-1,
                )),
        ]

        self.horizontal_scroll = [
            departure_pb2.Movement(
                scrolling_content=departure_pb2.ScrollingContent(
                    step_duration=50,
                    total_steps=0,
                    delta_x_per_step=-1,
                    delta_y_per_step=0,
                ))
        ]

        self.no_movement = [
            departure_pb2.Movement(no_movement=departure_pb2.NoMovement())
        ]
Beispiel #2
0
    def update(self, trains: list, current_station_ns_code: str = ""):
        requests_data = []

        (
            top_section_content_pixels,
            top_section_content_pixels_size,
            middle_section_content_pixels,
            middle_section_content_pixels_size,
            bottom_section_content_pixels,
            bottom_section_content_pixels_size,
        ) = self.next_content(trains, current_station_ns_code)

        # top section: 1st train
        requests_data.append(
            departure_pb2.BoardSectionUpdateRequest(
                section_index=0,
                content=departure_pb2.BoardSectionContent(
                    pixels=protobuf.serialise_pixels(top_section_content_pixels),
                    content_w=top_section_content_pixels_size[0],
                    content_h=top_section_content_pixels_size[1],
                    repeat_x=False,
                    repeat_y=False,
                ),
                movement=self.no_movement,
                continue_movement=False,
            )
        )

        # middle section: calling points of 1st train
        requests_data.append(
            departure_pb2.BoardSectionUpdateRequest(
                section_index=1,
                content=departure_pb2.BoardSectionContent(
                    pixels=protobuf.serialise_pixels(middle_section_content_pixels),
                    content_w=middle_section_content_pixels_size[0] + 192,
                    content_h=middle_section_content_pixels_size[1],
                    repeat_x=True,
                    repeat_y=False,
                ),
                movement=[
                    departure_pb2.Movement(
                        scrolling_content=departure_pb2.ScrollingContent(
                            step_duration=50,
                            total_steps=0,
                            delta_x_per_step=-1,
                            delta_y_per_step=0,
                        )
                    )
                ],
                continue_movement=True,
            )
        )

        # bottom section: 2nd train onwards
        if trains is None or len(trains) <= 2:  # no v-scroll if up to 2 trains
            next_movement = self.no_movement
        else:  # v-scroll if more than 2 trains
            next_movement = self.next_train_tracker

        requests_data.append(
            departure_pb2.BoardSectionUpdateRequest(
                section_index=2,
                content=departure_pb2.BoardSectionContent(
                    pixels=protobuf.serialise_pixels(bottom_section_content_pixels),
                    content_w=bottom_section_content_pixels_size[0],
                    content_h=bottom_section_content_pixels_size[1],
                    repeat_x=True,
                    repeat_y=True,
                ),
                movement=next_movement,
                continue_movement=True,
            )
        )

        # send gRPC message
        try:
            self.board_manager_stub.BoardSectionsUpdate(
                departure_pb2.BoardSectionsUpdateRequest(requests=requests_data)
            )
        # pylint: disable=protected-access
        except (grpc._channel._Rendezvous, grpc._channel._InactiveRpcError):
            logger.warning("connection to board failed")