📄 read_input_payload.m
字号:
%=============================================================================
%
% LTD DSP Software Schaumburg, IL.
%
% COPYRIGHT 2006 Motorola, Inc.
%
% All Rights Reserved
%
%------------------------------- Module Name ---------------------------------
%
% Module Name: read_input_payload.m
%
% Original Author: Mphahlele Moruthane
%
% Date of Origin (MM/DD/YY): 01/06/2006
%
%-------------------------------- Revisions ----------------------------------
%
% Person Date Comments
%
% jan/06/2006 - moruthane - created
%
%----------------------- Detailed Design Description -------------------------
%
% Read data from input file. Reads input payload in ASCII hex format.
% Reshapes entire file into 1 row. Converts each byte in the file to a
% string of 8 bytes (1 for each bit). Returns string of bits representing
% the file to the caller.
%
% Assumptions:
% File format consists of data in ASCII hex.
%
% This format was chosen because the AMBE file format generated by
% Motorola ATS "FFC" tool consists of:
%
% Lines of 72-bit frames in ASCII hex
% - Frame data is specified in hex, one 72-bit frame per line
% - 18 hex digits per line representing 72 bits
%
%=============================================================================
function payload = read_input_payload(input_filename)
%=============================================================================
% Define/initialise parameters & load pre-determined data
%=============================================================================
%init payload variables
payload = [];
%=============================================================================
% Open file
%=============================================================================
fid = fopen(input_filename, 'r');
try
%=============================================================================
% Read data
%=============================================================================
% read entire ASCII file
file_input_data = fread(fid, 'uchar');
% make sure input data is 1 row
[ nr, nc ] = size(file_input_data);
ascii_input_data = reshape(file_input_data, 1, nr*nc);
%Remove '0x' from start of data file
if((ascii_input_data(1) == 48)&&(ascii_input_data(2) == 120))
ascii_input_data = ascii_input_data(3:end);
end
% convert ASCII hex number to decimal
g = 1;
for h = 1:length(ascii_input_data),
switch(ascii_input_data(h)),
% Decimal (0-9) (0 = 48)
case {48, 49, 50, 51, 52, 53, 54, 55, 56, 57},
input_data(g) = ascii_input_data(h) - 48;
g = g+1;
% Lower-case hex digit (a-f) (a = 97)
case {97, 98, 99, 100, 101, 102},
input_data(g) = ascii_input_data(h) - 87;
g = g+1;
% Upper-case hex digit (A-F) (A = 65)
case {65, 66, 67, 68, 69, 70},
input_data(g) = ascii_input_data(h) - 55;
g = g+1;
otherwise,
% do nothing.
end
end
% convert each byte into a row of 4 bits, and append to payload
[ nr, nc ] = size(input_data);
for i = 1:nc,
input_bits_str = dec2bin(input_data(i), 4);
for j = 1:4,
input_bits(j) = str2double(input_bits_str(j));
end
payload = [ payload input_bits ];
end
catch
% Make sure to cleanup in case of error. (Just make sure files get closed)
% fclose(fid);
rethrow(lasterror);
end
%=============================================================================
% Close files
%=============================================================================
fclose(fid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -