Exemple #1
0
void CppSQLite3DB::close()
{
	if (mpDB)
	{
		int nRet = _sqlite3_close(mpDB);

		if (nRet != SQLITE_OK)
		{
			LPCTSTR szError = (LPCTSTR)_sqlite3_errmsg(mpDB);
			throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
		}

		mpDB = 0;
	}
}
Exemple #2
0
void CppSQLite3DB::close()
{
	if (mpDB)
	{
#ifndef IN_MEMORY_DB
//        sqlite3_exec(mpDB, "DETACH DATABASE backup", NULL, NULL, NULL);
#endif

		int nRet = _sqlite3_close(mpDB);

		if (nRet != SQLITE_OK)
		{
			LPCTSTR szError = (LPCTSTR)_sqlite3_errmsg(mpDB);
			throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
		}

		mpDB = 0;
	}
}
Exemple #3
0
int main(int argc, char **argv) { 

    int i;
    pthread_t p_thread;
    int thr_id;
    int status;

    int rc;

    void *socket_fd;
    struct sockaddr_in servaddr; //server addr

    // wifi
    struct termios tio, old_tio;
    int ret;

    unsigned char DataBuf[BUFFER_SIZE];
    int ReadMsgSize;

    unsigned char receiveBuffer[BUFFER_SIZE];
    int receiveSize = 0;
    unsigned char remainder[BUFFER_SIZE];
    int parsingSize = 0;

    char th_data[256];

    memset( &pastData, 0, sizeof( MGData ) );
    memset( &io, 0, sizeof( UINT8 )*8 );

    signal( SIGINT, (void *)sig_handler);
    fd = OpenSerial();
    if( fd == -1 )
    {
	writeLog("/work/iot/log", "Uart Open Fail." );
	return -1;
    }

    /******************** DB connect ***********************/
    // DB Open
    rc = _sqlite3_open( DBPATH, &pSQLite3 );
    if( rc != 0 )
    {
	writeLog( "/work/iot/log", "error DB Open" );
	return -1;
    }
    else
    {
	writeLog( "/work/iot/log", "DB Open" );
	printf("%s OPEN!!\n", DBPATH);
    }


    //sqlite3_busy_timeout( pSQLite3, 1000);
    //sqlite3_busy_timeout( pSQLite3, 5000);

    // DB Customize
    rc = _sqlite3_customize( &pSQLite3 );
    if( rc != 0 )
    {
	writeLog( "/work/iot/log", "error DB Customize" );
	return -1;
    }
    rc = _sqlite3_nolock( &pSQLite3 );
    if( rc != 0 )
    {
	writeLog( "/work/iot/log", "error set nolock" );
	return -1;
    }

    rc = init();
    if( rc == -1 )
    {
	writeLog( "/work/iot/log", "error init()" );
	return -1;
    }

    /***************** Server Connect **********************/
    if( -1 == ( m2mid = msgget( (key_t)2222, IPC_CREAT | 0666)))
    {
	writeLog( "/work/iot/log", "error msgget() m2mid" );
	return -1;
    }

    if( -1 == ( eventid = msgget( (key_t)3333, IPC_CREAT | 0666)))
    {
	writeLog( "/work/iot/log", "error msgget() eventid" );
	return -1;
    }

    memcpy( th_data, (void *)&fd, sizeof(fd) );
    if( pthread_create(&threads[2], NULL, &thread_main, (void *)th_data) == -1 )
    {
	writeLog("/work/iot/log", "[Uart] threads[2] thread_main error" );
	printf("error thread\n");
    }

    if( pthread_create(&threads[1], NULL, &ConnectPorcess, NULL ) == -1 )
    {
	writeLog("/work/iot/log", "[TCP/IP] thread Create error" );
    }
    usleep(1000);

    while(1)
    { 

	// receive Bridge
	ReadMsgSize = read(fd, DataBuf, BUFFER_SIZE); 
	if(ReadMsgSize > 0)
	{

	    if( receiveSize >= BUFFER_SIZE )
		continue;


	    /*
	       printf("STX ");
	       for( i = 0; i< ReadMsgSize; i++ )
	       printf("%02X ", DataBuf[i]);
	       printf(" ETX\n");
	       */

	    memcpy( receiveBuffer+receiveSize, DataBuf, ReadMsgSize );
	    receiveSize += ReadMsgSize;

	    //printf("receiveSize = %d\n", receiveSize );

	    parsingSize = uartParsingReceiveValue(receiveBuffer, receiveSize, remainder, parsingSize);

	    //printf("parsingSize(%d) ", parsingSize);

	    memset( receiveBuffer, 0 , sizeof(BUFFER_SIZE) );
	    receiveSize = 0;
	    memcpy( receiveBuffer, remainder, parsingSize );
	    receiveSize = parsingSize;

	    parsingSize = 0;	// add 20140508
	    memset( remainder, 0 , sizeof(BUFFER_SIZE) );
	}
	else
	{
	    //usleep(100);
	    //printf("Serial timeout %d\n", ReadMsgSize);
	}
    }




    /*******************************************************/
    _sqlite3_close( &pSQLite3 );

    writeLog( "/work/iot/log", "[IoTManager] END" );
    return 0; 
}