c语言转变java语言求帮助 - 爱问答

(爱问答)

c语言转变java语言求帮助

#include <stdint.h>

#include <stdio.h>

 

typedef enum {

    SABO_NO_ERR,

SABO_SYS_ERR,

SABO_POINTER_ERR,

SABO_OVERFLOW_ERR,

SABO_DATA_ERR,

} ErrCode;

 

void lib_debug(char *text,uint8_t *data,uint16_t length){

    uint16_t i = 0;

    printf("%s;length:%u;data:",text,length);

    for(i = 0; i < length; i++){

        printf(" %02X",data[ i ]);

    }

    printf(" END ");

}

 

uint8_t get_bcc(uint8_t *buff,uint16_t length){

uint8_t bcc = 0;

uint16_t i = 0;

for(i = 0;i < length;i++){

bcc ^= *(buff+i);

}

return bcc;

}

 

ErrCode analysis_tlv(uint8_t data,uint8_t head_code,uint8_t *buff,uint16_t max_len,void func(uint8_t*,uint16_t)){

static uint8_t star = 0,step = 0,dlen,bcc;

static uint16_t length = 0;

if(!buff)return SABO_POINTER_ERR;

if(star == 0){

if(data == head_code){

star = 1;

length = 0;

dlen = bcc = 0;

buff[length++] = data;

}

}else{

if(length < max_len){

buff[length++] = data;

if(length == 2){

dlen = buff[1];

if(dlen == 0){

star = 0;

return SABO_DATA_ERR;

}

}

if(dlen > 0){

bcc ^= data;

if((length-2) == dlen){

if(bcc == 0){

if(func){

func(buff,length);

}else{

star = 0;

return SABO_POINTER_ERR;

}

}star = 0;

}

}

}else{

star = 0;

return SABO_OVERFLOW_ERR;

}

}

return SABO_NO_ERR;

}

 

void recv_event(uint8_t *buff,uint16_t length){

lib_debug((char*)__func__,buff,length);

}

 

uint8_t rbuf[100];

void recv(uint8_t value){

ErrCode Err = analysis_tlv(value,0x7F,rbuf,100,recv_event);

if(Err > 0){

printf("ERROR:%u ",Err);

}

}

 

int main(){

uint8_t buf[1024] = {0x7F,0x16,0xA4,0x00,0x30,0x38,0x38,0x38,0x38,0x39,0x32,0x36,0x36,0xD0,0xBB,0xC9,0xFA,0x00,0x00,0x00,0x00,0x00,0x00,0xD1};

//uint8_t buf[1024] = {0x7F,0x16,0xA4,0x00,0x30,0x38,0x38,0x38,0x38,0x39,0x32,0x36,0x36,0xD0,0xBB,0xC9,0xFA,0x00,0x00,0x00,0x00,0x00,0x00,0xD1,0,1,2,3,4,5,6,0x7F,0x16,0xA4,0x00,0x30,0x38,0x38,0x38,0x38,0x39,0x32,0x36,0x36,0xD0,0xBB,0xC9,0xFA,0x00,0x00,0x00,0x00,0x00,0x00,0xD1,0x7F,0x16,0xA4,0x00,0x30,0x38,0x38,0x38,0x38,0x39,0x32,0x36,0x36,0xD0,0xBB,0xC9,0xFA,0x00,0x00,0x00,0x00,0x00,0x00,0xD1},i;

uint16_t i;

for(i = 0;i < 100;i++){

recv(*(buf+i));

}

while(1);

return 0;

}


你的这个是单片机的C程序 ,转成java没有意义的(java不直接支持硬件的)

相关标签:javac语言

下一篇:switch怎么输出var

上一篇:excel单元格内的不同汉字对应不同数字怎么做函数

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?