示例#1
0
void reading_storingProcess( std::map< unsigned, std::vector< unsigned > >& message_report )
{
    const char *input_file_path = SOURCE_DIR "/tests/2_5/2.5_example.in";
    std::fstream input_file( input_file_path, std::ios::binary | std::ios::in );

    check_is_file_open( input_file, input_file_path );

    unsigned new_message_capacity;
    Message newMessage;

    while ( true )
    {
        input_file >> newMessage;

        if ( input_file.eof() )
        {
            break;
        }

        if ( newMessage.getType() > 100000 )
        {
            continue;
        }

        new_message_capacity = 3 * sizeof( unsigned ) + newMessage.getLength();

        update_report( message_report, newMessage, new_message_capacity );
    }

    input_file.close();
}
示例#2
0
文件: tsip.cpp 项目: adbor/gps
/** encode byte stream into TSIP packets
*
*   The TSIP packet encode state machine that collects a stream
*   of bytes into TSIP packets.Encodes byte steam from a serial
*   byte stream from a Trimble Thunderbolt GPSDO into TSIP
*   packets. When a packet has been completed the corresponding
*   report is updated.
*/
int tsip::encode(UINT8 c)
{
	switch (m_state) {
 
	case START:
		// search for start
		if (c == DLE)
			m_state = FRAME;
		break;

	case FRAME:
		// check if mis-framed
		if (c == DLE || c == ETX)
			m_state = START;
		else {
			m_state = DATA;
			m_report_length = 0;
			m_report.raw.data[m_report_length++] = c;
		}
		break;

	case DATA:
		// found data DLE
		if (c == DLE) {
			m_state = DATA_DLE;
		}
		// add byte to report packet
		else if (m_report_length < MAX_DATA) {
			m_report.raw.data[m_report_length++] = c;
		}
		break;

	case DATA_DLE:
		// escaped data 
		if (c == DLE) {
			m_state = DATA;
			if (m_report_length < MAX_DATA) {
				m_report.raw.data[m_report_length++] = c;
			}
		}
		// end of frame
		else if (c == ETX) {
			m_state = START;
			return update_report();    //Whoohoo the moment we've been waitin for
		}
		// mis-framed
		else
			m_state = START;
			if (verbose) printf("waiting gps packet......\n");
		break;

	default:
		m_state = START;
		if (verbose) printf("waiting gps packet......\n");
		break;
	}

	return 0;
}
int SQLLiteReport::save_report(MediaConchLib::report reportKind, MediaConchLib::format format,
                               const std::string& filename, const std::string& file_last_modification,
                               const std::string& report, MediaConchLib::compression compress,
                               bool has_mil_version)
{
    std::stringstream create;

    if (file_is_registered(reportKind, format, filename))
        return update_report(reportKind, format, filename, file_last_modification, report, compress, has_mil_version);

    reports.clear();
    create << "INSERT INTO Report";
    create << " (FILENAME, FILE_LAST_MODIFICATION, TOOL, FORMAT, REPORT, COMPRESS, HAS_MIL_VERSION)";
    create << " VALUES (?, ?, ?, ?, ?, ?, ?);";
    query = create.str();

    const char* end = NULL;
    int ret = sqlite3_prepare_v2(db, query.c_str(), query.length() + 1, &stmt, &end);
    if (ret != SQLITE_OK || !stmt || (end && *end))
        return -1;

    ret = sqlite3_bind_blob(stmt, 1, filename.c_str(), filename.length(), SQLITE_STATIC);
    if (ret != SQLITE_OK)
        return -1;

    ret = sqlite3_bind_blob(stmt, 2, file_last_modification.c_str(), file_last_modification.length(), SQLITE_STATIC);
    if (ret != SQLITE_OK)
        return -1;

    ret = sqlite3_bind_int(stmt, 3, (int)reportKind);
    if (ret != SQLITE_OK)
        return -1;

    ret = sqlite3_bind_int(stmt, 4, (int)format);
    if (ret != SQLITE_OK)
        return -1;

    ret = sqlite3_bind_blob(stmt, 5, report.c_str(), report.length(), SQLITE_STATIC);
    if (ret != SQLITE_OK)
        return -1;

    ret = sqlite3_bind_int(stmt, 6, (int)compress);
    if (ret != SQLITE_OK)
        return -1;

    ret = sqlite3_bind_int(stmt, 7, (int)has_mil_version);
    if (ret != SQLITE_OK)
        return -1;

    return execute();
}
示例#4
0
int main (void){
	//Enable watchdog timer for 1 second.  Not sure why I have to do this, but the examples do.
	wdt_enable(WDTO_1S);
	
#ifdef DEBUG
	serial_init_b(9600);
#endif
	
	keyboard_init();
	usbInit();
	
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    uint8_t i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
	
	sei();

#ifdef DEBUG
	//Used as itoa destination
	char temp[32];
#endif

	//Main program loop
	while (1){
		wdt_reset();
		
		usbPoll();
		
		update_report();
		usbSetInterrupt(report_buffer, sizeof(report_buffer));
	}
}