Example #1
0
    def processing_loop(self):
        """
        This processing loop runs in a separate thread and sends out Doppler shifted frequencies at a fixed interval.
        """
        retries = 0
        while True:
            try:
                listPlansResponse = self.api_client.ListPlans(
                    groundstation_pb2.ListPlansRequest(
                        ground_station_id=self.groundstation_id,
                        aos_after=Timestamp(seconds=int(time.time()) - 120,
                                            nanos=0),
                        aos_before=Timestamp(seconds=int(time.time() + 3600),
                                             nanos=0),
                    ))
                break
            except grpc.RpcError as e:
                self.log.error("Caught RPC error {}".format(e))
                if retries >= MAX_RETRY_ATTEMPTS:
                    self.log.info("Maximum retries attempted. Giving up")
                    return
                retries += 1
                self.log.info("Retry attempt {}".format(retries))
                continue
            except Exception as e:
                # Catch all other exceptions so the block does not cause the rest of the flowgraph to hang.
                self.log.error("Caught non-RPC error {}".format(e))
                return

        self.log.debug("Fetched {} plans".format(len(listPlansResponse.plan)))

        plan = [x for x in listPlansResponse.plan if x.plan_id == self.plan_id]
        if not plan:
            self.log.fatal("No plans matching plan ID {} found.".format(
                self.plan_id))
            raise Exception('No plans matching plan ID {} found'.format(
                self.plan_id))
        else:
            plan = plan[0]

        interpolated_satellite_coordinates = interpolate_coordinates(
            plan.satellite_coordinates, self.corrections_per_second)
        self.log.debug("{} satellite coordinates interpolated".format(
            len(interpolated_satellite_coordinates)))
        for coord in interpolated_satellite_coordinates:
            if self.stopped:
                return
            coord_time = coord.time.seconds + coord.time.nanos / 10.**9
            if coord_time < time.time():
                continue
            while coord_time - time.time() > 1.1:
                time.sleep(1)
                if self.stopped:
                    return
            time.sleep(coord_time - time.time())
            if self.verbose:
                self.log.debug(
                    "Publishing to ports at {}. Scheduled time {}".format(
                        time.time(), coord_time))
            self.publish_to_ports(coord.range_rate)
def test_list_plans(stub_factory):
    client = stub_factory.get_gs_service_stub()

    request = groundstation_pb2.ListPlansRequest()
    request.ground_station_id = GS_ID
    request.aos_after.FromDatetime(datetime(2018, 12, 1, 0, 0))
    request.aos_before.FromDatetime(datetime(2018, 12, 31, 0, 0))

    result = client.ListPlans(request)
    assert result
    assert len(result.plan) > 0
Example #3
0
def test_request() -> None:
    test_server = setup_test_server()

    request = groundstation_pb2.ListPlansRequest(
        ground_station_id="2",
        aos_after=Timestamp(seconds=int(time.time()) - 2 * SECONDS_IN_MINUTE,
                            nanos=0),
        aos_before=Timestamp(seconds=int(time.time() + SECONDS_IN_HOUR),
                             nanos=0),
    )

    list_plans_method = test_server.invoke_unary_unary(method_descriptor=(
        groundstation_pb2.DESCRIPTOR.services_by_name['GroundStationService'].
        methods_by_name['ListPlans']),
                                                       invocation_metadata={},
                                                       request=request,
                                                       timeout=1)

    response, metadata, code, details = list_plans_method.termination()
    print(response.plan[0].satellite_coordinates[:3])
    assert response.plan[0].plan_id == "3"
    assert code == grpc.StatusCode.OK