示例#1
0
        private void processCommandPacket(networkPacket packet)
        {
            // We received a command packet. Authenticate it and then process it.
            commandPacket cmdPkt = new commandPacket(packet);

            log("Packet is a command packet. Decoded packet:");
            log(cmdPkt.ToString());

            // Verify the sequence number
            if (cmdPkt.challengeResponse != p + 1)
            {
                // Bad auth! drop the packet and reset to our first state.
                log("A crypto error has occurred");
                cryptoError();
                stateChange(nodeState.idle);
                return;
            }

            switch (cmdPkt.findCommandByteMeaning())
            {
                case commandByte.unknown:
                    log("Ignoring unknown command");
                    break;
                case commandByte.ping:
                    processPing(cmdPkt);
                    break;
                case commandByte.identify:
                    processIdentify(cmdPkt);
                    break;
                case commandByte.getSensor:
                    processGetSensor(cmdPkt);
                    break;
                case commandByte.setSensor:
                    processSetSensor(cmdPkt);
                    break;
                case commandByte.getSensorType:
                    processGetSensorType(cmdPkt);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }