diff --git a/electophysio01.cpp b/electophysio01.cpp index 3010cd19a17486a44eb59d596ee685392ac1c70d..c78e33c2faba7229050e81f9f2416cdcaa90c929 100644 --- a/electophysio01.cpp +++ b/electophysio01.cpp @@ -35,7 +35,12 @@ class ElectroPhysio01 int Stimperiod_delta_ms; int Stimperiod_max_ms; int Stimperiod_min_ms; - int Stimedur_ms; + + + int Stimedur_microsec; + int Stimedur_max_microsec; + int Stimedur_min_microsec; + int Stimedur_delta_microsec; int Stimdens_pApF; int Stimdens_delta_pApF; @@ -64,7 +69,11 @@ class ElectroPhysio01 ElectroPhysio01() { quit_flag = false; - Stimedur_ms = 1; + Stimedur_microsec = 1000; + Stimedur_max_microsec = 5000; + Stimedur_min_microsec = 100; + Stimedur_delta_microsec=100; + Stimperiod_ms = 1000; Stimperiod_min_ms = 200; @@ -90,12 +99,12 @@ class ElectroPhysio01 range =0; aref = AREF_GROUND; } - long currentTimeMilliSec() + long currentTimeMicroSec() { struct timespec spec; ::clock_gettime(CLOCK_REALTIME, &spec); - return spec.tv_sec*1000 + round(spec.tv_nsec / 1.0e6); + return spec.tv_sec*1.0e6 + round(spec.tv_nsec / 1.0e3); } void now(xmlTextWriterPtr out) { @@ -128,6 +137,7 @@ class ElectroPhysio01 int main(int argc,char** argv) { + int calc_resistance_state=0; double resistance=0; double* start_test_injection=NULL; std::string cell_name("NoName"); @@ -137,6 +147,7 @@ class ElectroPhysio01 std::string exit_message("OK"); int exit_status = EXIT_SUCCESS; bool dump_data_flag=true; + bool do_stimulation_flag=true; xmlTextWriterPtr xmlOutLog=NULL; string filenameout; for(;;) @@ -183,7 +194,7 @@ class ElectroPhysio01 SubDevice* inout=(i==0?&in_subdev:&out_subdev); inout->range_info = comedi_get_range(this->device, inout->fileno, this->chan, this->range); inout->maxdata = comedi_get_maxdata(this->device, inout->fileno, this->chan); - assert(inout->range_info->unit == UNIT_mA); + assert(inout->range_info->unit == UNIT_volt); } @@ -210,7 +221,7 @@ class ElectroPhysio01 ::noecho(); ::curs_set(0); - clock_last = clock_start = this->currentTimeMilliSec(); + clock_last = clock_start = this->currentTimeMicroSec(); while (!quit_flag) { @@ -229,6 +240,28 @@ class ElectroPhysio01 } break; } + + + + case '+': + { + if( Stimedur_microsec != Stimedur_max_microsec) + { + Stimedur_microsec = std::min ( Stimedur_max_microsec, Stimedur_microsec + Stimedur_delta_microsec); + dump_data_flag=true; + } + break; + } + case '-': + { + if( Stimedur_microsec != Stimedur_min_microsec) + { + Stimedur_microsec = std::max ( Stimedur_min_microsec, Stimedur_microsec - Stimedur_delta_microsec); + dump_data_flag=true; + } + break; + } + case KEY_RIGHT: { if( Stimperiod_ms != Stimperiod_max_ms) @@ -278,6 +311,16 @@ class ElectroPhysio01 case 'q': case 'Q': quit_flag=true; break; + case 'r':case 'R': + calc_resistance_state=(calc_resistance_state==0?1:0); + if( start_test_injection!=NULL) delete start_test_injection; + start_test_injection=NULL; + dump_data_flag=true; + break; + case 'T': case 't': + do_stimulation_flag=!do_stimulation_flag; + dump_data_flag=true; + break; default: ::beep(); break; @@ -326,8 +369,8 @@ class ElectroPhysio01 dump_data_flag=true; } - long clock_curr = this->currentTimeMilliSec(); - if(clock_last - clock_curr > 50*1000) //50sec) + long clock_curr = this->currentTimeMicroSec(); + if(calc_resistance_state==1 || (calc_resistance_state==2 && (clock_last - clock_curr) > 60*1E6)) //60sec) { dump_data_flag=true; clock_last=clock_curr; @@ -336,29 +379,51 @@ class ElectroPhysio01 if(dump_data_flag) { int y=0; + ::clear(); mvprintw(y,0,"ik1flag : %10s",(ik1flag?"on":"off")); ++y; mvprintw(y,0,"Stimperiod : %10d ms",Stimperiod_ms); ++y; + mvprintw(y,0,"Stimedur : %10.3f ms",(float)(Stimedur_microsec/1000.0)); ++y; mvprintw(y,0,"Stimdens : %10d pA/pF",Stimdens_pApF); ++y; mvprintw(y,0,"ik1dens : %10d pA/pF",ik1dens); ++y; mvprintw(y,0,"membrane_cap : %10d pF",membrane_cap); ++y; mvprintw(y,0,"cell-name : %10s",cell_name.c_str()); ++y; - mvprintw(y,0,"resistance : %10s",cell_name.c_str()); ++y; + if(calc_resistance_state!=0) + { + mvprintw(y,0,"resistance : %10f",resistance); ++y; + calc_resistance_state=2; + } + mvprintw(y,0,"calc res. : %10s",(calc_resistance_state!=0?"on":"off")); ++y; + mvprintw(y,0,"stimulation : %10s",(do_stimulation_flag?"on":"off")); ++y; + ++y; + + mvprintw(y,0,"'ARROW_LEFT' 'ARROW_RIGHT' to change Stimperiod"); ++y; + mvprintw(y,0,"'ARROW_UP' 'ARROW_DOWN' to change Stimdens"); ++y; + mvprintw(y,0,"'0'-'9' to change ik1dens"); ++y; + mvprintw(y,0,"'+'/'-' to change stimedur"); ++y; + mvprintw(y,0,"<space> to change ik1flag"); ++y; + mvprintw(y,0,"'T' to change stimulation"); ++y; + mvprintw(y,0,"'R' to change resistance"); ++y; mvprintw(y,0,"'S' to change capacitance/cell"); ++y; + mvprintw(y,0,"'R' show resistance every 60sec"); ++y; mvprintw(y,0,"'Q' to exit."); ++y; if(xmlOutLog!=NULL) { xmlTextWriterStartElement(xmlOutLog,BAD_CAST "data"); now(xmlOutLog); - xmlTextWriterWriteFormatAttribute(xmlOutLog,BAD_CAST"ms","%ld", this->currentTimeMilliSec()); + xmlTextWriterWriteFormatAttribute(xmlOutLog,BAD_CAST"ms","%ld", 1000*this->currentTimeMicroSec()); xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "ik1flag","%s",(ik1flag?"on":"off")); + xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "stimulation","%s",(do_stimulation_flag?"on":"off")); xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "Stimperiod","%d",Stimperiod_ms); xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "ik1dens","%d",ik1dens); xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "membrane_cap","%d",membrane_cap); xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "cell_name","%s",cell_name.c_str()); - xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "resistance","%f",resistance); - + xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "stimedur","%d",stimedur); + if(calc_resistance_state!=0) + { + xmlTextWriterWriteFormatElement(xmlOutLog,BAD_CAST "resistance","%f",resistance); + } xmlTextWriterEndElement(xmlOutLog); } refresh(); @@ -385,14 +450,18 @@ class ElectroPhysio01 - long clock_now = this->currentTimeMilliSec(); + long clock_now = this->currentTimeMicroSec(); - if( clock_now % Stimperiod_ms < Stimedur_ms) + + + + if(do_stimulation_flag && (clock_now % (1000*Stimperiod_ms) < Stimedur_microsec )) { injected_current = Stimdens_pApF * membrane_cap; } - else if( clock_now % Stimperiod_ms < Stimedur_ms -49 && clock_now % Stimperiod_ms > Stimedur_ms -50) + else if( calc_resistance_state!=0 && (clock_now % (1000*Stimperiod_ms) >= (1000*(Stimperiod_ms-10))) && (clock_now % (1000*Stimperiod_ms) <= (1000*(Stimperiod_ms-9)))) { + injected_current = -25 * membrane_cap; if( start_test_injection == NULL) { @@ -441,6 +510,7 @@ class ElectroPhysio01 xmlTextWriterEndElement(xmlOutLog); xmlTextWriterEndDocument(xmlOutLog); } + if( start_test_injection!=NULL) delete start_test_injection; ::comedi_close(this->device); clog << exit_message << endl; return exit_status; diff --git a/xml2table.xsl b/xml2table.xsl index 6ee03c141a0160b8f22a62ca101bb9f83ebd1eaa..b8c0432ae6321877032e7c607ce4036858093e21 100644 --- a/xml2table.xsl +++ b/xml2table.xsl @@ -6,7 +6,7 @@ <xsl:output method="text"/> <xsl:template match="/"> -<xsl:text>#time ik1flag Stimperiod ik1dens membrane_cap cell_name +<xsl:text>#time ik1flag Stimperiod ik1dens membrane_cap cell_name stimdur resistance </xsl:text> <xsl:apply-templates select="//data"/> </xsl:template> @@ -23,6 +23,10 @@ <xsl:value-of select="membrane_cap"/> <xsl:text> </xsl:text> <xsl:value-of select="cell_name"/> +<xsl:text> </xsl:text> +<xsl:value-of select="stimdur"/> +<xsl:text> </xsl:text> +<xsl:value-of select="resistance"/> <xsl:text> </xsl:text> </xsl:template>