mirror of
https://github.com/Show-maket/EthernetMaket.git
synced 2025-05-04 07:10:18 +00:00
small upd
This commit is contained in:
parent
e6f2883584
commit
a642e913ed
@ -40,7 +40,11 @@ void onSend(){
|
||||
#define TEST_1
|
||||
// #define TEST_2
|
||||
|
||||
|
||||
class VAR {
|
||||
public:
|
||||
uint16_t var = 1337;
|
||||
};
|
||||
VAR vvv;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -55,8 +59,12 @@ void setup()
|
||||
// Ethernet.setRtCount(3);
|
||||
|
||||
// client.setNoDelayedACK(true); // Не ждать ответа от сервера
|
||||
|
||||
client.setOnSendSuccess(onSend);
|
||||
|
||||
// client.setOnSendSuccess(onSend);
|
||||
client.setOnSendSuccess(std::bind([](VAR* bind_vvv){
|
||||
Serial.print("Sending Successfully: ");
|
||||
Serial.println(bind_vvv->var++);
|
||||
}, &vvv));
|
||||
}
|
||||
|
||||
#ifdef TEST_2
|
||||
@ -120,4 +128,41 @@ void loop()
|
||||
dataReady = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(client.available()>0){
|
||||
byte response[16];
|
||||
int len = client.read(response, sizeof(response));
|
||||
|
||||
if (len == 16)
|
||||
{
|
||||
// Проверка контрольной суммы
|
||||
uint8_t checksum = 0;
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
checksum += response[i];
|
||||
}
|
||||
|
||||
Serial.print("RX: ");
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Serial.print(response[i], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
|
||||
if (response[15] == checksum)
|
||||
{
|
||||
Serial.println("Checksum is OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Checksum is ERROR");
|
||||
}
|
||||
client.activityUpdate(); // Обновляем время последней активности
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Received an incomplete response");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -212,44 +212,12 @@ void EthernetMaketClient::tick_(){
|
||||
}
|
||||
//********************************************************
|
||||
|
||||
//? Проверка наличия доступных данных от сервера
|
||||
if (available() > 0)
|
||||
{
|
||||
byte response[16];
|
||||
int len = read(response, sizeof(response));
|
||||
|
||||
if (len == 16)
|
||||
{
|
||||
// Проверка контрольной суммы
|
||||
uint8_t checksum = 0;
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
checksum += response[i];
|
||||
}
|
||||
|
||||
Serial.print("RX: ");
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Serial.print(response[i], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
|
||||
if (response[15] == checksum)
|
||||
{
|
||||
Serial.println("Checksum is OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Checksum is ERROR");
|
||||
}
|
||||
lastActivityTime = millis(); // Обновляем время последней активности
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Received an incomplete response");
|
||||
}
|
||||
}
|
||||
//? -------------------------------------------------
|
||||
// //? Проверка наличия доступных данных от сервера
|
||||
// if (available() > 0)
|
||||
// {
|
||||
|
||||
// }
|
||||
// //? -------------------------------------------------
|
||||
}
|
||||
|
||||
bool EthernetMaketClient::dataWrite(){
|
||||
@ -330,3 +298,34 @@ void EthernetMaketClient::startConnection(IPAddress ip, uint16_t port, bool nonB
|
||||
isNonBlocking = nonBlock;
|
||||
connectStatus = CONNECT_START;
|
||||
};
|
||||
|
||||
void EthernetMaketClient::activityUpdate(){
|
||||
lastActivityTime = millis();
|
||||
}
|
||||
|
||||
EthernetMaketClient& EthernetMaketClient::operator=(const EthernetMaketClient& other) {
|
||||
if (this == &other) {
|
||||
return *this; // Защита от самоприсваивания
|
||||
}
|
||||
|
||||
// Копируем все данные
|
||||
this->lastActivityTime = other.lastActivityTime;
|
||||
this->startConnectionTime = other.startConnectionTime;
|
||||
this->stopStartTime = other.stopStartTime;
|
||||
this->isNonBlocking = other.isNonBlocking;
|
||||
this->connectStatus = other.connectStatus;
|
||||
// this->timeout = other.timeout;
|
||||
// this->connectionTimeout = other.connectionTimeout;
|
||||
// this->stopTimeout = other.stopTimeout;
|
||||
this->dstIP = other.dstIP;
|
||||
this->dstPort = other.dstPort;
|
||||
this->dataPtr = other.dataPtr;
|
||||
this->dataSize = other.dataSize;
|
||||
this->onSendSuccess = other.onSendSuccess;
|
||||
|
||||
// Отключаем исполнение старого клиента
|
||||
const_cast<EthernetMaketClient&>(other).connectStatus = CONNECT_IDLE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,15 @@ protected:
|
||||
static std::list<EthernetMaketClient*>& getInstances(); // Ленивое создание списка
|
||||
|
||||
void tick_();
|
||||
ConnectionStatusSimple connectStatus = CONNECT_IDLE;
|
||||
|
||||
public:
|
||||
ConnectionStatusSimple connectStatus = CONNECT_IDLE;
|
||||
EthernetMaketClient();
|
||||
EthernetMaketClient(uint8_t sock);
|
||||
~EthernetMaketClient();
|
||||
|
||||
EthernetMaketClient& operator=(const EthernetMaketClient& other);
|
||||
|
||||
ConnectionStatusSimple connectNonBlock(IPAddress ip, uint16_t port);
|
||||
void startConnection(IPAddress ip, uint16_t port, bool nonBlock = true);
|
||||
|
||||
@ -50,6 +52,8 @@ public:
|
||||
|
||||
void setOnSendSuccess(const std::function<void()>& callback);
|
||||
void resetOnSendSuccess();
|
||||
|
||||
void activityUpdate();
|
||||
};
|
||||
|
||||
#endif // __MAKET_TCP_H__
|
||||
|
@ -60,3 +60,7 @@ void EthernetMaketUDP::endPacketNonBlock()
|
||||
void EthernetMaketUDP::tick(){
|
||||
sendUDP_tick(_sock, _status);
|
||||
}
|
||||
|
||||
ConnectionStatusSimple EthernetMaketUDP::getState() const{
|
||||
return _status;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ public:
|
||||
using EthernetUDP::EthernetUDP;
|
||||
void endPacketNonBlock();
|
||||
void tick();
|
||||
ConnectionStatusSimple getState() const;
|
||||
};
|
||||
|
||||
#endif // __MAKET_UDP_H__
|
Loading…
x
Reference in New Issue
Block a user