/********************************************************************************************** * モジュール名称 :APP03 Mission TLM (L&M) PI tasks * * モジュールラベル :app03_PIs * * タスク区分 :Application-03 MGF task for Mission TLM (L&M) * * 機能 : * * コーリングシーケンス:void app03_(PI) * * 引数 :なし * * 戻り値 :なし * * 使用上の注意 :グローバル変数はアプリケーション01でまとめて初期化 * * エラー処理 :なし * * 注意 : EDIT権限は、MGF組 * * 作成日・作成者 :2011/07/26 rev by Y.K. * * 改定日・改定者 :2011/09/02 A. Matsuoka サイズ縮小 * * 改定日・改定者 :2011/09/15 put_TLM TI 修正 * * 改定日・改定者 :2011/10/06 uninitialized warning 除去 * * 改定日・改定者 :2011/10/11 rev by Y.K. * * 改定日・改定者 :2011/11/15 rev by Y.K. (CMP-mode) * * 改定日・改定者 :2012/06/07 A. Matsuoka 全面改定 * * 改定日・改定者 :2012/11/25 rev by Y.L. (TRG data部) * * 改定日・改定者 :2013/03/22 A. Matsuoka checkout TI 4bit shift * * 改定日・改定者 :2013/03/25 A. Matsuoka correction of TI of the last data of spin * * 改定日・改定者 :2013/04/05 A. Matsuoka correction of TI of the last data of spin * * 改定日・改定者 :2013/11/08 A. Matsuoka * * 1. format of M and L node data (multiple spins in one packet) * * 2. SW parameter set command length * * 3. correction of overflow judgement in app03_MGF_spin_fit * * 改定日・改定者 :2013/11/19 A. Matsuoka * * 改定日・改定者 :2017/03/25 A. Matsuoka * * correct the error causing the M-mode data lack * * in the specific condition when IP occurs between the exact * * integer seconds of TI and the first MGF sample after that. * ***********************************************************************************************/ #include "app_common.h" // **** revised by YK 111008 **** // #include "app_common_math.h" // **** revised by YK 111008 **** #include "app_MGF.h" #define MATH_PI (3.1415926536) void app_MGF_common( unsigned char, unsigned int ) ; /* 以下は APP03, APP13 に属する void app03_MGF( unsigned char, unsigned int ) ; void app03_MGFO( unsigned int ui_sunpulseCnt ) { app_MGF_common(0, ui_sunpulseCnt ) ; return; } void app13_MGFI( unsigned int ui_sunpulseCnt ) { app_MGF_common(1, ui_sunpulseCnt ) ; return; } */ /* Command check */ void app03_MGF_cmd_check( unsigned char) ; /* SpW mission read */ int app03_MGF_mss_read( unsigned char) ; /* conversion of SpW raw data into physical values */ void app03_MGF_mss_full_store(unsigned char) ; /* processing of data */ void app03_MGF_mss_process( unsigned char) ; /* functions for processing in app03_MGF_mss_process */ void app03_MGF_average(unsigned char, unsigned short) ; void app03_MGF_def_shift(unsigned char, unsigned short) ; void app03_MGF_spin_fit(unsigned char, unsigned short) ; void app03_MGF_TLM_header(unsigned char, unsigned short) ; void app03_MGF_every_1s_process(unsigned char, unsigned short) ; /* mission data out */ void app03_MGF_put_TLM_hmode(unsigned char, int, unsigned long) ; // add unsigned long 110914 void app03_MGF_put_TLM_HML(unsigned char, unsigned short) ; // add unsigned short 110914 // ########################################################################### // app03_MGF *** MGF メインルーチン(MGF-O/I 共通) *** // [INPUT] unsigned char uc_mgfoi 0:MGF-O 1:MGF-I // [INPUT] unsigned char ui_sunpulseCnt Sun-pulse counter // [return] void // ########################################################################### void app_MGF_common( unsigned char uc_mgfoi, unsigned int ui_sunpulseCnt ) { int i, i_mss_read ; app03_MGF_cmd_check(uc_mgfoi) ; for(i=0;i<2;i++) { // add 20131119 i_mss_read = app03_MGF_mss_read(uc_mgfoi) ; // add 20131119 // if(0 < app03_MGF_mss_read(uc_mgfoi)) { // delete 20131119 if(0 < i_mss_read) { // new mission data exist app03_MGF_mss_full_store(uc_mgfoi) ; app03_MGF_mss_process(uc_mgfoi) ; } if(i_mss_read < 5) break ; // add 20131119 } // match with for(i=0;i<2;i++) return ; } void app03_MGF_cmd_check(unsigned char uc_mgfoi) { unsigned char uc1 ; unsigned char uc_kind ; // add 20131108 Matsuoka int i,i2, m ; union uni_long { short s[2] ; unsigned char uc[4] ; long l ; } u_long ; unsigned char *puc, *puc1, *puc2, *puc10, *puc20 ; long *pl ; short *ps ; // initialize of software HK puc = Guc_MGF_HK[uc_mgfoi] ; // pointer of Guc_MGF_HK[uc_mgfoi][0] for(i=0;i<20;i++) *(puc++) = 0 ; // TLM Parameters puc = Guc_MGF_TLM_Param[uc_mgfoi] ; // pointer for Guc_MGF_TLM_Param[uc_mgfoi][0] puc1 = (puc10 = Guc_MGF_TLM_out[uc_mgfoi]) ; // pointer for Guc_MGF_TLM_out[uc_mgfoi][0] puc2 = (puc20 = Guc_MGF_TLM_rate[uc_mgfoi]) ; // pointer for Guc_MGF_TLM_rate[uc_mgfoi][0] if(*puc>0) { // new command exist *puc = 0 ; // reset command code puc+=2 ; // proceed to D2 'L-mode out' for(i=0;i<3;i++) { // L, M, H mode loop uc1 =*(puc++) ; // TLM out if(0x0f!=uc1) *puc1 = uc1 ; // replace of out puc1++ ; uc1 =*(puc++) ; // TLM rate if(0x0f!=uc1) *puc2 = uc1 ; // replace of rate puc2++ ; } } // TLM out and rate are stored in HK puc = Guc_MGF_HK[uc_mgfoi] + 12 ; // pointer for Guc_MGF_HK[uc_mgfoi][12] puc1 = puc10 ; // pointer for Guc_MGF_TLM_out[uc_mgfoi][0] puc2 = puc20 ; // pointer for Guc_MGF_TLM_rate[uc_mgfoi][0] for(i=0;i<3;i++) *(puc++) = ((*(puc1++))<<4) + (*(puc2++)) ; // Software Parameters for(i=0;i2) break ; // invalid axis, break from for loop #ifdef TLM_STAT memcpy(&Guc_MGF_TLM_stat[uc_mgfoi][14 + m*18], puc, 18) ; // copy to TLM_stat #endif ps = Gs_MGF_cnv[uc_mgfoi][m][0] ; // pointer of Gs_MGF_cnv[uc_mgfoi][m][0][0] for(i2=0;i2<9;i2++) { u_long.uc[0] = *(puc++) ; u_long.uc[1] = *(puc++) ; *(ps++) = u_long.s[0] ; } } // match with if(1==uc1) if(0x20==uc_kind) { // offset for conversion, add 20131108 Matsuoka // if(2==uc1) { // delete 20131108 Matsuoka // puc++ ; // delete 20131108 Matsuoka #ifdef TLM_STAT memcpy(&Guc_MGF_TLM_stat[uc_mgfoi][68], puc, 6) ; // copy to TLM_stat #endif ps = Gs_MGF_off[uc_mgfoi] ; // pointer for Gs_MGF_off[uc_mgfoi][0] for(i2=0;i2<3;i2++) { u_long.uc[0] = *(puc++) ; u_long.uc[1] = *(puc++) ; *(ps++) = (long) u_long.s[0] ; } } // match with if(2==uc1) if(0x30==uc_kind) { // bit shift and major values, add 20131108 Matsuoka // if(3==uc1) { // delete 20131108 Matsuoka // puc++ ; // delete 20131108 Matsuoka // Here puc = pointer of Guc_MGF_Sw_Param[uc_mgfoi][i][1], shift flag of x-axis puc2 = puc + 1 ; // pointer of Guc_MGF_Sw_Param[uc_mgfoi][i][2] , major flag of x-axis // copy of shift flag puc1 = Guc_MGF_shift_flag[uc_mgfoi] ; // pointer of Guc_MGF_shift_flag[uc_mgfoi][0] for(i2=0;i2<2;i2++) { if(0x0f != (*puc)) *puc1 = *puc ; puc1++ ; puc += 4 ; } // copy of major flag puc1 = Guc_MGF_mjr_flag[uc_mgfoi] ; // pointer of Guc_MGF_mjr_flag[uc_mgfoi][0] for(i2=0;i2<2;i2++) { if(0x0f != (*puc2)) *puc1 = *puc2 ; puc1++ ; puc2 += 4 ; } // copy of major values puc = Guc_MGF_Sw_Param[uc_mgfoi][i] + 3 ; // pointer of Guc_MGF_Sw_Param[uc_mgfoi][i][3], 4->3 change 20131108 Matsuoka pl = Gl_MGF_sub[uc_mgfoi] ; // pointer to Gl_MGF_sub[uc_mgfoi][0] for(i2=0;i2<3;i2++) { // Guc_MGF_Sw_Param[uc_mgfoi][i][4, 5, 8, 9, 12, 13] u_long.uc[0] = *(puc++) ; u_long.uc[1] = *(puc++) ; *(pl++) = ((long) u_long.s[0]) << 8 ; // b8=62.5pT for Gl_MGF_sub puc += 2 ; } } // match with if(3==uc1) Guc_MGF_Sw_Param[uc_mgfoi][i][0] = 0 ; // reset command code } // match with for(i=0;i0:Num of blocks, <=0:error // =========================================================================== i_numNewBlock = app_SetNonProcBlock( Guc_node_mgf[uc_mgfoi], 0, // [INPUT] Node/Data ID // ***** CHANGED! 110721 YK i_bufId, // [INPUT] Buffer ID // Gui_MGF_TLM_lastblock_TI[uc_mgfoi], // [INPUT] TI of Processed Block // ***** CHANGED! 111011 YK Gui_TLMm_blockTime[ Gd_N_MGFO + uc_mgfoi ], // ***** CHANGED! 111011 YK &tp_blockInfo); // [OUTPUT] Block Info // (return) >0:Num of blocks, <=0:No data (error) // copy i_numNewBlock lowest byte to HK u_long.l = i_numNewBlock ; Guc_MGF_HK[uc_mgfoi][19] = u_long.uc[3] ; // copy to HK if ( i_numNewBlock < 1 ) { // no data or error return i_numNewBlock ; } #ifdef TLM_STAT // copy i_numNewBlock to TLM_stat // now pc3 is pointer of Guc_MGF_TLM_stat[uc_mgfoi][82] // puc2 = u_long.uc ; // pointer of u_long.uc[0] // for(i=0;i<4;i++) *(puc3++) = *(puc2++) ; // copy to Guc_MGF_TLM_stat memcpy(&Guc_MGF_TLM_stat[uc_mgfoi][82], u_long.uc, 4) ; #endif // if(i_numNewBlock > 6) i_numNewBlock = 6 ; // delete 20131119 if(i_numNewBlock > 5) i_numNewBlock = 5 ; // add 20131119 #ifdef TLM_STAT // TLM_stat output if((1==Guc_MGF_TLM_out[uc_mgfoi][2]) && (0x0c==(0x0c&Guc_MGF_TLM_rate[uc_mgfoi][2]))) { // rate = c or larger Guc_MGF_TLM_stat[uc_mgfoi][0] = (uc_mgfoi<<4) + 0x0d ; // puc1 = Guc_MGF_hmode[uc_mgfoi] ; // pointer for Guc_MGF_hmode[uc_mgfoi][0] // puc2 = Guc_MGF_TLM_stat[uc_mgfoi] ; // pointer for Guc_MGF_TLM_stat[uc_mgfoi][0] // for (i=0; i Gui_MGF_TLM_lastblock_TI[uc_mgfoi] && // NEW data // ***** CHANGED! 111011 YK tp_blockInfo.ui_createTime > Gui_TLMm_blockTime[ Gd_N_MGFO + uc_mgfoi ] && // ***** CHANGED! 111011 YK tp_blockInfo.i_replyNum > 0 && // Data available tp_blockInfo.c_invalidFlg == 0 ) { // Data correct // **** Block read **** // extern int app_GetBlock ( unsigned char, unsigned char, int, M_T_BLOCK_INFO *, unsigned char []); // =========================================================================== // app_GetBlock *** Block DataのSRAM展開 *** // [INPUT] unsigned char uc_nodeId Node-ID // unsigned char uc_dataId Data-ID // int i_bufId Buffer-ID // M_T_BLOCK_INFO *tp_blockInfo Block Info // [OUTPUT] unsigned char uc_data[] Block data // [return] int 0:nrm others:error // =========================================================================== if (uc_mgfoi == 0) { // *********MGFO********************************************** i_flag = app_GetBlock( 3, // [INPUT] App-No:3 Guc_node_mgf[uc_mgfoi], 0, // [INPUT] Node/Data ID // ***** CHANGED! 110721 YK i_bufId, // [INPUT] Buffer ID &tp_blockInfo, // [INPUT] Block Info G03uc_data ); // [OUTPUT] 1 Block Data - copied } else { // *********MGFI*********************************************** i_flag = app_GetBlock( 13, // [INPUT] App-No:13 Guc_node_mgf[uc_mgfoi], 0, // [INPUT] Node/Data ID // ***** CHANGED! 110721 YK i_bufId, // [INPUT] Buffer ID &tp_blockInfo, // [INPUT] Block Info G13uc_data ); // [OUTPUT] 1 Block Data - copied } if(0==i_flag) { // normal read for(i2=0;i2>>> // unsigned int ui_time Data TI <<<< USER-DEF: 0x00000000-0xFFFFFFFF >>>> // unsigned char uc_comment[], Comment <<<< USER-DEF: <128B >>>> // unsigned char uc_sizeComment Comment - Size <<<< USER-DEF: <128B >>>> // unsigned char uc_data[] Data <<<< USER-DEF: <0x1E00 >>>> // int i_sizeData Data - Size <<<< USER-DEF: <0x1E00 >>>> // [return] int 0:nrm others:error // =========================================================================== ui_dataTi = ul_start_ti << 4 ; // 20130322 4 bit shift by A.Matsuoka i_flag = app_PutTlm( Gus_MGF_app_m[uc_mgfoi], // [INPUT] APP-NUM = 3 (MGF-O) = 13 (MGF-I) Guc_node_mgf[uc_mgfoi], // [INPUT] Node-ID 0, // [INPUT] Data-ID // ***** CHANGED! 110721 YK Guc_node_mgf[uc_mgfoi], // [INPUT] Header-ID (for PID-ID, CAT-ID setting) 4, // [INPUT] DR-ID (for CAT-ID) [0:HK 1:OS 2:L 3:M 4-9:H(0-5)] Guc_TLMh_cmp[Guc_node_mgf[uc_mgfoi]], // [INPUT] Comp mode // ***** CHANGED! 111115 YK // 0, // [INPUT] Comp mode // ***** CHANGED! 111115 YK uc_pacId, // [INPUT] Packet ID <<<< USER-DEF: 0x00- 0xFF >>>> ui_dataTi, // [INPUT] Data TI <<<< USER-DEF: 0x00000000-0xFFFFFFFF >>>> Guc_cmdDummy, // [INPUT] Comment ***** CHANGED by YK 110723 ****** 0, // [INPUT] Comment - Size ***** CHANGED by YK 110723 ****** Guc_MGF_hmode[uc_mgfoi], // [INPUT] Data <<<< USER-DEF: <0x1E00 >>>> i_sizeData); // [INPUT] Data - Size <<<< USER-DEF: <0x1E00 >>>> return ; } // ########################################################################### // app03_MGF_put_TLM_HML *** MGF M- and L-mode mission data output to tlm *** // [INPUT] unsigned char uc_mgfoi 0:MGF-O 1:MGF-I // [INPUT] unsigned short us_buff buffer number // [return] void // ########################################################################### void app03_MGF_put_TLM_HML(unsigned char uc_mgfoi, unsigned short us_buff) { int i, i2, id_hd[3] = {2, 3, 4}, i_sizeData, i_flag=0 ; int i_m_mode_l ; // add 20131108 Matsuoka int i_spin[9] = {0, 8, 0, 0, 8, 0, 0, 0, 4} ; int i_max_n[9] = {0, 360, 0, 0, 1320, 0, 0, 0, 1180} ; // number of spins in data packet. i_spin[1]=8, i_spin[4]=8, i_spin[8]=4, add 20131108 Matsuoka unsigned char uc_sizeComment = 0, uc_pacId = 0, uc_comment[128], uc_TLM_rate, uc_TLM_out ; // uco[360], uc_ti_b2 deleted 20131108 Matsuoka // unsigned int ui_dataTi=0 ; // delete 20131108 Matsuoka unsigned char *puc ; unsigned char *puc_tlm, *puc_tlm_first ; // add 20131108 Matsuoka unsigned short us_1s_TLM_length=0, us_TLM_test_length=0 ; // us_MGF_TLM_ML_header_length delete 20131108 Matsuoka // unsigned long ul_ml_start_ti ; // delete 20131108 Matsuoka union uni_long { unsigned long ul ; unsigned short us[2] ; unsigned char uc[4] ; } u_long ; // us_MGF_TLM_ML_header_length = Gus_MGF_TLM_ML_header_length ; // delete 20131108 Matsuoka if(Guc_MGF_1s_n[uc_mgfoi]<1) return ; // no data for TLM output // ul_ml_start_ti = (u_long.ul = Gul_MGF_ML_start_ti[uc_mgfoi] + 8) ; // delete 20131108 Matsuoka // uc_ti_b2 = u_long.uc[2] ; // delete 20131108 Matsuoka for(i=0;i<2;i++) { // mode loop, 0=L, 1=M, 3->2 change 20131108 Matsuoka uc_TLM_out = Guc_MGF_TLM_out[uc_mgfoi][i] ; // TLM out, =0 : non, =1 : normal out, =2 : test pattern uc_TLM_rate = Guc_MGF_TLM_rate[uc_mgfoi][i] ; // TLM rate if(0i_m_mode_l change 20131108 Matsuoka // for(i2=us_MGF_TLM_ML_header_length;i216 change 20131108 Matsuoka // i_sizeData = us_MGF_TLM_ML_header_length + us_TLM_test_length ; // delete 20131108 Matsuoka i_sizeData += us_TLM_test_length ; // total length of TLM // for(i2=0;i2= i_spin[uc_TLM_rate]) || (i_sizeData>i_max_n[uc_TLM_rate])) { // defined number of spin period data are stored, add 20131108 Matsuoka i_flag = app_PutTlm( Gus_MGF_app_m[uc_mgfoi], // [INPUT] APP-NUM = 3 (MGF-O) = 13 (MGF-I) Guc_node_mgf[uc_mgfoi], // [INPUT] Node-ID 0, // [INPUT] Data-ID // ***** CHANGED! 110721 YK Guc_node_mgf[uc_mgfoi], // [INPUT] Header-ID (for PID-ID, CAT-ID setting) id_hd[i], // [INPUT] DR-ID (for CAT-ID) [0:HK 1:OS 2:L 3:M 4-9:H(0-5)] Guc_TLMm_cmp[Guc_node_mgf[uc_mgfoi]], // [INPUT] Comp mode // ***** CHANGED! 110721 YK // 0, // [INPUT] Comp mode // ***** CHANGED! 110721 YK uc_pacId, // [INPUT] Packet ID <<<< USER-DEF: 0x00- 0xFF >>>> Gui_MGF_TLM_ti[uc_mgfoi][i], // [INPUT] Data TI <<<< USER-DEF: 0x00000000-0xFFFFFFFF >>>> uc_comment, // [INPUT] Comment <<<< USER-DEF: <128B >>>> uc_sizeComment, // [INPUT] Comment - Size <<<< USER-DEF: <128B >>>> puc_tlm_first, // [INPUT] Data <<<< USER-DEF: <0x1E00 >>>> // uco->puc_tlm_first change 20131108 Matsuoka i_sizeData); // [INPUT] Data - Size <<<< USER-DEF: <0x1E00 >>>> Guc_MGF_TLM_spin_n[uc_mgfoi][i] = 0 ; // initialize, add 20131108 Matsuoka i_sizeData = 0 ; // initialize, add 20131108 Matsuoka } // match with if(Guc_MGF_TLM_spin_n[uc_mgfoi][i] >= Gi_MGF_TLM_data_n[uc_mgfoi][i] = i_sizeData ; // store data length } // match with if((8==uc_TLM_rate) || (4==uc_TLM_rate) || } // match with if(0 long conversion memcpy(u_long.uc, Guc_MGF_raw[uc_mgfoi][ib][ip], 4) ; if(0==u_long.ul) continue ; // invalid data, skip to next packet ul_packet_ti = u_long.ul ; if(9==Gus_MGF_buff_stat[uc_mgfoi][0]) { // first entry Gul_MGF_buff_ti[uc_mgfoi][0] = ul_packet_ti ; Gus_MGF_buff_stat[uc_mgfoi][0] = 0 ; // conversion parameters Gs_MGF_cnv[0][0][2][0] = Gs_MGF_cnv[0][0][2][1] = Gs_MGF_cnv[0][1][2][0] = Gs_MGF_cnv[1][1][0][1] = Gs_MGF_cnv_const_xy ; Gs_MGF_cnv[0][1][2][1] = Gs_MGF_cnv[1][0][0][0] = Gs_MGF_cnv[1][0][0][1] = Gs_MGF_cnv[1][1][0][0] = -Gs_MGF_cnv_const_xy ; Gs_MGF_cnv[0][2][1][2] = Gs_MGF_cnv[1][2][2][2] = Gs_MGF_cnv_const_z ; } puc = Guc_MGF_raw[uc_mgfoi][ib][ip] + 4 ; // pointer of Guc_MGF_raw[uc_mgfoi][ib][ip][4], first byte of first dT // moved 20130325 u_long.l = 0 ; // clear // added 20130325 memcpy(&u_long.uc[2], puc, 2) ; // added 20130325 if(((ul_packet_ti != Gul_MGF_buff_ti[uc_mgfoi][i_buff]) && (u_long.l<20000)) || (usdb>=Gus_MGF_full_length) ) { // changed 20130325 to correct the TI of last data in the spin // new TI, next buffer Gul_MGF_buff_ti[uc_mgfoi][i_buff] = ul_packet_ti ; // replace TI Gus_MGF_buff_n[uc_mgfoi][i_buff] = (us_buff_n = usdb) ; // data count stored in the buffer Gus_MGF_buff_stat[uc_mgfoi][i_buff] = 3 ; // buffer status = fully stored i_buff_last = i_buff ; i_buff = (Gus_MGF_buff_in_store[uc_mgfoi] = i_buff_last<2 ? i_buff_last+1 : 0) ; // new buffer to store // now us_buff_n is data number in the last buffer usdb = 0 ; // initialize of data counter in current buffer Gus_MGF_buff_stat[uc_mgfoi][i_buff] = 0 ; // current buffer status = empty k = (us_buff_n < 128) ? us_buff_n : 128 ; Gul_MGF_buff_ti[uc_mgfoi][i_buff] = ul_packet_ti ; // TI of the current buffer // 20130405 add plt1 = Gl_MGF_last_1s_dt[uc_mgfoi][i_buff] ; // pointer for Gl_MGF_last_1s_dt[uc_mgfoi][i_buff][0] plt2 = Gl_MGF_full_dt[uc_mgfoi][i_buff_last] + us_buff_n - k ; // pointer for Gl_MGF_full_dt[uc_mgfoi][i_buff_last][Gus_MGF_buff_n[uc_mgfoi][i_buff_last] - k] pl1 = Gl_MGF_last_1s[uc_mgfoi][i_buff][0] ; // pointer for Gl_MGF_last_1s[uc_mgfoi][i_buff][0][0] pl2 = Gl_MGF_full[uc_mgfoi][i_buff_last][us_buff_n - k] ; // pointer for Gl_MGF_full[uc_mgfoi][i_buff][Gus_MGF_buff_n[uc_mgfoi][i_buff_last]-k][0] for(i=0;i=Gus_MGF_full_length) break ; // break from loop for(id=0;id 0) { // puc+4 = 3rd byte of Bx, valid flag check // dT copy u_long.ul = 0 ; // clear puc1 = Guc_MGF_HK[uc_mgfoi] + 1 ; // pointer of Guc_MGF_HK[uc_mgfoi][1] // u_long.uc[2] = (*(puc1++) = *puc) ; // u_long.uc[3] = (*(puc1++) = *(puc+1)) ; memcpy(&u_long.uc[2], puc, 2) ; memcpy(puc1, &u_long.uc[2], 2) ; *(pl1++) = u_long.l - Gs_MGF_dt_offset[uc_mgfoi] ; // dT copy // 20110902 changed // i = 2 ; for(i2=0;i2<3;i2++) { // xyz axis loop // for(k=0;k<3;k++) { // byte loop // u_long.uc[k+1] = (*(puc1++) = *(puc+i)) ; // variable store for uc -> long conversion // i++ ; // } i = 2 + i2*3 ; memcpy(&u_long.uc[1], puc+i, 3) ; memcpy(puc1+i, &u_long.uc[1], 3) ; // i += 3 ; u_long.uc[0] = u_long.uc[1]<128 ? 0 : 0xFF ; // sign *(pl2++) = u_long.l ; } // match with for(i2=0;i2<3;i2++) { Gus_MGF_buff_stat[uc_mgfoi][i_buff] = 1 ; // partially stored usdb++ ; // increment of the data counter in the buffer } // match with if((0x08&(*(puc+4))) > 0) puc += 11 ; // next data } // match with for(id=0;id0) { for(i=0;i<3;i++) *(pl++) = (l_sum[i]/usn)<<4 ; // 110915 } else { for(i=0;i<3;i++) *(pl++) = 0 ; } return ; } void app03_MGF_def_shift(unsigned char uc_mgfoi, unsigned short us_buff) { unsigned short us, usn, usn2 ; int ix ; long l_tmp, l_rng_max ; long *pl1, *pl2 ; unsigned short us_shift ; union uni_long { long l ; unsigned char uc[4] ; } u_long ; usn2 = Guc_MGF_last_1s_n[uc_mgfoi][us_buff] ; // data number stored in the last 1s buffer usn = Gus_MGF_buff_n[uc_mgfoi][us_buff] ; // data number stored in the buffer // major component in this spin for(ix=0;ix<3;ix++) { u_long.l = (0=Guc_MGF_shift_flag[uc_mgfoi][ix]) { // fixed shift Gus_MGF_rng_shift[uc_mgfoi][ix] = Guc_MGF_shift_flag[uc_mgfoi][ix] ; } else { // automatic shift l_rng_max =0 ; for(us=0;usl_rng_max) ? l_tmp : l_rng_max ; } for(us=0;usl_rng_max) ? l_tmp : l_rng_max ; } us_shift = 0; // initialize if(l_rng_max>=0x080000) us_shift = 1 ; if(l_rng_max>=0x100000) us_shift = 2 ; if(l_rng_max>=0x200000) us_shift = 3 ; if(l_rng_max>=0x400000) us_shift = 4 ; Gus_MGF_rng_shift[uc_mgfoi][ix] = us_shift ; // store } // match with if(4>=Guc_MGF_shift_flag[uc_mgfoi][ix]) } // match with for(ix=0;ix<3;ix++) return ; } void app03_MGF_spin_fit(unsigned char uc_mgfoi, unsigned short us_buff) { unsigned short us, usn, us_buff_next ; int i, i2, i_err ; long l_w ; long l_sin_s[3], l_cos_s[3], l_a[3], l_b[3], l_rms_v[3], l_rms, l_dcb[3], l_d_ave[3] ; // unsigned int ui_TrgTi; // removed! by YK 121125 long *pl, *pl2 ; short *ps, *ps1 ; #ifdef TLM_STAT unsigned char *puc1 ; #endif union uni_long { long l ; unsigned long ul ; short s[2] ; unsigned short us[2] ; unsigned char uc[4] ; } u_long ; short s_b[3], s_rms ; double d_ang, d_sin, d_cos, d_x ; usn = Gus_MGF_buff_n[uc_mgfoi][us_buff] ; // data number stored in the buffer if(usn<1) { // no data in this spin return ; } // Spin Period us_buff_next = us_buff<2 ? us_buff+1 : 0 ; l_w = Gl_MGF_full_dt[uc_mgfoi][us_buff][usn-1] + Gus_MGF_t_step[uc_mgfoi] - Gl_MGF_full_dt[uc_mgfoi][us_buff_next][0] ; if((0>=l_w) || 0xFFFF<=l_w) l_w = Gl_MGF_full_dt[uc_mgfoi][us_buff][usn-1] ; if((0>=l_w) || 0xFFFF<=l_w) l_w = 4000000/Gus_MGF_dt_unit[uc_mgfoi] ; Gul_MGF_spin_prd[uc_mgfoi] = (unsigned long) l_w ; for(i=0;i<3;i++) { // initialize for the summation l_sin_s[i] = 0 ; l_cos_s[i] = 0 ; // numbers to correct (full-mjr) to (full-ave) u_long.l = (Gl_MGF_mjr[uc_mgfoi][i] - Gl_MGF_ave[uc_mgfoi][i]) <<8 ; l_d_ave[i] = (long) u_long.s[0] ; } pl2 = Gl_MGF_full_dt[uc_mgfoi][us_buff] ; // pointer for Gl_MGF_full_dt[uc_mgfoi][us_buff][0] pl = Gl_MGF_full[uc_mgfoi][us_buff][0] ; // pointer for Gl_MGF_full[uc_mgfoi][us_buff][0][0] for(us=0;us 0x00008000 correction 20131108 Matsuoka l_b[i] = l_cos_s[i] /usn /8 ; // x(2/usn), 4 bit shift l_w = 0x00018000 & l_b[i] ; if((0x00010000==l_w) || (0x00008000==l_w)) l_rms_v[i] = 0xFFFFFFF ; u_long.l = (Gl_MGF_ave[uc_mgfoi][i]<<8) ; l_dcb[i] = (long) (u_long.s[0] - Gs_MGF_off[uc_mgfoi][i]) ; } // match with for(i=0; i<3; i++) // RMS calculation pl2 = Gl_MGF_full_dt[uc_mgfoi][us_buff] ; // pointer for Gl_MGF_full_dt[uc_mgfoi][us_buff][0] pl = Gl_MGF_full[uc_mgfoi][us_buff][0] ; // pointer for Gl_MGF_full[uc_mgfoi][us_buff][0][0] for(i=0;i> 8 ; // 8 bit shift if(l_rms_v[i2]<0xFFFFFFF) { d_x = l_a[i2]*d_sin + l_b[i2]*d_cos ; /* 20120605 */ u_long.l = l_w ; // Gl_MGF_full >> 8 l_w = (long) u_long.s[1] + l_d_ave[i2] ; // corrected to full-ave l_rms = (u_long.l = l_w - ((long) d_x)) ; if(u_long.uc[0]>=0x80) l_rms *= -1 ; // negative l_rms_v[i2] += l_rms ; } // match with if(l_rms_v[i2]<0xFFFFFFF) } // match with for(i2=0;i2<3;i2++) } // match with for(i=0;i>14) ; l_w = 0x00038000 & l_w ; if((0x00000000!=l_w) && (0x00038000!=l_w)) i_err = 1 ; *(ps1++) = s_b[i] = u_long.s[1] ; // lower 16 bits } // match with for(i=0; i<3; i++) if(0==i_err) { u_long.l = (l_rms_v[0]+l_rms_v[1]+l_rms_v[2])/3 ; s_rms = *ps1 = u_long.s[1] ; } else { s_rms = *ps1 = 0xFFFF ; } /* **** removed: by YK 121121 **** for(i=0 ;i=ui_TrgTi-512) { if (Gul_MGF_buff_ti[uc_mgfoi][us_buff]<=ui_TrgTi+512) { // +- 1sec break ; // break from for loop } } } // match with for(i=0 ;i=36) us_sw_param_n = 0 ; // reset Gus_MGF_Sw_Param_n[uc_mgfoi] = us_sw_param_n ; // Software Parameters in header if(us_sw_param_n<27) { u_long.s[0] = (*(Gs_MGF_cnv[uc_mgfoi][0][0] + us_sw_param_n)) ; // Gus_MGF_Sw_Param_n[uc_mgfoi]-th parameter in array Gs_MGF_cnv[uc_mgfoi][3][3][3] } else if(us_sw_param_n<30) { i = us_sw_param_n-27 ; u_long.s[0] = Gs_MGF_off[uc_mgfoi][i] ; // i = 0, 1, 2 } else if(us_sw_param_n<31) { // us_sw_param_n = 30 u_long.s[0] = Gs_MGF_dt_offset[uc_mgfoi] ; } puc1 = Guc_MGF_TLM_header_ML[uc_mgfoi] ; // Guc_MGF_TLM_header_ML[uc_mgfoi][0] = u_long.uc[i] ; // Guc_MGF_TLM_header_ML[uc_mgfoi][1] = u_long.uc[i+1] ; memcpy(puc1, u_long.uc, 2) ; puc1+= 2 ; // data number in the spin u_long.us[0] = Gus_MGF_buff_n[uc_mgfoi][us_buff] ; memcpy(puc1, u_long.uc, 2) ; puc1+= 2 ; // Spin fit result ps = Gs_MGF_spin_fit[uc_mgfoi][0] ; // pointer of Gs_MGF_spin_fit_a[uc_mgfoi][0][0] for(i=0;i<9;i++) { // axis * (a, b, rem) loop u_long.s[0] = *(ps++) ; // *(puc1++) = u_long.uc[0] ; // *(puc1++) = u_long.uc[1] ; memcpy(puc1, u_long.uc, 2) ; puc1 += 2 ; } return ; } void app03_MGF_every_1s_process(unsigned char uc_mgfoi, unsigned short us_buff) { int i, i2 ; int id ; // data index in the buffer int nd ; // data counter in 1-sec interval int n_1s ; // 1-sec interval counter long l_ti_equ, l_s[3], l_s_save[3] ; unsigned short us_ti_step_1hz ; unsigned short us_dt_unit ; unsigned long ul_1hz_ti, ul_buff_ti ; unsigned short us_shift[3] ; unsigned char *puc1, *puc2 ; long *pl, *pl1, *pl2, *pl3, *pl4, *pl10, *pl30 ; unsigned short *pus ; union uni_long { long l ; unsigned long ul ; short s[2] ; unsigned char uc[4] ; } u_long ; long l_1s_b[136][3] ; long l_1s_dt[136] ; // changed from us to long 20110903 n_1s = 0 ; // initialize of 1-sec interval counter nd = 0 ; // initialize of data number in 1-sec storage us_ti_step_1hz = Gus_MGF_ti_step_1hz ; ul_buff_ti = Gul_MGF_buff_ti[uc_mgfoi][us_buff] ; us_dt_unit = Gus_MGF_dt_unit[uc_mgfoi] ; ul_1hz_ti = (ul_buff_ti/us_ti_step_1hz)*us_ti_step_1hz ; // initial 1hz TI Gul_MGF_ML_start_ti[uc_mgfoi] = ul_1hz_ti ; pus = Gus_MGF_rng_shift[uc_mgfoi] ; // pointer of Gus_MGF_rng_shift[uc_mgfoi][0] for(i=0;i<3;i++) us_shift[i] = (*(pus++)) + 4 ; // copy to local variable // storing data in last 1-sec data buffer pl2 = Gl_MGF_last_1s_dt[uc_mgfoi][us_buff] ; // pointer of Gl_MGF_last_1s_dt[uc_mgfoi][us_buff][0] pl = Gl_MGF_last_1s[uc_mgfoi][us_buff][0] ; // pointer for Gl_MGF_last_1s[uc_mgfoi][us_buff][0][0] pl1 = pl10 = l_1s_dt ; // pointer of l_1s_dt[0] pl3 = pl30 = l_1s_b[0] ; // pointer of l_1s_b[0][0] for(id=0;id l_1s_b for(i=0;i<3;i++) *(pl3++) = (*(pl++)) ; // axis loop nd++ ; // increment of data counter in 1-sec interval } // match with for(id=0;id l_1s_b for(i=0;i<3;i++) *(pl3++) = (*(pl++)) ; // axis loop nd++ ; // increment of data counter in 1-sec interval // if(l_ti_equ>=(ul_1hz_ti+us_ti_step_1hz)) { // 1-sec data ready // if((l_ti_equ>=(ul_1hz_ti+us_ti_step_1hz)) || (nd>130)) { // 1-sec data ready 120607 if((l_ti_equ>=(ul_1hz_ti+us_ti_step_1hz)) || (nd>130) || (((id+1)==Gus_MGF_buff_n[uc_mgfoi][us_buff])&&(nd>=127))) { // 1-sec data ready 170325 puc1 = Guc_MGF_8hz[uc_mgfoi] + n_1s*50 ; // pointer for Guc_MGF_8hz[uc_mgfoi][n_1s*50] // 50 : length of averaged data for 1-sec interval : 2bytes + 6bytes * 8Hz puc2 = Guc_MGF_4hz[uc_mgfoi] + n_1s*26 ; // pointer for Guc_MGF_4hz[uc_mgfoi][n_1s*26] // 26 : length of averaged data for 1-sec interval : 2bytes + 6bytes * 4Hz u_long.ul = ul_1hz_ti ; *(puc1++) = (*(puc2++) = u_long.uc[2]) ; // 3th byte of 1Hz TI u_long.ul = nd ; *(puc1++) = (*(puc2++) = u_long.uc[3]) ; // number of data in 1sec interval // averaging // if(nd>=128) nd=128 ; // remove 170325 for(i2=0;i2<3;i2++) l_s[i2] = 0 ; // initialize pl4 = pl30 ; // pointer of l_1s_b[uc_mgfoi][0][0] // for(i=0;i> us_shift[i2]) ; // bit shift memcpy(puc1, &u_long.uc[2], 2) ; // 8Hz data store puc1 += 2 ; } if(31==i%32) { // 4Hz ; 32 = 128Hz / 4Hz for(i2=0;i2<3;i2++) { // axis loop u_long.l = ((l_s[i2] + l_s_save[i2])/2) >> us_shift[i2] ; // average two 8Hz data memcpy(puc2, &u_long.uc[2], 2) ; // 4Hz data store puc2 += 2 ; } } // match with if(31==i%32) for(i2=0;i2<3;i2++) l_s_save[i2] = l_s[i2] ; for(i2=0;i2<3;i2++) l_s[i2] = 0 ; // initialize } // match with if(15==i%16) } // match with for(i=0;i=(ul_1hz_ti+us_ti_step_1hz)) if(n_1s>6) break ; } // match with for(id=ids3;id