-
Notifications
You must be signed in to change notification settings - Fork 4
/
icm_init_mem_file.m
69 lines (60 loc) · 2.02 KB
/
icm_init_mem_file.m
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 m = icm_init_mem_file(cp, clearFile)
filename = fullfile(pwd, 'icm_comm.dat');
numFitter = cp.numFitter;
W = cp.imW;
H = cp.imH;
numImageCache = cp.maxNumCache;
frame = zeros(H, W);
frameIdx = 0;
frameTime = 0.0;
tic = 0;
% global status, only use first one of the array
% (1): measurement status. 1: running, 0 stopped.
% (2): lastWriteFrameIdx
% (3): workerStatus. 0: not running, 1: started, 2: targetReached
status = [1 0 0]';
if clearFile && exist(filename, 'file')
disp(['remove file ', filename])
delete(filename)
end
% Create the communications file if it is not already there.
if ~exist(filename, 'file')
disp(['init file ', filename])
[f, msg] = fopen(filename, 'wb');
if f ~= -1
for i = 1:numImageCache
fwrite(f, frame, 'uint8');
fwrite(f, frameIdx, 'uint32');
fwrite(f, frameTime, 'double');
fwrite(f, 0, 'uint64'); % snapTic
fwrite(f, 0, 'uint8'); % uvIris
fwrite(f, 0, 'uint8'); % uvStatus
fwrite(f, 0, 'double'); % avgTotalHeight
fwrite(f, 0, 'double'); % avgTotalPhase
fwrite(f, status, 'int32');
end
fclose(f);
else
error('MATLAB:demo:send:cannotOpenFile', ...
'Cannot open file "%s": %s.', filename, msg);
end
end
% Memory map the file.
disp(['creating memmapfile for', filename])
m = memmapfile(filename,...
'Writable', true,...
'Format', {...
'uint8', size(frame), 'frame';...
'uint32', size(frameIdx), 'frameIdx';...
'double', size(frameTime), 'frameTime';...
'uint64', [1 1], 'snapTic';...
'uint8', [1 1], 'uvIris';...
'uint8', [1 1], 'uvStatus';...
'double', [1, 1], 'avgTotalHeight';...
'double', [1, 1], 'avgTotalPhase';...
'int32', size(status), 'status';...
},...
'Repeat', numImageCache...
);
fprintf('init status = %d\n', m.Data(1).status);
return;