Beispiel #1
0
 public void queryAnalogChannel(QueryAnalogInputEvent inEvent)
 {
     log.Debug(string.Format("Querying Analog pin {0}", inEvent._pinToQuery));
     sendMessage(inEvent, buildMessage(new List <int> {
         0x03, 0x50, (int)inEvent._pinToQuery
     }));
 }
Beispiel #2
0
        /// <summary>
        /// Looks over the responce received from the device and tries to process it
        ///
        /// Will continue until processing is complete.  This is the same thread that sent the message.
        /// Try to limit processing as much as possible.  May eventually need to have another queue / processing thread.
        /// For now thougn, we keep it simple
        /// </summary>
        /// <param name="inMessageIdentifier">The message type we are sending</param>
        /// <param name="inResponce">The responce we recieved from the device</param>
        private void processResponce(Event inEvent, byte[] inResponce)
        {
            log.Debug(string.Format("Processing responce from message {0}", inEvent.identifier));
            switch (inEvent.identifier)
            {
            case EventIdentifier.ConnectRequest:
                logBytesArray(inResponce);
                if (inResponce.Length == 1 && inResponce[0] == 0x59)
                {
                    log.Debug("Received correct value for pind message");
                    if (deviceDelegate != null)
                    {
                        log.Debug("Sending device connected to the delegate");
                        deviceDelegate.deviceConnected();
                    }
                    if (!_hasStarted)
                    {
                        startSensorThreads();
                        _hasStarted = true;
                    }
                }
                break;

            case EventIdentifier.AnalogPinQueryRequest:
                QueryAnalogInputEvent queryAnalogEvent = (QueryAnalogInputEvent)inEvent;
                double voltage = getAnalogPinVoltage(inResponce);
                if (queryAnalogEvent._pinToQuery == AnalogPins.Thermistor_AN5)
                {
                    double resistance = getThermistorResistance(voltage);
                    double tempC      = getTempInC(resistance);
                    tempLog.Info(string.Format("{0}", tempC));
                    if (deviceDelegate != null)
                    {
                        log.Debug("Sending temp data to logical layer");
                        deviceDelegate.newThermistorData(tempC);
                    }
                }
                else if (queryAnalogEvent._pinToQuery == AnalogPins.Pressure_AN4)
                {
                    voltage = Math.Round(voltage, 2);
                    double pressure = (_slope * voltage) + _yIntercept;
                    log.Debug(string.Format("Received pressure reading : {0}", pressure));
                    pressureLog.Info(string.Format("{0}", pressure));
                    if (deviceDelegate != null)
                    {
                        log.Debug("Sending new pressure data to delegate");
                        deviceDelegate.newPressureData(pressure);
                    }
                }
                break;

            case EventIdentifier.QueryCounterRequest:
                logBytesArray(inResponce);
                int responce = (inResponce[3] << 24) | (inResponce[2] << 16) | (inResponce[1] << 8) | (inResponce[0]);
                handleNewFlowmeterCounterValue(inEvent, responce);
                break;

            default:
                log.Error(string.Format("Message type {0} does not expect a responce", inEvent.identifier));
                break;
            }
            log.Debug("Done processing responce");
        }