Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions libraries/WiFiS3/src/Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,22 @@ bool ModemClass::read_by_size_finished(string &rx) {
int pos_space = rx.find(" ");
if(pos != string::npos && pos_space != string::npos) {
string n = rx.substr(pos_space,pos);
/* add 4 because OK\r\n is always added at the end of data */
data_to_be_received = atoi(n.c_str()) + 4;
rx.clear();
data_received = 0;
st = WAIT_FOR_DATA;

int to_be_rx = atoi(n.c_str());
if(to_be_rx <= 0) {
while( _serial->available() ){
_serial->read();
}
rv = true;
first_call = true;
st = IDLE;
}
else {
/* add 4 because OK\r\n is always added at the end of data */
data_to_be_received = to_be_rx + 4;
data_received = 0;
st = WAIT_FOR_DATA;
}
rx.clear();
}
}
break;
Expand Down Expand Up @@ -206,7 +216,12 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
found = true;
read_by_size = false;
res = true;
data_res = data_res.substr(0, data_res.length() - (sizeof(RESULT_OK) - 1));
if(data_res.size() > 0) {
data_res = data_res.substr(0, data_res.length() - (sizeof(RESULT_OK) - 1));
}
else {
break;
}
}
}
else {
Expand Down
15 changes: 10 additions & 5 deletions libraries/WiFiS3/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,22 @@ int WiFiClient::_read() {
modem.read_using_size();

if(modem.write(string(PROMPT(_CLIENTRECEIVE)),res, "%s%d,%d\r\n" , CMD_WRITE(_CLIENTRECEIVE), _sock, size)) {
for(int i = 0, rv = 0; i < size && i < res.size(); i++) {
rx_buffer->store((uint8_t)res[i]);
rv++;
if(res.size() > 0) {
for(int i = 0, rv = 0; i < size && i < res.size(); i++) {
rx_buffer->store((uint8_t)res[i]);
rv++;
}
}
else {
rv = 0;
}
}
}
return rv;
}

/* -------------------------------------------------------------------------- */
bool WiFiClient::read_needed(size_t s) {
void WiFiClient::read_if_needed(size_t s) {
/* -------------------------------------------------------------------------- */
if(rx_buffer != nullptr) {
if((size_t)rx_buffer->available() < s) {
Expand All @@ -155,7 +160,7 @@ int WiFiClient::read() {
/* -------------------------------------------------------------------------- */
int WiFiClient::read(uint8_t *buf, size_t size) {
/* -------------------------------------------------------------------------- */
read_needed(size);
read_if_needed(size);
int rv = 0;
bool go_on = true;
if(_sock >= 0 && rx_buffer != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFiS3/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class WiFiClient : public Client {
void getSocket();
std::shared_ptr<FifoBuffer<uint8_t,RX_BUFFER_DIM>> rx_buffer;
int _read();
bool read_needed(size_t s);
void read_if_needed(size_t s);
void clear_buffer();
bool destroy_at_distructor;

Expand Down
15 changes: 10 additions & 5 deletions libraries/WiFiS3/src/WiFiSSLClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,22 @@ int WiFiSSLClient::_read() {
modem.avoid_trim_results();
modem.read_using_size();
if(modem.write(string(PROMPT(_SSLCLIENTRECEIVE)),res, "%s%d,%d\r\n" , CMD_WRITE(_SSLCLIENTRECEIVE), _sock, size)) {
for(int i = 0, rv = 0; i < size && i < res.size(); i++) {
rx_buffer->store((uint8_t)res[i]);
rv++;
if(res.size() > 0) {
for(int i = 0, rv = 0; i < size && i < res.size(); i++) {
rx_buffer->store((uint8_t)res[i]);
rv++;
}
}
else {
rv = 0;
}
}
}
return rv;
}

/* -------------------------------------------------------------------------- */
bool WiFiSSLClient::read_needed(size_t s) {
void WiFiSSLClient::read_if_needed(size_t s) {
/* -------------------------------------------------------------------------- */
if((size_t)rx_buffer->available() < s) {
_read();
Expand All @@ -154,7 +159,7 @@ int WiFiSSLClient::read() {
/* -------------------------------------------------------------------------- */
int WiFiSSLClient::read(uint8_t *buf, size_t size) {
/* -------------------------------------------------------------------------- */
read_needed(size);
read_if_needed(size);
int rv = 0;
bool go_on = true;
for(int i = 0; i < size && go_on; i++) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFiS3/src/WiFiSSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WiFiSSLClient : public WiFiClient {
bool _custom_root = false;
void getSocket();
int _read();
bool read_needed(size_t s);
void read_if_needed(size_t s);

private:
void upload_default_Cert();
Expand Down
15 changes: 10 additions & 5 deletions libraries/WiFiS3/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,22 @@ int WiFiUDP::_read() {
modem.avoid_trim_results();
modem.read_using_size();
if(modem.write(string(PROMPT(_UDPREAD)),res, "%s%d,%d\r\n" , CMD_WRITE(_UDPREAD), _sock, size)) {
for(int i = 0, rv = 0; i < size && i < res.size(); i++) {
rx_buffer.store((uint8_t)res[i]);
rv++;
if(res.size() > 0) {
for(int i = 0, rv = 0; i < size && i < res.size(); i++) {
rx_buffer.store((uint8_t)res[i]);
rv++;
}
}
else {
rv = 0;
}
}
}
return rv;
}

/* -------------------------------------------------------------------------- */
bool WiFiUDP::read_needed(size_t s) {
void WiFiUDP::read_if_needed(size_t s) {
/* -------------------------------------------------------------------------- */
if((size_t)rx_buffer.available() < s) {
_read();
Expand All @@ -210,7 +215,7 @@ int WiFiUDP::read() {
/* -------------------------------------------------------------------------- */
int WiFiUDP::read(unsigned char* buf, size_t size) {
/* -------------------------------------------------------------------------- */
read_needed(size);
read_if_needed(size);
int rv = 0;
bool go_on = true;
for(int i = 0; i < size && go_on; i++) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFiS3/src/WiFiUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WiFiUDP : public UDP {

protected:
virtual int _read();
virtual bool read_needed(size_t s);
virtual void read_if_needed(size_t s);

public:
WiFiUDP(); // Constructor
Expand Down