master
iotcat 5 years ago
parent 1dd8d62bae
commit 872df4332e
  1. 16
      lora-socket.h

@ -30,16 +30,19 @@ class LoRaSocket {
static void udp(const String& msg, const String& to = "0.0.0.0"); static void udp(const String& msg, const String& to = "0.0.0.0");
static void tcp(const String& msg, const String& to); static void tcp(const String& msg, const String& to);
static void rtcp(const String& msg); static void rtcp(const String& msg);
inline static void onReceived(void (*f)(String, String, String, String)){
static void onReceived(const String& msg, const String& from, const String& to, const String& type){ _f = f;
Serial.println(msg);
}; };
private: private:
static StringVec tcp_sendingStack, tcp_receiveStack; static StringVec tcp_sendingStack, tcp_receiveStack;
static Vector<unsigned int> tcp_sendingTryTimes; static Vector<unsigned int> tcp_sendingTryTimes;
/* LoRa Functions */ static void(*_f)(String, String, String, String);
inline static void _onReceived(const String& msg, const String& from, const String& to, const String& type){
(*_f)(msg, from, to, type);
};
/* LoRa Functions */
static void LoRa_tx_mode(); static void LoRa_tx_mode();
static void LoRa_rx_mode(); static void LoRa_rx_mode();
static void send(const String& s); static void send(const String& s);
@ -135,11 +138,11 @@ void LoRaSocket::getMsg(const String& msg){
if(!isGoodPackage(msg)) return; if(!isGoodPackage(msg)) return;
if(getToIP(msg) != LORA_SOCKET_IP && getToIP(msg) != "0.0.0.0") return; if(getToIP(msg) != LORA_SOCKET_IP && getToIP(msg) != "0.0.0.0") return;
if(getType(msg) == "udp") onReceived(getContent(msg), getFromIP(msg), getToIP(msg), "udp"); if(getType(msg) == "udp") _onReceived(getContent(msg), getFromIP(msg), getToIP(msg), "udp");
if(getType(msg) == "tcp"){ if(getType(msg) == "tcp"){
rtcp(msg); rtcp(msg);
if(tcp_receiveStack.Find(msg) != -1) return; if(tcp_receiveStack.Find(msg) != -1) return;
onReceived(getContent(msg), getFromIP(msg), getToIP(msg), "tcp"); _onReceived(getContent(msg), getFromIP(msg), getToIP(msg), "tcp");
receiveStackClassify(); receiveStackClassify();
} }
if(getType(msg) == "rtcp"){ if(getType(msg) == "rtcp"){
@ -174,6 +177,7 @@ void LoRaSocket::rtcp(const String& msg){
StringVec LoRaSocket::tcp_sendingStack, LoRaSocket::tcp_receiveStack; StringVec LoRaSocket::tcp_sendingStack, LoRaSocket::tcp_receiveStack;
Vector<unsigned int> LoRaSocket::tcp_sendingTryTimes; Vector<unsigned int> LoRaSocket::tcp_sendingTryTimes;
void (*LoRaSocket::_f)(String, String, String, String);
void LoRaSocket::ini() { void LoRaSocket::ini() {

Loading…
Cancel
Save