Пример #1
0
int closeConnection (int fd) {
    //printf("closeConnection called\n");
    syslog(LOG_DEBUG,"closeConnection called\n");

    cmdModeEnable(response, fd);

    //delay (300) ;
    char * closeCommand = "close\r";
    serialPuts(fd,closeCommand);
    //delay (300) ;

    serialReceive(response, fd);
    //printf("response to close command: %s\n", response);
    syslog(LOG_DEBUG,"response to close command: %s\n", response);


    //Exit command mode
    if( cmdModeDisable(response, fd) ==1){
        //printf("CMD mode Disabled\n");
        syslog(LOG_DEBUG,"CMD mode Disabled\n");
    }else{
        //printf("Couldn't Exit CMD mode\n");
        syslog(LOG_DEBUG,"Couldn't Exit CMD mode\n");
    }
    serialReceive(response, fd);
    //printf("response to exit command: %s\n", response);
    syslog(LOG_DEBUG,"response to exit command: %s\n", response);
    return 0;

}
Пример #2
0
void Server::waitForClient()
{

    printf("Waiting for client.\n");

	serialReceive(msgBuffer); // Recieve filename from client.

    FILE* stream;

    if(stream = fopen(msgBuffer, "r"))      // If opening a file with the name recieved is succesfull continue
    {
        long lengthOfFile = getFileLength(stream);      // Get file length of opened file in bytes.

        printf("User requested: %s with a size of %ld bytes\n", msgBuffer, lengthOfFile); // Print out filename and lenght of file.

        sprintf(msgBuffer, "%ld", lengthOfFile); // Convert lenght of file to string.

		serialSend(msgBuffer, strlen(msgBuffer)+1); // Send lenght of file


        sendFile(stream, lengthOfFile);     // Use function to send file, giving pointer and lenght of the file to send.

        fclose(stream);  // Close file.
    }
    else // If file couldnt be found, print out message and send to client 0 filelenght (its not found).
    {
        printf("Client tried to get: %s\n", msgBuffer);
        serialSend("0", 2);
    }

    printf("Client connection closed\n");
}
Пример #3
0
/*
 * Function to open a TCP connection with remote webserver.
 ******************************************************************************
 */
int openConnection(int fd, char* address, char* port){
    //printf("openConnection called to %s:%s\n", address, port);
    syslog(LOG_DEBUG, "openConnection called to %s:%s\n", address, port);


    /*WiFi Module Enter Command mode */
    if( cmdModeEnable(response, fd) ==1){
        //printf("CMD mode Enabled\n");
        syslog(LOG_DEBUG, "CMD mode Enabled\n");
    }else{
        //printf("CMD mode Failed\n");
        syslog(LOG_DEBUG, "CMD mode Failed\n");
    }

    serialPuts(fd,"close\r");
    serialReceive(response, fd);
    //printf("response to 'close': %s\n", response);
    syslog(LOG_DEBUG,"response to 'close': %s\n", response);

    serialPuts(fd,"set comm remote 0\r");
    serialReceive(response, fd);
    //printf("response to 'set comm remote 0': %s\n", response);
    syslog(LOG_DEBUG,"response to 'set comm remote 0': %s\n", response);

    //fflush (stdout) ;
    //serialFlush(fd);
    //delay (1000) ;

    //Open TCP connection
    // Command in form: "open "192.168.2.3 7892\r"
    //char * tcpOpenCommand = "open "192.168.2.3 7892\r";
    
    serialPrintf(fd, "open %s %s\r", address, port);
    serialReceive(response, fd);    
    //printf("response to open command: %s\n", response);
    syslog(LOG_DEBUG,"response to open command: %s\n", response);

    //fflush (stdout) ;
    //serialFlush(fd);

    //cmdModeDisable(response, fd);
    //printf("response to exit command: %s\n", response);
    return 0;
}
Пример #4
0
/*
 * Tell the Wifi module to exit command mode
 ******************************************************************************
 */
int cmdModeDisable(char * response, int serialLine){
    char * exitCommand = "exit\r";
    serialPuts(serialLine,exitCommand);

    serialReceive(response, serialLine);

    //printf("cmdModeDisable response: %s\n", response);
    syslog(LOG_DEBUG, "cmdModeDisable response: %s\n", response);

    if (checkCmdSyntax(response) == 1){
        serialPuts(serialLine,exitCommand);
        serialReceive(response, serialLine);
        if (checkCmdSyntax(response) == 0){
            return 1;
        }else{
            return 0;
        }
    }
    return 1;
}
Пример #5
0
void QSerialTerminal::close(void)
{
    if(serial != NULL)
    {
        timer.stop();
        disconnect(serial, SIGNAL(readyRead()), this, SLOT(serialReceive()));

        transmitThread->shutdown = true;
        transmitThread->wait();
        serial = NULL;
    }
}
Пример #6
0
cell pawn_serialReceive( AMX * amx, const cell * params )
{
	int cnt = ( params[2] < SERIAL_BUF_SZ ) ? params[2] : SERIAL_BUF_SZ;
	cnt = serialReceive( serialBuffer, cnt );
	int i;
	cell * data = amx_Address( amx, params[1] );
	if ( !data )
		return 0;
	for ( i=0; i<cnt; i++)
		data[i] = serialBuffer[i];
    return cnt;
}
Пример #7
0
void QSerialTerminal::keyPressEvent(QKeyEvent* event)
{
    if(!this->isVisible())
    {
        return;
    }

    if(serial != NULL)
    {
        char data = event->text().toLocal8Bit()[0];
        int key = event->key();

        switch(key)
        {
            case Qt::Key_Return:
            case Qt::Key_Enter:
                data = '\n';
                key = '\n';
                break;
        }

        if(key < 0x100)
        {
            transmitThread->enqueue(data);
            TotalTx++;
            if(serial->QueueReceiveSignals)
            {
                emit RefreshStatus();
                dirty = false;
            }
            else
            {
                dirty = true;
            }
        }

        event->accept();

        if(lastReceive.elapsed() > 200 &&
            serial->QueueReceiveSignals > 0 &&
            serial->bytesAvailable() > 0)
        {
            serialReceive();
        }
    }
    else
    {
        // Not connected to serial port, revert to being a plain text editor widget
        // so that Cut and Paste key shortcuts work.
        QPlainTextEdit::keyPressEvent(event);
    }
}
Пример #8
0
void QSerialTerminal::open(QextSerialPort* newSerialPort)
{
    if(serial != NULL)
    {
        close();
    }

    serial = newSerialPort;
    serial->setTimeout(500);

    transmitThread->serial = serial;
    connect(serial, SIGNAL(readyRead()), SLOT(serialReceive()));
    serial->QueueReceiveSignals = 10;
    timer.start(200, this);
    dirty = true;
}
Пример #9
0
/*
 * Put the Wifi Module into command mode.
 ******************************************************************************
 */
int cmdModeEnable(char * response, int serialLine){
    serialFlush(serialLine);
    delay (300) ;
    serialPuts(serialLine,"$$$");
    delay (300) ;

    int size = serialReceive(response, serialLine);
    if (size == 0){
        //printf("Nothing read as response\n");
        return 0;
    }else if( strcmp(response, "CMD\r\n") == 0){
        return 1;
    } else {
        return 0;
    }
}
Пример #10
0
void QSerialTerminal::timerEvent(QTimerEvent* e)
{
    if(lastReceive.elapsed() > 200 &&
        serial != NULL &&
        serial->QueueReceiveSignals > 0)
    {
        if(serial->bytesAvailable() > 0)
        {
            serialReceive();
        }

        if(dirty)
        {
            emit RefreshStatus();
            dirty = false;
        }
    }

    QPlainTextEdit::timerEvent(e);
}
Пример #11
0
int main( int argc, char **argv )
{
    char ch;
    int serfd;
    char data[256];
    char recvdata[256];
    int length;
    int recvlength;
    int i;
    char cmdline[256];
    int ret;

    //调试输出单元
    tracePrintfInit();
    {
        //modifyTraceLevelByMode(SYS_MODE, DEBUG_TRACE);
        //modifyTraceLevelByMode(IMG_MODE, DEBUG_TRACE);
        //modifyTraceLevelByMode(FT_MODE, DEBUG_TRACE);
    }

    printf("begin integrate\n");

    serfd = InitSerialCom(2,115200,'n',1, 8);
    if (serfd == -1)
    {
        printf("COM2 open failure\n");
        return 0;
    }

    i = 0;
    while(1)
    {
        memset(data, 0, 256);
        sprintf(data, "hello\n");
        length = strlen(data);
        SerialSend(serfd, (unsigned char *)data, length);

        memset(recvdata, 0, 256);

        recvlength = serialReceive(serfd, recvdata, 256);
        if (recvlength)
        {
            printf("|%s|%d\n", recvdata, recvlength);
            if (recvlength == 2)
            {
                if (strncmp(recvdata, "ok", strlen("ok")) == 0)
                {
                    printf("COM2 OK\n");
                    break;

                }
            }

        }
        i++;

        if (i > 50)
        {
            printf("COM2 FAILURE\n");
            break;
        }

        usleep(1000*500);
    }

    while(1)
    {
        memset(cmdline, 0, 256);
        scanf("%s", cmdline);

        if (strncmp(cmdline, "getRTCTime", strlen("getRTCTime")) == 0)
        {
            memset(data, 0, 64);
            get_current_time_string(data);
        }
        else if (strncmp(cmdline, "setUSBTest", strlen("setUSBTest")) == 0)
        {
            ret = confirm_usb_running();
            if (ret)
            {
                printf("testUSBSuccess\n");
            }
            else
            {
                printf("testUSBFailure\n");
            }
        }
        else if (strncmp(cmdline, "getSN", strlen("getSN")) == 0)
        {
            memset(data, 0, 64);
            get_pcba_sn(data, 64);
            printf("reportSN|%s\n", data);
        }
        else if (strncmp(cmdline, "getMac", strlen("getMac")) == 0)
        {
            memset(data, 0, 64);
            get_pcba_mac(data, 64);
            printf("reportMAC|%s\n", data);
        }
        else if (strncmp(cmdline, "getMediaBoradTestReport", strlen("getMediaBoradTestReport")) == 0)
        {
            memset(data, 0, 64);
            get_pcba_idx99(data, 64);
            printf("reportMediaBoardTestInfo|%s\n", data);
        }

    }




#if 0
    char ch;

    //调试输出单元
    tracePrintfInit();
    {
        //modifyTraceLevelByMode(SYS_MODE, DEBUG_TRACE);
        //modifyTraceLevelByMode(IMG_MODE, DEBUG_TRACE);
        //modifyTraceLevelByMode(FT_MODE, DEBUG_TRACE);
    }

    init_display_output_device(FMT_1080P_60);

    init_framebuf_module();

    ft_Font_Init();
    init_temperature_module();
    sync_time_from_rtc();

    prepare_bg();
    /*
        system("mkdir -p /media");
        system("mkdir -p /media/tfcard");
        system("mkdir -p /media/usb");
        system("mkdir -p /media/msata");
    */
    init_hard_device_task();

    system("rm /tmp/leftai_ok /tmp/rightai_ok");
    system("/tmp/sample_ai >/tmp/ai.log &");
    display_welcom();

    usleep(3000*1000);
    //ai_display_filter(1);

    while(1)
    {
#if 1
        if ((access("/tmp/leftai_ok", F_OK) == 0) &&
                (access("/tmp/rightai_ok", F_OK) == 0))
        {
            usleep(1000*1000);
            break;
        }
#else

        if (access("/tmp/rightai_ok", F_OK) == 0)
        {
            break;
        }

#endif

        ai_display_filter(0);

        if (get_ai_force_exit())
        {
            break;
        }

        usleep(1000*1000);

    }

    if ((access("/tmp/leftai_ok", F_OK) == 0) &&
            (access("/tmp/rightai_ok", F_OK) == 0))
    {
        set_test_status(audio_ok);
    }

    ai_display_filter(1);
    system("touch /tmp/exit_ai");


    // printf("aaaaaaa\n");

    display_stb_info();

    usleep(500*1000);
    // printf("dddddd\n");



    series_display();
    usleep(500*1000);

    display_msata();
    usleep(500*1000);

    display_tfcard();
    usleep(500*1000);

    display_usb();
    usleep(500*1000);

    while(1)
    {

        if (test_flag & gpio_test)
        {
            display_gpio_test();
            break;
        }
        else
        {
            display_gpio_putdown();
        }


        if (get_force_exit_gpio())
        {
            printf("\nGPIO failure\n");
            break;
        }
        usleep(1000*1000);
    }

    save_test_status();
    exit_timer();


    usleep(500*1000);
    printf("\nvideo play\n");
    display_player();
    //save_test_status();

#if 1
    while(1)
    {
        ch = getchar();
        if (ch == 'q')
        {
            break;
        }
        else if (ch == 'w')
        {
            test_framebuf();
        }
        else if (ch == 'e')
        {
            clearFramebuf();
        }
        else if (ch == 'r')
        {
            Pixel64 *pCanvas;
            int width;
            int height;
            GrPos Pos;
            GrRegion Region;

            decJpgFile("/nfs/wait4open.jpg", &pCanvas, &height, &width);
            Pos.x = Pos.y = 0;
            Region.x = Region.y = 0;
            Region.w = width;
            Region.h = height;

            paint_canvas_2_background(pCanvas, Pos, Region);

            refresh_background_2_device(Pos, Region);
        }
        else if (ch == 't')
        {
            Pixel64 *pCanvas;
            int width;
            int height;
            GrPos Pos;
            GrRegion Region;
            decPngFile("/nfs/ico_dir.png", &pCanvas, &width, &height);

            Pos.x = 100;
            Pos.y = 100;
            Region.x = 0;
            Region.y = 0;
            Region.w = width;
            Region.h = height;

            paint_canvas_2_logic_device(pCanvas, Pos, Region);
            pCanvas = get_logic_canvas();
            move_region_2_display(pCanvas, Pos, Region);

        }
        else if (ch == 'y')
        {
            GrPos Pos;
            Pixel64 FT;

            Pos.x = 137;
            Pos.y = 102;
            FT.RGB.a = 0xFF;
            FT.RGB.r = 0xD7;
            FT.RGB.g = 0xD7;
            FT.RGB.b = 0xD7;

            ft_Font_Str2Disp("hello world", FT, Pos, 40);
        }
        else if (ch == 'u')
        {
            fprintf(stderr, "开始装备测试\n");
            set_test_network(0);
        }
        else if (ch == 'i')
        {
            confirm_network_running(0);
        }
        else if (ch == 'o')
        {
            float temp;

            temp = read_temperature();
            printf("temperature %3.4f\n", temp);
        }
        else if (ch == 'p')
        {
            save_time_into_rtc();
        }
        else if (ch == 'a')
        {
            sync_time_from_rtc();
        }
        else if (ch == 's')
        {
            int value40;
            int value41;
            int value44;

            read_gpio_status(40, &value40);
            read_gpio_status(41, &value41);
            read_gpio_status(44, &value44);
            printf("40 = %d, 41 = %d, 44 = %d\n", value40, value41, value44);
        }
        else if (ch == 'd')
        {
            write_gpio_status(44, 0);
        }
        else if (ch == 'f')
        {
            write_gpio_status(44, 1);
        }
        else if (ch == 'g')
        {
            fd_ser = InitSerialCom(1,115200,'n',1, 8);
        }
        else if (ch == 'h')
        {
            unsigned char data[10];
            sprintf(data, "hello");
            SerialSend(fd_ser, data, 5);
        }
        else if (ch == 'j')
        {
            unsigned char data[10];
            memset(data, 0, 10);
            serialReceive(fd_ser, data, 10);
            printf("data\n", data);
        }
        else if (ch == 'k')
        {
            get_system_time();
        }
        else if (ch == 'l')
        {
            Pixel64 *pcanvas;
            Pixel64 FT;
            int i, j;
            FILE *wfp;
            pcanvas = getFramebuf();

            wfp = fopen("/nfs/screen.raw", "wb");
            for (i = 0; i < 720; i++)
            {
                for (j = 0; j < 1280; j++)
                {

                    FT.RGB.r = pcanvas[j].RGB.r;
                    FT.RGB.b = pcanvas[j].RGB.b;
                    FT.RGB.a = pcanvas[j].RGB.a;
                    FT.RGB.g = pcanvas[j].RGB.g;

                    fwrite(&(FT.RGB.r), 1, 1, wfp);
                    fwrite(&(FT.RGB.g), 1, 1, wfp);
                    fwrite(&(FT.RGB.b), 1, 1, wfp);
                }
                pcanvas += 1280;
            }
            fclose(wfp);
        }

    }
#endif

    close_logic_framebuf_module();
    ft_Font_Destroy();

    close_display_output_device();

    return 0;
#endif

}