示例#1
0
文件: LGX.cpp 项目: nismoryco/tuxeip
LGX_Read *_DecodeLGX(CommonDataService_Reply *reply, int replysize)
{
	void *data = NULL;
	LGX_Read *result = (LGX_Read *)malloc(sizeof(LGX_Read));
	if (result==NULL) {
		CIPERROR(Sys_Error, errno, 0);
		return NULL;
	}
	memset(result, 0, sizeof(LGX_Read));
	result->type = _GetLGXDataType(reply);
	result->elementsize = _GetLGXDataSize(result->type);
	data = _GetData(reply);
	if (result->elementsize <= 0 || data==NULL) {
		CIPERROR(Internal_Error, E_LGX, __LINE__);
		free(result);
		return NULL;
	}
	result->totalsize = replysize - (int)((char *)data - (char *)reply);
	result->Varcount = result->totalsize / result->elementsize;
	if (result->Varcount < 1) {
		CIPERROR(Internal_Error, E_LGX, __LINE__);
		free(result);
		return NULL;
	}
	result = (LGX_Read *)realloc(result, sizeof(LGX_Read) + result->totalsize);
	if (result == NULL) {
		CIPERROR(Sys_Error, errno, 0);
		return NULL;
	}
	memcpy((char*)result + sizeof(LGX_Read), data, result->totalsize);
	return result;
}
示例#2
0
文件: LGX.cpp 项目: tcrutt/tuxeip-1
void *_GetData(CommonDataService_Reply *reply)
{	if (reply==NULL)
	{
		CIPERROR(Internal_Error,E_InvalidReply,0);
		return(NULL);
	}
	if (reply->Status!=0)
	{
		CIPERROR(AB_Error,reply->Status,_GetExtendedStatus(reply));
		return(NULL);
	}
	CIPERROR(Internal_Error,Success,0);
	switch (_GetLGXDataType(reply))
	{
		case LGX_BOOL:
		case LGX_BITARRAY:
		case LGX_SINT:
		case LGX_INT:
		case LGX_DINT:
		case LGX_REAL:return(((char*)reply)+sizeof(CommonDataService_Reply)+sizeof(CIP_INT));
		default:CIPERROR(Internal_Error,E_UnsupportedDataType,0);return(NULL);
	}
}