function varargout = crcgui(varargin)
% CRCGUI MATLAB code for crcgui.fig
% CRCGUI, by itself, creates a new CRCGUI or raises the existing
% singleton*.
%
% H = CRCGUI returns the handle to a new CRCGUI or the handle to
% the existing singleton*.
%
% CRCGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CRCGUI.M with the given input arguments.
%
% CRCGUI('Property','Value',...) creates a new CRCGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before crcgui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to crcgui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help crcgui
% Last Modified by GUIDE v2.5 10-May-2018 20:01:55
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @crcgui_OpeningFcn, ...
'gui_OutputFcn', @crcgui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before crcgui is made visible.
function crcgui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to crcgui (see VARARGIN)
% Choose default command line output for crcgui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes crcgui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = crcgui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rawdatastr = get(handles.edit2, 'string' );
%rawdatastr = '10211111';
rawlen = length(rawdatastr);
rawdata = double(rawdatastr); %输入原始数据并转化为矩阵形式以便计算
for i = 1:rawlen
rawdata(i)= str2num(char(rawdata(i)));
if rawdata(i)~=0 && rawdata(i)~=1
errordlg('待编码数据输入有误,输入的字符只能为1或0');
return
end
end
genstr = get(handles.edit4, 'string' ); %输入生成多项式并转化为矩阵形式
genlen = length(genstr);
gen = double(genstr);
for i = 1:genlen
gen(i)= str2num(char(gen(i)));
if gen(i)~=0 && gen(i)~=1
errordlg('生成多项式输入有误,输入的字符只能为1或0');
return
end
if gen(1)==0 || gen(genlen)== 0
errordlg('生成多项式输入有误,首位及末尾只能为1');
return
end
end
data_back = rawdata;
for m = 1:genlen-1
rawdata = [rawdata 0];
end
dlen = length(rawdata);
cr = rawdata(1:genlen-1);
for p = genlen:dlen
cr(genlen) = rawdata(p);
if cr(1)
cr = xor(cr(2:genlen), gen(2:genlen)); %异或运算,相当于除法
else
cr = cr(2:genlen);
end
end
crcdata = [data_back cr];
%crcdata = [rawdata 0 0 0];
for i = 1:(dlen)
crcdatastr(i) = num2str(crcdata(i));
end
set(handles.edit6,'string',crcdatastr);
%{
a1=str2double(get(handles.edit2,'String'));
a2=str2double(get(handles.edit4,'String'));
set(handles.edit6,'String',num2str(a1+a2));
%}
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundC