Exemplo n.º 1
0
    void
    BasicModem::run(void)
    {
      char bfr[512];
      std::string line;

      while (!isStopping())
      {
        if (!IO::Poll::poll(*m_handle, 1.0))
          continue;

        size_t rv = m_handle->read(bfr, sizeof(bfr));
        if (rv == 0)
        {
          IMC::IoEvent iov;
          iov.setSource(getTask()->getSystemId());
          iov.setSourceEntity(getTask()->getEntityId());
          iov.setDestinationEntity(getTask()->getEntityId());
          iov.type = IMC::IoEvent::IOV_TYPE_INPUT_ERROR;
          getTask()->receive(&iov);
          break;
        }

        if (getReadMode() == READ_MODE_RAW)
        {
          for (size_t i = 0; i < rv; ++i)
            m_bytes.push(bfr[i]);
        }
        else
        {
          bfr[rv] = 0;
          m_task->spew("%s", Streams::sanitize(bfr).c_str());

          for (size_t i = 0; i < rv; ++i)
          {
            m_chars.push(bfr[i]);
          }

          while (!m_chars.empty())
          {
            if (!processInput(line))
              continue;

            if (line.empty())
              continue;

            if (!handleUnsolicited(line))
              m_lines.push(line);
          }
        }
      }
    }
Exemplo n.º 2
0
    //! Read the contents of the MT SBD message buffer.
    //! @param[in] data buffer to hold binary data.
    //! @param[in] data_size size of binary data buffer.
    //! @return number of bytes read.
    unsigned
    readBufferMT(uint8_t* data, unsigned data_size)
    {
        ReadMode saved_read_mode = getReadMode();
        Counter<double> timer(getTimeout());
        uint8_t bfr[2] = {0};
        uint8_t ccsum[2] = {0};
        unsigned length = 0;

        try
        {
            // Prepare to read raw data.
            setReadMode(READ_MODE_RAW);

            // Send command.
            sendAT("+SBDRB");

            // Read incoming data length.
            length = getBufferSizeMT(timer);
            getTask()->spew("reading %u bytes of SBD binary data", length);

            // Read data.
            if (length > data_size)
                throw BufferTooSmall(data_size, length);

            if (length > 0)
            {
                readRaw(timer, data, length);
                computeChecksum(data, length, ccsum);
            }

            // Read and validate.
            readRaw(timer, bfr, 2);
            if ((bfr[0] != ccsum[0]) || (bfr[1] != ccsum[1]))
                throw Hardware::InvalidChecksum(bfr, ccsum);

            setReadMode(saved_read_mode);
            expectOK();
        }
        catch (...)
        {
            setReadMode(saved_read_mode);
            throw;
        }

        return length;
    }
	FMOD::Sound* FMODAudioClip::createStreamingSound() const
	{
		if(getReadMode() != AudioReadMode::Stream || mStreamData == nullptr)
		{
			LOGERR("Invalid audio stream data.");
			return nullptr;
		}

		FMOD_MODE flags = FMOD_CREATESTREAM;

		FMOD_CREATESOUNDEXINFO exInfo;
		memset(&exInfo, 0, sizeof(exInfo));
		exInfo.cbsize = sizeof(exInfo);
		
		// Streaming from memory not supported.
		assert(mStreamData->isFile());

		exInfo.length = mStreamSize;
		exInfo.fileoffset = mStreamOffset;

		SPtr<FileDataStream> fileStream = std::static_pointer_cast<FileDataStream>(mStreamData);
		String pathStr = fileStream->getPath().toString();

		if (is3D())
			flags |= FMOD_3D;
		else
			flags |= FMOD_2D;

		FMOD::Sound* sound = nullptr;
		FMOD::System* fmod = gFMODAudio()._getFMOD();
		if (fmod->createSound(pathStr.c_str(), flags, &exInfo, &sound) != FMOD_OK)
		{
			LOGERR("Failed creating a streaming sound.");
			return nullptr;
		}

		sound->setMode(FMOD_LOOP_OFF);
		return sound;
	}