Repository navigation
Expand file tree
/
Copy pathREMO_FORM_get.m
More file actions
69 lines (57 loc) · 1.44 KB
/
Copy pathREMO_FORM_get.m
File metadata and controls
69 lines (57 loc) · 1.44 KB
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
function [data,FormatString,error] = REMO_FORM_get(Port,Bytes)
error = 0;
CheckSum = 0;
% get pre-check form ASA_PC
for i = 1:3
check = fread(Port,1,'uint8');
if check ~= hex2dec('BB');
error = 2;
warning('«Ê¥]ÀY¿ù»~');
return
end
end
% get TotalBytes
GetTotalBytes = fread(Port,1,'uint8');
CheckSum = GetTotalBytes;
% get FormatBytes
GetFormatBytes = fread(Port,1,'uint8');
CheckSum = CheckSum + GetFormatBytes;
% get data bytes
GetBytes = GetTotalBytes-GetFormatBytes;
% get FormatBytes
for i = 1:GetFormatBytes
FormatString(i) = fread(Port,1,'uint8');
CheckSum = CheckSum + FormatString(i);
end
FormatString = char(FormatString);
[Format,TypeNum,StructSize,error] = FormatGet(FormatString);
% get binary data in uint8 form ASA_PC
for i = 1:Bytes
Cdata(i) = fread(Port,1,'uint8');
CheckSum = CheckSum + Cdata(i);
end
% get check value form ASA_PC
CheckSum = rem(CheckSum,256);
GetCheckSum = fread(Port,1,'uint8');
% trans binary data to struct
i = 1;
for n = 1 : Bytes/StructSize
for j = 1:TypeNum
l = i + Format(j).TypeSize*Format(j).Num - 1;
arraydata = typecast( uint8(Cdata( i:l )) , Format(j).Type);
i = l+1;
celldata(j,n)= {arraydata};
end
end
data = cell2struct(celldata,{Format.Name},1);
if GetBytes~=Bytes+1
error = 3;
warning('Bytes¿ù»~');
return;
end
if CheckSum ~= GetCheckSum
error = 4;
warning('CheckSum¿ù»~');
return;
end
end