예제 #1
0
파일: ringbuf.c 프로젝트: semenovf/cwt
static BOOL rb_find(CwtRingBuffer *rb, const BYTE* bytes, size_t n, size_t from, size_t* index)
{
	size_t i = 0;
	size_t j = 0;

	CWT_ASSERT(rb);

	for( i = from; i < rb->m_count; i++ ) {
		if( rb_at(rb, i) == bytes[0] ) {

			if( i + n > rb->m_count ) {
				return FALSE;
			}

			for( j = 1; j < n; j++ ) {
				if( rb_at(rb, i+j) != bytes[j] )
					break;
			}

			if( j == n ) {
				if( index )
					*index = i;
				return TRUE;
			}
		}
	}
	return FALSE;
}
예제 #2
0
bool sp_write(struct ring_buf_data* p_pd)
{
    log_trace2("sp_write");
    if(S_OK != mb_validate(p_pd))
    {
        // message is not valid
        log_trace("ignoring invalid message send request, size: %d", rb_size(p_pd));
        return(false);
    }

    log_trace2("send: -->");
    for(uint8_t i=0, imax=rb_size(p_pd); i<imax; ++i)
    {
        const uint8_t val = rb_at(p_pd, i);
        const ssize_t bytesWritten = write(s_fd, &val, 1);
        if(1 != bytesWritten)
        {
            // error
            log_err("serial write error");
            return(false);
        }
        log_trace2("%c", val);
    }
    log_trace2("<--");

    // TODO: bug in atmega32 code requires an extra byte to be sent for now
    write(s_fd, "\n", 1);

    return(true);
}
예제 #3
0
파일: ringbuf.c 프로젝트: semenovf/cwt
/**
 * @brief Finds first occurrence of any character from @c bytes
 *
 * @param rb
 * @param bytes
 * @param n
 * @param from
 * @param index
 * @return
 */
static BOOL rb_find_any(CwtRingBuffer *rb, const BYTE* bytes, size_t n, size_t from, size_t* index)
{
	size_t i = 0, j = 0;

	CWT_ASSERT(rb);

	for( i = from; i < rb->m_count; i++ ) {
		for( j = 0; j < n; j++ ) {
			if( rb_at(rb, i) == bytes[j] ) {
				if( index )
					*index = i;
				return TRUE;
			}
		}
	}
	return FALSE;
}