/* check_sum校验和函数,返回的是1个字节的数据 */
int check_sum(unsigned char *p_data, int len, unsigned char *data)
{unsigned char ret_t = 0;if (NULL == p_data || len <= 0)return -1;for (int i = 0; i < len; i++) {ret_t += p_data[i];}*data = ret_t;return 0;
}int main(){int ret;unsigned char debug_array[] = {0x01, 0x34, 0x45 ,0x67,0x89, 0xAB, 0xCD, 0xEF};ret = check_sum(debug_array, ARRAY_SIZE(debug_array) - 1, &debug_array[ARRAY_SIZE(debug_array) - 1]);}