Ejemplo n.º 1
0
void I2C_init() {
    int actualClock;

    I2CConfigure(I2C_DEV, 0);

    actualClock = I2CSetFrequency(I2C_DEV, GetPeripheralClock(), I2C_SPEED);
    if(abs(actualClock-I2C_SPEED) > I2C_SPEED*0.1) {
        appendBuffer("ERROR: Could not set I2C clock\r\n");
    } else {
        appendBuffer("INFO: I2C Clock set\r\n");
    }

    I2CEnable(I2C_DEV, TRUE);
    appendBuffer("INFO: I2C Enabled\r\n");

    /*if(!StartTransfer(FALSE)) {
        while(1);
    }
    
    if(!TransmitOneByte((0x68 << 1) & 0b11111110)) {
        while(1);
    }

    if(!I2CByteWasAcknowledged(I2C_DEV)) {
        while(1);
    }

    TransmitOneByte(0x75);


    if(!I2CByteWasAcknowledged(I2C_DEV)) {
        while(1);
    }

    if(!StartTransfer(TRUE)) {
        while(1);
    }
    TransmitOneByte((0x68 << 1) | 0b00000001);

    if(!I2CByteWasAcknowledged(I2C_DEV)) {
        while(1);
    }

    I2CReceiverEnable(I2C_DEV, TRUE);
    while(!I2CReceivedDataIsAvailable(I2C_DEV));
    I2CAcknowledgeByte(I2C_DEV, FALSE);
    I2CGetByte(I2C_DEV);
    StopTransfer();*/
}
Ejemplo n.º 2
0
// PRIVATE MANIPULATORS
void Blob::slowSetLength(int length)
{
    BSLS_ASSERT(0 <= length);

    if (0 == length) {
        d_dataIndex          = 0;
        d_dataLength         = 0;
        d_preDataIndexLength = 0;
        return;                                                       // RETURN
    }

    // Grow if needed.

    while (length > d_totalSize) {
        BlobBuffer buf;
        d_bufferFactory_p->allocate(&buf);
        appendBuffer(buf);
    }

    if (1 == d_buffers.size()) {
        // This is a corner case.  We are not crossing any buffer boundaries
        // because we have only one buffer.  The rest of the code assumes that
        // 'd_dataIndex' will need to change.

        d_dataLength = length;
        return;                                                       // RETURN
    }

    if (length > d_dataLength) {
        // Move 'd_dataLength' to the beginning of the next buffer.

        d_dataLength = d_preDataIndexLength + d_buffers[d_dataIndex].size();
        BSLS_ASSERT(d_dataLength < length);

        int left = length - d_dataLength;
        do {
            d_preDataIndexLength += d_buffers[d_dataIndex].size();
            ++d_dataIndex;

            d_dataLength += bsl::min(left, d_buffers[d_dataIndex].size());
            left -= d_buffers[d_dataIndex].size();
        } while (left > 0);
        return;                                                       // RETURN
    }

    // We are decreasing the length.

    BSLS_ASSERT(d_preDataIndexLength >= length);
    int left = d_preDataIndexLength - length;
    d_dataLength = d_preDataIndexLength;

    do {
        --d_dataIndex;
        d_preDataIndexLength -= d_buffers[d_dataIndex].size();

        d_dataLength -= bsl::min(left, d_buffers[d_dataIndex].size());
        left -= d_buffers[d_dataIndex].size();
    } while (left >= 0);
}
bool
IpcLogOutputter::write(ELevel, const char* text)
{
	// ignore events from the buffer thread (would cause recursion).
	if (m_bufferThread != nullptr &&
		Thread::getCurrentThread().getID() == m_bufferThreadId) {
		return true;
	}

	appendBuffer(text);
	notifyBuffer();
	return true;
}
Ejemplo n.º 4
0
void UDPInternalConnection::notifyReceive()
{
  auto packet = socket_->readDataFrom(); //data:address

  //if (packet.second == this->host_address_) {
  // Если мы получили данные от хоста, с которым работаем - читаем пакет
  // Иначе - отбрасываем как некорректный
  appendBuffer(packet.first);

  if (isPending()) {
    setIdle();
    waitVar.notify_one();
  }

  //}
}
Ejemplo n.º 5
0
void
ParticleCloud::StartPreAmble()
{
    //
    // Start the pre-amble
    //

    //
    // All new buffers start with "&" which is removed by
    // MenloCloudFormatter::getDataBuffer()
    //
    appendBuffer("&");

    //
    // Note abbreviated codes are accepted for really small
    // devices or SMS/text message transports, but here
    // we do not need to. The Smartpux server accepts
    // both forms.
    //
    if (IsShortForm()) {

        if (m_accountId != NULL) {
            appendBuffer("A=" + m_accountId + "&");
        }

        if (m_token != NULL) {
            appendBuffer("P=" + m_token + "&");
        }

        if (m_sensorId != NULL) {
            appendBuffer("S=" + m_sensorId);
        }
    }
    else {

        if (m_accountId != NULL) {
            appendBuffer("AccountID=" + m_accountId + "&");
        }

        if (m_token != NULL) {
            appendBuffer("PassCode=" + m_token + "&");
        }

        if (m_sensorId != NULL) {
            appendBuffer("SensorID=" + m_sensorId);
        }
    }
}
Ejemplo n.º 6
0
void WriteWav::
        put( Signal::pBuffer buffer )
{
    TIME_WRITEWAV TaskTimer tt("WriteWav::put %s", buffer->getInterval().toString().c_str());

    // Make sure that all of buffer is expected

    if (buffer->getInterval() - _invalid_samples)
    {
        Signal::Interval expected = (buffer->getInterval() & _invalid_samples).spannedInterval();
        EXCEPTION_ASSERT( expected );

        buffer = Signal::BufferSource(buffer).readFixedLength( expected );
    }

    if (!_sndfile)
    {
        const int format=SF_FORMAT_WAV | SF_FORMAT_PCM_16;
        _sndfile.reset(new SndfileHandle(_filename, SFM_WRITE, format, buffer->number_of_channels (), buffer->sample_rate()));

        if (!*_sndfile)
        {
            TaskInfo("ERROR: WriteWav(%s) libsndfile couldn't create a file for %u channels and sample rate %f",
                     _filename.c_str(), buffer->number_of_channels (), buffer->sample_rate());
            return;
        }
    }

    _invalid_samples -= buffer->getInterval();

    buffer->sample_offset();
    appendBuffer(buffer);

    if (!_invalid_samples)
    {
        _sndfile.reset();

        if (_normalize)
            rewriteNormalized();
    }
}
Ejemplo n.º 7
0
void ConnectorSocketImpl::onDataReaded(BufferPtr mainBufferPtr, const IOBufferPtr& ioBuffer, const size_t& numberOfByteReaded){
    appendBuffer(mainBufferPtr, ioBuffer->data(), numberOfByteReaded);
}
Ejemplo n.º 8
0
LRESULT
CArchConsoleWindows::wndProc(HWND hwnd,
				UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_CLOSE:
		ShowWindow(m_frame, FALSE);
		m_show = false;
		return 0;

	case SYNERGY_MSG_CONSOLE_OPEN:
		return 0;

	case SYNERGY_MSG_CONSOLE_CLOSE:
		SendMessage(m_frame, WM_CLOSE, 0, 0);
		m_show = false;
		return 0;

	case SYNERGY_MSG_CONSOLE_SHOW:
		m_show = true;
		if (wParam != 0 || !m_buffer.empty()) {
			ShowWindow(m_frame, TRUE);
		}
		return 0;

	case SYNERGY_MSG_CONSOLE_WRITE:
		appendBuffer(reinterpret_cast<const char*>(wParam));
		return 0;

	case SYNERGY_MSG_CONSOLE_CLEAR:
		clearBuffer();
		return 0;

	case WM_SIZE:
		if (hwnd == m_frame) {
			MoveWindow(m_hwnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
		}
		break;

	case WM_SIZING:
		if (hwnd == m_frame) {
			// get window vs client area info
			int wBase = 40 * m_wChar;
			int hBase = 40 * m_hChar;
			DWORD style   = GetWindowLong(m_frame, GWL_STYLE);
			DWORD exStyle = GetWindowLong(m_frame, GWL_EXSTYLE);
			RECT rect;
			rect.left   = 100;
			rect.top    = 100;
			rect.right  = rect.left + wBase;
			rect.bottom = rect.top + hBase;
			AdjustWindowRectEx(&rect, style, FALSE, exStyle);
			wBase = rect.right - rect.left - wBase;
			hBase = rect.bottom - rect.top - hBase;

			// get closest size that's a multiple of the character size
			RECT* newRect = (RECT*)lParam;
			int width  = (newRect->right - newRect->left - wBase) / m_wChar;
			int height = (newRect->bottom - newRect->top - hBase) / m_hChar;
			width  = width  * m_wChar + wBase;
			height = height * m_hChar + hBase;

			// adjust sizing rect
			switch (wParam) {
			case WMSZ_LEFT:
			case WMSZ_TOPLEFT:
			case WMSZ_BOTTOMLEFT:
				newRect->left = newRect->right - width;
				break;

			case WMSZ_RIGHT:
			case WMSZ_TOPRIGHT:
			case WMSZ_BOTTOMRIGHT:
				newRect->right = newRect->left + width;
				break;
			}
			switch (wParam) {
			case WMSZ_TOP:
			case WMSZ_TOPLEFT:
			case WMSZ_TOPRIGHT:
				newRect->top = newRect->bottom - height;
				break;

			case WMSZ_BOTTOM:
			case WMSZ_BOTTOMLEFT:
			case WMSZ_BOTTOMRIGHT:
				newRect->bottom = newRect->top + height;
				break;
			}
			return TRUE;
		}
		break;

	default:
		break;
	}

	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Ejemplo n.º 9
0
void ReadBuffer::readMessage(const unsigned char *message, unsigned int length)
{
  //
  // To be here we must be the real owner
  // of the buffer and there must not be
  // pending bytes in the transport.
  //

  #ifdef TEST

  if (owner_ == 0)
  {
    *logofs << "ReadBuffer: PANIC! Class for FD#"
            << transport_ -> fd() << " doesn't "
            << "appear to be the owner of the buffer "
            << "while borrowing from the caller.\n"
            << logofs_flush;

    HandleCleanup();
  }

  #endif

  //
  // Be sure that any outstanding data from
  // the transport is appended to our own
  // byffer.
  //

  if (transport_ -> pending() != 0)
  {
    #ifdef WARNING
    *logofs << "ReadBuffer: WARNING! Class for FD#"
            << transport_ -> fd() << " has pending "
            << "data in the transport while "
            << "borrowing from the caller.\n"
            << logofs_flush;
    #endif

    readMessage();

    if (owner_ == 0)
    {
      convertBuffer();
    }
  }

  //
  // Can't borrow the buffer if there is data
  // from a partial message. In this case add
  // the new data to the end of our buffer.
  //

  if (length_ == 0)
  {
    #ifdef TEST
    *logofs << "ReadBuffer: Borrowing " << length
            << " bytes from the caller for FD#"
            << transport_ -> fd() << " with "
            << length_ << " bytes in the buffer.\n"
            << logofs_flush;
    #endif

    delete [] buffer_;

    buffer_ = (unsigned char *) message;
    size_   = length;

    length_ = length;

    owner_ = 0;
    start_ = 0;
  }
  else
  {
    #ifdef TEST
    *logofs << "ReadBuffer: Appending " << length
            << " bytes from the caller for FD#"
            << transport_ -> fd() << " with "
            << length_ << " bytes in the buffer.\n"
            << logofs_flush;
    #endif

    appendBuffer(message, length);
  }
}