OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [source/] [user_design.c] - Diff between revs 3 and 4

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 4
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//  CHIPS-2.0 USER DESIGN
//  CHIPS-2.0 USER DESIGN
//
//
//  :Author: Jonathan P Dawson
//  :Author: Jonathan P Dawson
//  :Date: 17/10/2013
//  :Date: 17/10/2013
//  :email: chips@jondawson.org.uk
//  :email: chips@jondawson.org.uk
//  :license: MIT
//  :license: MIT
//  :Copyright: Copyright (C) Jonathan P Dawson 2013
//  :Copyright: Copyright (C) Jonathan P Dawson 2013
//
//
//  Simple web app demo.
//  Simple web app demo.
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
 
 
void put_socket(unsigned i){
void put_socket(unsigned i){
        output_socket(i);
        output_socket(i);
}
}
void stdout_put_char(unsigned i){
void stdout_put_char(unsigned i){
        output_rs232_tx(i);
        output_rs232_tx(i);
}
}
 
 
#include "print.h"
#include "print.h"
#include "HTTP.h"
#include "HTTP.h"
 
 
int find(unsigned string[], unsigned search, unsigned start, unsigned end){
int find(unsigned string[], unsigned search, unsigned start, unsigned end){
        int value = start;
        int value = start;
        while(string[value]){
        while(string[value]){
               print_decimal(string[value]); print_string("\n");
               print_decimal(string[value]); print_string("\n");
               print_decimal(value); print_string("\n");
               print_decimal(value); print_string("\n");
               if(value == end) return -1;
               if(value == end) return -1;
               if(string[value] == search) return value;
               if(string[value] == search) return value;
               value++;
               value++;
        }
        }
        return -1;
        return -1;
}
}
 
 
void user_design()
void user_design()
{
{
        //simple echo application
        //simple echo application
        unsigned length;
        unsigned length;
        unsigned i, index;
        unsigned i, index;
        unsigned data[1460];
        unsigned data[1460];
        unsigned word;
        unsigned word;
        unsigned switches = 0;
        unsigned switches = 0;
        unsigned buttons = 0;
        unsigned buttons = 0;
        unsigned leds = 0;
        unsigned leds = 0;
        unsigned start, end;
        unsigned start, end;
 
 
        unsigned page[] =
        unsigned page[] =
"<html>\
"<html>\
<head>\
<head>\
<title>Chips-2.0 ATLYS Demo</title>\
<title>Chips-2.0 ATLYS Demo</title>\
</head>\
</head>\
<body>\
<body>\
<h1>Chips-2.0 ATLYS Demo</h1>\
<h1>Chips-2.0 ATLYS Demo</h1>\
<p>Welcome to the Chips-2.0 ATLYS Demo!</p>\
<p>Welcome to the Chips-2.0 ATLYS Demo!</p>\
<p>Switch Status: 00000000</p>\
<p>Switch Status: 00000000</p>\
<p>Button Status: 0000</p>\
<p>Button Status: 0000</p>\
<form>\
<form>\
        <input type=\"checkbox\" name=\"led1\" value=\"A\">led 0</input>\
        <input type=\"checkbox\" name=\"led1\" value=\"A\">led 0</input>\
        <input type=\"checkbox\" name=\"led2\" value=\"B\">led 1</input>\
        <input type=\"checkbox\" name=\"led2\" value=\"B\">led 1</input>\
        <input type=\"checkbox\" name=\"led3\" value=\"C\">led 2</input>\
        <input type=\"checkbox\" name=\"led3\" value=\"C\">led 2</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"D\">led 3</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"D\">led 3</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"E\">led 4</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"E\">led 4</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"F\">led 5</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"F\">led 5</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"G\">led 6</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"G\">led 6</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"H\">led 7</input>\
        <input type=\"checkbox\" name=\"led4\" value=\"H\">led 7</input>\
        <button type=\"sumbit\" value=\"Submit\">Update LEDs</button>\
        <button type=\"sumbit\" value=\"Submit\">Update LEDs</button>\
</form>\
</form>\
<p>This <a href=\"https://github.com/dawsonjon/Chips-Demo\">project</a>\
<p>This <a href=\"https://github.com/dawsonjon/Chips-Demo\">project</a>\
 is powered by <a href=\"https://github.com/dawsonjon/Chips-2.0\">Chips-2.0</a>.</p>\
 is powered by <a href=\"http:pyandchips.org\">Chips-2.0</a>.</p>\
</body>\
</body>\
</html>";
</html>";
 
 
        print_string("Welcome to the Atlys Chips-2.0 demo!\n");
        print_string("Welcome to the Atlys Chips-2.0 demo!\n");
        print_string("Connect your web browser to 192.168.1.1\n");
        print_string("Connect your web browser to 192.168.1.1\n");
        while(1){
        while(1){
 
 
                length = input_socket();
                length = input_socket();
                index = 0;
                index = 0;
                for(i=0;i<length;i+=2){
                for(i=0;i<length;i+=2){
                        word = input_socket();
                        word = input_socket();
                        data[index] = (word >> 8) & 0xff;
                        data[index] = (word >> 8) & 0xff;
                        index++;
                        index++;
                        data[index] = (word) & 0xff;
                        data[index] = (word) & 0xff;
                        index++;
                        index++;
                }
                }
 
 
                //Get LED values
                //Get LED values
                //==============
                //==============
 
 
                if(   data[0] == 'G'
                if(   data[0] == 'G'
                   && data[1] == 'E'
                   && data[1] == 'E'
                   && data[2] == 'T'
                   && data[2] == 'T'
                   && data[3] == ' '
                   && data[3] == ' '
                   && data[4] == '/'
                   && data[4] == '/'
                   && (data[5] == '?' || data[5] == ' ')){
                   && (data[5] == '?' || data[5] == ' ')){
                        start=5;
                        start=5;
                        end=find(data, ' ', start, index);
                        end=find(data, ' ', start, index);
                        leds = 0;
                        leds = 0;
                        if(find(data, 'A', start, end) != -1) leds |= 1;
                        if(find(data, 'A', start, end) != -1) leds |= 1;
                        if(find(data, 'B', start, end) != -1) leds |= 2;
                        if(find(data, 'B', start, end) != -1) leds |= 2;
                        if(find(data, 'C', start, end) != -1) leds |= 4;
                        if(find(data, 'C', start, end) != -1) leds |= 4;
                        if(find(data, 'D', start, end) != -1) leds |= 8;
                        if(find(data, 'D', start, end) != -1) leds |= 8;
                        if(find(data, 'E', start, end) != -1) leds |= 16;
                        if(find(data, 'E', start, end) != -1) leds |= 16;
                        if(find(data, 'F', start, end) != -1) leds |= 32;
                        if(find(data, 'F', start, end) != -1) leds |= 32;
                        if(find(data, 'G', start, end) != -1) leds |= 64;
                        if(find(data, 'G', start, end) != -1) leds |= 64;
                        if(find(data, 'H', start, end) != -1) leds |= 128;
                        if(find(data, 'H', start, end) != -1) leds |= 128;
                        output_leds(leds);
                        output_leds(leds);
 
 
                        //read switch values
                        //read switch values
                        //==================
                        //==================
                        switches = ~input_switches();
                        switches = ~input_switches();
                        //find first ':'
                        //find first ':'
                        index = find(page, ':', 0, 1460);
                        index = find(page, ':', 0, 1460);
                        index+=2;
                        index+=2;
                        //insert switch values
                        //insert switch values
                        if(switches & 128) page[index] = '0';
                        if(switches & 128) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(switches & 64) page[index] = '0';
                        if(switches & 64) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(switches & 32) page[index] = '0';
                        if(switches & 32) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(switches & 16) page[index] = '0';
                        if(switches & 16) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(switches & 8) page[index] = '0';
                        if(switches & 8) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(switches & 4) page[index] = '0';
                        if(switches & 4) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(switches & 2) page[index] = '0';
                        if(switches & 2) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(switches & 1) page[index] = '0';
                        if(switches & 1) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
 
 
                        //read button values
                        //read button values
                        //==================
                        //==================
                        buttons = ~input_buttons();
                        buttons = ~input_buttons();
                        //find next ':'
                        //find next ':'
                        index = find(page, ':', index+1, 1460);
                        index = find(page, ':', index+1, 1460);
                        index+=2;
                        index+=2;
                        //insert button values
                        //insert button values
                        if(buttons & 1) page[index] = '0';
                        if(buttons & 1) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(buttons & 2) page[index] = '0';
                        if(buttons & 2) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(buttons & 4) page[index] = '0';
                        if(buttons & 4) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
                        index ++;
                        index ++;
                        if(buttons & 8) page[index] = '0';
                        if(buttons & 8) page[index] = '0';
                        else page[index] = '1';
                        else page[index] = '1';
 
 
                        HTTP_OK(page);
                        HTTP_OK(page);
                } else {
                } else {
                        HTTP_Not_Found();
                        HTTP_Not_Found();
                }
                }
 
 
        }
        }
 
 
        //dummy access to peripherals
        //dummy access to peripherals
        index = input_rs232_rx();
        index = input_rs232_rx();
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.