Beispiel #1
0
        /// <summary>
        /// Process a chip object table message from the server.
        /// </summary>
        /// <param name="copyData">received message</param>
        /// <remarks>
        /// Returns the message contents to the client application by callback.
        /// </remarks>
        private void ProcessChipObjectTable(ref CopyData copyData)
        {
            // debug info
            OutputDebugString("processChipObjectTable");

            // message parsing variables
            byte[] buffer = null;
            buffer = this.GetBufferFromCopyData(ref copyData);
            int index = 0;

            // message format:
            // byte: flag: operation succeeded
            // then: multiple instances of the following:
            //       ushort: object type
            //       ushort: object start position
            //       ushort: object size
            //       ushort: number of object instances
            //       ushort: number of report IDs per instance

            // parse message
            byte operationSucceeded = this.GetByte(ref buffer, ref index);

            // parse operation success/failure from message payload
            bool operationSucceededFlag = false;
            if (operationSucceeded == 0)
            {
                operationSucceededFlag = true;
            }

            // calculate number of object table elements in the received data
            int bufferSize = buffer.Length;
            int numObjectTableElements = (bufferSize - 1) / ObjectTableElement.OBJECT_TABLE_ELEMENT_SIZE;

            // create object table
            ObjectTableElement[] objectTable = new ObjectTableElement[numObjectTableElements];

            // parse object table from message
            for (int i = 0; i < numObjectTableElements; i++)
            {
                // build object table element
                ObjectTableElement objectTableElement = new ObjectTableElement();
                objectTableElement.type = this.GetUshort(ref buffer, ref index);
                objectTableElement.start_position = this.GetUshort(ref buffer, ref index);
                objectTableElement.size = this.GetUshort(ref buffer, ref index);
                objectTableElement.instances = this.GetUshort(ref buffer, ref index);
                objectTableElement.num_report_ids_per_instance = this.GetUshort(ref buffer, ref index);

                // save object table element
                objectTable[i] = objectTableElement;
            }

            // trigger chip object table event
            this.NotifyChipObjectTable(operationSucceededFlag, ref objectTable);
        }
Beispiel #2
0
 /// <summary>
 /// handle chip object table events
 /// </summary>
 /// <param name="operationSucceeded">flag: the operation succeeded</param>
 /// <param name="objectTable">the chip object table</param>
 private void NotifyChipObjectTable(bool operationSucceeded, ref ObjectTableElement[] objectTable)
 {
     if (this.chipObjectTable != null)
     {
         this.chipObjectTable(operationSucceeded, ref objectTable);
     }
 }