示例#1
0
bool Engine::initialize()
{
    bool result = false;

    QAudioFormat format = m_format;

    if (selectFormat()) {
        if (m_format != format) {
            resetAudioDevices();
            if (m_file) {
                emit bufferLengthChanged(bufferLength());
                emit dataLengthChanged(dataLength());
                emit bufferChanged(0, 0, m_buffer);
                setRecordPosition(bufferLength());
                result = true;
            } else {
                m_bufferLength = audioLength(m_format, BufferDurationUs);
                m_buffer.resize(m_bufferLength);
                m_buffer.fill(0);
                emit bufferLengthChanged(bufferLength());
                if (m_generateTone) {
                    if (0 == m_tone.endFreq) {
                        const qreal nyquist = nyquistFrequency(m_format);
                        m_tone.endFreq = qMin(qreal(SpectrumHighFreq), nyquist);
                    }
                    // Call function defined in utils.h, at global scope
                    ::generateTone(m_tone, m_format, m_buffer);
                    m_dataLength = m_bufferLength;
                    emit dataLengthChanged(dataLength());
                    emit bufferChanged(0, m_dataLength, m_buffer);
                    setRecordPosition(m_bufferLength);
                    result = true;
                } else {
                    emit bufferChanged(0, 0, m_buffer);
                    m_audioInput = new QAudioInput(m_audioInputDevice, m_format, this);
                    m_audioInput->setNotifyInterval(NotifyIntervalMs);
                    result = true;
                }
            }
            m_audioOutput = new QAudioOutput(m_audioOutputDevice, m_format, this);
            m_audioOutput->setNotifyInterval(NotifyIntervalMs);
        }
    } else {
        if (m_file)
            emit errorMessage(tr("Audio format not supported"),
                              formatToString(m_format));
        else if (m_generateTone)
            emit errorMessage(tr("No suitable format found"), "");
        else
            emit errorMessage(tr("No common input / output format found"), "");
    }

    ENGINE_DEBUG << "Engine::initialize" << "m_bufferLength" << m_bufferLength;
    ENGINE_DEBUG << "Engine::initialize" << "m_dataLength" << m_dataLength;
    ENGINE_DEBUG << "Engine::initialize" << "format" << m_format;

    return result;
}
示例#2
0
PppConfOption* PppConfPacket::optionAt (const int optIdx) {
	ACE_TRACE("PppConfPacket::optionAt");
	
	int optNum = 0;
	
	if (codeVal() != Configure_Request &&
		codeVal() != Configure_Ack &&
		codeVal() != Configure_Nak)
			throw std::runtime_error("No options in this type of packet.");
	
	ACE_UINT8 optType, bufLen;
	ACE_UINT8* optPtr;
	int optPos = 0;
	
	do {
		optType = *(dataPtr() + optPos);
		bufLen = *(dataPtr() + optPos + 1) - 2;
		optPtr = dataPtr() + optPos + 2;
		optPos += bufLen + 2;
	} while ( optPos < dataLength() && optNum++ <= optIdx );
	
	if ( optNum != optIdx )
		throw std::runtime_error("Could not reach specified option index.");
		
	// TODO: use an auto_ptr here so there's no worry about deleting later
	return new PppConfOption(optType, bufLen, optPtr);
}
EXPORT_C TInt CDosExtensionBase::ExecuteMessageL(const RMessage2& aMessage)
{
    
    API_TRACE_( "[DOSSERVER] CDosExtensionBase::ExecuteMessageL(...)" );
	__ASSERT_DEBUG(aMessage.Function() == ECallFunction, 
		PanicClient(aMessage,EPanicIllegalFunction));

	TInt retVal(KErrNone);
	TBool parameterModifiedByDSY(EFalse);

	// Get data from RMessage
	TExtensionParPckg extPars;
	aMessage.ReadL(0, extPars);
	
	TInt dataLength(extPars().iParLength);
	if (dataLength >= 0)
	{
		HBufC8* dataBuffer = HBufC8::NewMaxLC( dataLength );
		TPtr8 dataPtr = dataBuffer->Des();
		aMessage.ReadL( 1, dataPtr );

		// Check autocomplete flag
		TUint autoCompl(aMessage.Int2());
		if (autoCompl == KAutoComplete)
		{
            COM_TRACE_4( "[DOSSERVER] MDosExtensionBaseDSY::CallFunctionL(0x%x,0x%x,0x%x,0x%x)"
                ,extPars().iFunc
                ,dataPtr.Ptr()
                ,dataPtr.Length()
                ,autoCompl );

			retVal = CallFunctionL(extPars().iFunc, const_cast<TUint8*>(dataPtr.Ptr()), dataPtr.Length(), parameterModifiedByDSY);

			if((retVal == KErrNone) && parameterModifiedByDSY)
			{
				// Write over client's parameters
				retVal = aMessage.Write(1, dataPtr);
			}
		}
		else
		{
			COM_TRACE_3( "[DOSSERVER] MDosExtensionBaseDSY::CallFunctionAndCompleteL(0x%x,0x%x,0x%x)"
                ,extPars().iFunc
                ,dataPtr.Ptr()
                ,dataPtr.Length() );
        
            CallFunctionAndCompleteL(extPars().iFunc, const_cast<TUint8*>(dataPtr.Ptr()), dataPtr.Length(), aMessage);
		}

		CleanupStack::PopAndDestroy(); // dataBuffer
	}
	else
	{
		// Client passed negative parameter length
		retVal = KErrGeneral;
	}

	return retVal;
}
示例#4
0
unsigned PppConfPacket::countOpts() {
	unsigned optNum = 0;
	for (int optPos = 0; optPos < dataLength(); optNum++ ) {
		ACE_UINT8 bufLen = *(dataPtr() + optPos + 1) - 2;
		optPos += bufLen + 2;
	}
			
	return optNum;
}
示例#5
0
文件: header.c 项目: fingunter/rpm
/**
 * Return (malloc'ed) copy of entry data.
 * @param type		entry data type
 * @param p		entry data
 * @param c		entry item count
 * @retval lengthPtr	no. bytes in returned data
 * @return 		(malloc'ed) copy of entry data, NULL on error
 */
static void *
grabData(rpm_tagtype_t type, rpm_constdata_t p, rpm_count_t c, int * lengthPtr)
{
    rpm_data_t data = NULL;
    int length;

    length = dataLength(type, p, c, 0, NULL);
    if (length > 0) {
	data = xmalloc(length);
	copyData(type, data, p, c, length);
    }

    if (lengthPtr)
	*lengthPtr = length;
    return data;
}
示例#6
0
	StaticSet(const CONTAINER_t & container) {

		const uint16_t listSize(container.size());
		uint32_t offsets[listSize + 1];

		uint32_t dataLength(0);

		const typename CONTAINER_t::const_iterator
			begin(container.begin()),
			end(container.end());

		typename CONTAINER_t::const_iterator iterator;

		uint16_t index;

		offsets[0] = 0;

		for (iterator = begin, index = 1; iterator != end; iterator++, index += 1) {
			offsets[index] = dataLength += iterator->size();
		}

		/*
		 * DEBUG

		std::cerr << "listSize: " << listSize << ", dataLength: " << dataLength << std::endl;
		*/

		StaticSetData< uint16_t, uint32_t, typename DATA_t::TYPE > data(listSize, dataLength);

		memcpy(const_cast< uint32_t * >(data.offsets), offsets, (listSize + 1) * sizeof(offsets[0]));

		/*
		 * DEBUG

		std::cerr << "size: " << *data.size << std::endl;

		for (int i(0); i <= *data.size; i++) {
			std::cerr << "offset[" << i << "]: " << data.offsets[i] << std::endl;
		}
		*/

		for (iterator = begin, index = 0; iterator != end; iterator++, index += 1) {
			iterator->copy(data.data + offsets[index]);
		}

		this->data.swap(data);
	}
示例#7
0
void Engine::audioDataReady()
{
    Q_ASSERT(0 == m_bufferPosition);
    const qint64 bytesReady = m_audioInput->bytesReady();
    const qint64 bytesSpace = m_buffer.size() - m_dataLength;
    const qint64 bytesToRead = qMin(bytesReady, bytesSpace);

    const qint64 bytesRead = m_audioInputIODevice->read(
                                       m_buffer.data() + m_dataLength,
                                       bytesToRead);

    if (bytesRead) {
        m_dataLength += bytesRead;
        emit dataLengthChanged(dataLength());
    }

    if (m_buffer.size() == m_dataLength)
        stopRecording();
}
示例#8
0
	static const uint32_t calculateSize(const CONTAINER_t & container) {

		uint32_t dataLength(0);
		const uint16_t offsetsLength(container.size() + 1);

		const typename CONTAINER_t::const_iterator end(container.end());
		typename CONTAINER_t::const_iterator iterator(container.begin());

		uint16_t index(1);

		for (; iterator != end; iterator++, index += 1) {
			dataLength += iterator->size();
		}

		const uint32_t
			TOTAL_SIZE_SIZE(sizeof(STATIC_SET_DATA_TYPE::SIZE_TYPE)),
			TOTAL_OFFSETS_SIZE(offsetsLength * sizeof(STATIC_SET_DATA_TYPE::OFFSETS_TYPE)),
			TOTAL_DATA_SIZE(dataLength * sizeof(STATIC_SET_DATA_TYPE::DATA_TYPE));

		return  TOTAL_SIZE_SIZE + TOTAL_OFFSETS_SIZE + TOTAL_DATA_SIZE;
	}
示例#9
0
文件: header.c 项目: fingunter/rpm
static int intAppendEntry(Header h, rpmtd td)
{
    indexEntry entry;
    int length;

    if (td->type == RPM_STRING_TYPE || td->type == RPM_I18NSTRING_TYPE) {
	/* we can't do this */
	return 0;
    }

    /* Find the tag entry in the header. */
    entry = findEntry(h, td->tag, td->type);
    if (!entry)
	return 0;

    length = dataLength(td->type, td->data, td->count, 0, NULL);
    if (length < 0)
	return 0;

    if (ENTRY_IN_REGION(entry)) {
	char * t = xmalloc(entry->length + length);
	memcpy(t, entry->data, entry->length);
	entry->data = t;
	entry->info.offset = 0;
    } else
	entry->data = xrealloc(entry->data, entry->length + length);

    copyData(td->type, ((char *) entry->data) + entry->length, 
	     td->data, td->count, length);

    entry->length += length;

    entry->info.count += td->count;

    return 1;
}
示例#10
0
文件: header.c 项目: fingunter/rpm
/** \ingroup header
 * Swap int32_t and int16_t arrays within header region.
 *
 * If a header region tag is in the set to be swabbed, as the data for a
 * a header region is located after all other tag data.
 *
 * @param entry		header entry
 * @param il		no. of entries
 * @param dl		start no. bytes of data
 * @param pe		header physical entry pointer (swapped)
 * @param dataStart	header data start
 * @param dataEnd	header data end
 * @param regionid	region offset
 * @param fast		use offsets for data sizes if possible
 * @return		no. bytes of data in region, -1 on error
 */
static int regionSwab(indexEntry entry, int il, int dl,
		entryInfo pe,
		unsigned char * dataStart,
		const unsigned char * dataEnd,
		int regionid, int fast)
{
    if ((entry != NULL && regionid >= 0) || (entry == NULL && regionid != 0))
	return -1;

    for (; il > 0; il--, pe++) {
	struct indexEntry_s ie;

	ie.info.tag = ntohl(pe->tag);
	ie.info.type = ntohl(pe->type);
	ie.info.count = ntohl(pe->count);
	ie.info.offset = ntohl(pe->offset);

	if (hdrchkType(ie.info.type))
	    return -1;
	if (hdrchkData(ie.info.count))
	    return -1;
	if (hdrchkData(ie.info.offset))
	    return -1;
	if (hdrchkAlign(ie.info.type, ie.info.offset))
	    return -1;

	ie.data = dataStart + ie.info.offset;
	if (dataEnd && (unsigned char *)ie.data >= dataEnd)
	    return -1;

	if (fast && il > 1) {
	    ie.length = ntohl(pe[1].offset) - ie.info.offset;
	} else {
	    ie.length = dataLength(ie.info.type, ie.data, ie.info.count,
				   1, dataEnd);
	}
	if (ie.length < 0 || hdrchkData(ie.length))
	    return -1;

	ie.rdlen = 0;

	if (entry) {
	    ie.info.offset = regionid;
	    *entry = ie;	/* structure assignment */
	    entry++;
	}

	/* Alignment */
	dl += alignDiff(ie.info.type, dl);

	/* Perform endian conversions */
	switch (ntohl(pe->type)) {
	case RPM_INT64_TYPE:
	{   uint64_t * it = ie.data;
	    for (; ie.info.count > 0; ie.info.count--, it += 1) {
		if (dataEnd && ((unsigned char *)it) >= dataEnd)
		    return -1;
		*it = htonll(*it);
	    }
	}   break;
	case RPM_INT32_TYPE:
	{   int32_t * it = ie.data;
	    for (; ie.info.count > 0; ie.info.count--, it += 1) {
		if (dataEnd && ((unsigned char *)it) >= dataEnd)
		    return -1;
		*it = htonl(*it);
	    }
	}   break;
	case RPM_INT16_TYPE:
	{   int16_t * it = ie.data;
	    for (; ie.info.count > 0; ie.info.count--, it += 1) {
		if (dataEnd && ((unsigned char *)it) >= dataEnd)
		    return -1;
		*it = htons(*it);
	    }
	}   break;
	}

	dl += ie.length;
    }

    return dl;
}
示例#11
0
/** \ingroup header
 * Swap int32_t and int16_t arrays within header region.
 *
 * If a header region tag is in the set to be swabbed, as the data for a
 * a header region is located after all other tag data.
 *
 * @param entry		header entry
 * @param il		no. of entries
 * @param dl		start no. bytes of data
 * @param pe		header physical entry pointer (swapped)
 * @param dataStart	header data start
 * @param dataEnd	header data end
 * @param regionid	region offset
 * @return		no. bytes of data in region, -1 on error
 */
static int regionSwab(indexEntry entry, int il, int dl,
		entryInfo pe,
		unsigned char * dataStart,
		const unsigned char * dataEnd,
		int regionid)
{
    for (; il > 0; il--, pe++) {
	struct indexEntry_s ie;
	rpmTagType type;

	ie.info.tag = ntohl(pe->tag);
	ie.info.type = ntohl(pe->type);
	ie.info.count = ntohl(pe->count);
	ie.info.offset = ntohl(pe->offset);

	if (hdrchkType(ie.info.type))
	    return -1;
	if (hdrchkData(ie.info.count))
	    return -1;
	if (hdrchkData(ie.info.offset))
	    return -1;
	if (hdrchkAlign(ie.info.type, ie.info.offset))
	    return -1;

	ie.data = dataStart + ie.info.offset;
	if (dataEnd && (unsigned char *)ie.data >= dataEnd)
	    return -1;

	ie.length = dataLength(ie.info.type, ie.data, ie.info.count, 1, dataEnd);
	if (ie.length < 0 || hdrchkData(ie.length))
	    return -1;

	ie.rdlen = 0;

	if (entry) {
	    ie.info.offset = regionid;
	    *entry = ie;	/* structure assignment */
	    entry++;
	}

	/* Alignment */
	type = ie.info.type;
	if (typeSizes[type] > 1) {
	    unsigned diff = typeSizes[type] - (dl % typeSizes[type]);
	    if (diff != typeSizes[type]) {
		dl += diff;
	    }
	}

	/* Perform endian conversions */
	switch (ntohl(pe->type)) {
	case RPM_INT64_TYPE:
	{   uint64_t * it = ie.data;
	    for (; ie.info.count > 0; ie.info.count--, it += 1) {
		if (dataEnd && ((unsigned char *)it) >= dataEnd)
		    return -1;
		*it = htonll(*it);
	    }
	}   break;
	case RPM_INT32_TYPE:
	{   int32_t * it = ie.data;
	    for (; ie.info.count > 0; ie.info.count--, it += 1) {
		if (dataEnd && ((unsigned char *)it) >= dataEnd)
		    return -1;
		*it = htonl(*it);
	    }
	}   break;
	case RPM_INT16_TYPE:
	{   int16_t * it = ie.data;
	    for (; ie.info.count > 0; ie.info.count--, it += 1) {
		if (dataEnd && ((unsigned char *)it) >= dataEnd)
		    return -1;
		*it = htons(*it);
	    }
	}   break;
	}

	dl += ie.length;
    }

    return dl;
}
示例#12
0
文件: main.c 项目: xythobuz/yasab
int main(int argc, char *argv[]) {
    FILE *fp;
    char c;
    time_t start = time(NULL), end;
    if ((argc < 3) || (argc > 4)) {
        printf("Usage:\n%s /dev/port /path/to.hex [q]\n", argv[0]);
        return 1;
    }

    // Open HEX File
    if ((fp = fopen(argv[2], "r")) == NULL) {
        printf("Could not open file %s\n", argv[2]);
        return 1;
    }

    // Read it's contents
    if (readHex(fp) != 0) {
        printf("Could not parse HEX file %s\n", argv[2]);
        fclose(fp);
        return 1;
    }

    fclose(fp);

    if (!isValid()) {
        printf("HEX-File not valid!\n");
        freeHex();
        return 1;
    }

    uint32_t min = minAddress();
    uint32_t max = maxAddress();
    uint32_t length = dataLength();
    printf("Hex File Path   : %s\n", argv[2]);
    printf("Minimum Address : 0x%X\n", min);
    printf("Maximum Address : 0x%X\n", max);
    printf("Data payload    : %i bytes\n\n", length);

    uint8_t *d = (uint8_t *)malloc(length * sizeof(uint8_t));
    if (d == NULL) {
        fprintf(stderr, "Not enough memory (%lu bytes)!\n", length * sizeof(uint8_t));
        freeHex();
        return 1;
    }
    parseData(d);
    freeHex();

    // Open serial port
    if ((fd = serialOpen(argv[1], 38400, 1)) == -1) {
        printf("Could not open port %s\n", argv[1]);
        free(d);
        return 1;
    }

    signal(SIGINT, intHandler);
    signal(SIGQUIT, intHandler);

ping:
    printf("Pinging bootloader... Stop with CTRL+C\n");

    if (argc > 3) {
        c = argv[3][0];
    } else {
        c = 'f';
    }
    serialWriteChar(fd, c);
    usleep(PINGDELAY * 1000);
    if ((serialReadRaw(fd, &c, 1) != 1) || (c != OKAY)) {
        goto ping;
    }

    printf("Got response... Acknowledging...\n");
    serialWriteChar(fd, CONFIRM);
    serialReadChar(fd, &c);
    if (c != ACK) {
        printf("Invalid acknowledge! Trying again...\n", c, c);
        goto ping;
    }

    printf("Connection established successfully!\n");
    printf("Sending target address...\n");

    serialWriteChar(fd, (min & 0xFF000000) >> 24);
    serialWriteChar(fd, (min & 0x00FF0000) >> 16);
    serialWriteChar(fd, (min & 0x0000FF00) >> 8);
    serialWriteChar(fd, min & 0x000000FF);

    serialReadChar(fd, &c);
    if (c != OKAY) {
        printf("Invalid acknowledge from YASAB!\n", c, c);
        free(d);
        serialClose(fd);
        return 1;
    }

    printf("Sending data length...\n");

    serialWriteChar(fd, (length & 0xFF000000) >> 24);
    serialWriteChar(fd, (length & 0x00FF0000) >> 16);
    serialWriteChar(fd, (length & 0x0000FF00) >> 8);
    serialWriteChar(fd, length & 0x000000FF);

    serialReadChar(fd, &c);
    if (c != OKAY) {
        printf("Invalid acknowledge from YASAB (%x)!\n", c, c);
        free(d);
        serialClose(fd);
        return 1;
    }

    printf("\n\n");

    for (uint32_t i = 0; i < length; i++) {
        serialWriteChar(fd, d[i]);
        if (serialHasChar(fd)) {
            serialReadChar(fd, &c);
            if (c == OKAY) {
                printNextPage();
            } else if (c == ERROR) {
                printf("YASAB aborted the connection!\n");
                free(d);
                serialClose(fd);
                return 1;
            } else {
                printf("Unknown answer from YASAB (%x)!\n", c, c);
            }
        }
        printProgress(i + 1, length);
    }

    end = time(NULL);
    printf("\n\nUpload finished after %3.1f seconds.\n", difftime(end, start));
    printf("YASAB - Yet another simple AVR Bootloader\n");
    printf("By xythobuz - Visit www.xythobuz.org\n");

    free(d);
    serialClose(fd);
    return 0;
}