コード例 #1
0
def main(argv):
    if (len(sys.argv) < 6):
        print "Usage: " + sys.argv[0] + " RFM_SEND NODEID CMD P1 P0\n"
        print helpmsg
    else:
        try:
            tt = sys.argv[1]
            cmd = sys.argv[2]
            for i in range(2, len(sys.argv)):
                if ((i == 3) and (not sys.argv[i].isdigit())):
                    cmd = neumonic(sys.argv[3])
                    if (cmd >= 0):
                        tt = tt + " " + str(cmd)
                else:
                    tt = tt + " " + sys.argv[i]

            FULLCMD = tt

            print FULLCMD
            naaradSoc = mysocket()
            naaradSoc.connect(serverinfo.SERVER, serverinfo.PORT)
            naaradSoc.send("open")
            time.sleep(0.1)
            naaradSoc.send(FULLCMD)
            #time.sleep(1);
            naaradSoc.send("done")
            time.sleep(0.1)
            naaradSoc.close()
        except MyException as e:
            print str(e)
コード例 #2
0
def getcpkt(server, port, nodeid):
    CMD = "getcpkt " + str(nodeid)
    soc = mysocket()
    soc.connect(server, port)
    soc.send("getcpkt App")
    soc.send(CMD)
    time.sleep(0.1)
    tt = soc.receive()
    soc.send("done")
    time.sleep(0.1)
    return tt
コード例 #3
0
ファイル: poll-sprinkler.py プロジェクト: sanbee/Naarad
def getpkt(nodeid):
    CMD = "getcpkt " + str(nodeid)
    soc = mysocket()
    soc.connect(SERVER, PORT)
    soc.send("open")
    time.sleep(0.1)
    soc.send(CMD)
    time.sleep(1)
    tt = soc.receive()
    soc.send("done")
    time.sleep(0.1)
    return tt
コード例 #4
0
ファイル: sendcmd.py プロジェクト: sanbee/Naarad
def main(argv):
    if (len(sys.argv) < 2):
        print("Usage: cmd")
    else:
        CMD = sys.argv[1]
        if (CMD == "shutdown"):
            if (not isYes("shutdown server at " + serverinfo.SERVER + "." +
                          " Are you sure?")):
                return

        naaradSoc = mysocket()
        naaradSoc.connect(serverinfo.SERVER, serverinfo.PORT)
        naaradSoc.send("sendcmd App")
        naaradSoc.send(CMD)
        time.sleep(0.1)
        naaradSoc.send("done")
        naaradSoc.close()
コード例 #5
0
def gethpkt(server, port, nodeid):
    soc = mysocket()
    soc.connect(server, port)
    soc.send("open")
    time.sleep(0.1)
    for i in range(len(nodeid)):
        CMD = "gethpkt " + str(nodeid[i])
        soc.send(CMD)
        time.sleep(0.1)
        tt = ''
        while (tt != "PHINISHED"):
            val = soc.receive()
            print val
            tt = val.split()[0]

    soc.send("done")
    time.sleep(0.1)
コード例 #6
0
ファイル: poll.py プロジェクト: sanbee/Naarad
def sendCommand(cmd, polltimeout):
    try:
        nodeID = cmd[1]
        cmdID = cmd[2]
        args = cmd[3] + " " + cmd[4]
        CMD = "RFM_SEND " + str(nodeID) + " " + str(cmdID) + " " + str(args)

        # nodeID=cmd[2];
        # CMD = cmd[1]+" "+cmd[2];
        print(CMD)

        soc = mysocket()

        soc.getSock().settimeout(1.0)
        soc.connect(SERVER, PORT)
        soc.send("open")
        time.sleep(0.1)

        soc.send(CMD)

        for i in range(12):
            try:
                soc.send("getcpkt " + str(nodeID))
                mesg = ""
                mesg = poll(soc, nodeID, 10)
                print(mesg)
                jdict = json.loads(mesg)

                if (isACK(jdict, cmdID, cmd[3])):
                    soc.send("done")
                    time.sleep(0.1)
                    print(mesg)
                    break
                else:
                    sys.stdout.write('o')
                    sys.stdout.flush()
                    time.sleep(polltimeout)
            except socket.timeout as tt:
                print("Attempt " + str(i) + " " + str(tt))

    except socket.error as e:
        if (e.errno == errno.ECONNREFUSED):
            print("socket: Connection refused")
        else:
            print("socket: I/O timed out")
コード例 #7
0
def startServer():
    NAARAD_PORT=1234;
    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
    serversocket.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 );
    serversocket.bind(('localhost', NAARAD_PORT));
    serversocket.listen(2);

    threadID=0;
    while 1:
        fd = select.select([serversocket.fileno()],[],[]);
        (clientsocket, address) = serversocket.accept()
        
        #     #now do something with the clientsocket
        myc1 = mysocket(clientsocket);
        connectionType=myc1.receive().strip();
        print ("connection accepted",address,connectionType);
        msg = myc1.receive();
        print "\'"+msg+"\'";
コード例 #8
0
def notifyNaaradSend(mesg):
    naaradSoc=mysocket();

    naaradSoc.connect(serverinfo.SERVER,serverinfo.PORT);
    naaradSoc.send("notify App");     time.sleep(0.1);
    naaradSoc.send(mesg);       time.sleep(0.1);
    #infopkt=naaradSoc.receive(True); # Do a blocking read
    #print(infopkt);
    packet=naaradSoc.receive(True); # Do a blocking read
    time.sleep(1);
    #naaradSoc.send("done");     time.sleep(1);
    #naaradSoc.close();

    jdict=json.loads(packet);
    
    # "time" is the time-stamp of the arrival of the packet on the server.  "tnot" is the
    # time-stamp when the notification was issued and the packets sent to the client.
    # Both time-stamps use the RTC of the server.
    dt=jdict["tnot"] - jdict['time'];
    return packet,dt;
コード例 #9
0
ファイル: decnotify.py プロジェクト: sanbee/Naarad
def decnotify(argv):
    """
    De-register continuous notification associated with the given UUID.
    """
    if (len(sys.argv) < 2):

        print("\nUsage: " + sys.argv[0] + " UUID\n")
        print(decnotify.__doc__)
    else:
        try:
            uuid = sys.argv[1]

            FULLCMD = "abortcnotify " + str(sys.argv[1])
            print(FULLCMD)

            naaradSoc = mysocket()
            naaradSoc.connect(serverinfo.SERVER, serverinfo.PORT)
            time.sleep(0.1)
            naaradSoc.send("De-cnotify App")
            naaradSoc.send(FULLCMD)
            naaradSoc.send("done")
        except MyException as e:
            print(str(e))
コード例 #10
0
ファイル: cnotify.py プロジェクト: sanbee/Naarad
def notify(argv):
    """
    The function returns a packet received from a NODEID with the
    specified command (CMD) and source (SOURCE).  Specified number of
    re-trails are made if a valid packet is not received within the
    given timeout length of time.

    The argument is a sys.argv styled list of strings.  The first
    string (argv[0]) is typically the name of the script calling this
    function (here, "notify.py").  It is ignored and therefore can be
    any string.  The rest of the strings are in the following order:

       "notify" NODEID CMD SOURCE TIMEOUT nRETRIALS 

    The first argument above (argv[1]) has to be the string "notify".
    NODEID is the node-ID for which notification is sought and is the
    value of the 'node_id' or 'node' fields, whichever is available,
    in the received packet.  CMD and SOURCE are the values of the
    'cmd' and 'source' fields in the received packet both of which
    must match the given values for the packet to be valid for
    notification. TIMEOUT is the length of time in seconds after which
    the socket connection is closed and a fresh trials is made till
    the number of trials exceeds nRETRIALS or a valid packet is
    received.  If the re-trials exceed nRETRIALS or the received
    packet is not valid, the packet JSON string is appended to the
    string "FAILED: " to indicate failure to receive a valid packet in
    the given timeout and re-trail attempts.

    The received packet is marked as valid if the time-stamp in the
    packet is no older than 1.5sec.  The packet as a JSON string and
    the different between the current time and time-stamp in the
    packet are both returned to the caller.
    """
    if (len(sys.argv) < 7):

        print("\nUsage: " + sys.argv[0] +
              " notify NODEID CMD SOURCE TIMEOUT nRETRIALS\n")
        print(notify.__doc__)
    else:
        try:
            naaradcmd = sys.argv[1]
            nodeid = sys.argv[2]
            cmd = sys.argv[3]
            src = str(sys.argv[4])

            FULLCMD = naaradcmd
            for i in range(2, 6):
                FULLCMD = FULLCMD + " " + str(sys.argv[i])

            print(FULLCMD)
            Retry = 0

            naaradSoc = mysocket()
            naaradSoc.connect(serverinfo.SERVER, serverinfo.PORT)
            time.sleep(0.1)
            naaradSoc.send("Cont Notification App")
            time.sleep(0.1)
            naaradSoc.send(FULLCMD)
            infopkt = naaradSoc.receive(True)
            # Do a blocking read
            print(infopkt)

            while True:
                packet = naaradSoc.receive(True)
                # Do a blocking read
                # End of transmission or the notification was
                # de-registered by the server or via abortnotify
                # command.
                if (len(packet) == 0):
                    break

                print(packet)


#            naaradSoc.send("done");
            naaradSoc.close()

        except MyException as e:
            print(str(e))