本文整理汇总了C++中CGXByteBuffer::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ CGXByteBuffer::Set方法的具体用法?C++ CGXByteBuffer::Set怎么用?C++ CGXByteBuffer::Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGXByteBuffer
的用法示例。
在下文中一共展示了CGXByteBuffer::Set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetValue
/*
* Returns value of given attribute.
*/
int CGXDLMSProfileGeneric::GetValue(CGXDLMSSettings& settings, CGXDLMSValueEventArgs& e)
{
if (e.GetIndex() == 1)
{
int ret;
CGXDLMSVariant tmp;
if ((ret = GetLogicalName(this, tmp)) != 0)
{
return ret;
}
e.SetValue(tmp);
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 2)
{
CGXByteBuffer tmp;
tmp.Set(e.GetValue().byteArr, e.GetValue().size);
int ret = GetProfileGenericData(e.GetSelector(), e.GetParameters(), tmp);
e.SetValue(tmp);
return ret;
}
if (e.GetIndex() == 3)
{
CGXByteBuffer data;
int ret = GetColumns(data);
e.SetValue(data);
return ret;
}
if (e.GetIndex() == 4)
{
e.SetValue(GetCapturePeriod());
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 5)
{
e.SetValue(GetSortMethod());
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 5)
{
return DLMS_ERROR_CODE_INVALID_PARAMETER;
}
if (e.GetIndex() == 7)
{
e.SetValue(GetEntriesInUse());
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 8)
{
e.SetValue(GetProfileEntries());
return DLMS_ERROR_CODE_OK;
}
return DLMS_ERROR_CODE_INVALID_PARAMETER;
}
示例2: GetProfileGenericDataByRange
/**
* Find start index and row count using start and end date time.
*
* @param start
* Start time.
* @param end
* End time
* @param index
* Start index.
* @param count
* Item count.
*/
void GetProfileGenericDataByRange(CGXDLMSValueEventArg* e)
{
int len, month = 0, day = 0, year = 0, hour = 0, minute = 0, second = 0, value = 0;
CGXDLMSVariant start, end;
CGXByteBuffer bb;
bb.Set(e->GetParameters().Arr[1].byteArr, e->GetParameters().Arr[1].size);
CGXDLMSClient::ChangeType(bb, DLMS_DATA_TYPE_DATETIME, start);
bb.Clear();
bb.Set(e->GetParameters().Arr[2].byteArr, e->GetParameters().Arr[2].size);
CGXDLMSClient::ChangeType(bb, DLMS_DATA_TYPE_DATETIME, end);
#if defined(_WIN32) || defined(_WIN64)//Windows
FILE* f;
_tfopen_s(&f, DATAFILE, _T("r"));
#else
FILE* f = fopen(DATAFILE, "r");
#endif
if (f != NULL)
{
#if defined(_WIN32) || defined(_WIN64)//Windows
while ((len = fscanf_s(f, "%d/%d/%d %d:%d:%d;%d", &month, &day, &year, &hour, &minute, &second, &value)) != -1)
#else
while ((len = fscanf(f, "%d/%d/%d %d:%d:%d;%d", &month, &day, &year, &hour, &minute, &second, &value)) != -1)
#endif
{
CGXDateTime tm(2000 + year, month, day, hour, minute, second, 0, 0x8000);
if (tm.CompareTo(end.dateTime) > 0)
{
// If all data is read.
break;
}
if (tm.CompareTo(start.dateTime) < 0)
{
// If we have not find first item.
e->SetRowBeginIndex(e->GetRowBeginIndex() + 1);
}
e->SetRowEndIndex(e->GetRowEndIndex() + 1);
}
fclose(f);
}
}
示例3: Secure
/**
* Chipher text.
*
* @param auth
* Authentication level.
* @param data
* Text to chipher.
* @param secret
* Secret.
* @return Chiphered text.
*/
int CGXSecure::Secure(
CGXDLMSSettings& settings,
CGXCipher* cipher,
unsigned long ic,
CGXByteBuffer& data,
CGXByteBuffer& secret,
CGXByteBuffer& reply)
{
int ret = 0, pos;
reply.Clear();
if (settings.GetAuthentication() == DLMS_AUTHENTICATION_HIGH)
{
CGXByteBuffer s;
int len = data.GetSize();
if (len % 16 != 0)
{
len += (16 - (data.GetSize() % 16));
}
if (secret.GetSize() > data.GetSize())
{
len = secret.GetSize();
if (len % 16 != 0)
{
len += (16 - (secret.GetSize() % 16));
}
}
s.Set(&secret);
s.Zero(s.GetSize(), len - s.GetSize());
reply.Set(&data);
reply.Zero(reply.GetSize(), len - reply.GetSize());
for (pos = 0; pos < len / 16; ++pos)
{
CGXCipher::Aes1Encrypt(reply, pos * 16, s);
}
return 0;
}
// Get server Challenge.
CGXByteBuffer challenge;
// Get shared secret
if (settings.GetAuthentication() != DLMS_AUTHENTICATION_HIGH_GMAC)
{
challenge.Set(&data);
challenge.Set(&secret);
}
if (settings.GetAuthentication() == DLMS_AUTHENTICATION_HIGH_MD5)
{
return CGXDLMSMD5::Encrypt(challenge, reply);
}
else if (settings.GetAuthentication() == DLMS_AUTHENTICATION_HIGH_SHA1)
{
return CGXDLMSSha1::Encrypt(challenge, reply);
}
else if (settings.GetAuthentication() == DLMS_AUTHENTICATION_HIGH_SHA256)
{
return CGXDLMSSha256::Encrypt(challenge, reply);
}
else if (settings.GetAuthentication() == DLMS_AUTHENTICATION_HIGH_GMAC)
{
CGXByteBuffer tmp;
CGXByteBuffer& key = settings.GetCipher()->GetBlockCipherKey();
ret = cipher->Encrypt(DLMS_SECURITY_AUTHENTICATION,
DLMS_COUNT_TYPE_TAG, ic, 0, secret, key, data, tmp);
if (ret == 0)
{
reply.SetUInt8(DLMS_SECURITY_AUTHENTICATION);
reply.SetUInt32(ic);
reply.Set(&tmp);
}
}
return ret;
}
示例4: GetValue
// Returns value of given attribute.
int CGXDLMSPppSetup::GetValue(CGXDLMSSettings& settings, CGXDLMSValueEventArg& e)
{
CGXByteBuffer data;
if (e.GetIndex() == 1)
{
int ret;
CGXDLMSVariant tmp;
if ((ret = GetLogicalName(this, tmp)) != 0)
{
return ret;
}
e.SetValue(tmp);
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 2)
{
e.SetValue(m_PHYReference);
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 3)
{
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
data.SetUInt8(m_LCPOptions.size());
CGXDLMSVariant type, len;
for(std::vector<CGXDLMSPppSetupLcpOption>::iterator it = m_LCPOptions.begin(); it != m_LCPOptions.end(); ++it)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(3);
type = it->GetType();
len = it->GetLength();
CGXDLMSVariant tmp = it->GetData();
GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, type);
GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, len);
GXHelpers::SetData(data, it->GetData().vt, tmp);
}
e.SetValue(data);
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 4)
{
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
data.SetUInt8(m_IPCPOptions.size());
CGXDLMSVariant type, len;
for(std::vector<CGXDLMSPppSetupIPCPOption>::iterator it = m_IPCPOptions.begin(); it != m_IPCPOptions.end(); ++it)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(3);
type = it->GetType();
len = it->GetLength();
GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, type);
GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, len);
GXHelpers::SetData(data, it->GetData().vt, it->m_Data);
}
e.SetValue(data);
return DLMS_ERROR_CODE_OK;
}
else if (e.GetIndex() == 5)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(2);
//Add username.
data.SetUInt8(DLMS_DATA_TYPE_OCTET_STRING);
data.SetUInt8(m_UserName.GetSize());
data.Set(&m_UserName, 0, -1);
//Add password.
data.SetUInt8(DLMS_DATA_TYPE_OCTET_STRING);
data.SetUInt8(m_Password.GetSize());
data.Set(&m_Password, 0, -1);
e.SetValue(data);
return DLMS_ERROR_CODE_OK;
}
return DLMS_ERROR_CODE_INVALID_PARAMETER;
}
示例5: GetValue
/*
* Returns value of given attribute.
*/
int CGXDLMSProfileGeneric::GetValue(CGXDLMSSettings& settings, CGXDLMSValueEventArg& e)
{
if (e.GetIndex() == 1)
{
int ret;
CGXDLMSVariant tmp;
if ((ret = GetLogicalName(this, tmp)) != 0)
{
return ret;
}
e.SetValue(tmp);
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 2)
{
CGXByteBuffer tmp;
tmp.Set(e.GetValue().byteArr, e.GetValue().size);
int ret = GetProfileGenericData(e.GetSelector(), e.GetParameters(), tmp);
e.SetValue(tmp);
return ret;
}
if (e.GetIndex() == 3)
{
CGXByteBuffer data;
int ret = GetColumns(data);
e.SetValue(data);
return ret;
}
if (e.GetIndex() == 4)
{
e.SetValue(GetCapturePeriod());
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 5)
{
e.SetValue(GetSortMethod());
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 6)
{
char empty[6] = {0};
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(4);
if (m_SortObject == NULL)
{
//ClassID
data.SetUInt8(DLMS_DATA_TYPE_UINT16);
data.SetUInt16(0);
//LN
data.SetUInt8(DLMS_DATA_TYPE_OCTET_STRING);
data.SetUInt8(6);
data.Set(empty, 6);
//Selected Attribute Index
data.SetUInt8(DLMS_DATA_TYPE_INT8);
data.SetUInt8(0);
//Selected Data Index
data.SetUInt8(DLMS_DATA_TYPE_UINT16);
data.SetUInt16(0);
}
else
{
int ret;
CGXDLMSVariant ln;
//ClassID
data.SetUInt8(DLMS_DATA_TYPE_UINT16);
data.SetUInt16(m_SortObject->GetObjectType());
//LN
data.SetUInt8(DLMS_DATA_TYPE_OCTET_STRING);
data.SetUInt8(6);
if ((ret = GetLogicalName(m_SortObject, ln)) != 0)
{
return ret;
}
data.Set(&ln.byteArr, 6);
//Selected Attribute Index
data.SetUInt8(DLMS_DATA_TYPE_INT8);
data.SetUInt8(m_SortObjectAttributeIndex);
//Selected Data Index
data.SetUInt8(DLMS_DATA_TYPE_UINT16);
data.SetUInt16(m_SortObjectDataIndex);
}
e.SetValue(data);
}
if (e.GetIndex() == 7)
{
e.SetValue(GetEntriesInUse());
return DLMS_ERROR_CODE_OK;
}
if (e.GetIndex() == 8)
{
e.SetValue(GetProfileEntries());
return DLMS_ERROR_CODE_OK;
}
return DLMS_ERROR_CODE_INVALID_PARAMETER;
}