예제 #1
0
bool CMMDVMController::start()
{
	findPort();

	bool ret = openModem();
	if (!ret)
		return false;

	findPath();

	Create();
	SetPriority(100U);
	Run();

	return true;
}
bool CDVRPTRControllerV2::open()
{
	findPort();

	bool ret = openModem();
	if (!ret)
		return false;

	findPath();

	Create();
	SetPriority(100U);
	Run();

	return true;
}
예제 #3
0
bool CGMSKModemWinUSB::open()
{
	wxASSERT(m_handle == INVALID_HANDLE_VALUE);

	bool res = openModem();
	if (!res) {
		wxLogError(wxT("Cannot find the GMSK Modem with address: 0x%04X"), m_address);
		return false;
	}

	wxLogInfo(wxT("Found the GMSK Modem with address: 0x%04X"), m_address);

	wxString version;

	int ret;
	do {
		unsigned char buffer[GMSK_MODEM_DATA_LENGTH];
		ret = io(GET_VERSION, 0xC0U, 0U, buffer, GMSK_MODEM_DATA_LENGTH);
		if (ret > 0) {
			wxString text((char*)buffer, wxConvLocal, ret);
			version.Append(text);
		} else if (ret < 0) {
			wxLogError(wxT("GET_VERSION returned %d"), -ret);
			close();
			return false;
		}
	} while (ret == int(GMSK_MODEM_DATA_LENGTH));

	wxLogInfo(wxT("Firmware version: %s"), version.c_str());

	// Trap firmware version 0.1.00 of DUTCH*Star and complain loudly
	if (version.Find(wxT("DUTCH*Star")) != wxNOT_FOUND && version.Find(wxT("0.1.00")) != wxNOT_FOUND) {
		wxLogWarning(wxT("This modem firmware is not supported by the repeater"));
		wxLogWarning(wxT("Please upgrade to a newer version"));
		close();
		return false;
	}

	// DUTCH*Star firmware has a broken concept of free space
	if (version.Find(wxT("DUTCH*Star")) != wxNOT_FOUND)
		m_brokenSpace = true;

	return true;
}
bool CDVRPTRControllerV2::findModem()
{
	m_serial.close();

	// Tell the repeater that the signal has gone away
	if (m_rx) {
		purgeRX();

		m_mutex.Lock();
		unsigned char data[2U];
		data[0U] = DQT_EOT;
		data[1U] = 0U;
		m_rxData.addData(data, 2U);
		m_mutex.Unlock();

		m_rx = false;
	}

	unsigned int count = 0U;

	// Purge the transmit buffer every 500ms to avoid overflow, but only try and reopen the modem every 2s
	while (!m_stopped) {
		purgeTX();

		count++;
		if (count >= 4U) {
			wxLogMessage(wxT("Trying to reopen the modem"));

			bool ret = findPort();
			if (ret) {
				ret = openModem();
				if (ret)
					return true;
			}

			count = 0U;
		}

		Sleep(500UL);
	}

	return false;
}
bool CGMSKModemLibUsb::open()
{
	wxASSERT(m_context != NULL);
	wxASSERT(m_handle == NULL);

	bool ret1 = openModem();
	if (!ret1) {
		wxLogError(wxT("Cannot find the GMSK Modem with address: 0x%04X"), m_address);
		return false;
	}

	wxLogInfo(wxT("Found the GMSK Modem with address: 0x%04X"), m_address);

	wxString version;

	int ret2;
	do {
		unsigned char buffer[GMSK_MODEM_DATA_LENGTH];
		ret2 = io(0xC0, GET_VERSION, 0, 0, buffer, GMSK_MODEM_DATA_LENGTH, USB_TIMEOUT);
		if (ret2 > 0) {
			wxString text((char*)buffer, wxConvLocal, ret2);
			version.Append(text);
		} else if (ret2 < 0) {
			wxLogError(wxT("GET_VERSION, err=%d"), ret2);
			close();
			return false;
		}
	} while (ret2 == int(GMSK_MODEM_DATA_LENGTH));

	wxLogInfo(wxT("Firmware version: %s"), version.c_str());

	// Trap firmware version 0.1.00 of DUTCH*Star and complain loudly
	if (version.Find(wxT("DUTCH*Star")) != wxNOT_FOUND && version.Find(wxT("0.1.00")) != wxNOT_FOUND) {
		wxLogWarning(wxT("This modem firmware is not fully supported by the GMSK Repeater"));
		wxLogWarning(wxT("Please upgrade to a newer version if possible"));
		m_broken = true;
	}

	return true;
}
예제 #6
0
void termnetd(portConf *pDevice)
{
   int mfd, mError = 0, sflg = 0, cnt, rv;
   FILE *tnlin = NULL, *tnlout = NULL, *mfp = NULL;
   char commbuf[256];
   fd_set readFds, excpFds;
   int nSynch = 0;
   struct sigaction sigact;

   if (dbg) syslog(LOG_DEBUG, "telnetd():Enter");
   memset(&sigact, 0, sizeof(sigact));
   sigact.sa_flags = SA_RESTART;

   sigact.sa_handler = disablePort;
   sigaction(SIGUSR1, &sigact, NULL);
   sigact.sa_handler = enablePort;
   sigaction(SIGUSR2, &sigact, NULL);
   sigact.sa_handler = SIG_IGN;
   sigaction(SIGALRM, &sigact, NULL);
   sigact.sa_handler = SIG_IGN;
   sigaction(SIGCHLD, &sigact, NULL);

   pDevc = pDevice;
   mfd = openModem(pDevc);
   pDevc->mfd = mfd;

   PortEnabled = 1;
   if ((rv = tnlInit(NULL, NULL, &tnlin, &tnlout, 15)) != -1)
   {
      if (dbg) syslog(LOG_DEBUG, "telnetd():libtn initialized");

      /*
      ** Enable the proccessing of a few options & set the 
      ** Baud rate and port settings of the device
      */
      tnlSetCallBack(TNL_ISSUBOPTDATA_CB, handleNewSubOptData);
      tnlSetCallBack(TNL_SPECIALCHAR_CB, handleSpecialChars);
      tnlSetCallBack(TNL_ERROR_CB, handleTelNetErrors);
      tnlEnableOption(TELOPT_BAUDRATE);
      tnlEnableOption(TELOPT_PORTSET);
      tnlEnableOption(TELOPT_DEVICE);
      tnlEnableOption(TELOPT_ECHO);

      if (dbg) syslog(LOG_DEBUG, "telnetd():Initial Baudrate of |%s|",
                                 pDevice->baud);
      tnlSetSubOption(TELOPT_BAUDRATE, pDevice->baud);
      if (dbg) syslog(LOG_DEBUG, "telnetd():Initial Port parms of |%s|",
                                 pDevice->port);
      tnlSetSubOption(TELOPT_PORTSET, pDevice->port);
      tnlSetSubOption(TELOPT_DEVICE, pDevice->devc);

      tnlOfferOption(TELOPT_SGA, 1);
      tnlRequestOption(TELOPT_SGA, 1);
      if (dbg) syslog(LOG_DEBUG, "telnetd():Options offered");

      for (;;)
      {
         if (mfp == NULL)
         {
            if (dbg) syslog(LOG_DEBUG, "telnetd():Opening buffered I/O for device");
            if ((mfp = fdopen(mfd, "w")) == NULL)
            {
               syslog(LOG_ERR, "Error opening buffer I/O for device %s:%m",
                               pDevice->devc);
               closeModem(pDevc);
               close(0);
               exit(1);
            }
            if (dbg) syslog(LOG_DEBUG, "telnetd():Done opening buffered I/O for device");
         }

         FD_ZERO(&readFds);
         FD_ZERO(&excpFds);
         FD_SET(fileno(tnlin), &readFds);
         FD_SET(mfd, &readFds);

         if (dbg) syslog(LOG_DEBUG, "telnetd():Calling tnlSelect");
         if ((sflg = tnlSelect(&readFds, NULL, &excpFds, NULL)) >= 0)
         {
            if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Returned from  tnlSelect");
            if (mfd && FD_ISSET(mfd, &readFds))
            {
               if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Have data from Modem");
               if ((cnt = read(mfd, commbuf, sizeof(commbuf) - 1)) > 0)
               {
                  commbuf[cnt] = '\0';
                  if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Read %d bytes from modem: |%s|",
                                              cnt, commbuf);
                  if (PortEnabled) 
                  {
                     if ((cnt = write(fileno(tnlout), commbuf, cnt)) < 0)
                     {
                           syslog(LOG_ERR, "telnetd():Error Writing to network:%m");
                        syslog(LOG_INFO, "telnetd():Shutting down proccess");
                        fclose(mfp);
                        close(mfd);
                        close(0);
                        exit(0);
                     }
                     if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Wrote %d bytes to Network",
                                         cnt);
                  }
                  else
                     if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Chucked %d bytes from modem",
                                         cnt);
               }
               else if (cnt < 0 && errno != EAGAIN && errno != EINTR)
               {
                  syslog(LOG_ERR, "telnetd():Error Reading from modem:%m");
                  mError = 1;
                  mfd = 0;
                  mfp = NULL;
                  exit(1);
               }
            }

            if (FD_ISSET(fileno(tnlin), &readFds))
            {
               if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Have data from Network!");
               if ((cnt = read(fileno(tnlin), commbuf, sizeof(commbuf))) > 0)
               {
                  commbuf[cnt] = '\0';
                  if (dbg) syslog(LOG_DEBUG, "telnetd():Read %d bytes from Network: |%s|",
                                              cnt, commbuf);
                  if (PortEnabled) 
                  {
                     if ((cnt = write(mfd, commbuf, cnt)) < 0)
                     {
                           syslog(LOG_ERR, "telnetd():Error Writing to modem:%m");
                           syslog(LOG_INFO, "Shutting down proccess");
                           closeModem(pDevc);
                           fclose(mfp);
                           pDevc->mfd = -1;
                           close(0);
                           exit(0);
                     }
                     if (dbg) syslog(LOG_DEBUG, "telnetd():Wrote %d bytes to modem",
                                         cnt);
                  }
                  else
                     if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Chucked %d bytes from network",
                                         cnt);
               }
               else
               {
                  if (dbg > 2) syslog(LOG_ERR, "telnetd():Error reading network:%m");
                  if (dbg > 2) syslog(LOG_DEBUG, "telnetd():Error reading network:%m");
                  if (dbg > 2) syslog(LOG_INFO, "telnetd():Shutting down proccess");
                  closeModem(pDevc);
                  fclose(mfp);
                  pDevc->mfd = -1;
                  close(0);
                  exit(0);
               }
            }

            if (FD_ISSET(fileno(tnlin), &excpFds))
            {
               nSynch = 1;
            }
         }
         else
            syslog(LOG_ERR, "telnetd():Quiting!! Error from tnlSelect:%m");
      }
   }
   else
      syslog(LOG_ERR, "telnetd():Error connecting:m");
   closeModem(pDevc);
   fclose(mfp);
   pDevc->mfd = -1;
   close(0);
}