예제 #1
0
 /// <summary>
 /// Sends a job to the port. If the job Sendcount is >= 3 the job will be canceled
 /// </summary>
 /// <param name="job">ZwaveJob to be sent</param>
 private void SendJob(ZWaveJob job)
 {
     DebugLogger.Logger.Trace(string.Format("{0}", job.ToString()));
     if (job.SendCount >= 3)
     {
         job.CancelJob();
     }
     else
     {
         ZWaveMessage msg = job.Request;
         if (msg != null)
         {
             DebugLogger.Logger.Trace(string.Format("Sending Message:{0}", msg.ToString()));
             job.Start();
             job.Resend = false;
             job.AwaitACK = true;
             job.SendCount++;
             this._sp.Write(msg.Message, 0, msg.Message.Length);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Message processing
        /// </summary>
        /// <param name="bufSeg">An ArraySegment for the buffer to be processed</param>
        /// <param name="job">The ZwaveJob to be processed</param>
        private void ProcessMessage(ArraySegment<byte> bufSeg, ZWaveJob job)
        {
            // Read the length byte
            byte len = bufSeg.Array[ZWaveProtocol.MessageBufferOffsets.MessageLength + bufSeg.Offset];

            // Read rest of the frame
            byte[] message = Utils.ByteSubstring(bufSeg.Array,
                bufSeg.Offset,
                bufSeg.Count);
            DebugLogger.Logger.Trace("Received: " + Utils.ByteArrayToString(message));

            ZWaveMessage zMessage = null;
            try
            {
                zMessage = new ZWaveMessage(message);
                //Checksum is correct
                SendACKToPort();
            }
            catch (MessageChecksumInvalidException ex)
            {
                DebugLogger.Logger.Error("Message Checksum invalid. Sending NAK.\nMessage: {0}", Utils.ByteArrayToString(message));
                SendNAKToPort();
                return;
            }
            if (job == null)
            {
                // Incoming response?
                DebugLogger.Logger.Trace("*** Incoming response");
                this.FireUnsubscribedMessageEvent(zMessage);
            }
            else
            {
                if (job.AwaitACK)
                {
                    // We wanted an ACK instead. Resend...
                    ResendCurrentJob(resendReason.ExpectingACK);
                }
                else
                {
                    job.AddResponse(zMessage);
                    this.FireUnsubscribedMessageEvent(zMessage);
                }
            }
        }
예제 #3
0
파일: ZWave.cs 프로젝트: christothes/ZSharp
 private void GetVersion()
 {
     DebugLogger.Logger.Trace("");
     ZWaveJob v = new ZWaveJob();
     v.Request = new ZWaveMessage(ZWaveProtocol.MessageType.REQUEST,
                                  ZWaveProtocol.Function.GET_VERSION);
     v.ResponseReceived += ResponseReceived;
     this._port.EnqueueJob(v);
 }
예제 #4
0
 /// <summary>
 /// Enqueue a new job to be sent by the controller
 /// </summary>
 public void EnqueueJob(ZWaveJob job)
 {
     this._jobQueue.Enqueue(job);
     if (job == CurrentJob)
     {
         //Process the new job
         ProcessJobQueue();
     }
 }
예제 #5
0
파일: ZWave.cs 프로젝트: christothes/ZSharp
 private void GetHomeID()
 {
     DebugLogger.Logger.Trace("");
     ZWaveJob h = new ZWaveJob();
     h.Request = new ZWaveMessage(ZWaveProtocol.MessageType.REQUEST,
                                  ZWaveProtocol.Function.MEMORY_GET_ID);
     h.ResponseReceived += ResponseReceived;
     this._port.EnqueueJob(h);
 }