* SerialWifiInterface: misc tidy-ups
This commit is contained in:
@@ -194,8 +194,7 @@ build_flags =
|
|||||||
${Heltec_lora32_v3.build_flags}
|
${Heltec_lora32_v3.build_flags}
|
||||||
-D MAX_CONTACTS=100
|
-D MAX_CONTACTS=100
|
||||||
-D MAX_GROUP_CHANNELS=1
|
-D MAX_GROUP_CHANNELS=1
|
||||||
-D BLE_PIN_CODE=123456
|
-D WIFI_DEBUG_LOGGING=1
|
||||||
-D BLE_DEBUG_LOGGING=1
|
|
||||||
-D WIFI_SSID="\"myssid\""
|
-D WIFI_SSID="\"myssid\""
|
||||||
-D WIFI_PWD="\"mypwd\""
|
-D WIFI_PWD="\"mypwd\""
|
||||||
; -D ENABLE_PRIVATE_KEY_IMPORT=1
|
; -D ENABLE_PRIVATE_KEY_IMPORT=1
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ void SerialWifiInterface::disable() {
|
|||||||
|
|
||||||
size_t SerialWifiInterface::writeFrame(const uint8_t src[], size_t len) {
|
size_t SerialWifiInterface::writeFrame(const uint8_t src[], size_t len) {
|
||||||
if (len > MAX_FRAME_SIZE) {
|
if (len > MAX_FRAME_SIZE) {
|
||||||
Serial.printf("writeFrame(), frame too big, len=%d\n", len);
|
WIFI_DEBUG_PRINTLN("writeFrame(), frame too big, len=%d\n", len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceConnected && len > 0) {
|
if (deviceConnected && len > 0) {
|
||||||
if (send_queue_len >= FRAME_QUEUE_SIZE) {
|
if (send_queue_len >= FRAME_QUEUE_SIZE) {
|
||||||
Serial.println("writeFrame(), send_queue is full!");
|
WIFI_DEBUG_PRINTLN("writeFrame(), send_queue is full!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,27 +39,22 @@ size_t SerialWifiInterface::writeFrame(const uint8_t src[], size_t len) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SER_WRITE_MIN_INTERVAL 0
|
|
||||||
|
|
||||||
bool SerialWifiInterface::isWriteBusy() const {
|
bool SerialWifiInterface::isWriteBusy() const {
|
||||||
return millis() < _last_write + SER_WRITE_MIN_INTERVAL; // still too soon to start another write?
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
|
size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
|
||||||
if (isWriteBusy())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!client) client = server.available();
|
if (!client) client = server.available();
|
||||||
|
|
||||||
if (client.connected()) {
|
if (client.connected()) {
|
||||||
if (!deviceConnected) {
|
if (!deviceConnected) {
|
||||||
Serial.println("Got connexion");
|
WIFI_DEBUG_PRINTLN("Got connection");
|
||||||
deviceConnected = true;
|
deviceConnected = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (deviceConnected) {
|
if (deviceConnected) {
|
||||||
deviceConnected = false;
|
deviceConnected = false;
|
||||||
Serial.println("Disconnected");
|
WIFI_DEBUG_PRINTLN("Disconnected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
class SerialWifiInterface : public BaseSerialInterface {
|
class SerialWifiInterface : public BaseSerialInterface {
|
||||||
bool deviceConnected;
|
bool deviceConnected;
|
||||||
bool _isEnabled;
|
bool _isEnabled;
|
||||||
uint32_t _pin_code;
|
|
||||||
unsigned long _last_write;
|
unsigned long _last_write;
|
||||||
unsigned long adv_restart_time;
|
unsigned long adv_restart_time;
|
||||||
|
|
||||||
@@ -49,3 +48,12 @@ public:
|
|||||||
size_t writeFrame(const uint8_t src[], size_t len) override;
|
size_t writeFrame(const uint8_t src[], size_t len) override;
|
||||||
size_t checkRecvFrame(uint8_t dest[]) override;
|
size_t checkRecvFrame(uint8_t dest[]) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if WIFI_DEBUG_LOGGING && ARDUINO
|
||||||
|
#include <Arduino.h>
|
||||||
|
#define WIFI_DEBUG_PRINT(F, ...) Serial.printf("WiFi: " F, ##__VA_ARGS__)
|
||||||
|
#define WIFI_DEBUG_PRINTLN(F, ...) Serial.printf("WiFi: " F "\n", ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define WIFI_DEBUG_PRINT(...) {}
|
||||||
|
#define WIFI_DEBUG_PRINTLN(...) {}
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user