本文整理汇总了C++中CGXByteBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ CGXByteBuffer类的具体用法?C++ CGXByteBuffer怎么用?C++ CGXByteBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CGXByteBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadDataBlock
int CGXCommunication::ReadDataBlock(CGXByteBuffer& data, CGXReplyData& reply)
{
//If ther is no data to send.
if (data.GetSize() == 0)
{
return DLMS_ERROR_CODE_OK;
}
int ret;
CGXByteBuffer bb;
//Send data.
if ((ret = ReadDLMSPacket(data, reply)) != DLMS_ERROR_CODE_OK)
{
return ret;
}
while (reply.IsMoreData())
{
bb.Clear();
if ((ret = m_Parser->ReceiverReady(reply.GetMoreData(), bb)) != 0)
{
return ret;
}
if ((ret = ReadDLMSPacket(bb, reply)) != DLMS_ERROR_CODE_OK)
{
return ret;
}
}
return DLMS_ERROR_CODE_OK;
}
示例2: GetColumns
int CGXDLMSProfileGeneric::GetColumns(CGXByteBuffer& data)
{
int cnt = m_CaptureObjects.size();
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
//Add count
GXHelpers::SetObjectCount(cnt, data);
std::string ln;
int ret;
CGXDLMSVariant tmp, ai, di;
for (std::vector<std::pair<CGXDLMSObject*, CGXDLMSCaptureObject*> >::iterator it = m_CaptureObjects.begin(); it != m_CaptureObjects.end(); ++it)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(4); //Count
tmp = it->first->GetObjectType();
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT16, tmp)) != 0) //ClassID
{
return ret;
}
(*it).first->GetLogicalName(ln);
tmp = ln;
ai = (*it).second->GetAttributeIndex();
di = (*it).second->GetDataIndex();
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, tmp)) != 0 || //LN
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_INT8, ai)) != 0 || //Attribute Index
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT16, di)) != 0) //Data Index
{
return ret;
}
}
return DLMS_ERROR_CODE_OK;
}
示例3: GetLogicalName
// Returns value of given attribute.
int CGXDLMSImageTransfer::GetValue(int index, int selector, CGXDLMSVariant& parameters, CGXDLMSVariant& value)
{
if (index == 1)
{
return GetLogicalName(this, value);
}
if (index == 2)
{
value = GetImageBlockSize();
return ERROR_CODES_OK;
}
if (index == 3)
{
value = m_ImageTransferredBlocksStatus;
return ERROR_CODES_OK;
}
if (index == 4)
{
value = m_ImageFirstNotTransferredBlockNumber;
return ERROR_CODES_OK;
}
if (index == 5)
{
value = m_ImageTransferEnabled;
return ERROR_CODES_OK;
}
if (index == 6)
{
value = m_ImageTransferStatus;
return ERROR_CODES_OK;
}
if (index == 7)
{
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
data.SetUInt8(m_ImageActivateInfo.size()); //Count
int ret;
CGXDLMSVariant size, id, signature;
for (std::vector<CGXDLMSImageActivateInfo>::iterator it = m_ImageActivateInfo.begin(); it != m_ImageActivateInfo.end(); ++it)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(3);//Item count.
size = it->GetSize();
id = it->GetIdentification();
signature = (*it).GetSignature();
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT32, size)) != 0 ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, id)) != 0 ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, signature)) != 0)
{
return ret;
}
}
value = data;
}
return ERROR_CODES_INVALID_PARAMETER;
}
示例4: GetProfileGenericData
/*
* 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;
}
示例5: malloc
CGXDLMSVariant::CGXDLMSVariant(CGXByteBuffer& value)
{
vt = DLMS_DATA_TYPE_OCTET_STRING;
size = value.GetSize();
if (size != 0)
{
byteArr = (unsigned char*) malloc(size);
memcpy(byteArr, value.GetData(), size);
}
else
{
byteArr = NULL;
}
}
示例6: GetValue
// Returns value of given attribute.
int CGXDLMSSpecialDaysTable::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)
{
e.SetByteArray(true);
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
//Add count
GXHelpers::SetObjectCount((unsigned long)m_Entries.size(), data);
int ret;
CGXDLMSVariant index, date, id;
for (std::vector<CGXDLMSSpecialDay*>::iterator it = m_Entries.begin(); it != m_Entries.end(); ++it)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(3); //Count
index = (*it)->GetIndex();
date = (*it)->GetDate();
id = (*it)->GetDayId();
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT16, index)) != DLMS_ERROR_CODE_OK ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, date)) != DLMS_ERROR_CODE_OK ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, id)) != DLMS_ERROR_CODE_OK)
{
return ret;
}
}
e.SetValue(data);
return DLMS_ERROR_CODE_OK;
}
return DLMS_ERROR_CODE_INVALID_PARAMETER;
}
示例7: 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);
}
}
示例8: GetBytes
/**
* Add new object to the byte buffer.
*
* @param value
* Value to add.
*/
int CGXDLMSVariant::GetBytes(CGXByteBuffer& value)
{
if (vt == DLMS_DATA_TYPE_OCTET_STRING)
{
value.AddRange(byteArr, size);
}
else if (vt == DLMS_DATA_TYPE_UINT8)
{
value.SetUInt8(cVal);
}
else if (vt == DLMS_DATA_TYPE_UINT16)
{
value.SetUInt16(uiVal);
}
else if (vt == DLMS_DATA_TYPE_UINT32)
{
value.SetUInt32(ulVal);
}
else if (vt == DLMS_DATA_TYPE_UINT64)
{
value.SetUInt64(ullVal);
}
else if (vt == DLMS_DATA_TYPE_STRING)
{
value.AddString(strVal.c_str());
}
else
{
//Invalid object type.
return ERROR_CODES_INVALID_PARAMETER;
}
return 0;
}
示例9: ReadDLMSPacket
// Read DLMS Data frame from the device.
int CGXCommunication::ReadDLMSPacket(CGXByteBuffer& data, CGXReplyData& reply)
{
int ret, pos;
CGXByteBuffer bb;
std::string tmp;
if (data.GetSize() == 0)
{
return DLMS_ERROR_CODE_OK;
}
Now(tmp);
tmp = "TX: " + tmp;
tmp += "\t" + data.ToHexString();
if (m_Trace > GX_TRACE_LEVEL_INFO)
{
printf("%s\r\n", tmp.c_str());
}
GXHelpers::Write("trace.txt", tmp + "\r\n");
int len = data.GetSize();
//Send data.
for (pos = 0; pos != data.GetSize(); ++pos)
{
pc.putc(data.GetData()[pos]);
}
// Loop until whole DLMS packet is received.
tmp = "";
do
{
if (Read(0x7E, bb) != 0)
{
return DLMS_ERROR_CODE_SEND_FAILED;
}
if (tmp.size() == 0)
{
Now(tmp);
tmp = "RX: " + tmp + "\t";
}
else
{
tmp += " ";
}
tmp += bb.ToHexString();
} while ((ret = m_Parser->GetData(bb, reply)) == DLMS_ERROR_CODE_FALSE);
tmp += "\r\n";
if (m_Trace > GX_TRACE_LEVEL_INFO)
{
printf("%s", tmp.c_str());
}
GXHelpers::Write("trace.txt", tmp);
if (ret == DLMS_ERROR_CODE_REJECTED)
{
ret = ReadDLMSPacket(data, reply);
}
return ret;
}
示例10: Read
int CGXCommunication::Read(unsigned char eop, CGXByteBuffer& reply)
{
bool bFound = false;
int pos, lastReadIndex = 0;
do
{
reply.SetUInt8(pc.getc());
if (reply.GetSize() > 5)
{
//Some optical strobes can return extra bytes.
for (pos = reply.GetSize() - 1; pos != lastReadIndex; --pos)
{
if (reply.GetData()[pos] == eop)
{
bFound = true;
break;
}
}
lastReadIndex = pos;
}
} while (!bFound);
return DLMS_ERROR_CODE_OK;
}
示例11: ValidateAuthentication
DLMS_SOURCE_DIAGNOSTIC CGXDLMSBase::ValidateAuthentication(
DLMS_AUTHENTICATION authentication,
CGXByteBuffer& password)
{
if (authentication == DLMS_AUTHENTICATION_NONE)
{
//Uncomment this if authentication is always required.
//return DLMS_SOURCE_DIAGNOSTIC_AUTHENTICATION_MECHANISM_NAME_REQUIRED;
}
if (authentication == DLMS_AUTHENTICATION_LOW)
{
CGXByteBuffer expected;
std::string name = "0.0.40.0.0.255";
if (GetUseLogicalNameReferencing())
{
CGXDLMSAssociationLogicalName* ln =
(CGXDLMSAssociationLogicalName*)GetItems().FindByLN(
DLMS_OBJECT_TYPE_ASSOCIATION_LOGICAL_NAME, name);
expected = ln->GetSecret();
}
else
{
CGXDLMSAssociationShortName* sn =
(CGXDLMSAssociationShortName*)GetItems().FindByLN(
DLMS_OBJECT_TYPE_ASSOCIATION_SHORT_NAME, name);
expected = sn->GetSecret();
}
if (expected.Compare(password.GetData(), password.GetSize()))
{
return DLMS_SOURCE_DIAGNOSTIC_NONE;
}
return DLMS_SOURCE_DIAGNOSTIC_AUTHENTICATION_FAILURE;
}
// Other authentication levels are check on phase two.
return DLMS_SOURCE_DIAGNOSTIC_NONE;
}
示例12: GetData
int CGXDLMSProfileGeneric::GetData(std::vector< std::vector<CGXDLMSVariant> >& table, CGXByteBuffer& data)
{
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
GXHelpers::SetObjectCount(table.size(), data);
std::vector<DLMS_DATA_TYPE> types;
DLMS_DATA_TYPE type;
int ret;
for (std::vector<std::pair<CGXDLMSObject*, CGXDLMSCaptureObject*> >::iterator it = m_CaptureObjects.begin();
it != m_CaptureObjects.end(); ++it)
{
if ((ret = (*it).first->GetDataType((*it).second->GetAttributeIndex(), type)) != 0)
{
return ret;
}
types.push_back(type);
}
for (std::vector< std::vector<CGXDLMSVariant> >::iterator row = table.begin(); row != table.end(); ++row)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
GXHelpers::SetObjectCount((*row).size(), data);
int pos = -1;
for (std::vector<CGXDLMSVariant>::iterator value = (*row).begin(); value != (*row).end(); ++value)
{
DLMS_DATA_TYPE tp = types[++pos];
if (tp == DLMS_DATA_TYPE_NONE)
{
tp = value->vt;
types[pos] = tp;
}
if ((ret = GXHelpers::SetData(data, tp, *value)) != 0)
{
return ret;
}
}
}
return DLMS_ERROR_CODE_OK;
}
示例13: GenerateChallenge
int CGXSecure::GenerateChallenge(DLMS_AUTHENTICATION authentication, CGXByteBuffer& challenge)
{
// Random challenge is 8 to 64 bytes.
// Texas Instruments accepts only 16 byte long challenge.
// For this reason challenge size is 16 bytes at the moment.
int len = 16;
//int len = rand() % 58 + 8;
unsigned char val;
for (int pos = 0; pos != len; ++pos)
{
val = rand();
challenge.SetUInt8(val);
}
return 0;
}
示例14: GetLogicalName
// Returns value of given attribute.
int CGXDLMSAutoAnswer::GetValue(int index, int selector, CGXDLMSVariant& parameters, CGXDLMSVariant& value)
{
if (index == 1)
{
return GetLogicalName(this, value);
}
if (index == 2)
{
value = GetMode();
return ERROR_CODES_OK;
}
if (index == 3)
{
int ret;
int cnt = m_ListeningWindow.size();
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
//Add count
GXHelpers::SetObjectCount(cnt, data);
CGXDLMSVariant f, s;
for (std::vector<std::pair<CGXDateTime, CGXDateTime> >::iterator it =
m_ListeningWindow.begin(); it != m_ListeningWindow.end(); ++it)
{
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(2); //Count
f = it->first;
s = it->second;
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, f)) != 0 || //start_time
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, s)) != 0) //end_time
{
return ret;
}
}
value = data;
return ERROR_CODES_OK;
}
if (index == 4)
{
value = GetStatus();
return ERROR_CODES_OK;
}
if (index == 5)
{
value = GetNumberOfCalls();
return ERROR_CODES_OK;
}
if (index == 6)
{
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
GXHelpers::SetObjectCount(2, data);
CGXDLMSVariant in = m_NumberOfRingsInListeningWindow;
CGXDLMSVariant out = m_NumberOfRingsOutListeningWindow;
int ret;
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, in)) != ERROR_CODES_OK ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, out)) != ERROR_CODES_OK)
{
return ret;
}
value = data;
return ERROR_CODES_OK;
}
return ERROR_CODES_INVALID_PARAMETER;
}
示例15: if
// Returns value of given attribute.
int CGXDLMSLimiter::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;
}
else if (e.GetIndex() == 2)
{
int ret;
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(3);
std::string ln;
m_MonitoredValue->GetLogicalName(ln);
CGXDLMSVariant type = m_MonitoredValue->GetObjectType();
CGXDLMSVariant tmp = ln;
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_INT16, type)) != 0 ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_OCTET_STRING, tmp)) != 0)
{
return ret;
}
//TODO: GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT8, m_Monitorede.GetValue().GetSelectedAttributeIndex());
e.SetValue(data);
}
else if (e.GetIndex() == 3)
{
e.SetValue(m_ThresholdActive);
return DLMS_ERROR_CODE_OK;
}
else if (e.GetIndex() == 4)
{
e.SetValue(m_ThresholdNormal);
}
else if (e.GetIndex() == 5)
{
e.SetValue(m_ThresholdEmergency);
}
else if (e.GetIndex() == 6)
{
e.SetValue(m_MinOverThresholdDuration);
}
else if (e.GetIndex() == 7)
{
e.SetValue(m_MinUnderThresholdDuration);
}
else if (e.GetIndex() == 8)
{
int ret;
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(3);
CGXDLMSVariant id = m_EmergencyProfile.GetID();
CGXDLMSVariant time = m_EmergencyProfile.GetActivationTime();
CGXDLMSVariant duration = m_EmergencyProfile.GetDuration();
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT16, id)) != 0 ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_DATETIME, time)) != 0 ||
(ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT32, duration)) != 0)
{
return ret;
}
e.SetValue(data);
}
else if (e.GetIndex() == 9)
{
int ret;
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_ARRAY);
data.SetUInt8(m_EmergencyProfileGroupIDs.size());
CGXDLMSVariant tmp;
for(std::vector<int>::iterator it = m_EmergencyProfileGroupIDs.begin(); it != m_EmergencyProfileGroupIDs.end(); ++it)
{
tmp = *it;
if ((ret = GXHelpers::SetData(data, DLMS_DATA_TYPE_UINT16, tmp)) != 0)
{
return ret;
}
}
e.SetValue(data);
}
else if (e.GetIndex() == 10)
{
e.SetValue(m_EmergencyProfileActive);
}
else if (e.GetIndex() == 11)
{
CGXByteBuffer data;
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(2);
data.SetUInt8(DLMS_DATA_TYPE_STRUCTURE);
data.SetUInt8(2);
int ret;
CGXDLMSVariant ln = m_ActionOverThreshold.GetLogicalName();
//.........这里部分代码省略.........