-
Notifications
You must be signed in to change notification settings - Fork 0
/
piping.m
61 lines (53 loc) · 1.64 KB
/
piping.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
classdef piping < handle
properties
topics
topic_names
param
settings
functions
end
methods
function self = piping()
self.topics = {};
self.topic_names = {};
end
function publish(self,name,data)
index = strcmp(name,[self.topic_names{1:end}]);
if any(index)
self.topics{index}{end+1} = data;
else
self.topic_names{end+1} = name;
self.topics{end+1}{1} = data;
end
end
function publish_list(self,name,data)
for packet = data
self.publish(name,packet);
end
end
function data = subscribe(self,name)
index = strcmp(name,[self.topic_names{1:end}]);
if any(index)
data = self.topics{index}{end};
else
error('Subcribed to a unpublished topic.')
end
end
function data = subscribe_history(self,name)
index = strcmp(name,[self.topic_names{1:end}]);
if any(index)
data = cell2mat(self.topics{index});
else
error('Subcribed to a unpublished topic.')
end
end
function data = subscribe_specific(self,name,history_index)
index = strcmp(name,[self.topic_names{1:end}]);
if any(index)
data = self.topics{index}{history_index};
else
error('Subcribed to a unpublished topic.')
end
end
end
end