Exemple #1
0
    INCOMING_RFLINK_FRAME ByteArrayToINCOMING_RFLINK_FRAME(byte[] bytes, int startOffset = 0)
    {
        INCOMING_RFLINK_FRAME frame = default;

        frame.frameType = bytes[startOffset];
        frame.frequency = BitConverter.ToUInt32(bytes, startOffset + 1);
        // Available : 433420, 433920, 868350, 868950.
        frame.RFLevel          = (sbyte)bytes[startOffset + 5];
        frame.floorNoise       = (sbyte)bytes[startOffset + 6];
        frame.pulseElementSize = bytes[startOffset + 7];
        frame.number           = BitConverter.ToUInt16(bytes, startOffset + 8);
        frame.repeats          = bytes[startOffset + 10];
        frame.delay            = bytes[startOffset + 11];
        frame.multiply         = bytes[startOffset + 12];
        frame.time             = BitConverter.ToUInt32(bytes, startOffset + 13);
        //frame.pulses = new byte[frame.number + 2];
        //Array.Copy(bytes, startOffset + 17, frame.pulses, 0, frame.number + 2);
        unsafe
        {
            fixed(byte *bPtr = bytes)
            {
                var j = 0;

                while (j < frame.number + 2)
                {
                    *(frame.pulses + j) = *(bPtr + startOffset + 17 + j);
                    j++;
                }
            }
        }
        return(frame);
    }
Exemple #2
0
 public unsafe RFPMessage(MessageType t, byte[] content, int startIndex, int count)
 {
     Type = t;
     if (t == MessageType.ASCII)
     {
         asciiContent = Encoding.ASCII.GetString(content, startIndex, count);
         IsAnswer     = asciiContent.StartsWith("ZIA--");
     }
     else
     {
         binaryContent = new byte[count];
         Array.Copy(content, startIndex, binaryContent, 0, count);
         frameType = (FrameType)binaryContent[5];
         if (frameType == FrameType.KNOWN_PROTOCOL)
         {
             frameKnown = ByteArrayToStructure <REGULAR_INCOMING_RF_TO_BINARY_USB_FRAME>(binaryContent, 5);
         }
         else if (frameType == FrameType.RFLINK)
         {
             frameRFLink = ByteArrayToINCOMING_RFLINK_FRAME(binaryContent, 5);
             if (count - 5 != (17 + frameRFLink.number + 2))
             {
                 UnityEngine.Debug.LogError("RFLink size is not good");
             }
         }
     }
 }