diff --git a/include/common/tmsg.h b/include/common/tmsg.h index f7e855db8a..be5b51d938 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -55,7 +55,6 @@ extern "C" { extern char* tMsgInfo[]; extern int32_t tMsgDict[]; -// extern int32_t tMsgRangeDict[]; typedef uint16_t tmsg_t; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 84dca38108..0c9d2c2192 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -35,17 +35,13 @@ #elif defined(TD_MSG_RANGE_CODE_) - typedef struct { - int32_t start; - int32_t end; - } TMsgRange; #undef TD_NEW_MSG_SEG #undef TD_DEF_MSG_TYPE #undef TD_CLOSE_MSG_TYPE - #define TD_NEW_MSG_SEG(TYPE) {(TYPE##_SEG_CODE) << 8, + #define TD_NEW_MSG_SEG(TYPE) #define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) - #define TD_CLOSE_MSG_TYPE(TYPE) TYPE}, - TMsgRange tMsgRangeDict[] = { + #define TD_CLOSE_MSG_TYPE(TYPE) TYPE, + int32_t tMsgRangeDict[] = { #elif defined(TD_MSG_NUMBER_) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 11a47142b8..197750a6a8 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -41,10 +41,10 @@ inline bool tmsgIsValid(tmsg_t type) { static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]); - for (int i = 0; i < sz; i++) { - if (type > tMsgRangeDict[i].start && type < tMsgRangeDict[i].end) { - return true; - } + + int segIdx = TMSG_SEG_CODE(type); + if (segIdx < sz) { + return type < tMsgRangeDict[segIdx]; } return false; }