Главная страница

Отчет_Разработка мобильных приложений_ЛР3. РМП_лр3. Необработанные


Скачать 0.75 Mb.
НазваниеНеобработанные
АнкорОтчет_Разработка мобильных приложений_ЛР3
Дата25.05.2021
Размер0.75 Mb.
Формат файлаdocx
Имя файлаРМП_лр3.docx
ТипДокументы
#209662
страница3 из 3
1   2   3

else //многосегментный
{
seg.name=header[0];
seg.number_of_segments=Integer.parseInt(header[0].substring(header[0].indexOf("/") + 1));
}
// читаемформатсигналов
while ((str = br.readLine()) != null) {
if (str.startsWith("#", 0)) {
str1+= str.replaceAll("#","")+"\n\r";
}
else {
if (cnt<=seg.number_of_signals) {
signal[cnt-1]=new SignHeader();
signal[cnt-1].index=cnt;
str=str.replaceAll("\\n","");
str=str.replaceAll("\\r","");
str=str.trim();
if (str!="") {
SignalHeader(str,cnt-1);
cnt++;
}
}}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
} catch (IOException e) {
tvOut.setText("IOException");
e.printStackTrace();
return;
}
tvHeader.setText(str1+"\n\rname: "+ seg.name+"\n\rnumber_of_segments: "+seg.number_of_segments+"\n\rnumber_of_signals: "+seg.number_of_signals+
"\n\rsampling_frequency: "+seg.sampling_frequency+"\n\rcounter_frequency: "+seg.counter_frequency+
"\n\rbase_counter_value: "+seg.base_counter_value+"\n\rnumber_of_samples_per_signal: "+seg.number_of_samples_per_signal+
"\n\rbase_time: "+seg.base_time+"\n\rbase_date: "+seg.base_date);
int i=signal_spinner.getSelectedItemPosition();
if (cnt-1tvSignal.setText("\n\rfile_name: "+ signal[i].file_name+"\n\rformat: "+signal[i].format+"\n\rsamples_per_frame: "+signal[i].samples_per_frame+
"\n\rskew: "+signal[i].skew+"\n\rbyte_offset: "+signal[i].byte_offset+
"\n\radc_gain: "+signal[i].adc_gain+"\n\rbaseline: "+signal[i].baseline+
"\n\runits: "+signal[i].units+"\n\radc_resolution: "+signal[i].adc_resolution+"\n\radc_zero: "+signal[i].adc_zero+
"\n\rinitial_value: "+signal[i].initial_value+"\n\rchecksum: "+signal[i].checksum+"\n\rblock_size: " +signal[i].block_size+
"\n\rdescription: "+signal[i].description);
return;
}
//Чтениеописанияформатадлякаждогосигналаиззаголовочногофайла
void SignalHeader(String str,int cnt) {
String arr[] = str.split(" "); // разбиваемстрокупопробелу
if (arr[0]==" ") return;
signal[cnt].file_name=arr[0];
if (arr[1].indexOf("x") == -1)
signal[cnt].format=Integer.parseInt(arr[1]);
else {
signal[cnt].format = Integer.parseInt(arr[1].substring(0,arr[1].indexOf("x")));
if (arr[1].indexOf(":") == -1)
signal[cnt].samples_per_frame=Integer.parseInt(arr[1].substring(arr[1].indexOf("x")+1));
else {
signal[cnt].samples_per_frame=Integer.parseInt(arr[1].substring(arr[1].indexOf("x")+1,arr[1].indexOf(":")));
if (arr[1].indexOf("+") == -1)
signal[cnt].skew=Integer.parseInt(arr[1].substring(arr[1].indexOf(":")+1));
else {
signal[cnt].skew=Integer.parseInt(arr[1].substring(arr[1].indexOf(":")+1,arr[1].indexOf("+")));
signal[cnt].byte_offset=Integer.parseInt(arr[1].substring(arr[1].indexOf("+")+1));
}
max_skew = Math.max(max_skew, signal[cnt].skew);
}
}
if (arr.length>2) {
if (arr[2].indexOf("(") == -1){
signal[cnt].adc_gain = Float.parseFloat(arr[2]);
if (arr.length>4) signal[cnt].baseline=Integer.parseInt(arr[4]);
else signal[cnt].baseline=0;
}
else {
signal[cnt].adc_gain = Float.parseFloat(arr[2].substring(0,arr[2].indexOf("(")-1));
signal[cnt].baseline=Integer.parseInt(arr[2].substring(arr[2].indexOf("(")+1,arr[2].indexOf(")")));
}
if (arr[2].indexOf("/") == -1) signal[cnt].units="mv";
else signal[cnt].units=arr[2].substring(arr[2].indexOf("/")+1);
}
else signal[cnt].adc_gain=200;
if (arr.length>3) {
signal[cnt].adc_resolution = Integer.parseInt(arr[3]);
if (arr.length>4) {
signal[cnt].adc_zero = Integer.parseInt(arr[4]);
if (arr.length>5) {
signal[cnt].initial_value = Integer.parseInt(arr[5]);
if (arr.length>6) {
signal[cnt].checksum = Integer.parseInt(arr[6]);
if (arr.length>7) {
signal[cnt].block_size = Integer.parseInt(arr[7]);
if (arr.length>8)
signal[cnt].description=arr[8];
else signal[cnt].description="";
}
else signal[cnt].block_size=0;
}
else signal[cnt].checksum=0;
}
else signal[cnt].initial_value=signal[cnt].adc_zero;
}
else signal[cnt].adc_zero=0;
}
else signal[cnt].adc_resolution=12; // covers only amplitude formats

if(signal[cnt].adc_resolution>highest_adc_resolution) {
highest_adc_resolution = signal[cnt].adc_resolution;
}
int bits_per_frame = signal[cnt].format * signal[cnt].samples_per_frame;
total_bits_per_frame += bits_per_frame;
total_bytes_per_frame = total_bits_per_frame / 8;
if(signal[cnt].samples_per_frame>highest_samples_per_frame) {
highest_samples_per_frame = signal[cnt].samples_per_frame;
}
}
//-------------------------------------------------------------------------------------------
void SignalFile() {
cntPoints=0;
//отступдляданногоинтервалаотначалавыбранногосегмента:
int BaseInterval= (int) ((Nint-1)*Integer.parseInt(Intervals[interval_spinner.getSelectedItemPosition()])*seg.sampling_frequency*total_bytes_per_frame);
//количествобайтмеждуточкфмиграфика
int tim= (int) (Integer.parseInt(Intervals[interval_spinner.getSelectedItemPosition()])*seg.sampling_frequency*total_bytes_per_frame/100);
int sig=signal_spinner.getSelectedItemPosition();
int signalBase=sig*signal[sig].format;//началоотсчетадляданногосигналавофрейме
int skewedSignalBase;
short num = 0;
int i=0;
byte[] buffer = new byte[tim];
try {
FileInputStream inputStream = new FileInputStream(fileD);
// открываемпотокдлячтения
BufferedInputStream br = new BufferedInputStream(inputStream);
br.skip(BaseInterval);//пропускаемучастокдоначалаинтервала
//
читаемсодержимоефрейма
while (br.read(buffer,0,tim) !=-1) {
skewedSignalBase = signalBase + signal[sig].skew *tim;
num= ByteBuffer.wrap(buffer).getShort(skewedSignalBase);
if(num != -1 << 15) {
// WFDB calls this value VFILL
// }
// else samples[cntPoints]=(float)-0.123456789;
samples[cntPoints]=((float)(num - signal[sig].baseline)) / signal[sig].adc_gain;
cntPoints++;
if (cntPoints==101) break;}
i++;
if (i>101) break;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ShowGraph();
return;
}
//Формированиеграфика
void ShowGraph() {
float Sec=Integer.parseInt(Intervals[interval_spinner.getSelectedItemPosition()]);
DataPoint[] points = new DataPoint[cntPoints];
DataPoint p;
for (int i = 0; i < cntPoints; i++) {
p=new DataPoint(i, samples[i]);
points[i] = p;
}
LineGraphSeries lineSeries = new LineGraphSeries<>(points);
linegraph.removeAllSeries();
linegraph.addSeries(lineSeries);
// set manual X bounds
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(linegraph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"0",String.valueOf(Sec*0.25), String.valueOf(Sec*0.5),
String.valueOf(Sec*0.75), String.valueOf(Sec)});
linegraph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
}

}
1   2   3


написать администратору сайта