Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed
Fork of SKM_SERWER_WWW by
Revision 2:8d5a84fcf90c, committed 2017-11-13
- Comitter:
- barti19941
- Date:
- Mon Nov 13 17:06:43 2017 +0000
- Parent:
- 1:623f51ea713b
- Child:
- 3:c05bbec8d96b
- Commit message:
- v1.0
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Mon Nov 13 17:06:43 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#5887ae6c0c2c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Mon Nov 13 17:06:43 2017 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
--- a/main.cpp Mon Feb 23 15:57:49 2015 +0000
+++ b/main.cpp Mon Nov 13 17:06:43 2017 +0000
@@ -1,44 +1,112 @@
#include "mbed.h"
-//Simple program allowing user to send messages from mbed COM out through UART to another UART COM.
-//Andrea Corrado
-//Updated 2015/02/23 Eric Gowland - Process on line termination.
+#include "EthernetInterface.h"
+#include "SDFileSystem.h"
+#include <string.h>
+#include <stdio.h>
+#define PORT 80
-Serial pc(USBTX, USBRX); // tx, rx
-Serial uart (PTC17, PTC16);
+const char *ip = "192.168.3.2";
+const char *mask = "255.255.255.0";
+const char *gateway = "192.168.3.2";
-char* PARSE_TRIGGERS = "\r\n";
-int PARSE_TRIGGERS_LENGTH = 2;
-int MAX_BUFFER_SIZE = 128;
+Serial pc(USBTX, USBRX);
+EthernetInterface eth; //uchwyt do Ethernet
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //inicjalizacja karty SD (MOSI,MISO,SCK,CS)
+TCPSocketConnection client;
+TCPSocketServer svr;
-bool isTriggerChar(char c);
+bool server_is_listened = false;
+bool client_is_connected = false;
-int main() {
- char buffer[MAX_BUFFER_SIZE];
- int pos = 0;
- char thisChar = 0;
- while(1) {
- if (pc.readable()) {
- thisChar = pc.getc();
- //Echo
- pc.putc(thisChar);
- //Buffer
- buffer[pos++] = thisChar;
- //If trigger or buffer overflow, output and reset buffer...
- if(pos >= MAX_BUFFER_SIZE || isTriggerChar(thisChar)) {
- pc.printf("\r\n");
- uart.printf("%.*s\r\n", pos, buffer);
- pos = 0;
+void Send_Data_From_SD()
+{
+ int i = 0;
+ const char *index = "/sd/www/index.html";
+ //const char *style = "/sd/www/style.css";
+ //const char *alien = "/sd/www/img/alien.jpg";
+ //const char *forrest = "/sd/www/img/forrest.jpg";
+ char send_char[1];
+ FILE *fp = fopen(index, "r");
+ while (1)
+ {
+ if (fgets(send_char,1, fp) == NULL) break;
+ client.send(send_char, 1); //przerobic na get line
+ i++;
+ }
+ fclose(fp);
+ /*
+ fp = fopen(style, "r");
+ while (fread(&send_char, sizeof(char), 1, fp) == 1) {
+ client.send(&send_char, 1);
+ }
+ fclose(fp);
+ fp = fopen(alien, "r");
+ while (fread(&send_char, sizeof(char), 1, fp) == 1) {
+ client.send(&send_char, 1);
+ }
+ fclose(fp);
+ fp = fopen(forrest, "r");
+ while (fread(&send_char, sizeof(char), 1, fp) == 1) {
+ client.send(&send_char, 1);
+ }
+ fclose(fp);
+ */
+ client_is_connected = false;
+
+}
+void Initialize_Server(void)
+{
+ eth.init(ip,mask,gateway); //inicjalizacja ethernet, statyczny adres ip
+ eth.connect(); //wlaczenie interfejsu
+ printf("Zainicjowano Ethernet! \n");
+ printf("Adres IP: %s\n",eth.getIPAddress());
+ printf("Maska: %s\n",eth.getNetworkMask());
+ printf("Brama: %s\n",eth.getGateway());
+ printf("Adres MAC urzadzenia: %s\n",eth.getMACAddress());
+ if (svr.bind(PORT) < 0)
+ {
+ printf("Nie udalo sie powiazac serwera TCP z portem 80 (HTTP)! \n");
+ return;
+ }
+ else
+ {
+ printf("Powiazano serwer TCP z portem 80 (HTTP). \n");
+ server_is_listened = true;
+ }
+
+ if (svr.listen(1) < 0)
+ {
+ printf("Nie udalo sie rozpoczac nasluchiwania polaczen przychodzacych serwera TCP! \n");
+ return;
+ }
+ else
+ {
+ printf("Serwer TCP rozpoczal nasluchiwanie polaczen przychodzacych. \n");
+ }
+}
+
+int main()
+{
+ pc.baud(9600);
+ printf("Zainicjowano UART! \n");
+ printf("Predkosc bitowa transmisji - 9600b/s.\n");
+ Initialize_Server();
+ while (server_is_listened) {
+ if (svr.accept(client))
+ {
+ printf("Nie udalo sie zaakceptowac polaczenia z klientem! \n");
+ }
+ else
+ {
+ printf("Polaczono z klientem. IP klienta: %s\n", client.get_address());
+ client_is_connected = true;
+ while (client_is_connected)
+ {
+ Send_Data_From_SD();
}
+ client.close();
+ printf("Wyslano dane do klienta i rozlaczono sesje. \n");
}
}
}
-
-bool isTriggerChar(char c) {
- for (int i = 0; i < PARSE_TRIGGERS_LENGTH; i++) {
- if(c == PARSE_TRIGGERS[i]) {
- return true;
- }
- }
- return false;
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon Nov 13 17:06:43 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#631c0f1008c3
--- a/mbed.bld Mon Feb 23 15:57:49 2015 +0000 +++ b/mbed.bld Mon Nov 13 17:06:43 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
