void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { Pf *pf; char *name; char *mystring; mxArray *input[1]; if( nlhs > 1 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } if( nrhs != 2 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! get_pf( prhs[0], &pf ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! mtlb_get_string( prhs[1], &name ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } pfconfig( "ask", (void *) matlabPfprompt ); mystring = pfget_string( pf, name ); antelope_mex_clear_register( 1 ); mxFree( name ); if( mystring == NULL ) { mexErrMsgTxt( "pfget_num: Couldn't get specified value" ); } else { input[0] = mxCreateString( mystring ); mexCallMATLAB( 1, plhs, 1, input, "str2double" ); mxDestroyArray( input[0] ); } }
static FP32 fetch_flow( enum enumPumpSelect PumpSelect ) { FP32 f_org; FP32 Ba, Tr, Pr; FP32 pf; // 读取传感器(未归一化、未校准的)流量 switch( Configure.PumpType[PumpSelect] ) { default: case enumPumpNone: // 没有流量计 或 未安装 return 0.0f; case enumOrifice_1: // 1L孔板流量计 case enumOrifice_2: // 2L孔板流量计 { Ba = get_Ba(); Tr = get_Tr( PumpSelect ); Pr = get_Pr( PumpSelect ); pf = get_pf( PumpSelect ); f_org = Calc_fstd( pf, Tr, Pr, Ba ); } break; } if ( f_org < 0.001f ) { return 0.0f; } // 实验确定归一化倍率 switch ( PumpSelect ) { case PP_TSP: return f_org * 125.0f; case PP_R24_A: case PP_R24_B: return f_org * 1.0f; case PP_SHI_C: case PP_SHI_D: return f_org * 1.0f; default: case PP_AIR: return 0.0f; } }
/********************************** 功能说明 *********************************** * 传感器标定->孔板差压 *******************************************************************************/ static void Calibrate_pf( enum enumPumpSelect PumpSelect ) { struct uMenu const menu[] = { { 0x0201u, "标定差压" }, { 0x1000u, "零点" }, { 0x1800u, "倍率" }, }; enum { opt_exit, opt_origin, opt_slope, opt_max, opt_min = 1 }; uint8_t option = opt_min; BOOL need_redraw = TRUE; uint16_t gray = Configure.DisplayGray; BOOL graychanged = FALSE; uint16_t *p_origin = &CalibrateRemote.origin[esid_pf][PumpSelect]; uint16_t *p_slope = &CalibrateRemote.slope [esid_pf][PumpSelect]; BOOL changed = FALSE; do { if ( need_redraw ) { cls(); Menu_Redraw( menu ); ShowPumpSelect( 0x0115u, PumpSelect ); need_redraw = FALSE; } ShowI16U( 0x100Cu, *p_origin, 0x0500u, NULL ); ShowI16U( 0x180Cu, *p_slope, 0x0503u, NULL ); Menu_Item_Mask( menu, option ); do{ Lputs( 0x0800u, "差压:" ); ShowFP32( 0x080C, get_pf( PumpSelect ), 0x0603, "kPa" ); } while( ! hitKey( 25u )); Menu_Item_Mask( menu, option ); switch( getKey()) { case K_DOWN: ++option; if ( option >= opt_max ) { option = opt_min; } break; case K_UP: if( option <= opt_min ) { option = opt_max; } --option; break; case K_OK: switch( option ) { case opt_origin: if ( EditI16U( 0x100Cu, p_origin, 0x0500u )) { changed = TRUE; } break; case opt_slope: if ( EditI16U( 0x180Cu, p_slope, 0x0503u )) { changed = TRUE; } break; default: break; } break; case K_ESC: if( ! changed ) { option = opt_exit; } else { switch( MsgBox( "保存标定数据 ?", vbYesNoCancel + vbDefaultButton3 )) { case vbYes: CalibrateSave(); option = opt_exit; break; case vbNo: CalibrateSave(); option = opt_exit; break; default: break; } need_redraw = TRUE; } break; case K_OK_UP: if ( gray < 2200u ) { ++gray; } if( ! releaseKey( K_OK_UP,100 )) { while( ! releaseKey( K_OK_UP, 1 )) { ++gray; DisplaySetGrayVolt( gray * 0.01f ); } } graychanged = true; break; case K_OK_DOWN: if ( gray > 200u ) { --gray; } if( ! releaseKey( K_OK_DOWN, 100 )) { while( ! releaseKey( K_OK_DOWN, 1 )) { --gray; DisplaySetGrayVolt( gray * 0.01f ); } } graychanged = true; break; case K_OK_RIGHT: if ( gray < ( 2000u - 50u )) { gray += 100u; } graychanged = true; break; case K_OK_LEFT: if ( gray > ( 200 + 20u )) { gray -= 20u; } graychanged = true; break; default: break; } if( graychanged == true ) { DisplaySetGrayVolt( gray * 0.01f ); Configure.DisplayGray = gray; ConfigureSave(); graychanged = FALSE;; } } while( opt_exit != option ); }
int pfput_mxArray( Pf *pf, char *name, const mxArray *array ) { Pf *sub_pf; double number; char *string; mxArray *in[2], *out[1]; char warning[STRSZ]; char *fieldname; mxArray *mxfield; mxArray *mxcell; int M,N; int rc; int i; if( mxIsClass( array, "dbpf" ) ) { if( ! get_pf( array, &sub_pf ) ) { return PFINVALID; } if( sub_pf->type == PFFILE) { /* Don't embed a PFFILE in something else */ sub_pf->type = PFARR; } switch (pf->type) { case PFFILE: case PFARR: setarr ( pf->value.arr, name, sub_pf ) ; break ; case PFTBL: settbl ( pf->value.tbl, (int) name, sub_pf ) ; break ; default : return PFINVALID; } antelope_mex_clear_register( 1 ); } else if( mxIsDouble( array ) ) { if( ! get_scalar( array, &number ) ) { return PFINVALID; } in[0] = (mxArray *) array; /* Input scalar */ mexCallMATLAB( 1, out, 1, in, "floor" ); in[1] = out[0]; /* floor( Input scalar ) */ mexCallMATLAB( 1, out, 2, in, "eq" ); mxDestroyArray( in[1] ); if( mxIsLogicalScalarTrue( out[0] ) ) { pfput_int( pf, name, (int) number ); } else { pfput_double( pf, name, number ); } antelope_mex_clear_register( 1 ); mxDestroyArray( out[0] ); } else if( mxIsChar( array ) ) { if( ! mtlb_get_string( array, &string ) ) { sprintf( warning, "failed to extract string for parameter %s\n", name ); mexWarnMsgTxt( warning ); return PFINVALID; } pfput_string( pf, name, string ); antelope_mex_clear_register( 1 ); mxFree( string ); } else if( mxIsStruct( array ) ) { if( mxGetNumberOfDimensions( array ) > 2 ) { sprintf( warning, "structure has too many dimensions for parameter %s\n", name ); mexWarnMsgTxt( warning ); return PFINVALID; } else if( mxGetM( array ) != 1 || mxGetN( array ) != 1 ) { sprintf( warning, "structure has too many elements for parameter %s\n", name ); mexWarnMsgTxt( warning ); return PFINVALID; } N = mxGetNumberOfFields( array ); sub_pf = pfnew( PFARR ); for( i = 0; i < N; i++ ) { fieldname = (char *) mxGetFieldNameByNumber( array, i ); mxfield = mxGetFieldByNumber( array, 0, i ); rc = pfput_mxArray( sub_pf, fieldname, mxfield ); if( rc == PFINVALID ) { pffree( sub_pf ); return PFINVALID; } } switch (pf->type) { case PFFILE: case PFARR: setarr ( pf->value.arr, name, sub_pf ) ; break ; case PFTBL: settbl ( pf->value.tbl, (int) name, sub_pf ) ; break ; default : pffree( sub_pf ); return PFINVALID; } antelope_mex_clear_register( 1 ); } else if( mxIsCell( array ) ) { if( mxGetNumberOfDimensions( array ) > 2 ) { sprintf( warning, "cell array has too many dimensions for parameter %s\n", name ); mexWarnMsgTxt( warning ); return PFINVALID; } M = mxGetM( array ); N = mxGetN( array ); sub_pf = pfnew( PFTBL ); for( i = 0; i < M * N; i++ ) { mxcell = mxGetCell( array, i ); rc = pfput_mxArray( sub_pf, (char *) i, mxcell ); if( rc == PFINVALID ) { pffree( sub_pf ); return PFINVALID; } } switch (pf->type) { case PFFILE: case PFARR: setarr ( pf->value.arr, name, sub_pf ) ; break ; case PFTBL: settbl ( pf->value.tbl, (int) name, sub_pf ) ; break ; default : pffree( sub_pf ); return PFINVALID; } antelope_mex_clear_register( 1 ); } else { return PFINVALID; } return 0; }
Tbl * get_frametbl( char *block_name, char *RTtype ) { static Arr *frametables = 0; Pf *pf; Tbl *frames; Tbl *siterows; siteinfo *sinfo[6]; char key[STRSZ]; int i; sprintf( key, "%s:%s", block_name, RTtype ); if( frametables == 0 ) { frametables = newarr( 0 ); } else if( ( frames = (Tbl *) getarr( frametables, key ) ) != 0 ) { return frames; } pf = get_pf( block_name ); siterows = pfget_tbl( pf, RTtype ); frames = sitetbl2frametbl( siterows ); freetbl( siterows, 0 ); setarr( frametables, key, (void *) frames ); sorttbl( frames, cmp_sinfo_order, 0 ); if( STREQ( RTtype, "LPRT" ) ) { if( maxtbl( frames ) % 3 != 0 ) { fprintf( stderr, "Wrong # of components in LPRT table\n" ); return 0; } for( i=0; i < maxtbl( frames ); i += 3 ) { sinfo[0] = (siteinfo *) gettbl( frames, 0 ); sinfo[1] = (siteinfo *) gettbl( frames, 1 ); sinfo[2] = (siteinfo *) gettbl( frames, 2 ); if( ! ( STREQ( sinfo[0]->sta, sinfo[1]->sta ) && STREQ( sinfo[1]->sta, sinfo[2]->sta ) ) ) { fprintf( stderr, "Unexpected order in LPRT table\n" ); return 0; } } } else if( STREQ( RTtype, "BBRT" ) ) { if( maxtbl( frames ) % 6 != 0 ) { fprintf( stderr, "Wrong # of components in BBRT table\n" ); return 0; } for( i=0; i < maxtbl( frames ); i += 6 ) { sinfo[0] = (siteinfo *) gettbl( frames, 0 ); sinfo[1] = (siteinfo *) gettbl( frames, 1 ); sinfo[2] = (siteinfo *) gettbl( frames, 2 ); sinfo[3] = (siteinfo *) gettbl( frames, 3 ); sinfo[4] = (siteinfo *) gettbl( frames, 4 ); sinfo[5] = (siteinfo *) gettbl( frames, 5 ); if( ! ( STREQ( sinfo[0]->sta, sinfo[1]->sta ) && STREQ( sinfo[1]->sta, sinfo[2]->sta ) && STREQ( sinfo[2]->sta, sinfo[3]->sta ) && STREQ( sinfo[3]->sta, sinfo[4]->sta ) && STREQ( sinfo[4]->sta, sinfo[5]->sta ) ) ) { fprintf( stderr, "Unexpected order in BBRT table\n" ); return 0; } } } return frames; }