Perform the full parsing of a message to be passed to a callback function This function returns a struct containing all the informations contained in the message : urbiMessage.timeStamp : the time stamp of the message urbiMessage.tag : the tag of the message urbiMessage.type : the type of the message: 'numeric', 'string', 'system', 'image', 'sound', or 'otherBIN') if type == numeric, then urbiMessage.value (the numeric value of the message) if type == string, then urbiMessage.value (the string value of the message) if type == system, then urbiMessage.value (the string value of the system message) if type == image, then urbiMessage.image is the same as the result of urbiGetImage(con) (with the fields matrix, width, height, timeStamp) if type == sound, then urbiMessage.sound is the same as the result of urbiGetSound(con, length) (with the fields samples, Fs, nbits, length) if type == otherBIN then urbiMessage.bin (the vector of bytes of the BIN info)
0001 function urbiMessage = urbiFullParse(string, timeStamp, con) 0002 % Perform the full parsing of a message to be passed to a callback function 0003 % This function returns a struct containing all the informations 0004 % contained in the message : 0005 % 0006 % urbiMessage.timeStamp : the time stamp of the message 0007 % urbiMessage.tag : the tag of the message 0008 % urbiMessage.type : the type of the message: 'numeric', 'string', 0009 % 'system', 'image', 'sound', or 'otherBIN') 0010 % 0011 % if type == numeric, then urbiMessage.value (the numeric value of the message) 0012 % if type == string, then urbiMessage.value (the string value of the message) 0013 % if type == system, then urbiMessage.value (the string value of the system message) 0014 % if type == image, then urbiMessage.image is the same as the result of urbiGetImage(con) 0015 % (with the fields matrix, width, height, timeStamp) 0016 % if type == sound, then urbiMessage.sound is the same as the result of urbiGetSound(con, length) 0017 % (with the fields samples, Fs, nbits, length) 0018 % if type == otherBIN then urbiMessage.bin (the vector of bytes of the BIN info) 0019 0020 0021 io_buffer = 'imageB.jpg'; 0022 0023 f = sscanf(string{2}, '%f') ; 0024 if ~isempty(f) 0025 type = 'numeric'; 0026 value = f; 0027 image = []; 0028 sound = []; 0029 bin = []; 0030 else 0031 s = string{2}; 0032 if strcmp(s, 'BIN') 0033 if strcmp(string{4}, 'jpeg') 0034 type = 'image'; 0035 value = []; 0036 pnet(con, 'readtofile', io_buffer, sscanf(string{3}, '%u')) ; 0037 data = imread(io_buffer) ; 0038 image = struct('matrix',data,'width',sscanf(string{5}, '%u'),'height', sscanf(string{6}, '%u'), 'timeStamp', timeStamp); 0039 sound = []; 0040 bin = []; 0041 elseif strcmp(string{4}, 'raw') 0042 type = 'sound'; 0043 value = []; 0044 image = []; 0045 % Parse the sound and store the structure 0046 Fs = str2num ( string{6} ); 0047 length = str2num ( string{3} ); 0048 nbits = str2num ( string{7} ); 0049 channel = str2num ( string{5} ); 0050 duration = length/(Fs*channel*(nbits/8))*1000; 0051 samples = pnet(con, 'read', length, 'noblock'); 0052 sound = struct('samples',samples,'Fs',Fs,'nbits', nbits, 'length', length, 'channel', channel, 'duration',duration); 0053 bin = []; 0054 else 0055 type = 'otherBIN'; 0056 value = []; 0057 image = []; 0058 sound = []; 0059 bin = pnet(con, 'read', str2num ( string{3} ), 'noblock'); 0060 end; 0061 else 0062 if strcmp(s, '***') 0063 type = 'system'; 0064 value = sprintf('%s ',string{3:end}); 0065 elseif strcmp(s, '!!!') 0066 type = 'error'; 0067 value = sprintf('%s ',string{3:end}); 0068 else 0069 type = 'string'; 0070 value = sprintf('%s ',string{2:end}); 0071 end; 0072 image = []; 0073 sound = []; 0074 bin = []; 0075 end; 0076 end; 0077 0078 urbiMessage = struct('timeStamp', timeStamp, 'type', type, 'value', value, 'image', image, 'sound', sound, 'bin', bin);