Beispiel #1
0
U8 proto_assembleFrame(U8* buf, U16* bufSize, U8* gatewayId, \
	U8 MsgIndex, U8 MsgType, U16 bodyLen, U8* pMsgBody)
{
	gateway_protocol_str protoStr = { 0 };

	memset(protoStr.head_str.prefix, GATEWAY_PREFIX, GATEWAY_PREFIX_CNT);//前导符
	memset(&(protoStr.head_str.start), GATEWAY_START, GATEWAY_START_CNT);//开始符
	memset(&(protoStr.head_str.protoVer), GATEWAY_PROTOCOL_VER, 1);//协议版本号

	protoStr.head_str.SourceAddr[0] = 0x01;
	protoStr.head_str.SourceAddr[1] = 0x00;
	protoStr.head_str.SourceAddr[2] = 0x00;
	protoStr.head_str.SourceAddr[3] = 0x00;
	protoStr.head_str.SourceAddr[4] = 0x00;
	protoStr.head_str.SourceAddr[5] = 0x00;
	memcpy(protoStr.head_str.DestAddr, gatewayId, GATEWAY_OADD_LEN);
	protoStr.head_str.MsgID = MsgIndex;
	protoStr.head_str.bodyLen = bodyLen;
	protoStr.head_str.MsgType = MsgType;
	readSysTime(&(protoStr.head_str.sysTime));
	protoStr.head_str.HeadCheck = countCheck(&(protoStr.head_str.protoVer), \
		(sizeof(protocol_head_str) - GATEWAY_PREFIX_CNT - GATEWAY_START_CNT));
	protoStr.pMsgBody = pMsgBody;
	protoStr.bodyChk = countCheck(protoStr.pMsgBody, bodyLen);
	createFrame(buf, bufSize, &protoStr);
	return NO_ERR;
}
Beispiel #2
0
/*
**	分析集中器的返回帧长度及校验的合法性.
**	@buf:		返回帧
**	@bufSize:	返回帧的长度
**	return:		合法返回NO_ERR; 非法返回ERROR, 下同
*/
U8 protoA_retFrameLen(U8* buf, U16 bufSize)
{
	U8	lu8data = 0;
	U16	lu16Length = 0;
	protocol_head_str protoHeadStr = { 0 };

	//检查消息头部长度
	if (bufSize < sizeof(protocol_head_str)) {
		printf("proto head length err\n");
		return ERROR;
	}

	memcpy((U8*)&(protoHeadStr), buf, sizeof(protocol_head_str));

	//检查整个buf的长度
	lu16Length = sizeof(protocol_head_str) + protoHeadStr.bodyLen + GATEWAY_EC_LEN + GATEWAY_SUFIX_CNT;
	if (bufSize != lu16Length) {
		printf("buf length err\n");
		return ERROR;
	}

	//检查前导符, 开始符和协议版本
	if (protoHeadStr.prefix[0] != GATEWAY_PREFIX || \
		protoHeadStr.prefix[1] != GATEWAY_PREFIX || \
		protoHeadStr.start != GATEWAY_START || \
		protoHeadStr.protoVer != GATEWAY_PROTOCOL_VER) {
		printf("prefix: %02X %02X\n", protoHeadStr.prefix[0], protoHeadStr.prefix[1]);
		printf("start: %02X\n", protoHeadStr.start);
		printf("protoVer: %02X\n", protoHeadStr.protoVer);
		return ERROR;
	}

	//检查结束符
	if (buf[bufSize - 1] != GATEWAY_SUFIX || \
		buf[bufSize - 2] != GATEWAY_SUFIX) {
		printf("suffix: %02X %02X\n", buf[bufSize - 1], buf[bufSize - 1]);
		return ERROR;
	}

	//检查头部校验
	lu16Length = (&(protoHeadStr.HeadCheck) - &(protoHeadStr.protoVer));
	lu8data = countCheck(&(protoHeadStr.protoVer), lu16Length);
	if (lu8data != protoHeadStr.HeadCheck) {
		printf("lu8data: %02X, HeadCheck: %02X\n", lu8data, protoHeadStr.HeadCheck);
		return ERROR;
	}

	//检查消息体校验
	lu8data = countCheck(buf + sizeof(protocol_head_str), protoHeadStr.bodyLen);
	if (buf[bufSize - 3] != lu8data) {
		printf("lu8data: %02X, EC: %02X\n", lu8data, buf[bufSize - 3]);
		return ERROR;
	}

	return NO_ERR;
}
Beispiel #3
0
void MockSupport::expectNoCall(const SimpleString& functionName)
{
    if (!enabled_) return;

    countCheck();

    MockCheckedExpectedCall* call = new MockCheckedExpectedCall;
    call->withName(appendScopeToName(functionName));
    unExpectations_.addExpectedCall(call);
}
Beispiel #4
0
MockExpectedCall& MockSupport::expectOneCall(const SimpleString& functionName)
{
    if (!enabled_) return MockIgnoredExpectedCall::instance();

    countCheck();

    MockCheckedExpectedCall* call = new MockCheckedExpectedCall;
    call->withName(appendScopeToName(functionName));
    if (strictOrdering_)
        call->withCallOrder(++expectedCallOrder_);
    expectations_.addExpectedCall(call);
    return *call;
}