#include "NodeLinkCommon.h" #include "MathHelper.h" /** * 数据编码 * * @author lxz (041820 14:21:27) * * @param slave * @param dst * @param src * @param len * * @return int */ int nodelink_decode(unsigned char *dst, unsigned char *src, int len) { int i; if (len > 0) { i=len-1; if (mh_crc8_calc(src, len) == 0) { while(i--) { dst[i]=src[i]; } return len - 1; } } return 0; } /** * 数据编码 * * @author lxz (041820 14:22:05) * * @param id * @param dst * @param src * @param len * * @return int */ int nodelink_encode(unsigned char *dst, unsigned char *src, int len) { int res = 0; unsigned char crc = 0; crc = mh_crc8_calc(src, len); res = len + 1; dst[len] = crc; while (len--) { dst[len] = src[len]; } return res; }