Skip to content
Snippets Groups Projects
CommsBehaviours.cpp 1.6 KiB
Newer Older
Matthew's avatar
Matthew committed
int SendCapabilities::start(String args) {
        //This is where you do your stuff for a simple behaviour
        _node->announce_capabilities();
        return "SendCapabilities behaviour " + _name;
};

PingServer::PingServer(VizBlocks* node, String name = "PingServer") : Behaviour(name), _node(node) { _background = true; }
Matthew's avatar
Matthew committed
void PingServer::update() {
        if (millis() > (_t+_interval)) {
                _t = millis();
                _node->announce(str);
        }
};
Matthew's avatar
Matthew committed
int PingServer::start(String args) {
        _background = true;
        _running = true;
        _t = millis();
        str = "{\"id\":\"" + String(_node->getId()) + "\",\"PingServer\":{}}";
        _node->announce(str);
        return "Pinging server";
};
Matthew's avatar
Matthew committed
void Link::update() {
        if (millis() > (_t+_timeoutInterval)) {
                String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Unlink\":{\"peerId\":\"" + _peerId + "\"}}";
                _node->announce(str);
                _peerId = "";
                _running = false;
        }
};
Matthew's avatar
Matthew committed
int Link::start(String args) {
        _running = true;
        if (args == name() || args.indexOf(" ")>0) {
                return "Invalid args (" + args + ") in behaviour " + name();
        }
        _t = millis();
        if (args == _peerId) {
                return "Link ping from (" + _peerId + ")";
        }
        _peerId = args;
        String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Link\":{\"peerId\":\"" + _peerId + "\"}}";
        _node->announce(str);
        return "New link with (" + _peerId + ")";
};
char * Link::args() {
        return "<String peerId>";
};