Example #1
0
void CMDI::PrepareTag(CVector<_BINARY>& vecbiTag, const string strTagName,
                      const int iLenDataBits)
{
    /*
    	Function called by all tags
    */
    /* Init vector length. 4 bytes for tag name and 4 bytes for data length
       plus the length of the actual data */
    vecbiTag.Init(8 * SIZEOF__BYTE + iLenDataBits);
    vecbiTag.ResetBitAccess();

    /* Set tag name (always four bytes long) */
    for (int i = 0; i < 4; i++)
        vecbiTag.Enqueue((uint32_t) strTagName[i], SIZEOF__BYTE);

    /* Set tag data length */
    vecbiTag.Enqueue((uint32_t) iLenDataBits, 32);
}
Example #2
0
/* Actual MDI protocol implementation *****************************************/
CVector<_BINARY> CMDI::GenAFPacket(const _BOOLEAN bWithSDC)
{
    /*
    	The AF layer encapsulates a single TAG Packet. Mandatory TAG items:
    	*ptr, dlfc, fac_, sdc_, sdci, robm, str0-3
    */
    int					i;
    CVector<_BINARY>	vecbiAFPkt;

    /* Increment MDI packet counter and generate counter tag */
    GenTagLoFrCnt();

    /* Payload length in bytes */
// TODO: check if padding bits are needed to get byte alignment!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    const int iPayloadLenBytes = (vecbiTagProTy.Size() +
                                  vecbiTagLoFrCnt.Size() + vecbiTagFAC.Size() + vecbiTagSDC.Size() +
                                  vecbiTagSDCChanInf.Size() + vecbiTagRobMod.Size() +
                                  vecbiTagStr[0].Size() + vecbiTagStr[1].Size() + vecbiTagStr[2].Size() +
                                  vecbiTagStr[3].Size()) / SIZEOF__BYTE;

    /* 10 bytes AF header, 2 bytes CRC, payload */
    const int iAFPktLenBits =
        iPayloadLenBytes * SIZEOF__BYTE + 12 * SIZEOF__BYTE;

    /* Init vector length */
    vecbiAFPkt.Init(iAFPktLenBits);
    vecbiAFPkt.ResetBitAccess();

    /* SYNC: two-byte ASCII representation of "AF" */
    vecbiAFPkt.Enqueue((uint32_t) 'A', SIZEOF__BYTE);
    vecbiAFPkt.Enqueue((uint32_t) 'F', SIZEOF__BYTE);

    /* LEN: length of the payload, in bytes (4 bytes long -> 32 bits) */
    vecbiAFPkt.Enqueue((uint32_t) iPayloadLenBytes, 32);

    /* SEQ: sequence number. Each AF Packet shall increment the sequence number
       by one for each packet sent, regardless of content. There shall be no
       requirement that the first packet received shall have a specific value.
       The counter shall wrap from FFFF_[16] to 0000_[16], thus the value shall
       count, FFFE_[16], FFFF_[16], 0000_[16], 0001_[16], etc.
       (2 bytes long -> 16 bits) */
    vecbiAFPkt.Enqueue((uint32_t) iSeqNumber, 16);

    iSeqNumber++;
    if (iSeqNumber > 0xFFFF)
        iSeqNumber = 0;

    /* AR: AF protocol Revision -
       a field combining the CF, MAJ and MIN fields */
    /* CF: CRC Flag, 0 if the CRC field is not used (CRC value shall be
       0000_[16]) or 1 if the CRC field contains a valid CRC (1 bit long) */
    if (bUseAFCRC == TRUE)
        vecbiAFPkt.Enqueue((uint32_t) 1, 1);
    else
        vecbiAFPkt.Enqueue((uint32_t) 0, 1);

    /* MAJ: major revision of the AF protocol in use (3 bits long) */
    vecbiAFPkt.Enqueue((uint32_t) AF_MAJOR_REVISION, 3);

    /* MIN: minor revision of the AF protocol in use (4 bits long) */
    vecbiAFPkt.Enqueue((uint32_t) AF_MINOR_REVISION, 4);

    /* Protocol Type (PT): single byte encoding the protocol of the data carried
       in the payload. For TAG Packets, the value shall be the ASCII
       representation of "T" */
    vecbiAFPkt.Enqueue((uint32_t) 'T', SIZEOF__BYTE);


    /* Payload -------------------------------------------------------------- */

// TODO: copy data byte wise -> check if possible to do that...

    /* *ptr tag */
    vecbiTagProTy.ResetBitAccess();
    for (i = 0; i < vecbiTagProTy.Size(); i++)
        vecbiAFPkt.Enqueue(vecbiTagProTy.Separate(1), 1);

    /* dlfc tag */
    vecbiTagLoFrCnt.ResetBitAccess();
    for (i = 0; i < vecbiTagLoFrCnt.Size(); i++)
        vecbiAFPkt.Enqueue(vecbiTagLoFrCnt.Separate(1), 1);

    /* fac_ tag */
    vecbiTagFAC.ResetBitAccess();
    for (i = 0; i < vecbiTagFAC.Size(); i++)
        vecbiAFPkt.Enqueue(vecbiTagFAC.Separate(1), 1);

    /* SDC tag must be delayed in some cases */
    if (bWithSDC == TRUE)
    {
        /* sdc_ tag */
        vecbiTagSDC.ResetBitAccess();
        for (i = 0; i < vecbiTagSDC.Size(); i++)
            vecbiAFPkt.Enqueue(vecbiTagSDC.Separate(1), 1);
    }

    /* sdci tag */
    vecbiTagSDCChanInf.ResetBitAccess();
    for (i = 0; i < vecbiTagSDCChanInf.Size(); i++)
        vecbiAFPkt.Enqueue(vecbiTagSDCChanInf.Separate(1), 1);

    /* robm tag */
    vecbiTagRobMod.ResetBitAccess();
    for (i = 0; i < vecbiTagRobMod.Size(); i++)
        vecbiAFPkt.Enqueue(vecbiTagRobMod.Separate(1), 1);

    /* strx tag */
    for (int j = 0; j < MAX_NUM_STREAMS; j++)
    {
        vecbiTagStr[j].ResetBitAccess();
        for (i = 0; i < vecbiTagStr[j].Size(); i++)
            vecbiAFPkt.Enqueue(vecbiTagStr[j].Separate(1), 1);
    }


    /* CRC: CRC calculated as described in annex A if the CF field is 1,
       otherwise 0000_[16] */
    if (bUseAFCRC == TRUE)
    {
        CCRC CRCObject;

        /* CRC -------------------------------------------------------------- */
        /* Calculate the CRC and put at the end of the stream */
        CRCObject.Reset(16);

        vecbiAFPkt.ResetBitAccess();

        /* 2 bytes CRC -> "- 2" */
        for (int i = 0; i < iAFPktLenBits / SIZEOF__BYTE - 2; i++)
            CRCObject.AddByte((_BYTE) vecbiAFPkt.Separate(SIZEOF__BYTE));

        /* Now, pointer in "enqueue"-function is back at the same place,
           add CRC */
        vecbiAFPkt.Enqueue(CRCObject.GetCRC(), 16);
    }
    else
        vecbiAFPkt.Enqueue((uint32_t) 0, 16);

    return vecbiAFPkt;
}
Example #3
0
/******************************************************************************\
* Encoder                                                                      *
\******************************************************************************/
void CDataEncoder::GeneratePacket(CVector<_BINARY>& vecbiPacket)
{
	int			i;
	_BOOLEAN	bLastFlag;

	/* Init size for whole packet, not only body */
	vecbiPacket.Init(iTotalPacketSize);
	vecbiPacket.ResetBitAccess();

	/* Calculate remaining data size to be transmitted */
	const int iRemainSize = vecbiCurDataUnit.Size() - iCurDataPointer;


	/* Header --------------------------------------------------------------- */
	/* First flag */
	if (iCurDataPointer == 0)
		vecbiPacket.Enqueue((uint32_t) 1, 1);
	else
		vecbiPacket.Enqueue((uint32_t) 0, 1);

	/* Last flag */
	if (iRemainSize > iPacketLen)
	{
		vecbiPacket.Enqueue((uint32_t) 0, 1);
		bLastFlag = FALSE;
	}
	else
	{
		vecbiPacket.Enqueue((uint32_t) 1, 1);
		bLastFlag = TRUE;
	}

	/* Packet Id */
	vecbiPacket.Enqueue((uint32_t) iPacketID, 2);

	/* Padded packet indicator (PPI) */
	if (iRemainSize < iPacketLen)
		vecbiPacket.Enqueue((uint32_t) 1, 1);
	else
		vecbiPacket.Enqueue((uint32_t) 0, 1);

	/* Continuity index (CI) */
	vecbiPacket.Enqueue((uint32_t) iContinInd, 3);

	/* Increment index modulo 8 (1 << 3) */
	iContinInd++;
	if (iContinInd == 8)
		iContinInd = 0;


	/* Body ----------------------------------------------------------------- */
	if (iRemainSize >= iPacketLen)
	{
		if (iRemainSize == iPacketLen)
		{
			/* Last packet */
			for (i = 0; i < iPacketLen; i++)
				vecbiPacket.Enqueue(vecbiCurDataUnit.Separate(1), 1);
		}
		else
		{
			for (i = 0; i < iPacketLen; i++)
			{
				vecbiPacket.Enqueue(vecbiCurDataUnit.Separate(1), 1);
				iCurDataPointer++;
			}
		}
	}
	else
	{
		/* Padded packet. If the PPI is 1 then the first byte shall indicate
		   the number of useful bytes that follow, and the data field is
		   completed with padding bytes of value 0x00 */
		vecbiPacket.Enqueue((uint32_t) (iRemainSize / SIZEOF__BYTE),
			SIZEOF__BYTE);

		/* Data */
		for (i = 0; i < iRemainSize; i++)
			vecbiPacket.Enqueue(vecbiCurDataUnit.Separate(1), 1);

		/* Padding */
		for (i = 0; i < iPacketLen - iRemainSize; i++)
			vecbiPacket.Enqueue(vecbiCurDataUnit.Separate(1), 1);
	}

	/* If this was the last packet, get data for next data unit */
	if (bLastFlag == TRUE)
	{
		/* Generate new data unit */
		MOTSlideShowEncoder.GetDataUnit(vecbiCurDataUnit);
		vecbiCurDataUnit.ResetBitAccess();

		/* Reset data pointer and continuity index */
		iCurDataPointer = 0;
	}


	/* CRC ------------------------------------------------------------------ */
	CCRC CRCObject;

	/* Reset bit access */
	vecbiPacket.ResetBitAccess();

	/* Calculate the CRC and put it at the end of the segment */
	CRCObject.Reset(16);

	/* "byLengthBody" was defined in the header */
	for (i = 0; i < (iTotalPacketSize / SIZEOF__BYTE - 2); i++)
		CRCObject.AddByte(vecbiPacket.Separate(SIZEOF__BYTE));

	/* Now, pointer in "enqueue"-function is back at the same place, add CRC */
	vecbiPacket.Enqueue(CRCObject.GetCRC(), 16);
}