dp_msac1.c
上传用户:hualang
上传日期:2022-04-11
资源大小:104k
文件大小:61k
开发平台:

C/C++

  1. /**********************  Filename: dp_msac1.c  *******************************/
  2. /* ========================================================================= */
  3. /*                                                                           */
  4. /* 0000  000   000  00000 0  000  0   0 0 0000                               */
  5. /* 0   0 0  0 0   0 0     0 0   0 0   0 0 0   0                              */
  6. /* 0   0 0  0 0   0 0     0 0     0   0 0 0   0      Einsteinstra遝 6        */
  7. /* 0000  000  0   0 000   0 0     00000 0 0000       91074 Herzogenaurach    */
  8. /* 0     00   0   0 0     0 0     0   0 0 0                                  */
  9. /* 0     0 0  0   0 0     0 0   0 0   0 0 0          Tel: ++49-9132-744-200  */
  10. /* 0     0  0  000  0     0  000  0   0 0 0    GmbH  Fax: ++49-9132-744-204  */
  11. /*                                                                           */
  12. /* ========================================================================= */
  13. /*                                                                           */
  14. /* Function:       MSAC_C1 functions                                         */
  15. /*                                                                           */
  16. /* ------------------------------------------------------------------------- */
  17. /*                                                                           */
  18. /* Technical support:       P. Fredehorst                                    */
  19. /*                          Tel. : ++49-9132/744-214                         */
  20. /*                          Fax. :              -204                         */
  21. /*                          eMail: pfredehorst@profichip.com                 */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24. /*****************************************************************************/
  25. /* contents:
  26.   - function prototypes
  27.   - data structures
  28.   - internal functions
  29. */
  30. /*****************************************************************************/
  31. /* include hierarchy */
  32. #include "..dp_incplatform.h"
  33. #include "..dp_incdp_inc.h"
  34. //#include "E5_Inc.h"
  35. #ifdef DP_MSAC_C1
  36. /*---------------------------------------------------------------------------*/
  37. /* function prototypes                                                       */
  38. /*---------------------------------------------------------------------------*/
  39. MSAC1_OPMODE        msac_c1_get_new_operation_mode  (UBYTE dev_num);
  40. void                msac_c1_set_job_running         (UBYTE dev_num, UBYTE running );
  41. void                msac_c1_ind_disable_done        (UBYTE dev_num, UBYTE sap_nr, UBYTE ret_val );
  42. void                msac_c1_stop                    (UBYTE dev_num);
  43. #ifdef DP_ALARM
  44.     void            stop_asm                        (UBYTE dev_num);
  45.     void            set_new_alarm_mode              (UBYTE dev_num);
  46.     UBYTE           alarm_enabled                   (UBYTE dev_num, UBYTE alarm_type );
  47.     UBYTE           acls                            (UBYTE dev_num, UBYTE alarm_type );
  48.     void            init_alarm                      (UBYTE dev_num, UBYTE power_on );
  49.     UBYTE           check_sequence_status           (UBYTE dev_num, UBYTE action, UBYTE alarm_type, UBYTE alarm_specifier );
  50.     UBYTE           check_type_status               (UBYTE dev_num, UBYTE action, UBYTE alarm_type );
  51.     UBYTE           check_send_diag                 (UBYTE dev_num, UBYTE alarm_type, ALARM_STATUS_PDU_PTR alarm_ptr, UBYTE callback );
  52.     void            check_send_alarm                (UBYTE dev_num);
  53.     DPV1_RET_VAL    msac_c1_alarm_quit              (UBYTE dev_num, UBYTE sap, DPV1_PTR pdu );
  54. #endif // #ifdef DP_ALARM
  55. /*---------------------------------------------------------------------------*/
  56. /* global variables                                                          */
  57. /*---------------------------------------------------------------------------*/
  58. #ifdef DP_FDL
  59. SECTION_DEF_CommuData  static    IND_RESP_BUF_PTR    dpv1_act_ind_ptr[MAX_DEV_NUM];
  60. SECTION_DEF_CommuData  static    IND_RESP_BUF_PTR    dpv1_act_ind_SAP50_ptr[MAX_DEV_NUM];
  61. #endif
  62. #ifdef DP_ALARM
  63.     // table for decoding the number of parallel alarms
  64. SECTION_DEF_CommuData  static    UBYTE alarm_decode[MAX_DEV_NUM][ALARM_TYPE_MAX+1];   //wusenlin 原先为ALARM_TYPE_MAX,+1防止越界
  65.     // this variable is used to store the status pdu
  66. //SECTION_DEF_CommuData  static    ALARM_STATUS_PDU  status_buffer[MAX_DEV_NUM];
  67. #endif // #ifdef DP_ALARM
  68. /*--------------------------------------------------------------------------*/
  69. /* function: msac_c1_init                                                   */
  70. /*--------------------------------------------------------------------------*/
  71. SECTION_DEF_CommuCode DP_ERROR_CODE msac_c1_init(UBYTE dev_num)
  72. {
  73. DP_ERROR_CODE error;
  74.     error = DP_OK;
  75.     dp_sys[dev_num].c1.DX_Entered     = FALSE;
  76.     dp_sys[dev_num].c1.Operation_Mode = DP_OPMODE_V0;
  77.     dp_sys[dev_num].c1.Start_State    = DP_SS_IDLE;
  78.     dp_sys[dev_num].c1.Fdl_Closing    = TRUE;
  79.     dp_sys[dev_num].c1.active_Job     = FALSE;
  80.     dp_sys[dev_num].c1.event          = 0x00;
  81. #ifdef DP_ALARM
  82.     init_alarm(dev_num, TRUE );
  83. #endif // #ifdef DP_ALARM
  84.     return error;
  85. }//DP_ERROR_CODE msac_c1_init(UBYTE dev_num)
  86. /*--------------------------------------------------------------------------*/
  87. /* function: msac_c1_pdu_received                                           */
  88. /*--------------------------------------------------------------------------*/
  89. SECTION_DEF_CommuCode void msac_c1_pdu_received(UBYTE dev_num, UBYTE sap_nr, IND_RESP_BUF_PTR ind_ptr, UBYTE req_add )
  90. {
  91. DPV1_PTR dpx_pdu_ptr = ((DPV1_PTR) &ind_ptr->user_data[0]);
  92.     DP_LOCK_IND(dev_num);
  93.     req_add = req_add;
  94.     switch( sap_nr )
  95.     {
  96.         case DP_C1_RD_WR_SAP_NR:
  97.         {
  98.             dpv1_act_ind_ptr[dev_num] = ind_ptr;
  99.             switch( BFWORD2BYTE(dpx_pdu_ptr->read.function_num) )
  100.             {
  101.                 case DPV1_FC_READ:
  102.                 {
  103.                     if( (BFWORD2BYTE(dpx_pdu_ptr->read.length) > 0) && (BFWORD2BYTE(dpx_pdu_ptr->read.length) <=240) && (BFWORD2BYTE(ind_ptr->data_len) == 4) )
  104.                     {
  105.                         dp_sys[dev_num].c1.event |= MSAC_C1_IND_DS_READ;
  106.                     }//if( (dpx_pdu_ptr->read.length > 0) && (dpx_pdu_ptr->read.length <=240) )
  107.                     else
  108.                     {
  109.                         dpx_pdu_ptr->read.function_num |= DPV1_ERROR_BIT_RESPONSE;
  110.                         ind_ptr->data_len = DPV1_LEN_NEG_RESPONSE;
  111.                         ind_ptr->fc       = FC_RESP_L;
  112.                         dpx_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
  113.                         dpx_pdu_ptr->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_TYPE;
  114.                         dpx_pdu_ptr->neg.err_code2 = 0x00;
  115.                         fdl_resp_provide(dev_num, sap_nr, FDL_PRIMARY_BUF );
  116.                     }//else of if( (dpx_pdu_ptr->read.length > 0) && (dpx_pdu_ptr->read.length <=240) )
  117.                     break;
  118.                 }//case DPV1_FC_READ:
  119.                 case DPV1_FC_WRITE:
  120.                 {
  121.                     if( BFWORD2BYTE(dpx_pdu_ptr->write.length) > 0 )
  122.                     {
  123.                         dp_sys[dev_num].c1.event |= MSAC_C1_IND_DS_WRITE;
  124.                     }//if( dpx_pdu_ptr->write.length > 0 )
  125.                     else
  126.                     {
  127.                         dpx_pdu_ptr->write.function_num |= DPV1_ERROR_BIT_RESPONSE;
  128.                         ind_ptr->data_len = DPV1_LEN_NEG_RESPONSE;
  129.                         ind_ptr->fc       = FC_RESP_L;
  130.                         dpx_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
  131.                         dpx_pdu_ptr->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_TYPE;
  132.                         dpx_pdu_ptr->neg.err_code2 = 0x00;
  133.                         fdl_resp_provide(dev_num, sap_nr, FDL_PRIMARY_BUF );
  134.                     }//else of if( dpx_pdu_ptr->write.length > 0 )
  135.                     break;
  136.                 }//case DPV1_FC_WRITE:
  137.                 #ifdef DP_ALARM
  138.                     case DPV1_FC_ALARM_ACK:  
  139.                     {
  140. logMsg2("DPV1-----step4!n",0,0,0,0,0,0);
  141.                         // check, if Alarm functions enabled
  142.                         if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  143.                         {
  144.                             dp_sys[dev_num].c1.event |= MSAC_C1_IND_ALARM_QUIT;
  145.                         }//if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  146.                         else
  147.                         {
  148. logMsg2("VPC3_SET_USER_LEAVE_MASTER--1!n",0,0,0,0,0,0);
  149.                             VPC3_SET_USER_LEAVE_MASTER(dev_num);
  150.                         }//else of if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  151.                         break;
  152.                     }//case DPV1_FC_ALARM_ACK:
  153.                 #endif
  154.                 default:
  155.                 {
  156. logMsg2("VPC3_SET_USER_LEAVE_MASTER--2!n",0,0,0,0,0,0);
  157.                     VPC3_SET_USER_LEAVE_MASTER(dev_num);
  158.                     break;
  159.                 }//default:
  160.             }//switch( dpx_pdu_ptr->read.function_num )
  161.             break;
  162.         }//case DP_C1_RD_WR_SAP_NR
  163.         #ifdef DP_ALARM
  164.             case DP_C1_ALARM_SAP_NR:
  165.             {
  166.                 if( BFWORD2BYTE(dpx_pdu_ptr->read.function_num) == DPV1_FC_ALARM_ACK )
  167.                 {
  168.                     //check, if Alarm functions enabled
  169.                     if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  170.                     {
  171.                         dpv1_act_ind_SAP50_ptr[dev_num] = ind_ptr;
  172.                         dp_sys[dev_num].c1.event |= MSAC_C1_IND_ALARM_QUIT_SAP50;
  173.                     }//if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  174.                     else
  175.                     {
  176. logMsg2("VPC3_SET_USER_LEAVE_MASTER--3!n",0,0,0,0,0,0);
  177.                         VPC3_SET_USER_LEAVE_MASTER(dev_num);
  178.                     }//else of if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  179.                 }//if( dpx_pdu_ptr->read.function_num == DPV1_FC_ALARM_ACK )
  180.                 else
  181.                 {
  182. logMsg2("VPC3_SET_USER_LEAVE_MASTER--4!n",0,0,0,0,0,0);
  183.                     VPC3_SET_USER_LEAVE_MASTER(dev_num);
  184.                 }//else of if( dpx_pdu_ptr->read.function_num == DPV1_FC_ALARM_ACK )
  185.                 break;
  186.             }//case DP_C1_ALARM_SAP_NR:
  187.         #endif//#ifdef DP_ALARM
  188.         default:
  189.         {
  190. logMsg("VPC3_SET_USER_LEAVE_MASTER--5!n",0,0,0,0,0,0);
  191.             VPC3_SET_USER_LEAVE_MASTER(dev_num);
  192.             break;
  193.         }//default:
  194.     }//switch( sap_nr )
  195.     DP_UNLOCK_IND(dev_num);
  196. }//void msac_c1_pdu_received(UBYTE dev_num, UBYTE sap_nr, IND_RESP_BUF_PTR ind_ptr, UBYTE req_add )
  197. /*--------------------------------------------------------------------------*/
  198. /* function: msac_c1_process                                                */
  199. /*--------------------------------------------------------------------------*/
  200. SECTION_DEF_CommuCode void msac_c1_process(UBYTE dev_num)
  201. {
  202. DPV1_PTR    dpv1_act_pdu_ptr;
  203.     if( dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1 )
  204.     {
  205.         if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_READ )
  206.         {
  207.             dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
  208.             msac_c1_set_job_running(dev_num,TRUE);
  209.             switch (user_dpv1_read_req(dev_num,DP_C1_RD_WR_SAP_NR, (DPV1_PTR) dpv1_act_pdu_ptr) )
  210.             {
  211.                 case DPV1_OK:
  212.                 {
  213.                     dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA + BFWORD2BYTE(dpv1_act_pdu_ptr->read.length);
  214.                     dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  215.                     fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  216.                     msac_c1_set_job_running(dev_num, FALSE );
  217.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_READ;
  218.                     break;
  219.                 }//case DPV1_OK:
  220.                 case DPV1_NOK:
  221.                 {
  222.                     dpv1_act_pdu_ptr->read.function_num |= DPV1_ERROR_BIT_RESPONSE;
  223.                     dpv1_act_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
  224.                     dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_NEG_RESPONSE;
  225.                     dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  226.                     fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  227.                     msac_c1_set_job_running(dev_num, FALSE );
  228.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_READ;
  229.                     break;
  230.                 }//case DPV1_NOK:
  231.                 case DPV1_DELAY:
  232.                 {
  233.                     /* user give pdu later back */
  234.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_READ;
  235.                     break;
  236.                 }//case DPV1_DELAY:
  237.                 default:
  238.                 {
  239.                     vpc3_errcb[dev_num].error_code = dp_sys[dev_num].c1.event;
  240.                     vpc3_errcb[dev_num].cn_id      = 0;
  241.                     // *** no further action of dpv1/c2 ***
  242.                     fatal_error(dev_num,_DP_C1, __LINE__, &vpc3_errcb[dev_num]);
  243.                     break;
  244.                 }//default:
  245.             }//switch (user_dpv1_read_req(dev_num,DP_C1_RD_WR_SAP_NR, (DPV1_PTR) dpv1_act_pdu_ptr) )
  246.         }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_READ )
  247.         if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_WRITE )
  248.         {
  249.             dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
  250.             msac_c1_set_job_running(dev_num, TRUE );
  251.             switch( user_dpv1_write_req(dev_num,DP_C1_RD_WR_SAP_NR,(DPV1_PTR) dpv1_act_pdu_ptr) )
  252.             {
  253.                 case DPV1_OK:
  254.                 {
  255.                     dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
  256.                     dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  257.                     fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  258.                     msac_c1_set_job_running(dev_num, FALSE );
  259.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_WRITE;
  260.                     break;
  261.                 }//case DPV1_OK:
  262.                 case DPV1_NOK:
  263.                 {
  264.                     dpv1_act_pdu_ptr->write.function_num |= DPV1_ERROR_BIT_RESPONSE;
  265.                     dpv1_act_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
  266.                     dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_NEG_RESPONSE;
  267.                     dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  268.                     fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  269.                     msac_c1_set_job_running(dev_num, FALSE );
  270.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_WRITE;
  271.                     break;
  272.                 }//case DPV1_NOK:
  273.                 case DPV1_DELAY:
  274.                 {
  275.                     /* user give pdu later back */
  276.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_DS_WRITE;
  277.                     break;
  278.                 }//case DPV1_DELAY:
  279.                 default:
  280.                 {
  281.                     vpc3_errcb[dev_num].error_code = dp_sys[dev_num].c1.event;
  282.                     vpc3_errcb[dev_num].cn_id      = 0;
  283.                     // *** no further action of dpv1/c2 ***
  284.                     fatal_error(dev_num,_DP_C1, __LINE__, &vpc3_errcb[dev_num]);
  285.                     break;
  286.                 }//default:
  287.             }//switch( user_dpv1_write_req(dev_num,DP_C1_RD_WR_SAP_NR,(DPV1_PTR) dpv1_act_pdu_ptr) )
  288.         }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_DS_WRITE )
  289.     }//if( dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1 )
  290. }//void msac_c1_process(UBYTE dev_num)
  291. /*---------------------------------------------------------------------------*/
  292. /*                                                                           */
  293. /* UBYTE msac_c1_transmit_delay(UBYTE dev_num,UBYTE sap, UBYTE event, DPV1_RET_VAL status, */
  294. /*                                                             DPV1_PTR pdu) */
  295. /*                                                                           */
  296. /*   function: msac_c1_transmit_delay receives response data from the user.  */
  297. /*             In this function the response data are checked. In dependence */
  298. /*             of the pdu-opcode und the status the length of the data and   */
  299. /*             the function-code is manipulated. Then the dpv1_msc1 transmit */
  300. /*             function is called.                                           */
  301. /*                                                                           */
  302. /*   return codes: DPV1_OK            ( transmit function is called )        */
  303. /*                 DPV1_ERR_NO_JOB    ( no active job               )        */
  304. /*                 DPV1_ERR_INV_PARAM ( invalid parameter           )        */
  305. /*                 DPV1_NO_VALID_SAP  ( invalid sap                 )        */
  306. /*                                                                           */
  307. /*---------------------------------------------------------------------------*/
  308. SECTION_DEF_CommuCode UBYTE msac_c1_transmit_delay(UBYTE dev_num, UBYTE sap, UBYTE event, DPV1_RET_VAL status, DPV1_PTR pdu )
  309. {
  310. DPV1_PTR    dpv1_act_pdu_ptr;
  311. UBYTE       ret_val;
  312.     ret_val = DPV1_OK;
  313.     if( (sap&0xff) == DP_C1_RD_WR_SAP_NR )//2009.11.7
  314.     {
  315.         if( dp_sys[dev_num].c1.active_Job )
  316.         {
  317.             dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
  318.             switch( status )
  319.             {
  320.                 case DPV1_OK:
  321.                 {
  322.                     if( (event&0xff) == MSAC_C1_IND_DS_WRITE )//2009.11.7
  323.                     {
  324.                         dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
  325.                         dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  326.                         fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  327.                         msac_c1_set_job_running(dev_num, FALSE );
  328.                     }//if( event == MSAC_C1_IND_DS_WRITE )
  329.                     else
  330.                     {
  331.                         dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA + BFWORD2BYTE(dpv1_act_pdu_ptr->read.length);
  332.                         dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  333.                         fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  334.                         msac_c1_set_job_running(dev_num, FALSE );
  335.                     }//else of if( event == MSAC_C1_IND_DS_WRITE )
  336.                     break;
  337.                 }//case DPV1_OK:
  338.                 case DPV1_NOK:
  339.                 {
  340.                     dpv1_act_pdu_ptr->read.function_num |= DPV1_ERROR_BIT_RESPONSE;
  341.                     dpv1_act_pdu_ptr->neg.err_decode = DPV1_ERRDC_DPV1;
  342.                     dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_NEG_RESPONSE;
  343.                     dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  344.                     fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  345.                     msac_c1_set_job_running(dev_num, FALSE );
  346.                     break;
  347.                 }//case DPV1_NOK:
  348.                 default:
  349.                 {
  350.                     ret_val = DPV1_ERR_INV_PARAM;
  351.                     break;
  352.                 }//default:
  353.             }//switch( status )
  354.         }//if( dp_sys[dev_num].c1.active_Job )
  355.         else
  356.         {
  357.             ret_val = DPV1_ERR_NO_JOB;
  358.         }//else of if( dp_sys[dev_num].c1.active_Job )
  359.     }//if( sap == DP_C1_RD_WR_SAP_NR )
  360.     else
  361.     {
  362.         //dummyline for compiler because warning
  363.         pdu = pdu;
  364.         ret_val = DPV1_NO_VALID_SAP;
  365.     }//else of if( sap == DP_C1_RD_WR_SAP_NR )
  366.     return (ret_val);
  367. }//UBYTE msac_c1_transmit_delay(UBYTE dev_num, UBYTE sap, UBYTE event, DPV1_RET_VAL status, DPV1_PTR pdu )
  368. /*--------------------------------------------------------------------------*/
  369. /* function: msac_c1_set_job_running                                        */
  370. /*--------------------------------------------------------------------------*/
  371. SECTION_DEF_CommuCode void msac_c1_set_job_running(UBYTE dev_num, UBYTE running )
  372. {
  373.     if( running )
  374.     {
  375.         dp_sys[dev_num].c1.active_Job = TRUE;
  376.     }//if( running )
  377.     else
  378.     {
  379.         dp_sys[dev_num].c1.active_Job = FALSE;
  380.         if( (dp_sys[dev_num].c1.Start_State == DP_SS_STOP) && (dp_sys[dev_num].c1.Fdl_Closing == FALSE) )
  381.         {
  382.             dp_sys[dev_num].c1.Start_State = DP_SS_IDLE;
  383.         }
  384.         if( dp_sys[dev_num].c1.Start_State == DP_SS_START_AGAIN )
  385.         {
  386.             // open C1-SAPs
  387.             fdl_ind_await(dev_num,DP_C1_RD_WR_SAP_NR);
  388.             dp_sys[dev_num].c1.Start_State=DP_SS_RUN;
  389.         }//if( dp_sys[dev_num].c1.Start_State == DP_SS_START_AGAIN )
  390.     }//else of if( running )
  391. }//void msac_c1_set_job_running(UBYTE dev_num, UBYTE running )
  392. /*--------------------------------------------------------------------------*/
  393. /* function: msac_c1_ind_disable_done                                       */
  394. /*--------------------------------------------------------------------------*/
  395. SECTION_DEF_CommuCode void msac_c1_ind_disable_done(UBYTE dev_num, UBYTE sap_nr, UBYTE ret_val )
  396. {
  397.     if( (sap_nr&0xff) == DP_C1_RD_WR_SAP_NR)//2009.11.7
  398.     {
  399.         if(ret_val != FDL_OK)
  400.         {
  401.             vpc3_errcb[dev_num].error_code = VPC3_MSAC_C1_CLOSE_FAILED;
  402.             fatal_error(dev_num,_DP_C1, __LINE__, &vpc3_errcb[dev_num]);
  403.         }//if(ret_val != FDL_OK)
  404.         dp_sys[dev_num].c1.Fdl_Closing = FALSE;
  405.         dp_sys[dev_num].c1.Start_State = (dp_sys[dev_num].c1.active_Job) ? DP_SS_STOP : DP_SS_IDLE;
  406.     }//if(sap_nr == DP_C1_RD_WR_SAP_NR)
  407. }//void msac_c1_ind_disable_done(UBYTE dev_num, UBYTE sap_nr, UBYTE ret_val )
  408. /*--------------------------------------------------------------------------*/
  409. /* function: msac_c1_check_ind_new_prm_data                                 */
  410. /*--------------------------------------------------------------------------*/
  411. SECTION_DEF_CommuCode UBYTE msac_c1_check_ind_new_prm_data(UBYTE dev_num)
  412. {
  413. UBYTE ret_val;
  414.     ret_val = TRUE;
  415.     switch( VPC3_GET_DP_STATE(dev_num) )
  416.     {
  417.         case WAIT_PRM:
  418.         {
  419.             dp_sys[dev_num].c1.Operation_Mode = msac_c1_get_new_operation_mode(dev_num);
  420.             break;
  421.         }
  422.         case WAIT_CFG:
  423.         {
  424.             dp_sys[dev_num].c1.Operation_Mode = msac_c1_get_new_operation_mode(dev_num);
  425.             if (dp_sys[dev_num].c1.Start_State == DP_SS_RUN)
  426.             {
  427.                 msac_c1_stop(dev_num);
  428.             }
  429.             break;
  430.         }
  431.         case DATA_EX:
  432.         {
  433.             dp_sys[dev_num].c1.Operation_Mode = msac_c1_get_new_operation_mode(dev_num);
  434.             msac_c1_stop(dev_num);
  435.             ret_val=FALSE;  /* avoid user-interaction */
  436.             break;
  437.         }
  438.     }//switch( VPC3_GET_DP_STATE(dev_num) )
  439.     #ifdef DP_ALARM
  440.         set_new_alarm_mode(dev_num);
  441.     #endif // #ifdef DP_ALARM
  442.     return ret_val;
  443. }//UBYTE msac_c1_check_ind_new_prm_data(UBYTE dev_num)
  444. /*--------------------------------------------------------------------------*/
  445. /* function: msac_c1_do_cfg_ok                                              */
  446. /*--------------------------------------------------------------------------*/
  447. SECTION_DEF_CommuCode void msac_c1_do_cfg_ok(UBYTE dev_num)
  448. {
  449.     if( VPC3_GET_DP_STATE(dev_num) == WAIT_CFG )
  450.     {
  451.         if(dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1)
  452.         {
  453.             if( dp_sys[dev_num].c1.Start_State == DP_SS_IDLE )
  454.             {
  455.                 fdl_ind_await(dev_num,DP_C1_RD_WR_SAP_NR);
  456.                 dp_sys[dev_num].c1.Start_State = DP_SS_RUN;
  457.                 #ifdef DP_ALARM_OVER_SAP50
  458.                     fdl_ind_await(dev_num,DP_C1_ALARM_SAP_NR);
  459.                 #endif//#ifdef DP_ALARM_OVER_SAP50
  460.             }
  461.             if( dp_sys[dev_num].c1.Start_State == DP_SS_STOP )
  462.             {
  463.                 dp_sys[dev_num].c1.Start_State = DP_SS_START_AGAIN;
  464.             }
  465.         }
  466.         dp_sys[dev_num].c1.DX_Entered = FALSE;
  467.     }//if( VPC3_GET_DP_STATE(dev_num) == WAIT_CFG )
  468. }//void msac_c1_do_cfg_ok(UBYTE dev_num)
  469. /*--------------------------------------------------------------------------*/
  470. /* function: msac_c1_do_cfg_not_ok                                          */
  471. /*--------------------------------------------------------------------------*/
  472. SECTION_DEF_CommuCode void msac_c1_do_cfg_not_ok(UBYTE dev_num)
  473. {
  474.     switch( VPC3_GET_DP_STATE(dev_num) )
  475.     {
  476.         case WAIT_PRM:
  477.         {
  478.             //do nothing
  479.             break;
  480.         }
  481.         case WAIT_CFG:
  482.         case DATA_EX:
  483.         {
  484.             msac_c1_stop(dev_num);
  485.             break;
  486.         }
  487.     }//switch( VPC3_GET_DP_STATE(dev_num) )
  488. }//void msac_c1_do_cfg_not_ok(UBYTE dev_num)
  489. /*--------------------------------------------------------------------------*/
  490. /* function: msac_c1_check_ind_dx_out                                       */
  491. /*--------------------------------------------------------------------------*/
  492. SECTION_DEF_CommuCode void msac_c1_check_ind_dx_out(UBYTE dev_num)
  493. {
  494.     if(    ( dp_sys[dev_num].c1.DX_Entered     == FALSE        )
  495.         && ( VPC3_GET_DP_STATE(dev_num)      == DATA_EX      )
  496.         && ( dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1 )
  497.       )
  498.     {
  499.         dp_sys[dev_num].c1.DX_Entered = TRUE;
  500.         #ifdef DP_ALARM
  501.             if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
  502.             {
  503.                 if( dp_sys[dev_num].al.enabled > 0x00 )
  504.                 {
  505.                     dp_sys[dev_num].al.count = 0;
  506.                     dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
  507.                     dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
  508.                     dp_sys[dev_num].al.state = AL_STATE_OPEN;
  509.                 }//if( dp_sys[dev_num].al.enabled > 0x00 )
  510.                 else
  511.                 {
  512.                     dp_sys[dev_num].al.enabled = 0;
  513.                     dp_sys[dev_num].al.mode    = 0;
  514.                 }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
  515.                 user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
  516.             }//if(  dp_sys[dev_num].al.state == AL_STATE_CLOSED  )
  517.         #endif // #ifdef DP_ALARM
  518.     }//if(    (dp_sys[dev_num].c1.DX_Entered     == FALSE        ) ...
  519. }//void msac_c1_check_ind_dx_out(UBYTE dev_num)
  520. /*--------------------------------------------------------------------------*/
  521. /* function: check_sequence_status                                          */
  522. /*--------------------------------------------------------------------------*/
  523. SECTION_DEF_CommuCode MSAC1_OPMODE msac_c1_get_new_operation_mode(UBYTE dev_num)
  524. {
  525. VPC3_UNSIGNED8_PTR prm_data;
  526.     if( VPC3_GET_PRM_LEN(dev_num) >= 10 )
  527.     {
  528.         prm_data = VPC3_GET_PRM_BUF_PTR(dev_num);
  529.         if( prm_data && ( *( prm_data + 7*BLACKFIN_MULTIPLER ) & DPV1_STATUS_1_DPV1_ENABLE ) )
  530.         {
  531.             return DP_OPMODE_V1;
  532.         }
  533.     }//if( VPC3_GET_PRM_LEN(dev_num) >= 10 )
  534.     return DP_OPMODE_V0;
  535. }//MSAC1_OPMODE msac_c1_get_new_operation_mode(UBYTE dev_num)
  536. /*--------------------------------------------------------------------------*/
  537. /* function: msac_c1_leave_dx                                               */
  538. /*--------------------------------------------------------------------------*/
  539. SECTION_DEF_CommuCode void msac_c1_leave_dx(UBYTE dev_num)
  540. {
  541.     if( VPC3_GET_DP_STATE(dev_num) != DATA_EX )
  542.     {
  543.         msac_c1_stop(dev_num);
  544.         if( (vpc3_get_master(dev_num) != 0xFF ) && (VPC3_GET_DP_STATE(dev_num) == WAIT_PRM ) )
  545.         {
  546.             GO_OFFLINE_VPC3(dev_num);
  547.             START_VPC3(dev_num);
  548.         }//if( (vpc3_get_master(dev_num) != 0xFF ) && (VPC3_GET_DP_STATE(dev_num) == WAIT_PRM ) )
  549.     }//if( VPC3_GET_DP_STATE(dev_num) != DATA_EX )
  550. }//void msac_c1_leave_dx(UBYTE dev_num)
  551. // SECTION_DEF_CommuCode void msac_c1_leave_dx_wiscom(UBYTE dev_num)
  552. // {
  553. //  //重新启用一类主站的非周期状态机
  554. //  if(1)
  555. //     {
  556. //         msac_c1_stop(dev_num);
  557. //         if( (vpc3_get_master(dev_num) != 0xFF ))
  558. //         {
  559. //              msac_c1_check_ind_new_prm_data(dev_num);
  560. //              msac_c1_do_cfg_ok(dev_num);
  561. //         
  562. //  //重新启动状态机
  563. //         #ifdef DP_ALARM
  564. //             if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
  565. //             {
  566. //  dp_sys[dev_num].al.state = AL_STATE_OPEN;
  567. // 
  568. //                 if( dp_sys[dev_num].al.enabled > 0x00 )
  569. //                 {
  570. //                     dp_sys[dev_num].al.count = 0;
  571. //                     dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
  572. //                     dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
  573. //                 }//if( dp_sys[dev_num].al.enabled > 0x00 )
  574. //                 else
  575. //                 {
  576. //                     dp_sys[dev_num].al.enabled = 0;
  577. //                     dp_sys[dev_num].al.mode    = 0;
  578. //                 }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
  579. // 
  580. //                 user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
  581. //             }//if(  dp_sys[dev_num].al.state == AL_STATE_CLOSED  )
  582. //         #endif // #ifdef DP_ALARM
  583. // 
  584. //   
  585. //         }//if( (vpc3_get_master(dev_num) != 0xFF ) && (VPC3_GET_DP_STATE(dev_num) == WAIT_PRM ) )
  586. //     }//if( VPC3_GET_DP_STATE(dev_num) != DATA_EX )
  587. // }//void msac_c1_leave_dx(UBYTE dev_num)
  588. /*--------------------------------------------------------------------------*/
  589. /* function: msac_c1_stop                                                   */
  590. /*--------------------------------------------------------------------------*/
  591. SECTION_DEF_CommuCode void msac_c1_stop(UBYTE dev_num)
  592. {
  593.     dp_sys[dev_num].c1.event = 0x00;
  594.     if( dp_sys[dev_num].c1.Start_State == DP_SS_RUN )
  595.     {
  596.         dp_sys[dev_num].c1.Fdl_Closing = TRUE;
  597.         // close msac_c1
  598.         fdl_ind_disable(dev_num,DP_C1_RD_WR_SAP_NR);
  599.         #ifdef DP_ALARM
  600.             //close ALARM SAP
  601.             stop_asm(dev_num);
  602.         #endif // #ifdef DP_ALARM
  603.     }//if( dp_sys[dev_num].c1.Start_State == DP_SS_RUN )
  604. }//void msac_c1_stop(UBYTE dev_num)
  605. #ifdef DP_ALARM
  606. /*--------------------------------------------------------------------------*/
  607. /* function: init_alarm                                                     */
  608. /*--------------------------------------------------------------------------*/
  609. SECTION_DEF_CommuCode void init_alarm(UBYTE dev_num, UBYTE power_on )
  610. {
  611.     dp_sys[dev_num].al.state   = AL_STATE_CLOSED;
  612.     if( power_on == FALSE )
  613.     {
  614.         user_alarm_state_info(dev_num, ALARM_TYPE_NONE_VALUE, SEQC_MODE_TOTAL_00 );
  615.     }
  616.     dpl_init_list__(&dp_sys[dev_num].al.queue_new);
  617.     dpl_init_list__(&dp_sys[dev_num].al.queue_ack);
  618.     dp_sys[dev_num].al.enabled = 0;
  619.     dp_sys[dev_num].al.mode    = 0;
  620.     dp_sys[dev_num].al.type_status = 0;
  621.     memset( &dp_sys[dev_num].al.sequence_status[0], 0, AL_SEQUENCE_STATUS_SIZE );
  622.     dp_sys[dev_num].al.sequence = 0;
  623.     dp_sys[dev_num].al.limit    = 0;
  624.     dp_sys[dev_num].al.count    = 0;
  625.     // init coding table
  626.     alarm_decode[dev_num][0] = SEQC_MODE_OFF     ;   // no sequence mode - 01 alarm  of every type
  627.     alarm_decode[dev_num][1] = SEQC_MODE_TOTAL_02;   // sequence mode - 02 alarms in total
  628.     alarm_decode[dev_num][2] = SEQC_MODE_TOTAL_04;   // sequence mode - 04 alarms in total
  629.     alarm_decode[dev_num][3] = SEQC_MODE_TOTAL_08;   // sequence mode - 08 alarms in total
  630.     alarm_decode[dev_num][4] = SEQC_MODE_TOTAL_12;   // sequence mode - 12 alarms in total
  631.     alarm_decode[dev_num][5] = SEQC_MODE_TOTAL_16;   // sequence mode - 16 alarms in total
  632.     alarm_decode[dev_num][6] = SEQC_MODE_TOTAL_24;   // sequence mode - 24 alarms in total
  633.     alarm_decode[dev_num][7] = SEQC_MODE_TOTAL_32;   // sequence mode - 32 alarms in total
  634. }//void init_alarm(UBYTE dev_num, UBYTE power_on )
  635. /*--------------------------------------------------------------------------*/
  636. /* function: set_new_alarm_mode                                             */
  637. /*--------------------------------------------------------------------------*/
  638. SECTION_DEF_CommuCode void set_new_alarm_mode(UBYTE dev_num)
  639. {
  640. VPC3_STRUC_PRM_PTR prm_data;
  641.     dp_sys[dev_num].al.enabled = 0;
  642.     dp_sys[dev_num].al.mode    = 0;
  643.     if( (VPC3_GET_PRM_LEN(dev_num) >= PRM_LEN_DPV1 ) && (dp_sys[dev_num].c1.Operation_Mode == DP_OPMODE_V1) )
  644.     {
  645.         prm_data = (VPC3_STRUC_PRM_PTR)VPC3_GET_PRM_BUF_PTR(dev_num);
  646.         if ( prm_data )
  647.         {
  648.             dp_sys[dev_num].al.enabled = (prm_data->dpv1_status_2 & DPV1_STATUS_2_ALARM_TYPE_MASK );
  649.             dp_sys[dev_num].al.mode    = (prm_data->dpv1_status_3 & DPV1_STATUS_3_ALARM_MODE_MASK );
  650.         }
  651.     }
  652. }//void set_new_alarm_mode(UBYTE dev_num)
  653. /*--------------------------------------------------------------------------*/
  654. /* function: alarm_enabled                                                  */
  655. /*--------------------------------------------------------------------------*/
  656. SECTION_DEF_CommuCode UBYTE alarm_enabled(UBYTE dev_num, UBYTE alarm_type )
  657. {
  658.     if(    ((alarm_type == ALARM_TYPE_PULL
  659.         ||   alarm_type == ALARM_TYPE_PLUG)      && (dp_sys[dev_num].al.enabled & ALARM_TYPE_PULLPLUG_VALUE))
  660.         ||  (alarm_type == ALARM_TYPE_PROCESS    && (dp_sys[dev_num].al.enabled & ALARM_TYPE_PROCESS_VALUE))
  661.         ||  (alarm_type == ALARM_TYPE_DIAGNOSTIC && (dp_sys[dev_num].al.enabled & ALARM_TYPE_DIAGNOSTIC_VALUE))
  662.         ||  (alarm_type == ALARM_TYPE_STATUS     && (dp_sys[dev_num].al.enabled & ALARM_TYPE_STATUS_VALUE))
  663.         ||  (alarm_type == ALARM_TYPE_UPDATE     && (dp_sys[dev_num].al.enabled & ALARM_TYPE_UPDATE_VALUE))
  664.         || ((alarm_type >= ALARM_TYPE_MANU_MIN
  665.         &&   alarm_type <= ALARM_TYPE_MANU_MAX)  && (dp_sys[dev_num].al.enabled & ALARM_TYPE_MANUFACTURER_VALUE))
  666.       )
  667.     {
  668.         return TRUE;
  669.     }
  670.     else
  671.     {
  672.         return FALSE;
  673.     }
  674. }//UBYTE alarm_enabled(UBYTE dev_num, UBYTE alarm_type )
  675. /*--------------------------------------------------------------------------*/
  676. /* function: alarm_process                                                  */
  677. /*--------------------------------------------------------------------------*/
  678. SECTION_DEF_CommuCode void alarm_process(UBYTE dev_num)
  679. {
  680. DPV1_PTR    dpv1_act_pdu_ptr;
  681.     // check, if Alarm functions enabled
  682.     if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  683.     {
  684.         check_send_alarm(dev_num);
  685.         if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT )
  686.         {
  687.             dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_ptr[dev_num]->user_data[0]);
  688.             msac_c1_set_job_running(dev_num, TRUE );
  689.             //switch (dev_num, msac_c1_alarm_quit(dev_num, DP_C1_RD_WR_SAP_NR, dpv1_act_pdu_ptr ) )
  690. switch (msac_c1_alarm_quit(dev_num, DP_C1_RD_WR_SAP_NR, dpv1_act_pdu_ptr ) )
  691.             {
  692.                 case DPV1_OK:
  693.                 {
  694.                     dpv1_act_ind_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
  695.                     dpv1_act_ind_ptr[dev_num]->fc       = FC_RESP_L;
  696.                     fdl_resp_provide(dev_num, DP_C1_RD_WR_SAP_NR, FDL_PRIMARY_BUF );
  697.                     msac_c1_set_job_running(dev_num, FALSE );
  698.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT;
  699.                     break;
  700.                 }
  701.                 case DPV1_NOK:
  702.                 {
  703.                     msac_c1_set_job_running(dev_num, FALSE );
  704.                     dp_sys[dev_num].al.state = AL_STATE_CLOSED;
  705.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT;
  706. logMsg2("VPC3_SET_USER_LEAVE_MASTER--6!n",0,0,0,0,0,0);
  707.                     VPC3_SET_USER_LEAVE_MASTER(dev_num);
  708.                     break;
  709.                 }
  710.                 case DPV1_DELAY:
  711.                 {
  712.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT;
  713.                     break;
  714.                 }
  715.                 default:
  716.                 {
  717.                     break;
  718.                 }
  719.             }//switch (msac_c1_alarm_quit(dev_num,alarm_sap, dpv1_act_pdu_ptr) )
  720.         }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT )
  721.         if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT_SAP50 )
  722.         {
  723.             dpv1_act_pdu_ptr = ((DPV1_PTR) &dpv1_act_ind_SAP50_ptr[dev_num]->user_data[0]);
  724.             msac_c1_set_job_running(dev_num, TRUE );
  725.             switch (msac_c1_alarm_quit(dev_num, DP_C1_ALARM_SAP_NR, dpv1_act_pdu_ptr ) )
  726.             {
  727.                 case DPV1_OK:
  728.                 {
  729.                     dpv1_act_ind_SAP50_ptr[dev_num]->data_len = DPV1_LEN_HEAD_DATA;
  730.                     dpv1_act_ind_SAP50_ptr[dev_num]->fc       = FC_RESP_L;
  731.                     fdl_resp_provide(dev_num, DP_C1_ALARM_SAP_NR, FDL_PRIMARY_BUF );
  732.                     msac_c1_set_job_running(dev_num, FALSE );
  733.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT_SAP50;
  734.                     break;
  735.                 }
  736.                 case DPV1_NOK:
  737.                 {
  738.                     msac_c1_set_job_running(dev_num, FALSE );
  739.                     dp_sys[dev_num].al.state = AL_STATE_CLOSED;
  740.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT_SAP50;
  741. logMsg("VPC3_SET_USER_LEAVE_MASTER--7!n",0,0,0,0,0,0);
  742.                     VPC3_SET_USER_LEAVE_MASTER(dev_num);
  743.                     break;
  744.                 }
  745.                 case DPV1_DELAY:
  746.                 {
  747.                     dp_sys[dev_num].c1.event &= ~MSAC_C1_IND_ALARM_QUIT_SAP50;
  748.                     break;
  749.                 }
  750.                 default:
  751.                 {
  752.                     break;
  753.                 }
  754.             }//switch (msac_c1_alarm_quit(dev_num,alarm_sap, dpv1_act_pdu_ptr) )
  755.         }//if( dp_sys[dev_num].c1.event & MSAC_C1_IND_ALARM_QUIT_SAP50 )
  756.     }//if( dp_sys[dev_num].al.state == AL_STATE_OPEN )
  757. }//void alarm_process(UBYTE dev_num)
  758. /*--------------------------------------------------------------------------*/
  759. /* function: stop_asm                                                       */
  760. /*--------------------------------------------------------------------------*/
  761. SECTION_DEF_CommuCode void stop_asm(UBYTE dev_num)
  762. {
  763.     //clear alarm message in diagnostic buffer
  764.     reset_diagnostic_buffer(dev_num);
  765. #ifdef DP_ALARM_OVER_SAP50
  766.     fdl_ind_disable(dev_num,DP_C1_ALARM_SAP_NR);
  767. #endif//#ifdef DP_ALARM_OVER_SAP50
  768.     init_alarm(dev_num, FALSE );
  769. }//void stop_asm(UBYTE dev_num)
  770. /*--------------------------------------------------------------------------*/
  771. /* function: acls                                                           */
  772. /*--------------------------------------------------------------------------*/
  773. SECTION_DEF_CommuCode UBYTE acls(UBYTE dev_num,UBYTE alarm_type)
  774. {
  775.     if( alarm_type == ALARM_TYPE_DIAGNOSTIC )
  776.         return 0;
  777.     if( alarm_type == ALARM_TYPE_PROCESS )
  778.         return 1;
  779.     if( alarm_type == ALARM_TYPE_PULL )
  780.         return 2;
  781.     if( alarm_type == ALARM_TYPE_PLUG )
  782.         return 3;
  783.     if( alarm_type == ALARM_TYPE_STATUS )
  784.         return 4;
  785.     if( alarm_type == ALARM_TYPE_UPDATE )
  786.         return 5;
  787.     if( alarm_type >= ALARM_TYPE_MANU_MIN && alarm_type <= ALARM_TYPE_MANU_MAX )
  788.         return 6;
  789.         return 0;//ignore
  790. }//UBYTE acls(UBYTE dev_num,UBYTE alarm_type)
  791. /*--------------------------------------------------------------------------*/
  792. /* function: set_alarm__                                                    */
  793. /*--------------------------------------------------------------------------*/
  794. SECTION_DEF_CommuCode UBYTE set_alarm__(UBYTE dev_num, ALARM_STATUS_PDU_PTR user_alarm_ptr, UBYTE callback )
  795. {
  796. UBYTE seq_nr;
  797.     seq_nr = ((user_alarm_ptr->spec & SEQ_NR_MASK) >> SPEC_SEQ_START);
  798. //     if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
  799. //  {
  800. //  TRACE("set_alarm__: return SET_ALARM_AL_STATE_CLOSED");
  801. //         return SET_ALARM_AL_STATE_CLOSED;
  802. //  }
  803.     if( alarm_enabled(dev_num, user_alarm_ptr->type ) == FALSE )
  804. {
  805. // TRACE("set_alarm__: return SET_ALARM_ALARMTYPE_NOTSUPP");
  806.         return SET_ALARM_ALARMTYPE_NOTSUPP;
  807. }
  808.     if( (seq_nr&0xff) > MAX_SEQ_NR )//2009.11.7
  809. {
  810. // TRACE("set_alarm__: return SET_ALARM_SEQ_NR_ERROR");
  811.         return SET_ALARM_SEQ_NR_ERROR;
  812. }
  813.     if( (user_alarm_ptr->spec & SPEC_MASK) > 0x03 )
  814. {
  815. // TRACE("set_alarm__: return SET_ALARM_SPECIFIER_ERROR");
  816.         return SET_ALARM_SPECIFIER_ERROR;
  817. }
  818.     user_alarm_ptr->callback = callback;
  819.     dpl_put_blk_to_list_end__(&dp_sys[dev_num].al.queue_new, &user_alarm_ptr->list_head);
  820. logMsg2("DPV1-----step1!n",0,0,0,0,0,0);
  821.     return SET_ALARM_OK;
  822. }//UBYTE set_alarm__(UBYTE dev_num, ALARM_STATUS_PDU_PTR user_alarm_ptr, UBYTE callback )
  823. /*--------------------------------------------------------------------------*/
  824. /* function: check_send_alarm                                               */
  825. /*--------------------------------------------------------------------------*/
  826. SECTION_DEF_CommuCode void check_send_alarm(UBYTE dev_num)
  827. {
  828. ALARM_UNION_ALARM tmp_anchor;
  829. ALARM_UNION_ALARM tmp_alarm;
  830. UBYTE tmp_alarm_specifier;
  831. UBYTE tmp_alarm_callback;
  832. UBYTE tmp_alarm_type;
  833. UBYTE alarm_found;
  834.     tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_new;
  835.     tmp_alarm .list_ptr =  dp_sys[dev_num].al.queue_new.next_blk_ptr;
  836.     tmp_alarm_specifier = 0;
  837.     tmp_alarm_type      = 0;
  838.     alarm_found         = 0;
  839.     while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  840.     {
  841.         tmp_alarm_type      = tmp_alarm.data_ptr->type;
  842.         tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
  843.         tmp_alarm_callback  = tmp_alarm.data_ptr->callback;
  844.         if( dp_sys[dev_num].al.sequence == FALSE )
  845.         {
  846.             //type mode
  847.             //only one alarm of a specific ALARM_TYPE can be active at one time
  848.             if( check_type_status(dev_num, AL_ALARM_STATUS_ACTION_CHECK, tmp_alarm_type ) == FALSE )
  849.             {
  850. logMsg2("DPV1-----step2!n",0,0,0,0,0,0);
  851.                 if( check_send_diag(dev_num, tmp_alarm_type, tmp_alarm.data_ptr, tmp_alarm_callback ) == DP_OK )
  852.                 {
  853. logMsg2("DPV1-----step3!n",0,0,0,0,0,0);
  854.                     check_type_status(dev_num, AL_ALARM_STATUS_ACTION_SET, tmp_alarm_type );
  855.                     check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_SET, tmp_alarm_type, tmp_alarm_specifier );
  856.                     dpl_remove_blk__(tmp_alarm.list_ptr);
  857.                     tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
  858.                     dpl_put_blk_to_list_end__(tmp_anchor.list_ptr, tmp_alarm.list_ptr);
  859.                 }
  860.                 break;
  861.             }//if( check_type_status(dev_num, AL_ALARM_STATUS_ACTION_CHECK, tmp_alarm_type ) == FALSE )
  862.         }//if( alarm_sequence == FALSE )
  863.         else
  864.         {
  865.             //sequence mode
  866.             //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
  867.             if( dp_sys[dev_num].al.sequence == TRUE && dp_sys[dev_num].al.count < dp_sys[dev_num].al.limit )
  868.             {
  869.                 check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_SET, tmp_alarm_type, tmp_alarm_specifier );
  870.                 dpl_remove_blk__(tmp_alarm.list_ptr);
  871.                 tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
  872.                 dpl_put_blk_to_list_end__(tmp_anchor.list_ptr, tmp_alarm.list_ptr);
  873.                 dp_sys[dev_num].al.count++;
  874.             }
  875.             else
  876.             {
  877.                 //don't send alarm, because limit is reached
  878.                 break;
  879.             }
  880.         }//else of if( alarm_sequence == FALSE )
  881.         tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
  882.     }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  883. }//void check_send_alarm(UBYTE dev_num)
  884. /*--------------------------------------------------------------------------*/
  885. /* function: check_send_diag                                                */
  886. /*--------------------------------------------------------------------------*/
  887. SECTION_DEF_CommuCode UBYTE check_send_diag(UBYTE dev_num, UBYTE alarm_type, ALARM_STATUS_PDU_PTR alarm_ptr, UBYTE callback )
  888. {
  889. VPC3_UNION_DIAG_PTR tmp_diag;
  890. UBYTE               user_diag[DIAG_BUFSIZE];
  891. UBYTE               ret_value;
  892.     if( !VPC3_GET_DIAG_FLAG(dev_num) )
  893.     {
  894.         //old diagnostic message is send
  895.         if( callback == TRUE )
  896.         {
  897.             //send alarm over the function user_alarm
  898.             ret_value = user_alarm(dev_num, alarm_type, alarm_ptr->spec, alarm_ptr, TRUE );
  899.         }//if( callback == TRUE )
  900.         else
  901.         {
  902.             tmp_diag.byte_ptr = user_diag;
  903.             memcpy( tmp_diag.byte_ptr, (UBYTE *)&alarm_ptr->header, szAlarmHeader );
  904.             memcpy( tmp_diag.byte_ptr + szAlarmHeader, alarm_ptr->user_data_ptr, alarm_ptr->header - szAlarmHeader );
  905.             ret_value = set_diagnosis(dev_num, tmp_diag, alarm_ptr->header, 0x00, TRUE );
  906.         }//else of if( callback == TRUE )
  907.     }//if( !VPC3_GET_DIAG_FLAG(dev_num) )
  908.     else
  909.     {
  910.         //wait - old diagnosis is not send
  911.         ret_value = DP_DIAG_OLD_DIAG_NOT_SEND_ERROR;
  912.     }//else of if( !VPC3_GET_DIAG_FLAG(dev_num) )
  913. logMsg("check_send_diag-----ret_value=%02x!n",ret_value,0,0,0,0,0);
  914.     return ret_value;
  915. }//UBYTE check_send_diag(UBYTE dev_num, UBYTE alarm_type, ALARM_STATUS_PDU_PTR alarm_ptr, UBYTE callback )
  916. /*--------------------------------------------------------------------------*/
  917. /* function: clear_alarm                                                    */
  918. /*--------------------------------------------------------------------------*/
  919. SECTION_DEF_CommuCode void clear_alarm(UBYTE dev_num, UBYTE alarm_type_bit_field, UBYTE sequence_number )
  920. {
  921. ALARM_UNION_ALARM tmp_anchor;
  922. ALARM_UNION_ALARM tmp_alarm;
  923. UBYTE tmp_alarm_specifier;
  924. UBYTE tmp_alarm_type;
  925. UBYTE tmp_alarm_type_bit_field;
  926.     //reset all alarms
  927.     if( (alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) && (sequence_number == SEQUENCE_NUMBER_ALL ) )
  928.     {
  929.         dpl_init_list__(&dp_sys[dev_num].al.queue_new);
  930.         dpl_init_list__(&dp_sys[dev_num].al.queue_ack);
  931.         dp_sys[dev_num].al.type_status = 0;
  932.         memset( &dp_sys[dev_num].al.sequence_status[0], 0, AL_SEQUENCE_STATUS_SIZE );
  933.         dp_sys[dev_num].al.count    = 0;
  934.     }//if( (alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) && (sequence_number == SEQUENCE_NUMBER_ALL ) )
  935.     else
  936.     {
  937.         tmp_alarm_type_bit_field = 0;
  938.         if ( ALARM_TYPE_DIAGNOSTIC_VALUE & (alarm_type_bit_field) )
  939.         {
  940.             tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_DIAGNOSTIC - 1));
  941.         }
  942.         if ( ALARM_TYPE_PROCESS_VALUE & (alarm_type_bit_field) )
  943.         {
  944.             tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_PROCESS - 1));
  945.         }
  946.         if ( ALARM_TYPE_PULLPLUG_VALUE & (alarm_type_bit_field) )
  947.         {
  948.             tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_PULL - 1)) | (1 << (ALARM_TYPE_PLUG - 1));
  949.         }
  950.         if ( ALARM_TYPE_STATUS_VALUE & (alarm_type_bit_field) )
  951.         {
  952.             tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_STATUS - 1));
  953.         }
  954.         if ( ALARM_TYPE_UPDATE_VALUE & (alarm_type_bit_field) )
  955.         {
  956.             tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_UPDATE - 1));
  957.         }
  958.         if ( ALARM_TYPE_MANUFACTURER_VALUE & (alarm_type_bit_field) )
  959.         {
  960.             tmp_alarm_type_bit_field |= (1 << (ALARM_TYPE_MAX - 1));
  961.         }
  962.         tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_new;
  963.         tmp_alarm .list_ptr =  dp_sys[dev_num].al.queue_new.next_blk_ptr;
  964.         tmp_alarm_specifier = 0;
  965.         tmp_alarm_type      = 0;
  966.         while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  967.         {
  968.             tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
  969.             tmp_alarm_type      = tmp_alarm.data_ptr->type;
  970.             if(    (( tmp_alarm_type_bit_field & (1 << (acls(dev_num,tmp_alarm_type)))   ) || ( alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) )
  971.                 && ( ( (tmp_alarm_specifier >> SPEC_SEQ_START) == sequence_number ) || ( sequence_number == SEQUENCE_NUMBER_ALL ) )
  972.               )
  973.             {
  974.                 if( dp_sys[dev_num].al.sequence == FALSE )
  975.                 {
  976.                     //type mode
  977.                     //only one alarm of a specific ALARM_TYPE can be active at one time
  978.                     check_type_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type );
  979.                     check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
  980.                 }//if( alarm_sequence == FALSE )
  981.                 else
  982.                 {
  983.                     //sequence mode
  984.                     //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
  985.                     check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
  986.                     dp_sys[dev_num].al.count--;
  987.                 }//else of if( alarm_sequence == FALSE )
  988.             }//if(  .....
  989.             tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
  990.         }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  991.     }//else of if( ( alarm_type_bit_field == ALARM_TYPE_ALL_VALUE ) && ( sequence_number == SEQUENCE_NUMBER_ALL ) )
  992. }//void clear_alarm(UBYTE dev_num, UBYTE alarm_type_bit_field, UBYTE sequence_number )
  993. /*--------------------------------------------------------------------------*/
  994. /* function: check_type_status                                              */
  995. /*--------------------------------------------------------------------------*/
  996. SECTION_DEF_CommuCode UBYTE check_type_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type )
  997. {
  998. UBYTE ret_value;
  999.     alarm_type = (UBYTE)(1 << ( acls(dev_num,alarm_type)));
  1000.     if( action == AL_ALARM_STATUS_ACTION_SET )
  1001.     {
  1002.         dp_sys[dev_num].al.type_status |= alarm_type;
  1003.         ret_value = TRUE;
  1004.     }
  1005.     else
  1006.     if( action == AL_ALARM_STATUS_ACTION_RESET )
  1007.     {
  1008.         dp_sys[dev_num].al.type_status &= ~alarm_type;
  1009.         ret_value = FALSE;
  1010.     }
  1011.     else
  1012.     {
  1013.         ret_value = ( dp_sys[dev_num].al.type_status & alarm_type ) ? TRUE : FALSE;
  1014.     }
  1015.     return ret_value;
  1016. }//UBYTE check_type_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type )
  1017. /*--------------------------------------------------------------------------*/
  1018. /* function: check_sequence_status                                          */
  1019. /*--------------------------------------------------------------------------*/
  1020. SECTION_DEF_CommuCode UBYTE check_sequence_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type, UBYTE alarm_specifier )
  1021. {
  1022. VPC3_UNSIGNED8_PTR  tmp_alarm_sequence_status_ptr;
  1023. UBYTE               ret_value;
  1024.     alarm_type = (1 << ( acls(dev_num,alarm_type)));
  1025. //?应是:alarm_type = acls(dev_num,alarm_type);
  1026.     // bit field index in alarm_sequence_status
  1027.     alarm_type = alarm_type * MAX_SEQ_NR + (alarm_specifier >> SPEC_SEQ_START);
  1028.     // bit mask at byte field index in alarm_sequence_status
  1029.     alarm_specifier = (UBYTE)(1 << (alarm_type & 0x07));
  1030.     /* byte field index in alarm_sequence_status */
  1031.     tmp_alarm_sequence_status_ptr = dp_sys[dev_num].al.sequence_status + (alarm_type >> 3);
  1032.     if( *tmp_alarm_sequence_status_ptr & alarm_specifier )
  1033.     {
  1034.         if( action == AL_ALARM_STATUS_ACTION_RESET )
  1035.         {
  1036.             /* reset only if set */
  1037.             *tmp_alarm_sequence_status_ptr &= ~alarm_specifier;
  1038.         }
  1039.         ret_value = TRUE;
  1040.     }
  1041.     else
  1042.     {
  1043.         if( action == AL_ALARM_STATUS_ACTION_SET )
  1044.         {
  1045.             /* set only if reset */
  1046.             *tmp_alarm_sequence_status_ptr |= alarm_specifier;
  1047.         }
  1048.         ret_value = FALSE;
  1049.     }
  1050.     return(ret_value );
  1051. }//UBYTE check_sequence_status(UBYTE dev_num, UBYTE action, UBYTE alarm_type, UBYTE alarm_specifier )
  1052. /*--------------------------------------------------------------------------*/
  1053. /* msac_c1_alarm_quit (UBYTE dev_num,called by DPV1)                                      */
  1054. /*--------------------------------------------------------------------------*/
  1055. SECTION_DEF_CommuCode DPV1_RET_VAL msac_c1_alarm_quit(UBYTE dev_num, UBYTE sap, DPV1_PTR pdu )
  1056. {
  1057. ALARM_UNION_ALARM   tmp_anchor;
  1058. ALARM_UNION_ALARM   tmp_alarm;
  1059. DPV1_RET_VAL        ret_value;
  1060. UBYTE               tmp_alarm_specifier;
  1061. UBYTE               tmp_alarm_slot_nr;
  1062. UBYTE               tmp_alarm_type;
  1063. UBYTE               alarm_found;
  1064. UBYTE               alarm_type;
  1065. UBYTE               slot_nr;
  1066. UBYTE               seq_nr;
  1067.     ret_value = DPV1_OK;
  1068.     if( ( (sap&0xff) == DP_C1_RD_WR_SAP_NR) || ( (sap&0xff) == DP_C1_ALARM_SAP_NR))
  1069.     {
  1070.         slot_nr    = BFWORD2BYTE(pdu->alarm.slot_num);
  1071.         alarm_type = BFWORD2BYTE(pdu->alarm.alarm_type);
  1072.         seq_nr     = (pdu->alarm.specifier & SEQ_NR_MASK) >> SPEC_SEQ_START;
  1073.         tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
  1074.         tmp_alarm .list_ptr =  dp_sys[dev_num].al.queue_ack.next_blk_ptr;
  1075.         tmp_alarm_specifier = 0;
  1076.         tmp_alarm_slot_nr   = 0;
  1077.         tmp_alarm_type      = 0;
  1078.         alarm_found         = FALSE;
  1079.         while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  1080.         {
  1081. logMsg2("DPV1-----step5!n",0,0,0,0,0,0);
  1082.             tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
  1083.             tmp_alarm_slot_nr   = tmp_alarm.data_ptr->slot;
  1084.             tmp_alarm_type      = tmp_alarm.data_ptr->type;
  1085.             if(    ((tmp_alarm_specifier & SEQ_NR_MASK) >> SPEC_SEQ_START == seq_nr     )
  1086.                 && ( tmp_alarm_type                                       == alarm_type )
  1087.                 && ( tmp_alarm_slot_nr                                    == slot_nr    )
  1088.               )
  1089.             {
  1090.                 //alarm found
  1091.                 alarm_found = TRUE;
  1092.                 break;
  1093.             }
  1094.             tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
  1095.         }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  1096.         if( alarm_found == TRUE )
  1097.         {
  1098. logMsg2("DPV1-----step6!n",0,0,0,0,0,0);
  1099.             if( dp_sys[dev_num].al.sequence == FALSE )
  1100.             {
  1101.                 //type mode
  1102.                 //only one alarm of a specific ALARM_TYPE can be active at one time
  1103.                 check_type_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type );
  1104.                 check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
  1105.             }//if( alarm_sequence == FALSE )
  1106.             else
  1107.             {
  1108.                 //sequence mode
  1109.                 //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
  1110.                 check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
  1111.                 dp_sys[dev_num].al.count--;
  1112.             }//else of if( alarm_sequence == FALSE )
  1113.             dpl_remove_blk__(tmp_alarm.list_ptr );
  1114.             user_alarm_ack_req(dev_num, tmp_alarm.data_ptr );
  1115.         }//if( alarm_found == TRUE )
  1116.         else
  1117.         {
  1118. logMsg2("msac_c1_alarm_quit----DPV1_NOK--1!n",0,0,0,0,0,0);
  1119.             ret_value = DPV1_NOK;
  1120.         }//else of if( alarm_found == TRUE )
  1121.     }
  1122.     else
  1123.     {
  1124. logMsg2("msac_c1_alarm_quit----DPV1_NOK--2!n",0,0,0,0,0,0);
  1125.         return DPV1_NOK;
  1126.     }
  1127.     return ret_value;
  1128. }//DPV1_RET_VAL msac_c1_alarm_quit(UBYTE dev_num,UBYTE sap, DPV1_PTR pdu)
  1129. //wusenlin 增加用于报警状态机在通断电情况下报警超时时取消报警
  1130. SECTION_DEF_CommuCode int msac_c1_alarm_quit_wiscom(UBYTE dev_num, UBYTE sap, 
  1131. UBYTE slot_nr, UBYTE  alarm_type, UBYTE seq_nr)
  1132. {
  1133. #define TYPE_QUIT_LEAVEMASTER 
  1134. //ALARM_UNION_ALARM   tmp_anchor;
  1135. //ALARM_UNION_ALARM   tmp_alarm;
  1136. DPV1_RET_VAL        ret_value;
  1137. //UBYTE               tmp_alarm_specifier;
  1138. //UBYTE               tmp_alarm_slot_nr;
  1139. //UBYTE               tmp_alarm_type;
  1140. //UBYTE               alarm_found;
  1141.     msac_c1_set_job_running(dev_num, TRUE );
  1142.     ret_value = DPV1_OK;
  1143. #ifdef TYPE_QUIT_LEAVEMASTER
  1144. //直接退出状态机
  1145. VPC3_SET_USER_LEAVE_MASTER(dev_num);
  1146. //重新启动状态机
  1147. if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
  1148. {
  1149. dp_sys[dev_num].al.state = AL_STATE_OPEN;
  1150. if( dp_sys[dev_num].al.enabled > 0x00 )
  1151. {
  1152. dp_sys[dev_num].al.count = 0;
  1153. dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
  1154. dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
  1155. }//if( dp_sys[dev_num].al.enabled > 0x00 )
  1156. else
  1157. {
  1158. dp_sys[dev_num].al.enabled = 0;
  1159. dp_sys[dev_num].al.mode    = 0;
  1160. }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
  1161. user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
  1162. }//if(  dp_sys[dev_num].al.state == AL_STATE_CLOSED  )
  1163. #else
  1164.     if( ( (sap&0xff) == DP_C1_RD_WR_SAP_NR) || ( (sap&0xff) == DP_C1_ALARM_SAP_NR))//2009.11.7
  1165.     {
  1166. //         slot_nr    = BFWORD2BYTE(pdu->alarm.slot_num);
  1167. //         alarm_type = BFWORD2BYTE(pdu->alarm.alarm_type);
  1168. //         seq_nr     = (pdu->alarm.specifier & SEQ_NR_MASK) >> SPEC_SEQ_START;
  1169.         tmp_anchor.list_ptr = &dp_sys[dev_num].al.queue_ack;
  1170.         tmp_alarm .list_ptr =  dp_sys[dev_num].al.queue_ack.next_blk_ptr;
  1171.         tmp_alarm_specifier = 0;
  1172.         tmp_alarm_slot_nr   = 0;
  1173.         tmp_alarm_type      = 0;
  1174.         alarm_found         = FALSE;
  1175.         while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  1176.         {
  1177. logMsg2("DPV1-----step5!n",0,0,0,0,0,0);
  1178.             tmp_alarm_specifier = tmp_alarm.data_ptr->spec;
  1179.             tmp_alarm_slot_nr   = tmp_alarm.data_ptr->slot;
  1180.             tmp_alarm_type      = tmp_alarm.data_ptr->type;
  1181.             if(    ((tmp_alarm_specifier & SEQ_NR_MASK) >> SPEC_SEQ_START == (seq_nr & SEQ_NR_MASK) >> SPEC_SEQ_START     )
  1182.                 && ( tmp_alarm_type                                       == alarm_type )
  1183.                 && ( tmp_alarm_slot_nr                                    == slot_nr    )
  1184.               )
  1185.             {
  1186.                 //alarm found
  1187.                 alarm_found = TRUE;
  1188.                 break;
  1189.             }
  1190.             tmp_alarm.list_ptr = tmp_alarm.list_ptr->next_blk_ptr;
  1191.         }//while( (DPL_HOST_PTR_COMPARE_TYPE) tmp_alarm.list_ptr != (DPL_HOST_PTR_COMPARE_TYPE) tmp_anchor.list_ptr )
  1192.         if( alarm_found == TRUE )
  1193.         {
  1194. logMsg2("DPV1-----step6!n",0,0,0,0,0,0);
  1195.             if( dp_sys[dev_num].al.sequence == FALSE )
  1196.             {
  1197.                 //type mode
  1198.                 //only one alarm of a specific ALARM_TYPE can be active at one time
  1199.                 check_type_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type );
  1200.                 check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
  1201.             }//if( alarm_sequence == FALSE )
  1202.             else
  1203.             {
  1204.                 //sequence mode
  1205.                 //several alarms (2 to 32) of the same or different ALARM_TYPE can be active at one time
  1206.                 check_sequence_status(dev_num, AL_ALARM_STATUS_ACTION_RESET, tmp_alarm_type, tmp_alarm_specifier );
  1207.                 dp_sys[dev_num].al.count--;
  1208.             }//else of if( alarm_sequence == FALSE )
  1209.             dpl_remove_blk__(tmp_alarm.list_ptr );
  1210. TRACE("msac_c1_alarm_quit_wiscom OK");
  1211.             //user_alarm_ack_req(dev_num, tmp_alarm.data_ptr );
  1212.         }//if( alarm_found == TRUE )
  1213.         else
  1214.         {
  1215. //重新启动状态机
  1216.             if( dp_sys[dev_num].al.state == AL_STATE_CLOSED )
  1217.             {
  1218. dp_sys[dev_num].al.state = AL_STATE_OPEN;
  1219.                 if( dp_sys[dev_num].al.enabled > 0x00 )
  1220.                 {
  1221.                     dp_sys[dev_num].al.count = 0;
  1222.                     dp_sys[dev_num].al.limit = alarm_decode[dev_num][ dp_sys[dev_num].al.mode ];
  1223.                     dp_sys[dev_num].al.sequence = (dp_sys[dev_num].al.mode == SEQC_MODE_TOTAL_00 ) ? FALSE : TRUE;
  1224.                 }//if( dp_sys[dev_num].al.enabled > 0x00 )
  1225.                 else
  1226.                 {
  1227.                     dp_sys[dev_num].al.enabled = 0;
  1228.                     dp_sys[dev_num].al.mode    = 0;
  1229.                 }//else of if( dp_sys[dev_num].al.enabled > 0x00 )
  1230.                 user_alarm_state_info(dev_num, dp_sys[dev_num].al.enabled, dp_sys[dev_num].al.mode );
  1231.             }//if(  dp_sys[dev_num].al.state == AL_STATE_CLOSED  )
  1232. TRACE("msac_c1_alarm_quit_wiscom NOK1");
  1233.             ret_value = DPV1_NOK;
  1234.         }//else of if( alarm_found == TRUE )
  1235.     }
  1236.     else
  1237.     {
  1238. TRACE("msac_c1_alarm_quit_wiscom NOK2");
  1239.         ret_value = DPV1_NOK;
  1240.     }
  1241. #endif//wusenlin
  1242. msac_c1_set_job_running(dev_num, FALSE );
  1243.     return ret_value;
  1244. }//DPV1_RET_VAL msac_c1_alarm_quit(UBYTE dev_num,UBYTE sap, DPV1_PTR pdu)
  1245. #endif//#ifdef DP_ALARM
  1246. #endif //#ifdef DP_MSAC_C1
  1247. /*****************************************************************************/
  1248. /*  Copyright (C) profichip GmbH 2004. Confidential.                         */
  1249. /*****************************************************************************/