summaryrefslogtreecommitdiffstats
path: root/Kod/bilbana/yc4/display/get_response.m
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-11-14 09:59:31 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-11-14 10:05:49 +0100
commit14b2064d325f8065dad48421c16db9b4ac678cfe (patch)
treea336ca6548355d9cd4bc3448fae2eeccb25057be /Kod/bilbana/yc4/display/get_response.m
parent74f1d443644c8654d9fbc3bf48f5d3b87e48c199 (diff)
parent50ed829577446a0ae66395a1c20f47e79282d4cd (diff)
downloadtfyy51-14b2064d325f8065dad48421c16db9b4ac678cfe.tar.gz
Merge branch 'display-io' into car-function
Diffstat (limited to 'Kod/bilbana/yc4/display/get_response.m')
-rw-r--r--Kod/bilbana/yc4/display/get_response.m56
1 files changed, 56 insertions, 0 deletions
diff --git a/Kod/bilbana/yc4/display/get_response.m b/Kod/bilbana/yc4/display/get_response.m
new file mode 100644
index 0000000..0c77a00
--- /dev/null
+++ b/Kod/bilbana/yc4/display/get_response.m
@@ -0,0 +1,56 @@
+function [ack, start_code, responses] = get_response(display_data)
+% GET RESPONSE
+% In-depth explanation
+% [flag, display_data] = matlabclient(2)
+
+ack = false;
+start_code = '';
+responses = [];
+
+if isempty(display_data)
+ return
+end
+bcc = display_data(length(display_data));
+
+
+pointer = 1;
+
+if display_data(pointer) == 6
+ ack = true;
+else
+ return
+end
+
+if pointer > length(display_data)
+ return
+end
+
+pointer = pointer + 1;
+if display_data(1) == 17
+ start_code = 'DC1';
+elseif display_data(1) == 18
+ start_code = 'DC2';
+end
+
+pointer = pointer + 1;
+% total length
+
+data = struct;
+while pointer < length(display_data) - 1 % last value is bcc
+ pointer = pointer + 1;
+ if display_data(pointer) ~= 27
+ % TODO: no ESC?
+ end
+ pointer = pointer + 1;
+ data.id = char(display_data(pointer));
+
+ pointer = pointer + 1;
+ data.length = display_data(pointer);
+ if data.id == 'A'
+ pointer = pointer + 1;
+ data.data = display_data(pointer);
+ else
+ pointer = pointer + data.length;
+ end
+ responses = [responses, data];
+end