Example #1
0
/*-----------------------------------------------------------------------------------*/
static err_t
http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
    char mydata[1024];
    int len;
    char *pc;
    int i, j;
    char *data;
    char *pdata;
    char fname[40];
    struct fs_file file = {0, 0};
    struct http_state *hs;
    char Digit1=0, Digit2=0, Digit3=0;
    int ADCVal = 0;
    char uart_buf[40];


    hs = arg;

    if (err == ERR_OK && p != NULL)
    {

        /* Inform TCP that we have taken the data. */
        tcp_recved(pcb, p->tot_len);

        if (hs->file == NULL)
        {
            data = p->payload;


            if ((strncmp(data, "GET /valt.css", 13) == 0) || (strncmp(data, "POST /valt.css", 14) == 0 ))
            {



                pbuf_free(p);



                //delay_read(delay_fin,delh,delm,dels);
                //tempc_read(tempc1,tempc2);


                // ADCVal = adc_p1;
                // ADCVal = ADCVal/8;
                // Digit1= ADCVal/100;
                // Digit2= (ADCVal-(Digit1*100))/10;
                // Digit3= ADCVal-(Digit1*100)-(Digit2*10);

                // *((data_control_html)+ 0xaa) = 0x30 + Digit1; /* ADC value 1st digit */
                // *((data_control_html)+ 0xab) = 0x30 + Digit2; /* ADC value 2nd digit */
                // *((data_control_html)+ 0xac) = 0x30 + Digit3; /* ADC value 3rd digit*/

                i=0;
                /* Update the ADC value in control.html */
                *((data_valt_css)+ 0x32) = tempc1[i++];
                *((data_valt_css)+ 0x33) = tempc1[i++];
                *((data_valt_css)+ 0x34) = tempc1[i++];
                *((data_valt_css)+ 0x35) = tempc1[i++];
                *((data_valt_css)+ 0x36) = tempc1[i++];

                i=0;
                /* Update the ADC value in control.html */
                *((data_valt_css)+ 0x57) = tempc2[i++];
                *((data_valt_css)+ 0x58) = tempc2[i++];
                *((data_valt_css)+ 0x59) = tempc2[i++];
                *((data_valt_css)+ 0x5a) = tempc2[i++];
                *((data_valt_css)+ 0x5b) = tempc2[i++];
                /*
                sprintf(uart_buf,"%s:%s\r\n",tempc1,tempc2);

                printUART2((unsigned int *)uart_buf);
                strcat(data_control_html,uart_buf);
                */
                sprintf(uart_buf,"%02d:%02d:%02d",delh[0],delm[0],dels[0]);
                *((data_valt_css)+ 0xa5) = uart_buf[0];
                *((data_valt_css)+ 0xa6) = uart_buf[1];
                *((data_valt_css)+ 0xa8) = uart_buf[3];
                *((data_valt_css)+ 0xa9) = uart_buf[4];
                *((data_valt_css)+ 0xab) = uart_buf[6];
                *((data_valt_css)+ 0xac) = uart_buf[7];

                sprintf(uart_buf,"%02d:%02d:%02d",delh[1],delm[1],dels[1]);
                *((data_valt_css)+ 0x20a) = uart_buf[0];
                *((data_valt_css)+ 0x20b) = uart_buf[1];
                *((data_valt_css)+ 0x20d) = uart_buf[3];
                *((data_valt_css)+ 0x20e) = uart_buf[4];
                *((data_valt_css)+ 0x210) = uart_buf[6];
                *((data_valt_css)+ 0x211) = uart_buf[7];

                sprintf(uart_buf,"%02d:%02d:%02d %02d",delh[2],delm[2],dels[2],sdoor);
                for(i=0; i<11; i++)
                    *((data_valt_css)+ (0x259+i)) = uart_buf[i];

                for(i=0; i<17; i++)
                    *((data_valt_css)+ (0x2db+i)) = ubuff[i];

                sprintf(uart_buf,"%c%c%c",0x20,0x20,0x20);
                for(i=0; i<3; i++)
                    *((data_valt_css)+ (0x292+i)) = uart_buf[i];

                sprintf(uart_buf,"%i",ebuff[33]);
                for(i=0; i<strlen(uart_buf); i++)
                    *((data_valt_css)+ (0x292+i)) = uart_buf[i];

                sprintf(uart_buf,"%c%c%c",0x20,0x20,0x20);
                for(i=0; i<3; i++)
                    *((data_valt_css)+ (0x2b6+i)) = uart_buf[i];

                sprintf(uart_buf,"%i",ebuff[34]);
                for(i=0; i<strlen(uart_buf); i++)
                    *((data_valt_css)+ (0x2b6+i)) = uart_buf[i];


                sprintf(uart_buf,"%02d:%1d:%1d",chk_modes(),sdoor,ebuff[39]);
                *((data_valt_css)+ 0x7c) = uart_buf[0];
                *((data_valt_css)+ 0x7d) = uart_buf[1];
                *((data_valt_css)+ 0x7e) = uart_buf[2];
                *((data_valt_css)+ 0x7f) = uart_buf[3];
                *((data_valt_css)+ 0x80) = uart_buf[4];
                *((data_valt_css)+ 0x81) = uart_buf[5];


                if(start==1)
                {
                    sprintf(uart_buf,"START \"");
                    *((data_valt_css)+ 0x245) = 0x66;
                }

                else
                {
                    sprintf(uart_buf," STOP \"");
                    *((data_valt_css)+ 0x245) = 0x32;
                }

                *((data_valt_css)+ 0x233) = uart_buf[0];
                *((data_valt_css)+ 0x234) = uart_buf[1];
                *((data_valt_css)+ 0x235) = uart_buf[2];
                *((data_valt_css)+ 0x236) = uart_buf[3];
                *((data_valt_css)+ 0x237) = uart_buf[4];
                *((data_valt_css)+ 0x238) = uart_buf[5];
                *((data_valt_css)+ 0x239) = uart_buf[6];

                //	*((data_valt_css)+ 0x211) = uart_buf[7];

                uint16_t cp1;
                uint16_t cp2;
                uint16_t cp3;
                uint16_t cp4;
                uint16_t cp5;
                uint16_t cp6;

                cp1=0xd6;
                cp2=0x104;
                cp3=0x132;
                cp4=0x160;
                cp5=0x18e;
                cp6=0x1bc;

                if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_9)) *((data_valt_css)+ cp1) = 0x6e;//n
                else {
                    *((data_valt_css)+ cp1) = 0x66;//f
                    //	if(leds[0]==3)leds[0] = 2;
                }

                if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_10)) *((data_valt_css)+cp2) = 0x6e;
                else {
                    *((data_valt_css)+ cp2) = 0x66;
                    //if(leds[1]==3)leds[1] = 2;
                }

                if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_11)) *((data_valt_css)+ cp3) = 0x6e;
                else {
                    *((data_valt_css)+ cp3) = 0x66;
                    //if(leds[2]==3)leds[2] = 2;
                }

                if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_12)) *((data_valt_css)+cp4) = 0x6e;
                else {
                    *((data_valt_css)+ cp4) = 0x66;
                    //if(leds[3]==3)leds[3] = 2;
                }

                if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_13)) *((data_valt_css)+ cp5) = 0x6e;
                else *((data_valt_css)+ cp5) = 0x66;

                if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_14)) *((data_valt_css)+ cp6) = 0x6e;
                else *((data_valt_css)+ cp6) = 0x66;

                fs_open("/valt.css", &file);

                hs->file = file.data;
                hs->left = file.len;

                send_data(pcb, hs);

                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                tcp_sent(pcb, http_sent);
            }
            else if ((strncmp(data, "GET /ind.html", 13) == 0) || (strncmp(data, "POST /ind.html", 14) == 0 ))
            {

                pbuf_free(p);

                fs_open("/ind.html", &file);

                hs->file = file.data;
                hs->left = file.len;
                //  test_i2c();
                send_data(pcb, hs);

                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                tcp_sent(pcb, http_sent);
            }
            else if (strncmp(data, "GET /uppu", 9) == 0)
            {

                pbuf_free(p);

                fs_open("/index.html", &file);

                hs->file = file.data;
                hs->left = file.len;

                send_data(pcb, hs);

                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                tcp_sent(pcb, http_sent);
            }
            else if ((strncmp(data, "GET /val.js", 11) == 0)|| (strncmp(data, "POST /val.js", 12) == 0 ))
            {
                char i,ii;
                char _buf[3];
                char cl;

                for(i=0; i<33; i++)
                {
                    sprintf(_buf,"%i;",ebuff[i]);
                    cl = strlen(_buf);
                    for(ii=0; ii<cl; ii++)
                        *((data_val_js)+ 0x42+(i*12)+ii) = _buf[ii];

                }
                pbuf_free(p);

                fs_open("/val.js", &file);

                hs->file = file.data;
                hs->left = file.len;

                send_data(pcb, hs);
                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                tcp_sent(pcb, http_sent);
                /*
                pbuf_free(p);

                fs_open("/foot.html", &file);

                hs->file = file.data;
                hs->left = file.len;

                send_data(pcb, hs);

                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                // tcp_sent(pcb, http_sent);
            }
            else if (strncmp(data, "GET /method=get", 15) == 0)
            {
                i = 16;
                // out_off(d7);
                //onmousedown
                //onmouseup
                if (data[18] == 0x6C /* l */)
                {
                    i=21;
                    //ET-STM32F ARM KIT Hardware Board
                    if(data[i]==0x31 /* 1 */)
                    {
                        out_toggle_s(k0);
                        //leds[0] = 1;
                    }

                    else if(data[i]==0x32 /* 2 */)
                    {
                        out_toggle_s(k1);
                        //leds[1] = 1;
                    }

                    else if(data[i]==0x33 /* 3 */)
                    {
                        out_toggle_s(k2);
                        //leds[2] = 1;
                    }

                    else if(data[i]==0x34 /* 4 */)
                    {
                        out_toggle_s(k3);
                        //leds[3] = 1;
                    }
                    else if(data[i]==0x35 /* 5 */)
                    {
                        out_toggle_s(k4);
                        //out_toggle(k4);
                    }
                    else if(data[i]==0x36 /* 6 */)
                    {
                        out_toggle_s(k5);
                        //out_toggle(k5);
                    }
                    else  if(data[i]==0x37 /* 7 */)
                    {

                        outpp(0x00);
                    }
                    else if(data[i]==0x38 /* 8 */)
                    {
                        if(start==1)
                        {
                            start = 3;
                        }
                        else
                        {
                            start = 5;

                        }
                    }
                    else if(data[i]==0x39 /* 8 */)
                    {
                        if(data[i+1]==0x30)
                        {
                            ebuff[33] += 1;
                        }
                        else if(data[i+1]==0x31)
                        {
                            ebuff[33] -= 1;
                        }
                        else if(data[i+1]==0x32)
                        {
                            ebuff[34] += 1;
                        }
                        else if(data[i+1]==0x33)
                        {
                            ebuff[34] -= 1;
                        }
                        eemodes = 10;
                    }
                    pbuf_free(p);
                    fs_open("/valt.css", &file);

                }

                else if (data[15] == 0x25/* % */)
                {
                    i=18;
                    if (data[i] == 0x03a /* : */)
                    {

                        char delims[] = ":";
                        char *result = NULL;

                        unsigned char ci,cl,cf,bci;
                        char bv;
                        ci=0;
                        bci=0;
                        result = strtok( data, delims );
                        while( result != NULL ) {
                            if(bci!=0)
                            {
                                bv=0;
                                cl = strlen(result);
                                bv = atoi(result);
                                ebuff[ci] = bv;
                                ci++;

                            }
                            if(ci==33)	break;
                            result = strtok( NULL, delims );
                            bci++;
                        }

                        eemodes=10;
                        pbuf_free(p);
                        //fs_open("/ind.html", &file);
                    }
                    else pbuf_free(p);
                }
                else
                {
                    pbuf_free(p);

                    // fs_open("/valt.css", &file);
                }
                hs->file = file.data;
                hs->left = file.len;

                send_data(pcb, hs);

                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                tcp_sent(pcb, http_sent);
            }
            else if (strncmp(data, "GET ", 4) == 0)
            {
                for (i = 0; i < 40; i++)
                {
                    if (((char *)data + 4)[i] == ' ' ||
                            ((char *)data + 4)[i] == '\r' ||
                            ((char *)data + 4)[i] == '\n')
                    {
                        ((char *)data + 4)[i] = 0;
                    }
                }

                i = 0;
                j = 0;

                do
                {
                    fname[i] = ((char *)data + 4)[j];
                    j++;
                    i++;
                } while (fname[i - 1] != 0 && i < 40);

                pbuf_free(p);

                if (!fs_open(fname, &file))
                {
                    fs_open("/index.html", &file);
                }
                hs->file = file.data;
                hs->left = file.len;

                send_data(pcb, hs);

                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                tcp_sent(pcb, http_sent);
            }
            else if(strncmp(data, "POST ", 5) == 0)
            {
                pdata = data;
                for (i = 0; i < 40; i++)
                {
                    if (((char *)data + 5)[i] == ' ' ||
                            ((char *)data + 5)[i] == '\r' ||
                            ((char *)data + 5)[i] == '\n')
                    {
                        ((char *)data + 5)[i] = 0;
                    }
                }

                i = 0;
                j = 0;

                do
                {
                    fname[i] = ((char *)data + 5)[j];
                    j++;
                    i++;
                } while (fname[i - 1] != 0 && i < 40 && fname[i - 1] != 20);

                pbuf_free(p);

                if (!fs_open(fname, &file))
                {
                    // *((data_foot_html)+ 0xa2) = 0x30 + Digit3; /* ADC value 3rd digit*/

                    //post_svs(pdata);
                    fs_open("/index.html", &file);
                }

                /*
                strcat(file.data, hs->file);
                file.data = file.data;
                file.len = strlen(file.data);
                */
                hs->file = file.data;
                hs->left = file.len;

                send_data(pcb, hs);

                /* Tell TCP that we wish be to informed of data that has been
                   successfully sent by a call to the http_sent() function. */
                tcp_sent(pcb, http_sent);

            }
            else
            {
                close_conn(pcb, hs);
            }
        }
        else
        {
            pbuf_free(p);
        }
    }

    if (err == ERR_OK && p == NULL)
    {

        close_conn(pcb, hs);
    }

    return ERR_OK;
}
Example #2
0
void outputmsg(const msgblk_t * blk)
{
    acarsmsg_t msg;
    int i, k;

    /* fill msg struct */
    msg.lvl = blk->lvl;
    msg.err = blk->err;

    k = 0;
    msg.mode = blk->txt[k];
    k++;

    for (i = 0; i < 7; i++, k++) {
        msg.addr[i] = blk->txt[k];
    }
    msg.addr[7] = '\0';

    /* ACK/NAK */
    msg.ack = blk->txt[k];
    k++;

    msg.label[0] = blk->txt[k];
    k++;
    msg.label[1] = blk->txt[k];
    k++;
    msg.label[2] = '\0';

    msg.bid = blk->txt[k];
    if (msg.bid == 0)
        msg.bid = ' ';
    k++;

    /* txt start  */
    msg.bs = blk->txt[k];
    k++;

    msg.no[0] = '\0';
    msg.fid[0] = '\0';
    msg.txt[0] = '\0';

    if ((msg.bs == 0x03 || msg.mode > 'Z' || msg.bid > '9') && airflt)
        return;

    if (msg.bs != 0x03) {
        if (msg.mode <= 'Z' && msg.bid <= '9') {
            /* message no */
            for (i = 0; i < 4 && k < blk->len - 1; i++, k++) {
                msg.no[i] = blk->txt[k];
            }
            msg.no[i] = '\0';

            /* Flight id */
            for (i = 0; i < 6 && k < blk->len - 1; i++, k++) {
                msg.fid[i] = blk->txt[k];
            }
            msg.fid[i] = '\0';
        }

        /* Message txt */
        for (i = 0; k < blk->len - 1; i++, k++)
            msg.txt[i] = blk->txt[k];
        msg.txt[i] = 0;
    }

    /* txt end */
    msg.be = blk->txt[blk->len - 1];

    switch (outtype) {
    case 1:
        twiddle(&msg);
        printoneline(&msg, blk->chn, blk->tm);
        break;
    case 2:
        /* printmsg wants it un-twiddled */
        printmsg(&msg, blk->chn, blk->tm);
        twiddle(&msg);
        break;
    default:
        twiddle(&msg);
        break;
    }

    if (sockfd > 0) {
        if (netout == 0)
            outpp(&msg);
        else
            outsv(&msg, blk->chn, blk->tm);
    }
}