Skip to content

Commit 3187496

Browse files
committed
Merge branch 'esp8266' of https://github.com/ficeto/Arduino into ficeto-esp8266
2 parents 947188e + fdbd40d commit 3187496

File tree

5 files changed

+127
-12
lines changed

5 files changed

+127
-12
lines changed

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_pwm.c

+12-11
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ uint16_t pwm_steps[17];
3333
uint8_t pwm_steps_len = 0;
3434
uint32_t pwm_steps_mask[17];
3535

36-
int pwm_sort_asc(const void* a, const void* b){
37-
return (*((uint16_t*)a) > *((uint16_t*)b)) - (*((uint16_t*)a) < *((uint16_t*)b));
38-
}
39-
4036
int pwm_sort_array(uint16_t a[], uint16_t al){
41-
qsort(a, al, sizeof(uint16_t), pwm_sort_asc);
42-
int i;
43-
int bl = 1;
44-
for(i = 1; i < al; i++){
45-
if(a[i] != a[i-1]) a[bl++] = a[i];
46-
}
47-
return bl;
37+
uint16_t i, j;
38+
for (i = 1; i < al; i++) {
39+
uint16_t tmp = a[i];
40+
for (j = i; j >= 1 && tmp < a[j-1]; j--)
41+
a[j] = a[j-1];
42+
a[j] = tmp;
43+
}
44+
int bl = 1;
45+
for(i = 1; i < al; i++){
46+
if(a[i] != a[i-1]) a[bl++] = a[i];
47+
}
48+
return bl;
4849
}
4950

5051
uint32_t pwm_get_mask(uint16_t value){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
WiFiTelnetToSerial - Example Transparent UART to Telnet Server for esp8266
3+
4+
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
5+
This file is part of the ESP8266WiFi library for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
#include <ESP8266WiFi.h>
22+
23+
//how many clients should be able to telnet to this ESP8266
24+
#define MAX_SRV_CLIENTS 1
25+
const char* ssid = "**********";
26+
const char* password = "**********";
27+
28+
WiFiServer server(21);
29+
WiFiClient serverClients[MAX_SRV_CLIENTS];
30+
31+
void setup() {
32+
Serial1.begin(115200);
33+
WiFi.begin(ssid, password);
34+
Serial1.print("\nConnecting to "); Serial1.println(ssid);
35+
uint8_t i = 0;
36+
while (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);
37+
if(i == 21){
38+
Serial1.print("Could not connect to"); Serial1.println(ssid);
39+
while(1) delay(500);
40+
}
41+
//start UART and the server
42+
Serial.begin(115200);
43+
server.begin();
44+
server.setNoDelay(true);
45+
46+
Serial1.print("Ready! Use 'telnet ");
47+
Serial1.print(WiFi.localIP());
48+
Serial1.println(" 21' to connect");
49+
}
50+
51+
void loop() {
52+
uint8_t i;
53+
//check if there are any new clients
54+
if (server.hasClient()){
55+
for(i = 0; i < MAX_SRV_CLIENTS; i++){
56+
//find free/disconnected spot
57+
if (!serverClients[i] || !serverClients[i].connected()){
58+
if(serverClients[i]) serverClients[i].stop();
59+
serverClients[i] = server.available();
60+
Serial1.print("New client: "); Serial1.print(i);
61+
continue;
62+
}
63+
}
64+
//no free/disconnected spot so reject
65+
WiFiClient serverClient = server.available();
66+
serverClient.stop();
67+
}
68+
//check clients for data
69+
for(i = 0; i < MAX_SRV_CLIENTS; i++){
70+
if (serverClients[i] && serverClients[i].connected()){
71+
if(serverClients[i].available()){
72+
//get data from the telnet client and push it to the UART
73+
while(serverClients[i].available()) Serial.write(serverClients[i].read());
74+
}
75+
}
76+
}
77+
//check UART for data
78+
if(Serial.available()){
79+
size_t len = Serial.available();
80+
uint8_t sbuf[len];
81+
Serial.readBytes(sbuf, len);
82+
//push UART data to all connected telnet clients
83+
for(i = 0; i < MAX_SRV_CLIENTS; i++){
84+
if (serverClients[i] && serverClients[i].connected()){
85+
serverClients[i].write(sbuf, len);
86+
delay(1);
87+
}
88+
}
89+
}
90+
}

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiServer.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ void WiFiServer::begin()
7373
tcp_arg(listen_pcb, (void*) this);
7474
}
7575

76+
void WiFiServer::setNoDelay(bool nodelay){
77+
if(!_pcb) return;
78+
if(nodelay) tcp_nagle_disable(_pcb);
79+
else tcp_nagle_enable(_pcb);
80+
}
81+
82+
bool WiFiServer::getNoDelay(){
83+
if(!_pcb) return false;
84+
return tcp_nagle_disabled(_pcb);
85+
}
86+
7687
extern "C" uint32_t esp_micros_at_task_start();
7788

7889
bool WiFiServer::hasClient(){

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiServer.h

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class WiFiServer : public Server {
4646
WiFiClient available(uint8_t* status = NULL);
4747
bool hasClient();
4848
void begin();
49+
void setNoDelay(bool nodelay);
50+
bool getNoDelay();
4951
virtual size_t write(uint8_t);
5052
virtual size_t write(const uint8_t *buf, size_t size);
5153
uint8_t status();

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/include/ClientContext.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,18 @@ class ClientContext {
9898
delete this;
9999
}
100100
}
101-
101+
102+
void setNoDelay(bool nodelay){
103+
if(!_pcb) return;
104+
if(nodelay) tcp_nagle_disable(_pcb);
105+
else tcp_nagle_enable(_pcb);
106+
}
107+
108+
bool getNoDelay(){
109+
if(!_pcb) return false;
110+
return tcp_nagle_disabled(_pcb);
111+
}
112+
102113
uint32_t getRemoteAddress() {
103114
if(!_pcb) return 0;
104115

0 commit comments

Comments
 (0)