
#ifndef DEFMACROS_INC_INCLUDE
#define DEFMACROS_INC_INCLUDE

#define ID_FC_ERROR                    3000
#define ID_CHECK_ABORT                 0
#define ID_CHECK_SUCCESS               1

#define BLOCK_MODE_AUTO                0x08
#define BLOCK_MODE_MAN                 0x10
#define BLOCK_MODE_OUT_OF_SERVICE      0x80
#define BLOCK_MODE_RCAS                0x02
#define BLOCK_MODE_LO                  0x20

#ifndef PHYS_FACTORY_RESET_ADDRESS
#define PHYS_FACTORY_RESET_ADDRESS     2712
#endif

#ifndef PHYS_FACTORY_RESET_CMD
#define PHYS_FACTORY_RESET_CMD         2506
#endif

//#define _DTM_

#ifdef _DTM_
#define _PDM_ 800
#endif


#define DI_1_VALUE                  \
    {1, "Alarm active"      },      \
    {2, "Clean active"      } 

#define DI_2_VALUE                  \
    {1, "HOLD active"       }


#define DO_1_VALUE                  \
    {0, "Hold inactive"     },      \
    {1, "Hold active"       }

#define DO_2_VALUE                  \
    { 0x00,  "LED ON"       },      \
    { 0x01,  "LED OFF"      } 



#define DEF_DISPLAY_FORMAT(decimal_poin)					    \
    	SELECT(decimal_poin)					                \
    	{														\
    		CASE 0:		".0f";									\
    		CASE 1:		".1f";									\
    		CASE 2:		".2f";									\
    		CASE 3:		".3f";									\
    		CASE 4:		".4f";									\
    		CASE 5:		".5f";									\
    		CASE 6:		".6f";									\
    		CASE 7:		".7f";									\
    		DEFAULT:	"7.4f";								    \
    	}


#define STATUS_INPUT_LIMIT(quality)                        \
        IF ((quality) == 0x20)                             \
        {                                                  \
            { 0x00,    [status_limit_OK]                 },\
            { 0x03,    [status_limit_VALUE_CONSTANT]     } \
        }                                                  \
        ELSE {                                             \
            IF ((quality) == 0x30)                         \
            {                                              \
                { 0x00,    [status_limit_OK]             },\
                { 0x03,    [status_limit_VALUE_CONSTANT] } \
            }                                              \
             ELSE {                                        \
                { 0x00,    [status_limit_OK]             },\
                { 0x01,    [status_limit_UNDERFLOW]      },\
                { 0x02,    [status_limit_OVERFLOW]       },\
                { 0x03,    [status_limit_VALUE_CONSTANT] } \
            }                                              \
        }

#define STATUS_OUTPUT_LIMIT                                \
        { 0x00,    [status_limit_OK]                 },    \
        { 0x01,    [status_limit_UNDERFLOW]          },    \
        { 0x02,    [status_limit_OVERFLOW]           },    \
        { 0x03,    [status_limit_VALUE_CONSTANT]     }

#define STATUS_INPUT_NO_RCAS                      \
        { 0x20,    [status_GOOD_00]         },    \
        { 0x21,    [status_GOOD_01]         },    \
        { 0x22,    [status_GOOD_02]         },    \
        { 0x23,    [status_GOOD_03]         },    \
        { 0x24,    [status_GOOD_04]         },    \
        { 0x25,    [status_GOOD_05]         },    \
        { 0x26,    [status_GOOD_06]         },    \
        { 0x28,    [status_GOOD_08]         },    \
        { 0x29,    [status_GOOD_09]         },    \
        { 0x2A,    [status_GOOD_10]         },    \
        { 0x2F,    [status_GOOD_15]         },    \
        { 0x10,    [status_UNCERTAIN_00]    },    \
        { 0x11,    [status_UNCERTAIN_01]    },    \
        { 0x12,    [status_UNCERTAIN_02]    },    \
        { 0x13,    [status_UNCERTAIN_03]    },    \
        { 0x14,    [status_UNCERTAIN_04]    },    \
        { 0x15,    [status_UNCERTAIN_05]    },    \
        { 0x16,    [status_UNCERTAIN_06]    },    \
        { 0x17,    [status_UNCERTAIN_07]    },    \
        { 0x18,    [status_UNCERTAIN_08]    },    \
        { 0x1A,    [status_UNCERTAIN_10]    },    \
        { 0x1C,    [status_UNCERTAIN_12]    },    \
        { 0x1D,    [status_UNCERTAIN_13]    },    \
        { 0x1E,    [status_UNCERTAIN_14]    },    \
        { 0x00,    [status_BAD_00]          },    \
        { 0x01,    [status_BAD_01]          },    \
        { 0x02,    [status_BAD_02]          },    \
        { 0x03,    [status_BAD_03]          },    \
        { 0x04,    [status_BAD_04]          },    \
        { 0x05,    [status_BAD_05]          },    \
        { 0x06,    [status_BAD_06]          },    \
        { 0x07,    [status_BAD_07]          },    \
        { 0x08,    [status_BAD_08]          },    \
        { 0x09,    [status_BAD_09]          },    \
        { 0x0A,    [status_BAD_10]          },    \
        { 0x0F,    [status_BAD_15]          }

#define STATUS_INPUT_RCAS                         \
        { 0x20,    [status_GOOD_00]         },    \
        { 0x30,    [status_GOOD_RCAS_00]    },    \
        { 0x31,    [status_GOOD_RCAS_01]    },    \
        { 0x35,    [status_GOOD_RCAS_05]    },    \
        { 0x38,    [status_GOOD_RCAS_08]    },    \
        { 0x00,    [status_BAD_00]          },    \
        { 0x01,    [status_BAD_01]          },    \
        { 0x03,    [status_BAD_03]          },    \
        { 0x04,    [status_BAD_04]          },    \
        { 0x07,    [status_BAD_07]          }

#define STATUS_OUTPUT_NO_RCAS                     \
        { 0x20,    [status_GOOD_00]        },     \
        { 0x21,    [status_GOOD_01]        },     \
        { 0x22,    [status_GOOD_02]        },     \
        { 0x23,    [status_GOOD_03]        },     \
        { 0x24,    [status_GOOD_04]        },     \
        { 0x25,    [status_GOOD_05]        },     \
        { 0x26,    [status_GOOD_06]        },     \
        { 0x28,    [status_GOOD_08]        },     \
        { 0x29,    [status_GOOD_09]        },     \
        { 0x2A,    [status_GOOD_10]        },     \
        { 0x2F,    [status_GOOD_15]        },     \
        { 0x10,    [status_UNCERTAIN_00]   },     \
        { 0x11,    [status_UNCERTAIN_01]   },     \
        { 0x12,    [status_UNCERTAIN_02]   },     \
        { 0x13,    [status_UNCERTAIN_03]   },     \
        { 0x14,    [status_UNCERTAIN_04]   },     \
        { 0x15,    [status_UNCERTAIN_05]   },     \
        { 0x16,    [status_UNCERTAIN_06]   },     \
        { 0x17,    [status_UNCERTAIN_07]   },     \
        { 0x18,    [status_UNCERTAIN_08]   },     \
        { 0x1A,    [status_UNCERTAIN_10]   },     \
        { 0x1C,    [status_UNCERTAIN_12]   },     \
        { 0x1D,    [status_UNCERTAIN_13]   },     \
        { 0x1E,    [status_UNCERTAIN_14]   },     \
        { 0x00,    [status_BAD_00]         },     \
        { 0x01,    [status_BAD_01]         },     \
        { 0x02,    [status_BAD_02]         },     \
        { 0x03,    [status_BAD_03]         },     \
        { 0x04,    [status_BAD_04]         },     \
        { 0x05,    [status_BAD_05]         },     \
        { 0x06,    [status_BAD_06]         },     \
        { 0x07,    [status_BAD_07]         },     \
        { 0x08,    [status_BAD_08]         },     \
        { 0x09,    [status_BAD_09]         },     \
        { 0x0A,    [status_BAD_10]         },     \
        { 0x0F,    [status_BAD_15]         }

#define STATUS_OUTPUT_RCAS                        \
        { 0x30,    [status_GOOD_RCAS_00]    },    \
        { 0x31,    [status_GOOD_RCAS_01]    },    \
        { 0x32,    [status_GOOD_RCAS_02]    },    \
        { 0x33,    [status_GOOD_RCAS_03]    },    \
        { 0x34,    [status_GOOD_RCAS_04]    },    \
        { 0x35,    [status_GOOD_RCAS_05]    },    \
        { 0x36,    [status_GOOD_RCAS_06]    },    \
        { 0x37,    [status_GOOD_RCAS_07]    },    \
        { 0x38,    [status_GOOD_RCAS_08]    },    \
        { 0x10,    [status_UNCERTAIN_00]    },    \
        { 0x11,    [status_UNCERTAIN_01]    },    \
        { 0x12,    [status_UNCERTAIN_02]    },    \
        { 0x13,    [status_UNCERTAIN_03]    },    \
        { 0x14,    [status_UNCERTAIN_04]    },    \
        { 0x15,    [status_UNCERTAIN_05]    },    \
        { 0x16,    [status_UNCERTAIN_06]    },    \
        { 0x17,    [status_UNCERTAIN_07]    },    \
        { 0x00,    [status_BAD_00]          },    \
        { 0x01,    [status_BAD_01]          },    \
        { 0x02,    [status_BAD_02]          },    \
        { 0x03,    [status_BAD_03]          },    \
        { 0x04,    [status_BAD_04]          },    \
        { 0x05,    [status_BAD_05]          },    \
        { 0x06,    [status_BAD_06]          },    \
        { 0x07,    [status_BAD_07]          }

#define STATUS_GENERAL                  \
        {    0,    [bad_0]           }, \
        {    1,    [bad_1]           }, \
        {    2,    [bad_2]           }, \
        {    3,    [bad_3]           }, \
        {    4,    [bad_4]           }, \
        {    5,    [bad_5]           }, \
        {    6,    [bad_6]           }, \
        {    7,    [bad_7]           }, \
        {    8,    [bad_8]           }, \
        {    9,    [bad_9]           }, \
        {   10,    [bad_10]          }, \
        {   11,    [bad_11]          }, \
        {   12,    [bad_12]          }, \
        {   13,    [bad_13]          }, \
        {   14,    [bad_14]          }, \
        {   15,    [bad_15]          }, \
        {   16,    [bad_16]          }, \
        {   17,    [bad_17]          }, \
        {   18,    [bad_18]          }, \
        {   19,    [bad_19]          }, \
        {   20,    [bad_20]          }, \
        {   21,    [bad_21]          }, \
        {   22,    [bad_22]          }, \
        {   23,    [bad_23]          }, \
        {   24,    [bad_24]          }, \
        {   25,    [bad_25]          }, \
        {   26,    [bad_26]          }, \
        {   27,    [bad_27]          }, \
        {   28,    [bad_28]          }, \
        {   29,    [bad_29]          }, \
        {   30,    [bad_30]          }, \
        {   31,    [bad_31]          }, \
        {   64,    [uncertain_64]    }, \
        {   65,    [uncertain_65]    }, \
        {   66,    [uncertain_66]    }, \
        {   67,    [uncertain_67]    }, \
        {   68,    [uncertain_68]    }, \
        {   69,    [uncertain_69]    }, \
        {   70,    [uncertain_70]    }, \
        {   71,    [uncertain_71]    }, \
        {   72,    [uncertain_72]    }, \
        {   73,    [uncertain_73]    }, \
        {   74,    [uncertain_74]    }, \
        {   75,    [uncertain_75]    }, \
        {   76,    [uncertain_76]    }, \
        {   77,    [uncertain_77]    }, \
        {   78,    [uncertain_78]    }, \
        {   79,    [uncertain_79]    }, \
        {   80,    [uncertain_80]    }, \
        {   81,    [uncertain_81]    }, \
        {   82,    [uncertain_82]    }, \
        {   83,    [uncertain_83]    }, \
        {   84,    [uncertain_84]    }, \
        {   85,    [uncertain_85]    }, \
        {   86,    [uncertain_86]    }, \
        {   87,    [uncertain_87]    }, \
        {   88,    [uncertain_88]    }, \
        {   89,    [uncertain_89]    }, \
        {   90,    [uncertain_90]    }, \
        {   91,    [uncertain_91]    }, \
        {   92,    [uncertain_92]    }, \
        {   93,    [uncertain_93]    }, \
        {   94,    [uncertain_94]    }, \
        {   95,    [uncertain_95]    }, \
        {   96,    [uncertain_96]    }, \
        {   97,    [uncertain_97]    }, \
        {   98,    [uncertain_98]    }, \
        {   99,    [uncertain_99]    }, \
        {  100,    [uncertain_100]   }, \
        {  101,    [uncertain_101]   }, \
        {  102,    [uncertain_102]   }, \
        {  103,    [uncertain_103]   }, \
        {  128,    [good_128]        }, \
        {  129,    [good_129]        }, \
        {  130,    [good_130]        }, \
        {  131,    [good_131]        }, \
        {  132,    [good_132]        }, \
        {  133,    [good_133]        }, \
        {  134,    [good_134]        }, \
        {  135,    [good_135]        }, \
        {  136,    [good_136]        }, \
        {  137,    [good_137]        }, \
        {  138,    [good_138]        }, \
        {  139,    [good_139]        }, \
        {  140,    [good_140]        }, \
        {  141,    [good_141]        }, \
        {  142,    [good_142]        }, \
        {  143,    [good_143]        }, \
        {  144,    [good_144]        }, \
        {  145,    [good_145]        }, \
        {  146,    [good_146]        }, \
        {  147,    [good_147]        }, \
        {  148,    [good_148]        }, \
        {  149,    [good_149]        }, \
        {  150,    [good_150]        }, \
        {  151,    [good_151]        }, \
        {  152,    [good_152]        }, \
        {  153,    [good_153]        }, \
        {  154,    [good_154]        }, \
        {  155,    [good_155]        }, \
        {  160,    [good_160]        }, \
        {  161,    [good_161]        }, \
        {  162,    [good_162]        }, \
        {  163,    [good_163]        }, \
        {  164,    [good_164]        }, \
        {  165,    [good_165]        }, \
        {  166,    [good_166]        }, \
        {  167,    [good_167]        }, \
        {  192,    [good_192]        }, \
        {  193,    [good_193]        }, \
        {  194,    [good_194]        }, \
        {  195,    [good_195]        }, \
        {  196,    [good_196]        }, \
        {  197,    [good_197]        }, \
        {  198,    [good_198]        }, \
        {  199,    [good_199]        }, \
        {  200,    [good_200]        }, \
        {  201,    [good_201]        }, \
        {  202,    [good_202]        }, \
        {  203,    [good_203]        }, \
        {  204,    [good_204]        }, \
        {  205,    [good_205]        }, \
        {  206,    [good_206]        }, \
        {  207,    [good_207]        }, \
        {  208,    [good_208]        }, \
        {  209,    [good_209]        }, \
        {  210,    [good_210]        }, \
        {  211,    [good_211]        }, \
        {  212,    [good_212]        }, \
        {  213,    [good_213]        }, \
        {  214,    [good_214]        }, \
        {  215,    [good_215]        }, \
        {  216,    [good_216]        }, \
        {  217,    [good_217]        }, \
        {  218,    [good_218]        }, \
        {  219,    [good_219]        }, \
        {  220,    [good_220]        }, \
        {  221,    [good_221]        }, \
        {  222,    [good_222]        }, \
        {  223,    [good_223]        }, \
        {  224,    [good_224]        }, \
        {  225,    [good_225]        }, \
        {  226,    [good_226]        }, \
        {  227,    [good_227]        }

#define AI_UNIT                                           \
        { 1001, [unit_1001],     [unit_1001_help]     },   \
        { 1002, [unit_1002],     [unit_1002_help]     },   \
        { 1105, [unit_1105],     [unit_1105_help]     },   \
        { 1136, [unit_1136],     [unit_1136_help]     },   \
        { 1138, [unit_1138],     [unit_1138_help]     },   \
        { 1157, [unit_1157],     [unit_1157_help]     },   \
        { 1213, [unit_1213],     [unit_1213_help]     },   \
        { 1243, [unit_1243],     [unit_1243_help]     },   \
        { 1281, [unit_1281],     [unit_1281_help]     },   \
        { 1283, [unit_1283],     [unit_1283_help]     },   \
        { 1284, [unit_1284],     [unit_1284_help]     },   \
        { 1295, [unit_1295],     [unit_1295_help]     },   \
        { 1299, [unit_1299],     [unit_1299_help]     },   \
        { 1302, [unit_1302],     [unit_1302_help]     },   \
        { 1342, [unit_1342],     [unit_1342_help]     },   \
        { 1422, [unit_1422],     [unit_1422_help]     },   \
        { 1423, [unit_1423],     [unit_1423_help]     },   \
        { 1424, [unit_1424],     [unit_1424_help]     },   \
        { 1425, [unit_1425],     [unit_1425_help]     },   \
        { 1551, [unit_1551],     [unit_1551_help]     },   \
        { 1552, [unit_1552],     [unit_1552_help]     },   \
        { 1555, [unit_1555],     [unit_1555_help]     },   \
        { 1556, [unit_1556],     [unit_1556_help]     },   \
        { 1558, [unit_1558],     [unit_1558_help]     },   \
        { 1559, [unit_1559],     [unit_1559_help]     },   \
        {33000, [MT_unit_33000], [MT_unit_33000_help] },   \
        {33001, [MT_unit_33001], [MT_unit_33001_help] },   \
        {33002, [MT_unit_33002], [MT_unit_33002_help] },   \
        {33003, [MT_unit_33003], [MT_unit_33003_help] },   \
        {33004, [MT_unit_33004], [MT_unit_33004_help] },   \
        {33005, [MT_unit_33005], [MT_unit_33005_help] },   \
        {33006, [MT_unit_33006], [MT_unit_33006_help] },   \
        {34000, [MT_unit_34000], [MT_unit_34000_help] },   \
        {34001, [MT_unit_34001], [MT_unit_34001_help] },   \
        {34002, [MT_unit_34002], [MT_unit_34002_help] },   \
        {34003, [MT_unit_34003], [MT_unit_34003_help] },   \
        {35001, [MT_unit_35001], [MT_unit_35001_help] },   \
        {35002, [MT_unit_35002], [MT_unit_35002_help] },   \
        {36000, [MT_unit_36000], [MT_unit_36000_help] },   \
        {40000, [MT_unit_40000], [MT_unit_40000_help] },   \
        {40001, [MT_unit_40001], [MT_unit_40001_help] },   \
        {40002, [MT_unit_40002], [MT_unit_40002_help] },   \
        {40003, [MT_unit_40003], [MT_unit_40003_help] },   \
        {40004, [MT_unit_40004], [MT_unit_40004_help] }    \
//        { 1996,    [not_used]                           },    \
//        { 1998,    [unknown]                            },    \
//        { 1999,    [special]                            },    \
//        { 1997,    " "                                  }     \

#define AO_UNIT            \
        { 1138, [unit_1138],    [unit_1138_help]    },    \
        { 1342, [unit_1342],    [unit_1342_help]    }    \

#define CB_FAIL_SAFE			0x010000		/* Bit  0 */
#define CB_REQ_LOC_OP			0x020000		/* Bit  1 */
#define CB_LOCAL_OP				0x040000		/* Bit  2 */
#define CB_OVERRIDE				0x080000		/* Bit  3 */
#define CB_DISC_DIR				0x100000		/* Bit  4 */
#define CB_TORQUE_D_OP			0x200000		/* Bit  5 */
#define CB_TORQUE_D_CL			0x400000		/* Bit  6 */
#define CB_TRAV_TIME			0x800000		/* Bit  7 */
#define CB_ACT_OPEN				0x000100		/* Bit  8 */
#define CB_ACT_CLOSE			0x000200		/* Bit  9 */
#define CB_UPDATE_EVT			0x000400		/* Bit 10 */
#define CB_SIMULATE				0x000800		/* Bit 11 */
#define CB_DISTURBANCE			0x001000		/* Bit 12 */
#define CB_CONTR_ERR			0x002000		/* Bit 13 */
#define CB_CONTR_INACT			0x004000		/* Bit 14 */
#define CB_SELFTEST				0x008000		/* Bit 15 */
#define CB_TOT_VALVE_TRAV		0x000001		/* Bit 16 */
#define CB_BREAK_TIME_UNDER		0x000002		/* Bit 18 */
#define CB_BREAK_TIME_OVER		0x000004		/* Bit 19 */
#define CB_CYCLE_TEST			0x000008		/* Bit 20 */
#define CB_TRAVEL_TIME_UNDER	0x000010		/* Bit 21 */
#define CB_TRAVEL_TIME_OVER		0x000020		/* Bit 22 */


#define _CIP_ENABLE                 0x0001      /* "CIP Enable",              "CIP Enable"             */
#define _SIP_ENABLE                 0x0002      /* "SIP Enable",              "SIP Enable"             */
#define _AUTOCLAVE_ENABLE           0x0004      /* "AutoClave Enable",        "AutoClave Enable"       */
#define _TTM_ENABLE                 0x0008      /* "TTM Enable",              "TTM Enable"             */

#define _ACT_ENABLE                 0x0010      /* "ACT Enable",              "ACT Enable"             */
#define _DLI_ENABLE                 0x0020      /* "DLI Enable",              "DLI Enable"             */
#define _CIP_RESET_ENABLE           0x0040      /* "CIP Reset Enable",        "CIP Reset Enable"       */
#define _SIP_RESET_ENABLE           0x0080      /* "SIP Reset Enable",        "SIP Reset Enable"       */

#define _AUTOCLAVE_RESET_ENABLE     0x0100      /* "AutoClave Reset Enable",  "AutoClave Reset Enable" */
#define _TTM_RESET_ENABLE           0x0200      /* "TTM Reset Enable",        "TTM Reset Enable"       */
#define _ACT_RESET_ENABLE           0x0400      /* "ACT Reset Enable",         Reserve                 */
#define _DLI_RESET_ENABLE           0x0800      /* "DLI Reset Enable",        "DLI Reset Enable"       */

#define _PH_STRESS_RESET_ENABLE     0x1000      /* "pH Stress Reset Enable",  "pH Stress Reset Enable" */
#define _OPERATION_DAY_ENABLE       0x2000      /* "Operation Day Enable",    "Operation Day Enable"   */
#define _MAX_TEMP_ENABLE            0x4000      /* "Max Temp Enable",         "Max Temp Enable"        */
#define _MAX_TEMP_DATE_ENABLE       0x8000      /* "Max Temp Date Enable",    "Max Temp Date Enable"   */

#define _SAN_CYCLE_ENABLE           0x10000     /* "SAN Cycle Enable",        "SAN Cycle Enable"       */

/*__cal_flags*/
#define _CAL_VALUE_STABLE_FLAG      0x0001      /* "cal value stable flag",   "cal value stable flag"  */
#define _BUFFER_RECOGNIZED          0x0002      /* "buffer recognized",       "buffer recognized"      */
#define _CAL_TIMEOUT                0x0004      /* "cal timeout",             "cal timeout"            */
#define _CAL_FAILURED               0x0008      /* "cal failured",            "cal failured"           */
#define _CAL_SUCCED                 0x0010      /* "cal succed",              "cal succed"             */
#define _CAL_SAVED_SUCCED           0x0020      /* "cal saved succed",        "cal saved succed"       */
#define _CAL_CALCULATED_SUCCED      0x0040      /* "cal calculated succed",   "cal calculated succed"  */
#define _ISM_SENSOR_CONNECT_FLAG    0x0080      /* "ISM sensor connect flag", "ISM sensor connect flag"*/
#define _CAL_OUT_OF_LIMIT           0x0100      /* "cal data out of limit",   "cal data out of limit"  */
#define _CAL_VALUE_OUT_OF_RANGE     0x0200      /* "cal value out of range",  "cal value out of range" */
#define _WRITE_CAL_UNIT_ERROR       0x0400      /* "write cal unit error",    "write cal unit error"   */
#define _SENSOR_TYPE_CHANGE         0x0800      /* "Sensor type change",      "Sensor type change"     */
#define _MODEL_TYPE_CHANGE          0x1000      /* "model type change",       "model type change"      */
#define _AUTOCLAVE_CHANGE           0x2000      /* "autoclave change",        "autoclave change"       */

#define DELAYTIMES                  6

#define SENSOR_CHANNEL_DIGITAL (trans1_sensor_type >= 128)
#define SENSOR_CHANNEL_ANALOG  (trans1_sensor_type <  128)
#define SENSOR_CONNECTED       (trans1_cal_flags & 0x80)

#define SENSOR_DIGITAL_CONNECT_ONLY        (SENSOR_CHANNEL_DIGITAL && SENSOR_CONNECTED)
#define SENSOR_ANALOG_DIGITAL_CONNECTED    (SENSOR_CHANNEL_ANALOG || SENSOR_DIGITAL_CONNECT_ONLY)


#define SENSOR_PH       ((trans1_sensor_type == 1) || (trans1_sensor_type == 129) || (trans1_sensor_type == 130))
#define SENSOR_PH_RR    ((trans1_sensor_type == 1) || (trans1_sensor_type == 129) || (trans1_sensor_type == 138))
#define SENSOR_PH_RPNA  (trans1_sensor_type == 130)
#define SENSOR_COND     ((trans1_sensor_type == 3) || (trans1_sensor_type == 4) || (trans1_sensor_type == 131) || (trans1_sensor_type == 132))
#define SENSOR_O2       (((trans1_sensor_type > 4) && (trans1_sensor_type < 9)) || ((trans1_sensor_type > 132) && (trans1_sensor_type < 137)))
#define SENSOR_O2_OPT   ((trans1_sensor_type == 9) || (trans1_sensor_type == 137))
#define SENSOR_CO2      (trans1_sensor_type == 138)
#define SENSOR_CO2_B    (trans1_sensor_type == 139)

#define SENSOR_O3       (trans1_sensor_type == 140)

#define SENSOR_O2_1       (((trans1_sensor_type > 4) && (trans1_sensor_type < 9)) || ((trans1_sensor_type > 132) && (trans1_sensor_type < 137)))
#define SENSOR_O2_OPT_1   ((trans1_sensor_type == 9) || (trans1_sensor_type == 137))


#define OFFSET_UNIT1_ENABLE   0x01
#define OFFSET_UNIT2_ENABLE   (trans1_offset_unit2_code!=1996)
#define SLOPE_UNIT1_ENABLE    0x01
#define SLOPE_UNIT2_ENABLE    (trans1_slope_unit2_code!=1996)



#define _ANALOG_CHANNEL_SENSOR_TYPE                                   \
        { 1, [MT_sensor_type_1],       [MT_sensor_type_1_help]      },\
        { 3, [MT_sensor_type_3],       [MT_sensor_type_3_help]      },\
        { 4, [MT_sensor_type_4],       [MT_sensor_type_4_help]      },\
        { 5, [MT_sensor_type_5],       [MT_sensor_type_5_help]      },\
        { 6, [MT_sensor_type_6],       [MT_sensor_type_6_help]      },\
        { 7, [MT_sensor_type_7],       [MT_sensor_type_7_help]      }
        //{ 12, [MT_sensor_type_12],       [MT_sensor_type_12_help]    }

#define _ISM_CHANNEL_SENSOR_TYPE                                      \
        { 129, [MT_sensor_type_129],   [MT_sensor_type_129_help]    },\
        { 130, [MT_sensor_type_130],   [MT_sensor_type_130_help]    },\
        { 131, [MT_sensor_type_131],   [MT_sensor_type_131_help]    },\
        { 132, [MT_sensor_type_132],   [MT_sensor_type_132_help]    },\
        { 133, [MT_sensor_type_133],   [MT_sensor_type_133_help]    },\
        { 134, [MT_sensor_type_134],   [MT_sensor_type_134_help]    },\
        { 135, [MT_sensor_type_135],   [MT_sensor_type_135_help]    },\
        { 136, [MT_sensor_type_136],   [MT_sensor_type_136_help]    },\
        { 137, [MT_sensor_type_137],   [MT_sensor_type_137_help]    },\
        { 138, [MT_sensor_type_138],   [MT_sensor_type_138_help]    },\
        { 139, [MT_sensor_type_139],   [MT_sensor_type_139_help]    },\
        { 140, [MT_sensor_type_140],   [MT_sensor_type_140_help]    }

#define _TEMPERATURE_CHANNEL                                          \
        { 1,  [unit_1001],             [unit_1001_help]             },\
        { 2,  [unit_1002],             [unit_1002_help]             },\
        { 3,  [MT_unit_40004],         [MT_unit_40004_help]         },\
        { 8,  "mbar P",                "40006"                     }

#define _ISM_SENSOR_CHANNEL                                           \
        { 4,  [MT_unit_40000],         [MT_unit_40000_help]         },\
        { 5,  [MT_unit_40001],         [MT_unit_40001_help]         },\
        { 6,  [MT_unit_40002],         [MT_unit_40002_help]         },\
        { 7,  [MT_unit_40003],         [MT_unit_40003_help]         }

#define _PH_SENSOR_CHANNEL                                            \
        { 10,  [unit_1422],            [unit_1422_help]             },\
        { 11,  [unit_1243],            [unit_1243_help]             },\
        { 12,  [MT_unit_36000],        [MT_unit_36000_help]         },\
        { 13,  [MT_unit_rpna_mohm],    [MT_unit_rpna_mohm_help]     },\
        { 14,  [MT_unit_rg_mohm],      [MT_unit_rg_mohm_help]       },\
        { 15,  [MT_unit_rr_mohm],      [MT_unit_rr_mohm_help]       }

#define _O2_SENSOR_CHANNEL                                            \
        { 20, [MT_unit_34000],         [MT_unit_34000_help]         },\
        { 21, [MT_unit_34001],         [MT_unit_34001_help]         },\
        { 22, [unit_1558],             [unit_1558_help]             },\
        { 23, [MT_unit_o2_ug_l],       [MT_unit_o2_ug_l_help]       },\
        { 24, [unit_1423],             [unit_1423_help]             },\
        { 25, [unit_1424],             [unit_1424_help]             },\
        { 26, [MT_unit_34002],         [MT_unit_34002_help]         },\
        { 27, [MT_unit_34003],         [MT_unit_34003_help]         },\
        { 29, [unit_1213],             [unit_1213_help]             },\
        { 28, [unit_1138],             [unit_1138_help]             }

#define _CO2_Pharma_SENSOR_CHANNEL                                    \
        { 50, [MT_unit_35001],         [MT_unit_35001_help]         },\
        { 51, [MT_unit_co2_hpa],       [MT_unit_co2_hpa_help]       },\
        { 52, [MT_unit_co2_mbar],      [MT_unit_co2_mbar_help]      },\
        { 53, [MT_unit_co2_mmhg],      [MT_unit_co2_mmhg_help]      },\
        { 54, [MT_unit_co2_mg_l],      [MT_unit_co2_mg_l_help]      },\
        { 55, [MT_unit_co2_mv],        [MT_unit_co2_mv_help]        }

#define _CO2_Beverage_SENSOR_CHANNEL                                  \
        { 60, [MT_unit_co2_hpa_hi],    [MT_unit_co2_hpa_hi_help]    },\
        { 61, [MT_unit_co2_mbar_hi],   [MT_unit_co2_mbar_hi_help]   },\
        { 62, [MT_unit_co2_g_l_hi],    [MT_unit_co2_g_l_hi_help]    },\
        { 63, [MT_unit_co2_vv_hi],     [MT_unit_co2_vv_hi_help]     },\
        { 69, "g/100ml",               "g/100ml unit"               }

#define _O3_SENSOR_CHANNEL                                            \
        { 64, [MT_unit_o3_ppm],        [MT_unit_o3_ppm_help]        },\
        { 65, [MT_unit_o3_ppb],        [MT_unit_o3_ppb_help]        },\
        { 66, [MT_unit_o3_mg_l],       [MT_unit_o3_mg_l_help]       },\
        { 67, [MT_unit_o3_ug_l],       [MT_unit_o3_ug_l_help]       },\
        { 68, [MT_unit_o3_na],         [MT_unit_o3_na_help]         }

#define _COND_SENSOR_CHANNEL                                          \
        { 47, [unit_1551],             [unit_1551_help]             },\
        { 48, [unit_1299],             [unit_1299_help]             },\
        { 30, [unit_1302],             [unit_1302_help]             },\
        { 31, [unit_1552],             [unit_1552_help]             },\
        { 32, [unit_1555],             [unit_1555_help]             },\
        { 33, [unit_1556],             [unit_1556_help]             },\
        { 49, [unit_1295],             [unit_1295_help]             },\
        { 34, [MT_unit_tds_nacl_ppm],  [MT_unit_tds_nacl_ppm_help]  },\
        { 35, [MT_unit_tds_nacl_ppb],  [MT_unit_tds_nacl_ppb_help]  },\
        { 36, [MT_unit_tds_nacl_ppk],  [MT_unit_tds_nacl_ppk_help]  },\
        { 37, [MT_unit_tds_caco3_ppm], [MT_unit_tds_caco3_ppm_help] },\
        { 38, [MT_unit_tds_caco3_ppb], [MT_unit_tds_caco3_ppb_help] },\
        { 39, [MT_unit_tds_caco3_ppk], [MT_unit_tds_caco3_ppk_help] },\
        { 40, [MT_unit_33000],         [MT_unit_33000_help]         },\
        { 41, [MT_unit_33001],         [MT_unit_33001_help]         },\
        { 42, [MT_unit_33002],         [MT_unit_33002_help]         },\
        { 43, [MT_unit_33003],         [MT_unit_33003_help]         },\
        { 44, [MT_unit_33004],         [MT_unit_33004_help]         },\
        { 45, [MT_unit_33005],         [MT_unit_33005_help]         },\
        { 46, [MT_unit_33006],         [MT_unit_33006_help]         }

#define _FB_AO_CHANNEL             \
        { 1, [MT_ao_channel] }     \
/*
#define _FB_DI_CHANNEL             \
        { 1,  [MT_di_channel_1] }, \
        { 2,  [MT_di_channel_2] }  \

#define _FB_DO_CHANNEL             \
        { 1,  [MT_do_channel_1] }, \
        { 2,  [MT_do_channel_2] }  \

#define _CAL_UNIT                                           \
        { 20, [MT_unit_34000],    [MT_unit_34000_help]    },\  // "%air"
        { 21, [MT_unit_34001],    [MT_unit_34001_help]    },\  // "%O2"
        { 22, [unit_1558],        [unit_1558_help]        },\  // "mg/l"
        { 23, [unit_1559],        [unit_1559_help]        },\  // "ug/l"
        { 24, [unit_1423],        [unit_1423_help]        },\  // "ppm"
        { 25, [unit_1424],        [unit_1424_help]        },\  // "ppb"
        { 26, [MT_unit_34002],    [MT_unit_34002_help]    },\  // "%O2G"
        { 27, [MT_unit_34003],    [MT_unit_34003_help]    },\  // "ppmO2G"
        { 28, [unit_1138],        [unit_1138_help]        },\  // "mbar"
        { 47, [unit_1551],        [unit_1551_help]        },\  // "S/cm"
        { 30, [unit_1302],        [unit_1302_help]        },\  // "mS/cm"
        { 31, [unit_1552],        [unit_1552_help]        },\  // "uS/cm"
        { 49, [unit_1295],        [unit_1295_help]        },\  // "Ohm-cm"
        { 33, [unit_1556],        [unit_1556_help]        },\  // "KOhm-cm"
        { 32, [unit_1555],        [unit_1555_help]        },\  // "MOhm-cm"
        { 50, [MT_unit_35001],    [MT_unit_35001_help]    },\  // "%CO2"
        { 51, [MT_unit_co2_hpa],  [MT_unit_co2_hpa_help]  },\  // "hPa(CO2)"
        { 52, [MT_unit_co2_mbar], [MT_unit_co2_mbar_help] },\  // "mbar(CO2)"
        { 53, [MT_unit_co2_mmhg], [MT_unit_co2_mmhg_help] },\  // "mmHg(CO2)"
        { 54, [MT_unit_co2_mg_l], [MT_unit_co2_mg_l_help] },\  // "mg/l(CO2)"
        { 55, [MT_unit_co2_mv],   [MT_unit_co2_mv_help]   }    // "mV(CO2)"
*/

#define _O2_CAL_UNIT                                        \
        { 22, [unit_1558],        [unit_1558_help]        },\
        { 23, [MT_unit_o2_ug_l],        [unit_1559_help]        },\
        { 24, [unit_1423],        [unit_1423_help]        },\
        { 25, [unit_1424],        [unit_1424_help]        },\
        { 21, [MT_unit_34001],    [MT_unit_34001_help]    },\
        { 20, [MT_unit_34000],    [MT_unit_34000_help]    },\
        { 26, [MT_unit_34002],    [MT_unit_34002_help]    },\
        { 27, [MT_unit_34003],    [MT_unit_34003_help]    }

#define _ODO_CAL_UNIT                                       \
        { 22, [unit_1558],        [unit_1558_help]        },\
        { 23, [MT_unit_o2_ug_l],        [unit_1559_help]        },\
        { 24, [unit_1423],        [unit_1423_help]        },\
        { 25, [unit_1424],        [unit_1424_help]        },\
        { 21, [MT_unit_34001],    [MT_unit_34001_help]    },\
        { 20, [MT_unit_34000],    [MT_unit_34000_help]    },\
        { 26, [MT_unit_34002],    [MT_unit_34002_help]    },\
        { 27, [MT_unit_34003],    [MT_unit_34003_help]    },\
        { 28, [unit_1138],        [unit_1138_help]        }

#define _CO2_P_CAL_UNIT                                     \
        { 50, [MT_unit_35001],    [MT_unit_35001_help]    },\
        { 51, [unit_1136],        [MT_unit_co2_hpa_help]  },\
        { 52, [unit_1138],        [MT_unit_co2_mbar_help] },\
        { 53, [unit_1157],        [MT_unit_co2_mmhg_help] },\
        { 54, [unit_1558],        [MT_unit_co2_mg_l_help] }

#define _COND_CAL_UNIT                                      \
        { 30, [unit_1302],        [unit_1302_help]        },\
        { 31, "uS/cm",        [unit_1552_help]        },\
        { 47, [unit_1551],        [unit_1551_help]        }

#define _RES_CAL_UNIT                                      \
        { 32, [unit_1555],        [unit_1555_help]        },\
        { 33, [unit_1556],        [unit_1556_help]        },\
        { 49, [unit_1295],        [unit_1295_help]        }

#define _CO2_B_1POINT_UNIT                                  \
        { 60, [unit_1136],        [MT_unit_co2_hpa_help]  },\
        { 61, [unit_1138],        [MT_unit_co2_mbar_help] }

#define _CO2_B_PROCAL_UNIT                                  \
        { 60, [unit_1136],        [MT_unit_co2_hpa_help]  },\
        { 61, [unit_1138],        [MT_unit_co2_mbar_help] },\
        { 62, [unit_1105],        [MT_unit_co2_mg_l_help] },\
        { 63, [MT_unit_35002],    [MT_unit_35002_help]    }

#define _O3_CAL_UNIT                                       \
        { 64, [unit_1423],        [MT_unit_o3_ppm_help]  },\
        { 65, [unit_1424],        [MT_unit_o3_ppb_help]  },\
        { 66, [unit_1558],        [MT_unit_o3_mg_l_help] },\
        { 67, [MT_unit_o2_ug_l],        [MT_unit_o3_ug_l_help] }

#define _CAL_UNITCODE                                       \
        {  1558, [unit_1558],     [unit_1558_help]        },\
        {  1559, [MT_unit_o2_ug_l],     [unit_1559_help]        },\
        {  1423, [unit_1423],     [unit_1423_help]        },\
        {  1424, [unit_1424],     [unit_1424_help]        },\
        { 34000, [MT_unit_34000], [MT_unit_34000_help]    },\
        { 34001, [MT_unit_34001], [MT_unit_34001_help]    },\
        { 34002, [MT_unit_34002], [MT_unit_34002_help]    },\
        { 34003, [MT_unit_34003], [MT_unit_34003_help]    },\
        {  1138, [unit_1138],     [unit_1138_help]        },\
        {  1302, [unit_1302],     [unit_1302_help]        },\
        {  1552, "uS/cm",     [unit_1552_help]        },\
        {  1555, [unit_1555],     [unit_1555_help]        },\
        {  1556, [unit_1556],     [unit_1556_help]        },\
        {  1422, [unit_1422],     [unit_1422_help]        },\
        {  1243, [unit_1243],     [unit_1243_help]        },\
        {  1551, [unit_1551],     [unit_1551_help]        },\
        {  1295, [unit_1295],     [unit_1295_help]        },\
        { 36000, [MT_unit_36000], [MT_unit_36000_help]    },\
        { 35001, [MT_unit_35001], [MT_unit_35001_help]    },\
        {  1136, [unit_1136],     [unit_1136_help]        },\
        {  1157, [unit_1157],     [unit_1157_help]        }

#define _TEMPERATURE_UNIT                                   \
        {  1001, [unit_1001],     [unit_1001_help]        },\
        {  1002, [unit_1002],     [unit_1002_help]        },\
        { 40004, [MT_unit_40004], [MT_unit_40004_help]    }

#define _ISM_SENSOR_UNIT                                    \
        { 40000, [MT_unit_40000], [MT_unit_40000_help]    },\
        { 40001, [MT_unit_40001], [MT_unit_40001_help]    },\
        { 40002, [MT_unit_40002], [MT_unit_40002_help]    },\
        { 40003, [MT_unit_40003], [MT_unit_40003_help]    }

#define _PH_SENSOR_UNIT                                     \
        {  1422, [unit_1422],     [unit_1422_help]        },\
        {  1423, [unit_1423],     [unit_1423_help]        },\
        { 36000, [MT_unit_36000], [MT_unit_36000_help]    },\
        {  1283, [unit_1283],     [unit_1283_help]        },\
        {  1284, [unit_1284],     [unit_1284_help]        }

#define _O2_SENSOR_UNIT                                     \
        { 34000, [MT_unit_34000], [MT_unit_34000_help]    },\
        { 34001, [MT_unit_34001], [MT_unit_34001_help]    },\
        {  1558, [unit_1558],     [unit_1558_help]        },\
        {  1559, [unit_1559],     [unit_1559_help]        },\
        {  1423, [unit_1423],     [unit_1423_help]        },\
        {  1424, [unit_1424],     [unit_1424_help]        },\
        { 34002, [MT_unit_34002], [MT_unit_34002_help]    },\
        { 34003, [MT_unit_34003], [MT_unit_34003_help]    },\
        {  1213, [unit_1213],     [unit_1213_help]        },\
        {  1138, [unit_1138],     [unit_1138_help]        }

#define _CO2_Pharma_SENSOR_UNIT                             \
        { 35001, [MT_unit_35001], [MT_unit_35001_help]    },\
        {  1136, [unit_1136],     [unit_1136_help]        },\
        {  1157, [unit_1157],     [unit_1157_help]        }

#define _COND_SENSOR_UNIT                                   \
        {  1302, [unit_1302],     [unit_1302_help]        },\
        {  1552, [unit_1552],     [unit_1552_help]        },\
        {  1555, [unit_1555],     [unit_1555_help]        },\
        {  1423, [unit_1423],     [unit_1423_help]        },\
        {  1424, [unit_1424],     [unit_1424_help]        },\
        {  1425, [unit_1425],     [unit_1425_help]        },\
        { 33000, [MT_unit_33000], [MT_unit_33000_help]    },\
        { 33001, [MT_unit_33001], [MT_unit_33001_help]    },\
        { 33002, [MT_unit_33002], [MT_unit_33002_help]    },\
        { 33003, [MT_unit_33003], [MT_unit_33003_help]    },\
        { 33004, [MT_unit_33004], [MT_unit_33004_help]    },\
        { 33005, [MT_unit_33005], [MT_unit_33005_help]    },\
        { 33006, [MT_unit_33006], [MT_unit_33006_help]    },\
        {  1551, [unit_1551],     [unit_1551_help]        },\
        {  1299, [unit_1299],     [unit_1299_help]        },\
        {  1295, [unit_1295],     [unit_1295_help]        },\
        {  1556, [unit_1556],     [unit_1556_help]        }

#define _CAL_COMM_ERROR                      \
        if (status >= ID_FC_ERROR)\
        { \
            ACKNOWLEDGE([MT_context_method_abort]);\
            process_abort();\
        }

#define _CAL_ERROR                      \
        ACKNOWLEDGE([MT_context_cal_err]);

#define _CAL_EXIT                      \
        /* Enter Calibration Mode*/\
        if (!((trans1_cal_mode==3)||(trans1_cal_mode==18)||(trans1_cal_mode==5)||(trans1_cal_mode==6)||(trans1_cal_mode==11)||(trans1_cal_mode==14)||(trans1_cal_mode==17)||(trans1_cal_mode==21)||(trans1_cal_mode==23)||(trans1_cal_mode==25)||(trans1_cal_mode==26)))\
        {\
            ACKNOWLEDGE([MT_context_re_install_sensor]);\
        }\
        /* Enter Calibration Mode*/\
        iassign(trans1_cal_mode, 0); /*O2 Process Slope*/\
        status = WriteCommand(write_trans1_cal_mode);\
        _CAL_COMM_ERROR

#define _CAL_STATUS_ERROR                      \
        /* Calc proposed Calibration Values*/\
        ReadCommand (read_trans1_cal_flags);   \
        if (trans1_cal_flags & _CAL_FAILURED) \
        { \
            _CAL_ERROR\
            _CAL_EXIT\
            ACKNOWLEDGE([MT_context_method_abort]);\
            process_abort();\
        }

/* Write O2 Cal Unit*/
#define _WRITE_O2_CAL_UNIT                      \
        /*default %air unit*/\
        iassign(trans1_o2_cal_unit, 20);\
        while(1)\
        {\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_o2_cal_unit);\
            status = WriteCommand(write_trans1_o2_cal_unit);\
            _CAL_COMM_ERROR\
            _CAL_STATUS_ERROR\
            DELAY(5, [MT_context_waiting_for_chk_cal_unit]);\
            _CAL_STATUS_ERROR\
            /* Calc proposed Calibration Values*/\
            ReadCommand (read_trans1_cal_flags);   \
            if (trans1_cal_flags & _WRITE_CAL_UNIT_ERROR) \
            {\
                DELAY(3, [MT_context_waiting_invalid_unit_select]);\
                _CAL_STATUS_ERROR\
            }\
            else\
            {\
                break;\
            }\
        }

/* Write COND Cal Unit*/
#define _WRITE_COND_CAL_UNIT                      \
            /*default ms/cm unit*/\
            iassign(trans1_cond_cal_unit, 30);\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_cond_cal_unit);\
            status = WriteCommand(write_trans1_cond_cal_unit);\
            _CAL_COMM_ERROR\
            DELAY(3, [MT_context_waiting_for_chk_cal_unit]);\
            _CAL_STATUS_ERROR

/* Write RES Cal Unit*/
#define _WRITE_RES_CAL_UNIT                      \
            /*default Ohm/cm unit*/\
            iassign(trans1_res_cal_unit, 49);\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_res_cal_unit);\
            status = WriteCommand(write_trans1_res_cal_unit);\
            _CAL_COMM_ERROR\
            DELAY(3, [MT_context_waiting_for_chk_cal_unit]);\
            _CAL_STATUS_ERROR

/* Write ODO Cal Unit*/
#define _WRITE_ODO_CAL_UNIT                      \
            /*default %air unit*/\
            iassign(trans1_o2_cal_unit, 20);\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_odo_cal_unit);\
            status = WriteCommand(write_trans1_odo_cal_unit);\
            _CAL_COMM_ERROR\
            DELAY(3, [MT_context_waiting_for_chk_cal_unit]);\
            _CAL_STATUS_ERROR

/* Write O3 Cal Unit*/
#define _WRITE_O3_CAL_UNIT                      \
            /*default ppm unit*/\
            iassign(trans1_o3_cal_unit, 65);\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_o3_cal_unit);\
            status = WriteCommand(write_trans1_o3_cal_unit);\
            _CAL_COMM_ERROR\
            DELAY(3, [MT_context_waiting_for_chk_cal_unit]);\
            _CAL_STATUS_ERROR

/* Write CO2 Cal Unit*/
#define _WRITE_CO2_P_CAL_UNIT                      \
            /*default %CO2 unit*/\
            iassign(trans1_co2_p_cal_unit, 50);\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_co2_p_cal_unit);\
            status = WriteCommand(write_trans1_co2_p_cal_unit);\
            _CAL_COMM_ERROR\
            DELAY(3, [MT_context_waiting_for_chk_cal_unit]);\
            _CAL_STATUS_ERROR

#define _WRITE_CO2_B_1P_CAL_UNIT                      \
            /*default hpa unit*/\
            iassign(trans1_co2_b_1point_unit, 60);\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_co2_b_1point_unit);\
            status = WriteCommand(write_trans1_co2_b_1point_unit);\
            _CAL_COMM_ERROR\
            DELAY(3, [MT_context_waiting_for_chk_cal_unit]);\
            _CAL_STATUS_ERROR

#define _WRITE_CO2_B_PRO_CAL_UNIT                      \
            /*default hpa unit*/\
            iassign(trans1_co2_b_procal_unit, 60);\
           /*Write Cal Unit*/\
            GET_DEV_VAR_VALUE([MT_context_select_cal_unit], trans1_co2_b_procal_unit);\
            status = WriteCommand(write_trans1_co2_b_procal_unit);\
            _CAL_COMM_ERROR\
            _CAL_STATUS_ERROR

#define _WRITE_CHECK_CAL_UNIT                      \
            /* Calc proposed Calibration Values*/\
            ReadCommand (read_trans1_cal_flags);   \
            if (trans1_cal_flags & _WRITE_CAL_UNIT_ERROR) \
            {\
                DELAY(3, [MT_context_waiting_invalid_unit_select]);\
                _CAL_STATUS_ERROR\
            }\
            else\
            {\
                break;\
            }

/* Select CAL Compensation Mode*/
#define _CAL_COMPENSATION_MODE                      \
       /*Select CAL Compensation Mode*/\
        GET_DEV_VAR_VALUE([MT_context_select_cal_compensation_mode], trans1_cal_com_mode);\
        status = WriteCommand(write_trans1_cal_com_mode);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR\
	    ReadCommand (read_trans1_cal_com_mode);   \
        if ((trans1_cal_com_mode == 1)||(trans1_cal_com_mode == 2))\
        {\
           /*Input Compensation Value*/\
            GET_DEV_VAR_VALUE([MT_context_input_compensation_value], trans1_cal_linear_val);\
            status = WriteCommand(write_trans1_cal_linear_val);\
            _CAL_COMM_ERROR\
            _CAL_STATUS_ERROR\
        }

/* ENTRY_CAL_Point = 0*/
#define _ENTRY_CAL_POINT_0                      \
        /* ENTRY_CAL_Point = 0 */\
        iassign(trans1_entry_cal_point, 0);\
        status = WriteCommand(write_trans1_entry_cal_point);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR

/* ENTRY_CAL_Point = 1*/
#define _ENTRY_CAL_POINT_1                      \
        /* ENTRY_CAL_Point = 1 */\
        iassign(trans1_entry_cal_point,1);\
        status = WriteCommand(write_trans1_entry_cal_point);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR

/* CAL_RECODE_POINT = 0*/
#define _CAL_RECODE_POINT_0                      \
        /* CAL_RECODE_POINT = 0 */\
        iassign(trans1_cal_recode_point, 0);\
         status = WriteCommand(write_trans1_cal_recode_point);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR

/* CAL_RECODE_POINT = 1*/
#define _CAL_RECODE_POINT_1                      \
        /* CAL_RECODE_POINT = 1 */\
        iassign(trans1_cal_recode_point, 1);\
         status = WriteCommand(write_trans1_cal_recode_point);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR

#define _RE_READ_CAL_DATA_AFTER_CALIBRATION                 \
    	    ReadCommand(read_trans1_last_cal_date);         \ 
    	    ReadCommand(read_trans1_enable_flag);           \ 
    	    ReadCommand(read_trans1_offset_unit1_code);     \ 
    	    ReadCommand(read_trans1_offset_unit2_code);     \ 
    	    ReadCommand(read_trans1_slope_unit1_code);      \ 
    	    ReadCommand(read_trans1_slope_unit2_code);      \ 
    	    ReadCommand(read_trans1_offset_with_unit1);     \ 
    	    ReadCommand(read_trans1_offset_with_unit2);     \ 
    	    ReadCommand(read_trans1_slope_with_unit1);      \ 
    	    ReadCommand(read_trans1_slope_with_unit2);      \ 
    	    ReadCommand(read_trans1_mv_offset);             \ 
    	    ReadCommand(read_trans1_pt_slope);              \ 
    	    ReadCommand(read_trans1_pt_offset);             \ 
    	    ReadCommand(read_trans1_ntc22k_offset);         \ 
        if(SENSOR_CHANNEL_DIGITAL)                          \ 
        {                                                   \
            ReadCommand(read_trans1_history_block_enable);  \ 
            ReadCommand(read_trans1_fact_date);             \ 
            ReadCommand(read_trans1_fact_o1);               \ 
            ReadCommand(read_trans1_fact_o2);               \ 
            ReadCommand(read_trans1_fact_s1);               \ 
            ReadCommand(read_trans1_fact_s2);               \ 
            if(trans1_history_block_enable & 0x01)          \
            {                                               \
                ReadCommand(read_trans1_1st_date);          \ 
                ReadCommand(read_trans1_1st_o1);            \ 
                ReadCommand(read_trans1_1st_o2);            \ 
                ReadCommand(read_trans1_1st_s1);            \ 
                ReadCommand(read_trans1_1st_s2);            \ 
            }                                               \
            if(trans1_history_block_enable & 0x02)          \
            {                                               \
                ReadCommand(read_trans1_cal1_date);         \ 
                ReadCommand(read_trans1_cal1_o1);           \ 
                ReadCommand(read_trans1_cal1_o2);           \ 
                ReadCommand(read_trans1_cal1_s1);           \
                ReadCommand(read_trans1_cal1_s2);           \
            }                                               \
            if(trans1_history_block_enable & 0x04)          \
            {                                               \
                ReadCommand(read_trans1_cal2_date);         \
                ReadCommand(read_trans1_cal2_o1);           \
                ReadCommand(read_trans1_cal2_o2);           \
                ReadCommand(read_trans1_cal2_s1);           \
                ReadCommand(read_trans1_cal2_s2);           \
            }                                               \
            if(trans1_history_block_enable & 0x08)          \
            {                                               \    
                ReadCommand(read_trans1_cal3_date);         \
                ReadCommand(read_trans1_cal3_o1);           \         
                ReadCommand(read_trans1_cal3_o2);           \
                ReadCommand(read_trans1_cal3_s1);           \
                ReadCommand(read_trans1_cal3_s2);           \
            }                                               \
        }        

/* Calc function*/
#define _CALC_FUNCTION                      \
        /* Calc proposed Calibration Values*/\
        while (1)\
        {\
            _CAL_STATUS_ERROR\
            ReadCommand (read_trans1_cal_flags);   \
            if (trans1_cal_flags & _CAL_CALCULATED_SUCCED)\
            {\
                DELAY(2, "Checking, please wait...");\
                break;\
            }\
            DELAY(4, "Checking, please wait...");\
        }\
        if (trans1_cal_flags & _CAL_OUT_OF_LIMIT)\
        {\
            ACKNOWLEDGE([MT_context_calc_function]);\
        }\
        ReadCommand(read_trans1_cal_slope);  \
        ReadCommand(read_trans1_cal_offset); \
        var_id2[0] = VARID(trans1_cal_slope); \
        var_id2[1] = VARID(trans1_cal_offset); \        
        var_id4[0] = VARID(trans1_cal_slope); \
        var_id4[1] = VARID(trans1_cal_offset); \
        if((trans1_cal_mode >=1)&&(trans1_cal_mode <=3)||(trans1_cal_mode >=19)&&(trans1_cal_mode <=21))\
        {\
            ReadCommand(read_trans1_ph_ip);  \
            trans1_cal_slope1 = trans1_cal_slope * 59.16/100;                 /*mV/pH for slope*/\
            trans1_cal_offset1 = trans1_cal_offset/trans1_cal_slope1 + trans1_ph_ip;     /*pH unit for Offset*/\
            var_id4[2] = VARID(trans1_cal_slope1); \
            var_id4[3] = VARID(trans1_cal_offset1); \
            acknowledge([MT_context_slope_offset_1], var_id4);\
        }\
        else if((trans1_cal_mode == 4)||(trans1_cal_mode == 18))\
        {\
            var_id1[0] = VARID(trans1_cal_offset); \
            acknowledge([MT_context_offset_8], var_id1);\
        }\
        else if((trans1_cal_mode >=5)&&(trans1_cal_mode <=8))\
        {\
            acknowledge([MT_context_slope_offset_3], var_id2);\
        }\
        else if((trans1_cal_mode >=9)&&(trans1_cal_mode <=14))\
        {\
            acknowledge([MT_context_slope_offset_4], var_id2);\
        }\
        else if((trans1_cal_mode >=15)&&(trans1_cal_mode <=17))\
        {\
            acknowledge([MT_context_slope_offset_5], var_id2);\
        }\
        else if((trans1_cal_mode >=22)&&(trans1_cal_mode <=23))\
        {\
            acknowledge([MT_context_slope_offset_7], var_id2);\
        }\
        else\
        {\
            acknowledge([MT_context_slope_offset_6], var_id2);\
        }\
        trans1_cal_save_type = 0;                           \
        if ((trans1_proccal_mode==0)&&(trans1_cal_mode == 17))\
        {\
            do\
            {\
                trans1_cal_save_type = SELECT_FROM_LIST("Complete calibration procedure.Select either Adjust,Calibrate or Abort:\n","Adjust;Calibrate;Abort");\
                _CAL_COMM_ERROR\
                _CAL_STATUS_ERROR\
            }\
            while (trans1_cal_save_type == 1);\
            /* Process calibration value*/\
            status = WriteCommand(write_trans1_cal_save_type);\
            _CAL_COMM_ERROR\
            _CAL_STATUS_ERROR\
        }\
        else\
        {\
            trans1_cal_save_type = SELECT_FROM_LIST("Complete calibration procedure.Select either Adjust,Calibrate or Abort:\n","Adjust;Calibrate;Abort");\
            /* Process calibration value*/\
            status = WriteCommand(write_trans1_cal_save_type);\
            _CAL_COMM_ERROR\
            _CAL_STATUS_ERROR\
        }\
        if(trans1_cal_save_type < 2)    /*0 - adjust, 1 - calibration*/\
        {\
            processing = 1;\
            while(processing)\
            {\
                DELAY(5, [MT_context_wait_until_new_calc_values]);\
                ReadCommand (read_trans1_cal_flags);   \
                _CAL_STATUS_ERROR\
                /*Read Saving Status*/\
                if((trans1_cal_flags & _CAL_SAVED_SUCCED))\
                {\
                    processing = 0; /*end loop*/\
                }\
            }\
        }\
        _CAL_EXIT\
        ACKNOWLEDGE([MT_context_cal_finish]);

/* _PROCESS_CAL_POINT*/
#define _PROCESS_CAL_POINT                      \
        var_id2[0] = VARID(trans1_cal_value1);\
        var_id2[1] = VARID(trans1_cal_unitcode);\
        get_dev_var_value([MT_context_pv_lv], var_id2, trans1_cal_point);\
        status = WriteCommand(write_trans1_cal_point);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR

/* _PROCESS_CAL_DIS*/
#if _PDM_ >= 800
#define _PROCESS_CAL_DIS                      \
    ReadCommand (read_trans1_cal_unitcode);   \
    var_id2[0] = VARID(trans1_cal_value1);\
    var_id2[1] = VARID(trans1_cal_unitcode);\
    display([MT_context_to_continue_PDM8], var_id2);\
    _CAL_COMM_ERROR\
    _CAL_STATUS_ERROR

#else
#define _PROCESS_CAL_DIS                      \
    ReadCommand (read_trans1_cal_unitcode);   \
    var_id2[0] = VARID(trans1_cal_value1);\
    var_id2[1] = VARID(trans1_cal_unitcode);\
    display([MT_context_to_continue], var_id2);\
    _CAL_COMM_ERROR\
    _CAL_STATUS_ERROR
#endif

/* _CAL_POINT_1_ENT*/
#define _CAL_POINT_1_ENT                      \
        ReadCommand (read_trans1_cal_unitcode);   \
        var_id1[0] = VARID(trans1_cal_unitcode);\
        get_dev_var_value([MT_context_entry_cal_point_1], var_id1, trans1_cal_point);\
        status = WriteCommand(write_trans1_cal_point);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR

/* _CAL_POINT_2_ENT*/
#define _CAL_POINT_2_ENT                      \
        var_id1[0] = VARID(trans1_cal_unitcode);\
        get_dev_var_value([MT_context_entry_cal_point_2], var_id1, trans1_cal_point);\
        status = WriteCommand(write_trans1_cal_point);\
        _CAL_COMM_ERROR\
        _CAL_STATUS_ERROR

/* _CAL_POINT_1_DIS*/
#if _PDM_ >= 800
#define _CAL_POINT_1_DIS                        \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);    \
        var_id3[0] = VARID(trans1_cal_value1);   \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_check_Stability], var_id3);
#else
#define _CAL_POINT_1_DIS                        \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);    \
        var_id3[0] = VARID(trans1_cal_value1);   \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_display_calpoint_1], var_id3);
#endif

/* _CAL_POINT_1_DYN*/
#if _PDM_ >= 800
#define _CAL_POINT_1_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_info_stable], var_id3);\
        _CAL_STATUS_ERROR

#else
#define _CAL_POINT_1_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_manual_drift_calpoint_1], var_id3);\
        _CAL_STATUS_ERROR
#endif

/* _CAL_POINT_2_DIS*/
#if _PDM_ >= 800
#define _CAL_POINT_2_DIS                      \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);    \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_check_Stability], var_id3);
#else
#define _CAL_POINT_2_DIS                      \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);    \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_display_calpoint_2], var_id3);
#endif

/* _CAL_POINT_2_DYN*/
#if _PDM_ >= 800
#define _CAL_POINT_2_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_info_stable], var_id3);
#else
#define _CAL_POINT_2_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_manual_drift_calpoint_2], var_id3);

#endif

/* _CAL_BUFFER_1_DIS*/
#if _PDM_ >= 800
#define _CAL_BUFFER_1_DIS                      \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);   \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_check_Stability], var_id3);
#else
#define _CAL_BUFFER_1_DIS                      \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);   \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_display_buffer_1], var_id3);

#endif
/* _CAL_BUFFER_1_DYN*/
#if _PDM_ >= 800
#define _CAL_BUFFER_1_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_info_stable], var_id3);
#else
#define _CAL_BUFFER_1_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_manual_drift_buffer_1], var_id3);
#endif
/* _CAL_BUFFER_2_DIS*/
#if _PDM_ >= 800
#define _CAL_BUFFER_2_DIS                      \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);   \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_check_Stability], var_id3);
#else
#define _CAL_BUFFER_2_DIS                      \
        ReadCommand (read_trans1_cal_value1);   \
        ReadCommand (read_trans1_cal_point);   \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        delay(3, [MT_context_manual_drift_buffer_2], var_id3);
#endif

/* _CAL_BUFFER_2_DYN*/
#if _PDM_ >= 800
#define _CAL_BUFFER_2_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_info_stable], var_id3);
#else
#define _CAL_BUFFER_2_DYN                      \
        var_id3[0] = VARID(trans1_cal_value1); \
        var_id3[1] = VARID(trans1_cal_unitcode); \
        var_id3[2] = VARID(trans1_cal_point); \
        display([MT_context_manual_buffer_2], var_id3);
#endif

/* _CALFLAG_STABLE*/
#define _CALFLAG_STABLE                      \
                ReadCommand (read_trans1_cal_flags);   \
                if ((trans1_cal_flags & _CAL_TIMEOUT)||(trans1_cal_flags & _CAL_FAILURED))\
                {\
                    if (trans1_cal_flags & _CAL_TIMEOUT)\
                    {\
                        ACKNOWLEDGE([MT_context_cal_timeout]);\
                    }\
                    _CAL_ERROR\
                    _CAL_EXIT\
                    DELAY(4, [MT_context_method_abort]);\
                    process_abort();\
                }\
                if (trans1_cal_flags & _CAL_VALUE_STABLE_FLAG)\
                {\
                    break;\
                }

#endif
