Пример #1
0
 def _create_channel_file(self):
     channel_file = RadioWriter('in/input.csv', '\n')
     first_channel = RadioChannel(
         {
             'number': '1',
             'name': 'National 2m',
             'medium_name': 'Natl 2m',
             'short_name': 'NATL 2M',
             'zone_id': '',
             'rx_freq': '146.520',
             'rx_ctcss': '',
             'rx_dcs': '',
             'rx_dcs_invert': '',
             'tx_power': '',
             'tx_offset': '',
             'tx_ctcss': '',
             'tx_dcs': '',
             'tx_dcs_invert': '',
             'digital_timeslot': '',
             'digital_color': '',
             'digital_contact_id': '',
         },
         digital_contacts=None,
         dmr_ids=None)
     second_channel = RadioChannel(
         {
             'number': '2',
             'name': 'Colcon Denver',
             'medium_name': 'ConDenvr',
             'short_name': 'CONDENV',
             'zone_id': '1',
             'rx_freq': '145.310',
             'rx_ctcss': '',
             'rx_dcs': '',
             'rx_dcs_invert': '',
             'tx_power': '',
             'tx_offset': '-0.600',
             'tx_ctcss': '88.5',
             'tx_dcs': '',
             'tx_dcs_invert': '',
             'digital_timeslot': '',
             'digital_color': '',
             'digital_contact_id': '',
         },
         digital_contacts=None,
         dmr_ids=None)
     channel_file.writerow(RadioChannel.create_empty().headers(
         radio_types.DEFAULT))
     channel_file.writerow(first_channel.output(radio_types.DEFAULT, 1))
     channel_file.writerow(second_channel.output(radio_types.DEFAULT, 2))
     channel_file.close()
Пример #2
0
 def _create_zone_data(self):
     zone_id_file = RadioWriter('in/zones.csv', '\n')
     zone = RadioZone({
         'number': 1,
         'name': 'Zone 1',
     })
     zone_id_file.writerow(RadioZone.create_empty().headers(
         radio_types.DEFAULT))
     zone_id_file.writerow(zone.output(radio_types.DEFAULT))
     zone_id_file.close()
Пример #3
0
	def _output_contacts_d878(self, style):
		logging.info(f"Writing {style} contacts")
		if self._digital_contacts is None:
			logging.error(f"No digital contacts found for {style}.")
			return

		dmr_contact_file = RadioWriter(f'out/{style}/{style}_talkgroup.csv', '\r\n')

		headers = DmrContact.create_empty()
		dmr_contact_file.writerow(headers.headers(style))
		for dmr_contact in self._digital_contacts.values():
			dmr_contact_file.writerow(dmr_contact.output(style))

		dmr_contact_file.close()
Пример #4
0
	def _output_radioids_d878(self, style):
		logging.info(f"Writing {style} radio IDs")
		if self._dmr_ids is None:
			logging.error(f"No DMR ids found for {style}.")
			return

		radio_id_file = RadioWriter(f'out/{style}/{style}_radioid.csv', '\r\n')

		headers = DmrId.create_empty()
		radio_id_file.writerow(headers.headers(style))
		for dmr_id in self._dmr_ids.values():
			radio_id_file.writerow(dmr_id.output(style))

		radio_id_file.close()
		return
Пример #5
0
	def _output_zones_d878(self, style):
		logging.info(f"Writing {style} zones")
		if self._zones is None:
			logging.error(f"No zones list found for {style}.")
			return

		zone_file = RadioWriter(f'out/{style}/{style}_zone.csv', '\r\n')

		headers = RadioZone.create_empty()
		zone_file.writerow(headers.headers(style))
		for zone in self._zones.values():
			if not zone.has_channels():
				continue
			zone_file.writerow(zone.output(style))

		zone_file.close()
Пример #6
0
 def _create_dmr_user_data(self):
     user_file = RadioWriter('in/user.csv', '\n')
     dmr_user = DmrUser({
         'RADIO_ID': '00000',
         'CALLSIGN': 'N0CALL',
         'FIRST_NAME': 'Sample',
         'LAST_NAME': 'User',
         'CITY': 'Somewhere',
         'STATE': 'Stateville',
         'COUNTRY': 'Theremany',
         'REMARKS': 'Sample Entry',
     })
     user_file.writerow(DmrUser.create_empty().headers(radio_types.DEFAULT))
     user_file.writerow(dmr_user.output(radio_types.DEFAULT))
     user_file.close()
     return
Пример #7
0
	def _output_user_d878(self, style):
		logging.info(f"Writing {style} users")
		if self._users is None:
			logging.error(f"No zones list found for {style}.")
			return

		users_file = RadioWriter(f'out/{style}/{style}_digital_contacts.csv', '\n')

		headers = DmrUser.create_empty()
		users_file.writerow(headers.headers(style))

		rows_processed = 1
		for user in self._users.values():
			users_file.writerow(user.output(style))
			rows_processed += 1
			logging.debug(f"Writing user row {rows_processed}")
			if rows_processed % file_util.USER_LINE_LOG_INTERVAL == 0:
				logging.info(f"Writing user row {rows_processed}")

		users_file.close()
Пример #8
0
    def generate_all_declared(self):
        file_errors = self._validate_files_exist()
        if len(file_errors) > 0:
            logging.error("--- FILE MISSING ERRORS, CANNOT CONTINUE ---")
            for err in file_errors:
                logging.error(f"\t\t{err.message}")
            return
        else:
            logging.info("All necessary files found")

        digital_contacts, digi_contact_errors = self._generate_digital_contact_data(
        )
        dmr_ids, dmr_id_errors = self._generate_dmr_id_data()
        zones, zone_errors = self._generate_zone_data()
        user, user_data_errors = self._generate_user_data()

        feed = open("in/input.csv", "r")
        csv_reader = csv.DictReader(feed)

        line_num = 1
        radio_channel_errors = []
        for line in csv_reader:
            line_errors = self._validator.validate_radio_channel(
                line, line_num, feed.name)
            radio_channel_errors += line_errors
            line_num += 1

        all_errors = digi_contact_errors + dmr_id_errors + zone_errors + user_data_errors + radio_channel_errors
        if len(all_errors) > 0:
            logging.error("--- VALIDATION ERRORS, CANNOT CONTINUE ---")
            for err in all_errors:
                logging.error(
                    f"\t\tfile: `{err.file_name}` line:{err.line_num} validation error: {err.message}"
                )
            return
        else:
            logging.info(
                "File validation complete, no obvious formatting errors found")

        radio_files = dict()
        radio_channels = dict()
        headers_gen = RadioChannel.create_empty()
        FileUtil.safe_create_dir('out')

        channel_numbers = dict()
        for radio in self.radio_list:
            FileUtil.safe_create_dir(f'out/{radio}')
            logging.info(f"Generating for radio type `{radio}`")

            if RadioChannel.skip_radio_csv(radio):
                logging.info(
                    f"`{radio}` uses special output style. Skipping channels csv"
                )
                continue
            output = RadioWriter(f'out/{radio}/{radio}_channels.csv', '\r\n')
            file_headers = headers_gen.headers(radio)
            output.writerow(file_headers)
            radio_files[radio] = output
            channel_numbers[radio] = 1

        logging.info("Processing radio channels")
        line_num = 1
        for line in csv_reader:
            logging.debug(f"Processing radio line {line_num}")
            if line_num % file_util.RADIO_LINE_LOG_INTERVAL == 0:
                logging.info(f"Processing radio line {line_num}")

            self._validator.validate_radio_channel(line, line_num, feed.name)

            radio_channel = RadioChannel(line, digital_contacts, dmr_ids)
            radio_channels[radio_channel.number] = radio_channel
            line_num += 1

            if radio_channel.zone_id.fmt_val(None) is not None:
                zones[radio_channel.zone_id.fmt_val()].add_channel(
                    radio_channel)

            for radio in self.radio_list:
                if not radio_types.supports_dmr(
                        radio) and radio_channel.is_digital():
                    continue
                if radio not in radio_files.keys():
                    continue

                input_data = radio_channel.output(radio,
                                                  channel_numbers[radio])
                radio_files[radio].writerow(input_data)
                channel_numbers[radio] += 1

        additional_data = RadioAdditionalData(radio_channels, dmr_ids,
                                              digital_contacts, zones, user)
        for radio in self.radio_list:
            if radio in radio_files.keys():
                radio_files[radio].close()
            additional_data.output(radio)

        logging.info("Radio generator complete")
        return
Пример #9
0
    def _create_dmr_data(self):
        dmr_id_file = RadioWriter('in/dmr_id.csv', '\n')
        dmr_id = DmrId({
            'number': 1,
            'radio_id': '00000',
            'name': 'DMR',
        })
        dmr_id_file.writerow(DmrId.create_empty().headers(radio_types.DEFAULT))
        dmr_id_file.writerow(dmr_id.output(radio_types.DEFAULT))
        dmr_id_file.close()

        digital_contacts_file = RadioWriter('in/digital_contacts.csv', '\n')
        analog_contact = DmrContact({
            'number': 1,
            'digital_id': dmr_id.radio_id.fmt_val(),
            'name': 'Analog',
            'call_type': 'all',
        })
        group_contact = DmrContact({
            'number': 2,
            'digital_id': 99999,
            'name': 'Some Repeater',
            'call_type': 'group',
        })
        digital_contacts_file.writerow(DmrContact.create_empty().headers(
            radio_types.DEFAULT))
        digital_contacts_file.writerow(
            analog_contact.output(radio_types.DEFAULT))
        digital_contacts_file.writerow(
            group_contact.output(radio_types.DEFAULT))
        digital_contacts_file.close()