Ejemplo n.º 1
0
        /**
	     * Send an object through the telemetry link.
	     * @throws IOException
	     * @param[in] obj Object handle to send
	     * @param[in] type Transaction type \return Success (true), Failure (false)
	     */
        private bool transmitSingleObject(UAVObject obj, int type, bool allInstances)
        {
            int length;
            int allInstId = uavConsts.ALL_INSTANCES;

            ByteBuffer bbuf = new ByteBuffer(uavConsts.MAX_PACKET_LENGTH);
            
            // Determine data length
            if (type == uavConsts.TYPE_OBJ_REQ || type == uavConsts.TYPE_ACK)
            {
                length = 0;
            }
            else
            {
                length = obj.getNumBytes();
            }

            // Setup type and object id fields
            bbuf.put((byte)(uavConsts.SYNC_VAL & 0xff));
            bbuf.put((byte)(type & 0xff));
            bbuf.putShort((UInt16)(length + 2 /* SYNC, Type */+ 2 /* Size */+ 4 /* ObjID */+ (obj
                            .isSingleInstance() ? 0 : 2)));
            bbuf.putUint32((UInt32)obj.getObjID());

            // Setup instance ID if one is required
            if (!obj.isSingleInstance())
            {
                // Check if all instances are requested
                if (allInstances)
                    bbuf.putShort((UInt16)(allInstId & 0xffff));
                else
                    bbuf.putShort((UInt16)(obj.getInstID() & 0xffff));
            }

            // Check length
            if (length >= uavConsts.MAX_PAYLOAD_LENGTH)
                return false;

            // Copy data (if any)
            if (length > 0)
                try
                {
                    if (obj.pack(bbuf) == 0)
                        return false;
                }
                catch (Exception e)
                {
                    // TODO Auto-generated catch block
                    Debug.Write(e.Message);
                    return false;
                }

            // Calculate checksum
            bbuf.put((byte)(CRC.updateCRC(0, bbuf.array(), bbuf.position()) & 0xff));

            int packlen = bbuf.position();
            bbuf.position(0);
            byte[] dst = new byte[packlen];
            bbuf.get(dst, 0, packlen);

            if (type == uavConsts.TYPE_OBJ_ACK || type == uavConsts.TYPE_OBJ_REQ)
            {
                // Once we send a UAVTalk packet that requires an ack or object let's set up
                // the transaction here
                setupTransaction(obj, allInstances, type);
            }

            ch.write(dst);


            // Update stats
            ++txStats.Objects;
            txStats.Bytes += bbuf.position();
            txStats.ObjectBytes += length;

            // Done
            return true;
        }
Ejemplo n.º 2
0
        private void updateObjReq(UAVObject obj) {
		    bool succeeded = false;

		    // The lock on UAVTalk must be release before the transaction succeeded signal is sent
		    // because otherwise if a transaction timeout occurs at the same time we can get a
		    // deadlock:
		    // 1. processInputStream -> updateObjReq (locks uavtalk) -> tranactionCompleted (locks transInfo)
		    // 2. transactionTimeout (locks transInfo) -> sendObjectRequest -> ? -> setupTransaction (locks uavtalk)
            lock (updateObjReqSyncLock)
            {
			    if(respObj != null && respType == uavConsts.TYPE_OBJ_REQ && respObj.getObjID() == obj.getObjID() &&
					    ((respObj.getInstID() == obj.getInstID() || !respAllInstances))) {

				    // Indicate complete
				    respObj = null;
				    succeeded = true;
			    }
		    }

		    // Notify listener
		    if (succeeded && transactionListener != null)
				    transactionListener.TransactionSucceeded(obj);
	    }
Ejemplo n.º 3
0
	    private void updateAck(UAVObject obj) {
            lock (updateAckSyncLock)
            {
                Debug.WriteLine("Received ack: " + obj.getName());
                //Assert.assertNotNull(obj);
                if (respObj != null && respObj.getObjID() == obj.getObjID()
                        && (respObj.getInstID() == obj.getInstID() || respAllInstances))
                {

                    // Indicate complete
                    respObj = null;

                    // Notify listener
                    if (transactionListener != null)
                        transactionListener.TransactionSucceeded(obj);
                }
            }
	    }