示例#1
0
        private void processSetSensor(commandPacket cmdPkt)
        {
            log("Packet is a SET_SENSOR command.");

            setSensorPacket req = new setSensorPacket(cmdPkt);

            if (req.sensorToInterrogate == 0 ||
                req.sensorToInterrogate > sensors.Count )
            {
                // TODO: Respond with an error code, as the hardware should
                throw new NotImplementedException();
            }

            // TODO: Check sensor types

            virtualNodeSensor toChange = sensors[req.sensorToInterrogate];
            changeSensor(toChange, req.newValue);
            toChange.setValue(req.newValue);

            challengeResponsePacket resp = new challengeResponsePacket(CSharpNetwork.controllerID, cmdPkt.challengeResponse + 1);

            sendPacket(resp);

            stateChange(nodeState.idle);
        }
示例#2
0
        private void processGetSensor(commandPacket cmdPkt)
        {
            log("Packet is a GET_SENSOR command.");

            getSensorPacket req = new getSensorPacket(cmdPkt);

            challengeResponsePacket resp = new challengeResponsePacket(CSharpNetwork.controllerID, cmdPkt.challengeResponse + 1);

            if (req.isGetSensorCount)
            {
                log("Packet is requesting sensor count");
                resp.payload = sensors.Count;
            }
            else
            {
                // Find the value we wish to send, and set it in our packet
                resp.payload = sensors[req.sensorToInterrogate].getVal();
            }

            sendPacket(resp);
            stateChange(nodeState.idle);
        }