pull/11/merge
Kevin Zhao 8 years ago committed by GitHub
commit cb6d6d6ebb

@ -29,6 +29,7 @@ downloadHandler(void* parameter, uint8_t* buffer, uint32_t bytesRead)
if (bufferPosition + bytesRead < MAX_BUFFER_SIZE) {
memcpy(downloadBuffer + bufferPosition, buffer, bytesRead);
bufferPosition = bufferPosition + bytesRead;
return true;
}
else
@ -77,7 +78,8 @@ int main(int argc, char** argv) {
directoryEntry = LinkedList_getNext(directoryEntry);
}
bufferPosition = 0;
/* Download a file from the server */
IedConnection_getFile(con, &error, "IEDSERVER.BIN", downloadHandler, NULL);

@ -82,6 +82,43 @@ BerDecoder_decodeUint32(uint8_t* buffer, int intlen, int bufPos) {
return value;
}
int32_t
BerDecoder_decodeInt32(uint8_t* buffer, int intlen, int bufPos)
{
int32_t value = 0;
int flag = buffer[bufPos]&0x80;//flag=1表示负数flag=0表示正数
int i=0;
if(flag)
{
for(i=0;i<4;i++)
{
value<<=8;
if(i<4-intlen)
{
value+=0xff;
}
else
{
value+=buffer[bufPos + i-(4-intlen)];
}
}
}
else
{
for (i = 0; i < intlen; i++)
{
value <<= 8;
value += buffer[bufPos + i];
}
}
return value;
}
float
BerDecoder_decodeFloat(uint8_t* buffer, int bufPos)
{

@ -34,6 +34,9 @@ BerDecoder_decodeString(uint8_t* buffer, int strlen, int bufPos, int maxBufPos);
uint32_t
BerDecoder_decodeUint32(uint8_t* buffer, int intlen, int bufPos);
int32_t
BerDecoder_decodeInt32(uint8_t* buffer, int intlen, int bufPos);
float
BerDecoder_decodeFloat(uint8_t* buffer, int bufPos);

@ -212,7 +212,7 @@ mmsClient_handleFileReadRequest(
uint32_t invokeId,
ByteBuffer* response)
{
int32_t frsmId = (int32_t) BerDecoder_decodeUint32(buffer, maxBufPos - bufPos, bufPos);
int32_t frsmId = BerDecoder_decodeInt32(buffer, maxBufPos - bufPos, bufPos);
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: mmsClient_handleFileReadRequest read request for frsmId: %i\n", frsmId);
@ -232,7 +232,7 @@ mmsClient_handleFileCloseRequest(
uint32_t invokeId,
ByteBuffer* response)
{
int32_t frsmId = (int32_t) BerDecoder_decodeUint32(buffer, maxBufPos - bufPos, bufPos);
int32_t frsmId = BerDecoder_decodeInt32(buffer, maxBufPos - bufPos, bufPos);
MmsFileReadStateMachine* frsm = getFrsm(connection, frsmId);
@ -698,7 +698,7 @@ mmsMsg_parseFileOpenResponse(uint8_t* buffer, int bufPos, int maxBufPos, int32_t
switch (tag) {
case 0x80: /* frsmId */
*frsmId = (int32_t) BerDecoder_decodeUint32(buffer, length, bufPos);
*frsmId = BerDecoder_decodeInt32(buffer, length, bufPos);
bufPos += length;
break;

Loading…
Cancel
Save