Beispiel #1
0
def get_status_info():
    current_pass_json = {}
    scheduled_pass_json = {}
    current_pass_json['azimuth'] = 'NA'
    current_pass_json['altitude'] = 'NA'
    current_pass_json['frequency'] = 'NA'
    current_pass_json['tle0'] = 'NA'
    current_pass_json['tle1'] = 'NA'
    current_pass_json['tle2'] = 'NA'
    # current_pass_json = jsonify(current_pass_json)
    scheduled_pass_json['Info'] = 'There are no scheduled observations.'
    # scheduled_pass_json = jsonify(scheduled_pass_json)

    current_pass_sock = Commsocket('127.0.0.1', client_settings.CURRENT_PASS_TCP_PORT)
    scheduled_pass_sock = Commsocket('127.0.0.1', client_settings.TASK_FEEDER_TCP_PORT)

    current_pass_check = current_pass_sock.connect()
    scheduled_pass_check = scheduled_pass_sock.connect()

    if scheduled_pass_check:
        scheduled_pass_json = scheduled_pass_sock.send("Requesting scheduled observations\n")
        scheduled_pass_json = json.loads(scheduled_pass_json)
    else:
        logger.info('No observation currently')

    if current_pass_check:
        current_pass_json = current_pass_sock.send("Requesting current observations\n")
        current_pass_json = json.loads(current_pass_json)
    else:
        logger.info('No observation currently')

    # return current_pass_json
    return jsonify(observation=dict(current=current_pass_json, scheduled=scheduled_pass_json))
Beispiel #2
0
def get_jobs():
    logger.info('Get jobs started')
    """Query SatNOGS Network API to GET jobs."""
    url = urljoin(settings.SATNOGS_NETWORK_API_URL, 'jobs/')
    params = {'ground_station': settings.SATNOGS_STATION_ID}
    headers = {'Authorization': 'Token {0}'.format(settings.SATNOGS_API_TOKEN)}
    logger.debug('URL: {0}'.format(url))
    logger.debug('Params: {0}'.format(params))
    logger.debug('Headers: {0}'.format(headers))
    logger.info('Trying to GET observation jobs from the network')
    response = requests.get(url,
                            params=params,
                            headers=headers,
                            verify=settings.SATNOGS_VERIFY_SSL)

    if not response.status_code == 200:
        raise Exception('Status code: {0} on request: {1}'.format(
            response.status_code, url))

    for job in scheduler.get_jobs():
        if job.name in [spawn_observer.__name__]:
            job.remove()

    sock = Commsocket('127.0.0.1', settings.TASK_FEEDER_TCP_PORT)

    tasks = []
    for obj in response.json():
        tasks.append(obj)
        start = parser.parse(obj['start'])
        job_id = str(obj['id'])
        kwargs = {'obj': obj}
        logger.info('Adding new job: {0}'.format(job_id))
        logger.debug('Observation obj: {0}'.format(obj))
        scheduler.add_job(spawn_observer,
                          'date',
                          run_date=start,
                          id='observer_{0}'.format(job_id),
                          kwargs=kwargs)
    tasks.reverse()

    while sys.getsizeof(json.dumps(tasks)) > sock.tasks_buffer_size:
        tasks.pop()

    b = sock.connect()
    if b:
        sock.send_not_recv(json.dumps(tasks))
    else:
        logger.info('Task listener thread not online')
Beispiel #3
0
def get_jobs():
    logger.info('Get jobs started')
    """Query SatNOGS Network API to GET jobs."""
    url = urljoin(settings.NETWORK_API_URL, 'jobs/')
    params = {'ground_station': settings.GROUND_STATION_ID}
    headers = {'Authorization': 'Token {0}'.format(settings.API_TOKEN)}
    logger.debug('URL: {0}'.format(url))
    logger.debug('Params: {0}'.format(params))
    logger.debug('Headers: {0}'.format(headers))
    logger.info('Trying to GET observation jobs from the network')
    response = requests.get(url, params=params, headers=headers, verify=settings.VERIFY_SSL)

    if not response.status_code == 200:
        raise Exception('Status code: {0} on request: {1}'.format(response.status_code, url))

    for job in scheduler.get_jobs():
        if job.name in [spawn_observer.__name__]:
            job.remove()

    sock = Commsocket('127.0.0.1', settings.TASK_FEEDER_TCP_PORT)

    tasks = []
    for obj in response.json():
        tasks.append(obj)
        start = parser.parse(obj['start'])
        job_id = str(obj['id'])
        kwargs = {'obj': obj}
        logger.info('Adding new job: {0}'.format(job_id))
        logger.debug('Observation obj: {0}'.format(obj))
        scheduler.add_job(spawn_observer,
                          'date',
                          run_date=start,
                          id='observer_{0}'.format(job_id),
                          kwargs=kwargs)
    tasks.reverse()

    while sys.getsizeof(json.dumps(tasks)) > sock.tasks_buffer_size:
        tasks.pop()

    b = sock.connect()
    if b:
        sock.send_not_recv(json.dumps(tasks))
    else:
        logger.info('Task listener thread not online')
Beispiel #4
0
def ecss_encoder(port):
    logger.info('Started ecss encoder')
    sock = Commsocket('127.0.0.1', port)
    sock.bind()
    sock.listen()
    while 1:
        conn = sock.accept()
        if conn:
            data = conn.recv(sock.tasks_buffer_size)
            ecss_packetizer(data)
Beispiel #5
0
    def _communicate_tracking_info(self):
        """
        Runs as a daemon thread, communicating tracking info to remote socket.
        Uses observer and satellite objects set by trackobject().
        Will exit when observation_end timestamp is reached.
        """
        sock = Commsocket(self._IP, self._PORT)
        sock.connect()

        # track satellite
        while self.is_alive:

            # check if we need to exit
            self.check_observation_end_reached()

            p = pinpoint(self.observer_dict, self.satellite_dict)
            if p['ok']:
                self.send_to_socket(p, sock)
                time.sleep(self.SLEEP_TIME)

        sock.disconnect()
Beispiel #6
0
    def _communicate_tracking_info(self):
        """
        Runs as a daemon thread, communicating tracking info to remote socket.
        Uses observer and satellite objects set by trackobject().
        Will exit when observation_end timestamp is reached.
        """
        sock = Commsocket(self._IP, self._PORT)
        sock.connect()

        # track satellite
        while self.is_alive:

            # check if we need to exit
            self.check_observation_end_reached()

            p = pinpoint(self.observer_dict, self.satellite_dict)
            if p['ok']:
                dict = {
                    'azimuth': p['az'].conjugate() * 180 / math.pi,
                    'altitude': p['alt'].conjugate() * 180 / math.pi,
                    'frequency':
                    self._frequency * (1 - (p['rng_vlct'] / ephem.c)),
                    'tle0': self.satellite_dict['tle0'],
                    'tle1': self.satellite_dict['tle1'],
                    'tle2': self.satellite_dict['tle2']
                }
                socketio.emit('update_rotator',
                              dict,
                              namespace='/update_status')
                self.send_to_socket(p, sock)
                time.sleep(self.SLEEP_TIME)

        sock.disconnect()
Beispiel #7
0
def task_feeder(port):
    sleep(1)
    logger.info('Started task feeder')
    sock = Commsocket('127.0.0.1', port)
    sock.bind()
    sock.listen()
    while 1:
        try:
            conn = sock.accept()
        except IOError:
            logger.info('Task feeder is terminated or something bad happened to accept')
            return
        if conn:
            data = conn.recv(sock.tasks_buffer_size)
            # Data must be sent to socket.io here
            socketio.emit('backend_msg', data, namespace='/control_rx')
Beispiel #8
0
def ecss_packetizer(ecss, buf):
    Commsocket(packet_settings.FRAME_RECEIVER_IP,
               packet_settings.FRAME_RECEIVER_PORT)
    assert ((ecss['type'] == 0) or (ecss['type'] == 1))
    assert (ecss['app_id'] < packet_settings.LAST_APP_ID)
    data_size = ecss['size']
    app_id = htons(ecss['app_id'])
    app_id_ms = app_id & 0xFF00
    app_id_ls = app_id & 0x00FF
    app_id_ms = app_id_ms >> 8
    buf[0] = (packet_settings.ECSS_VER_NUMBER << 5 | ecss['type'] << 4
              | packet_settings.ECSS_DATA_FIELD_HDR_FLG << 3 | app_id_ls)
    buf[1] = app_id_ms
    seq_flags = packet_settings.TC_TM_SEQ_SPACKET
    seq_count = htons(ecss['seq_count'])
    seq_count_ms = (seq_count >> 8) & 0x00FF
    seq_count_ls = seq_count & 0x00FF
    buf[2] = (seq_flags << 6 | seq_count_ls)
    buf[3] = seq_count_ms
    if ecss['type'] == 0:
        buf[6] = packet_settings.ECSS_PUS_VER << 4
    elif ecss['type'] == 1:
        buf[6] = (packet_settings.ECSS_SEC_HDR_FIELD_FLG << 7
                  | packet_settings.ECSS_PUS_VER << 4 | ecss['ack'])
    buf[7] = ecss['ser_type']
    buf[8] = ecss['ser_subtype']
    buf[9] = ecss['dest_id']
    buf_pointer = packet_settings.ECSS_DATA_OFFSET
    for i in range(0, data_size):
        buf[buf_pointer + i] = ecss['data'][i]
    data_w_headers = data_size + packet_settings.ECSS_DATA_HEADER_SIZE + packet_settings.ECSS_CRC_SIZE - 1
    packet_size_ms = htons(data_w_headers) & 0xFF00
    packet_size_ls = htons(data_w_headers) & 0x00FF
    buf[4] = packet_size_ls
    buf[5] = packet_size_ms >> 8
    buf_pointer = buf_pointer + data_size
    for i in range(0, buf_pointer):
        buf[buf_pointer + 1] = buf[buf_pointer + 1] ^ buf[i]

    size = buf_pointer + 2
    assert (size > packet_settings.MIN_PKT_SIZE
            and size < packet_settings.MAX_PKT_SIZE)
    logger.debug('Packet in hex: %s',
                 ''.join(' {:02x} '.format(x) for x in buf))
    return packet_settings.SATR_OK
Beispiel #9
0
 def _status_interface(self, port):
     sock = Commsocket('127.0.0.1', port)
     # sock.get_sock().bind(('127.0.0.1',port))
     sock.bind()
     sock.listen()
     while self.is_alive:
         conn = sock.accept()
         if conn:
             conn.recv(sock.buffer_size)
             dict = {
                 'azimuth': "{0:.2f}".format(self._azimuth),
                 'altitude': "{0:.2f}".format(self._altitude),
                 'frequency': self._frequency,
                 'tle0': self.satellite_dict['tle0'],
                 'tle1': self.satellite_dict['tle1'],
                 'tle2': self.satellite_dict['tle2']
             }
             conn.send(json.dumps(dict))
             conn.close()
Beispiel #10
0
def task_feeder(port):
    sleep(1)
    logger.info('Started task feeder')
    sock = Commsocket('127.0.0.1', port)
    sock.bind()
    sock.listen()
    while 1:
        try:
            conn = sock.accept()
        except IOError:
            logger.info('Task feeder is terminated or something bad happened to accept')
            return
        if conn:
            data = conn.recv(sock.tasks_buffer_size)
            # Data must be sent to socket.io here
            socketio.emit('backend_msg', data, namespace='/control_rx')
Beispiel #11
0
 def _status_interface(self, port):
     sock = Commsocket('127.0.0.1', port)
     # sock.get_sock().bind(('127.0.0.1',port))
     sock.bind()
     sock.listen()
     while self.is_alive:
         conn = sock.accept()
         if conn:
             conn.recv(sock.buffer_size)
             dict = {'azimuth': "{0:.2f}".format(self._azimuth),
               'altitude': "{0:.2f}".format(self._altitude),
               'frequency': self._frequency,
               'tle0': self.satellite_dict['tle0'],
               'tle1': self.satellite_dict['tle1'],
               'tle2': self.satellite_dict['tle2']}
             conn.send(json.dumps(dict))
             conn.close()
Beispiel #12
0
    def _communicate_tracking_info(self):
        """
        Runs as a daemon thread, communicating tracking info to remote socket.
        Uses observer and satellite objects set by trackobject().
        Will exit when observation_end timestamp is reached.
        """
        sock = Commsocket(self._IP, self._PORT)
        sock.connect()

        # track satellite
        while self.is_alive:

            # check if we need to exit
            self.check_observation_end_reached()

            p = pinpoint(self.observer_dict, self.satellite_dict)
            if p['ok']:
                self.send_to_socket(p, sock)
                time.sleep(self._sleep_time)

        sock.disconnect()