-
Notifications
You must be signed in to change notification settings - Fork 5
/
SubMessage.cpp
74 lines (60 loc) · 1.25 KB
/
SubMessage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "SubMessage.h"
#include <string.h>
#include <stdio.h>
SubMessage::SubMessage()
{
}
SubMessage::SubMessage(Message *messagein)
{
AttachToMessage(messagein);
}
SubMessage::~SubMessage()
{
}
void SubMessage::AttachToMessage(Message *messagein)
{
message=messagein;
}
int SubMessage::AddToMessage()
{
message->AddToBody(&Type,1);
message->AddToBody(&Len,1);
message->AddToBody(Body,Len);
return 0;
}
void SubMessage::PrintState()
{
fprintf(stderr,"SubMsg Layer:");
switch(message->Source)
{
case PDM:fprintf(stderr,"PDM ");break;
case POD:fprintf(stderr,"POD ");break;
default:fprintf(stderr,"UNKOWN ");break;
}
fprintf(stderr,"Type:%02x ",Type);
fprintf(stderr,"Len:%d ",Len);
for(int i=0;i<Len;i++) fprintf(stderr,"%02x",Body[i]);
fprintf(stderr,"\n");
}
int SubMessage::ParseSubMessage(unsigned char *MsgBody,int LenBody)
{
if(LenBody<2) return -1;
Type=MsgBody[0];
if (Type==0x1D)
{
Len=LenBody-1;
memcpy(Body,MsgBody+1,Len);
return Len+1;
}
else
{
Len=MsgBody[1];
memcpy(Body,MsgBody+2,Len);
return Len+2;
}
return -1;
}
int SubMessage::SetSubMessage()
{
return 0;
}