[En-Nut-Discussion] Question about CGI

tictac tictac at irc.pl
Mon Aug 21 22:41:28 CEST 2006


It's my first post on this list so I'd like to say hello to everyone ;)
I'm going to use NutOS and its tcp-ip stack to bulid a simple webcam, 
using Sony Ericsson MCA-25 camera connected to serial port of atmega128. 
I have written a cgi function that reads image data from camera and 
sends it to the client's browser - it is based on Simon Schulz's code. 
Everything works fine exept one thing: when I open webpage (with image 
from my cam) and then hit reload button before file transfer is 
finished, NutOS restarts.
Why is it so ? Can anybody give me a hint please ? I thought that 
writing to a stream in a loop using fputc() can't be interrupted.
Here is the cgi function that reads image from usart:

int Cam(FILE * stream, REQUEST * req)
{
    unsigned int i;
    unsigned int len = 0;
        unsigned char frametype = 0;
        unsigned char buffer[800];
//send headers
        NutHttpSendHeaderTop(stream, req, 200, "Ok");
        NutHttpSendHeaderBot(stream, "image/jpeg", -1);
//camera commands to make photo     
        puts("MCA25 ImageGrab()");
        mca25_start_image_grab();
        puts("MCA25 GrabJpeg()");
        mca25_grab_jpeg();
        puts("Receiving JPEG file...");
   
        //this function grabs data from cam
        mca25_grab_data(buffer, &len, &frametype);
   
        for (i=0;i<len;i++) fputc(buffer[i],stream);
       
        while (frametype == 0x48)
        {
            mca25_send_data_ack();
            mca25_grab_data(buffer, &len, &frametype);
            for (i=0;i<len;i++) fputc(buffer[i],stream);
        }
       
       //reconfigure camera
        usart1_puts("\xF9\x01\xEF\x0B\xE3\x07\x23\x0C\x01\x79\xF9");
       
        puts("JPEG file transfer complete...");

        fflush(stream);
           
   
    return 0;               
}

I would greatly appreciate any help ;)
Regards
Paul Melnarowicz






More information about the En-Nut-Discussion mailing list