www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > 公眾號(hào)精選 > 嵌入式大雜燴
[導(dǎo)讀]文件操作平時(shí)用得很多,為了方便使用,可以自己根據(jù)實(shí)際需要再封裝一層:

#include // 獲取結(jié)構(gòu)體成員大小 #define GET_MEMBER_SIZE(type, member)   sizeof(((type*)0)->member) // 獲取結(jié)構(gòu)體成員偏移量 #define GET_MEMBER_OFFSET(type, member)  ((size_t)(&(((type*)0)->member))) typedef struct _test_struct0 { char x; char y; char z;

}test_struct0; typedef struct _test_struct1 { char a; char c; 
 short b; int d;
 test_struct0 e;
}test_struct1; int main(int arc, char *argv[]) { printf("GET_MEMBER_SIZE(test_struct1, a) = %ld\n", GET_MEMBER_SIZE(test_struct1, a)); printf("GET_MEMBER_SIZE(test_struct1, c) = %ld\n", GET_MEMBER_SIZE(test_struct1, c)); printf("GET_MEMBER_SIZE(test_struct1, b) = %ld\n", GET_MEMBER_SIZE(test_struct1, b)); printf("GET_MEMBER_SIZE(test_struct1, d) = %ld\n", GET_MEMBER_SIZE(test_struct1, d)); printf("GET_MEMBER_SIZE(test_struct1, e) = %ld\n", GET_MEMBER_SIZE(test_struct1, e)); printf("test_struct1 size = %ld\n", sizeof(test_struct1)); printf("GET_MEMBER_OFFSET(a): %ld\n", GET_MEMBER_OFFSET(test_struct1, a)); printf("GET_MEMBER_OFFSET(c): %ld\n", GET_MEMBER_OFFSET(test_struct1, c)); printf("GET_MEMBER_OFFSET(b): %ld\n", GET_MEMBER_OFFSET(test_struct1, b)); printf("GET_MEMBER_OFFSET(d): %ld\n", GET_MEMBER_OFFSET(test_struct1, d)); printf("GET_MEMBER_OFFSET(e): %ld\n", GET_MEMBER_OFFSET(test_struct1, e)); return 0;
}

運(yùn)行結(jié)果:

文件操作

文件操作平時(shí)用得很多,為了方便使用,可以自己根據(jù)實(shí)際需要再封裝一層:

代碼:

左右滑動(dòng)查看全部代碼>>>

// 微信公眾號(hào):嵌入式大雜燴 #include   static int file_opt_write(const char *filename, void *ptr, int size) {   
    FILE *fp; size_t num;

    fp = fopen(filename, "wb"); if(NULL == fp)
    { printf("open %s file error!\n", filename); return -1;   
    }
    
    num = fwrite(ptr, 1, size, fp); if(num != size)
    {
        fclose(fp); printf("write %s file error!\n", filename); return -1;
    } 

    fclose(fp); return num;
} static int file_opt_read(const char *filename, void *ptr, int size) {
    FILE *fp; size_t num;

    fp = fopen(filename, "rb"); if(NULL == fp)
    { printf("open %s file error!\n", filename); return -1;
    }
    
    num = fread(ptr, 1, size, fp); if(num != size)
    {
        fclose(fp); printf("write %s file error!\n", filename); return -1;
    } 
    fclose(fp); return num;
} typedef struct _test_struct { char a; char c; 
 short b; int d;
}test_struct; int main(int arc, char *argv[]) { #define FILE_NAME "./test_file" test_struct write_data = {0};
    write_data.a = 1;
    write_data.b = 2;
    write_data.c = 3;
    write_data.d = 4; printf("write_data.a = %d\n", write_data.a); printf("write_data.b = %d\n", write_data.b); printf("write_data.c = %d\n", write_data.c); printf("write_data.d = %d\n", write_data.d);
    file_opt_write(FILE_NAME, (test_struct*)&write_data, sizeof(test_struct));

    test_struct read_data = {0};
    file_opt_read(FILE_NAME, (test_struct*)&read_data, sizeof(test_struct)); printf("read_data.a = %d\n", read_data.a); printf("read_data.b = %d\n", read_data.b); printf("read_data.c = %d\n", read_data.c); printf("read_data.d = %d\n", read_data.d); return 0;
}

運(yùn)行結(jié)果:

進(jìn)度條

有時(shí)候,加上進(jìn)度條可以比較方便知道當(dāng)前的下載進(jìn)度、寫入文件的進(jìn)度等。

代碼:

左右滑動(dòng)查看全部代碼>>>

// 微信公眾號(hào):嵌入式大雜燴 #include   #include   #include   typedef struct _progress { int cur_size; int sum_size;
}progress_t; void progress_bar(progress_t *progress_data) { int percentage = 0; int cnt = 0; char proc[102]; memset(proc, '\0', sizeof(proc));

    percentage = (int)(progress_data->cur_size * 100 / progress_data->sum_size); printf("percentage = %d %%\n", percentage); if (percentage <= 100)
    { while (cnt <= percentage) { printf("[%-100s] [%d%%]\r", proc, cnt);
            fflush(stdout);  
            proc[cnt] = '#';  
            usleep(100000);
            cnt++;
        }

    } printf("\n");
} int main(int arc, char *argv[]) { progress_t progress_test = {0};

    progress_test.cur_size = 65;
    progress_test.sum_size = 100;
    progress_bar(&progress_test); return 0;
}

運(yùn)行結(jié)果:

日志輸出

日志輸出常常需要帶一些格式。最簡(jiǎn)單的方式如:

代碼:

左右滑動(dòng)查看全部代碼>>>

// 微信公眾號(hào):嵌入式大雜燴 #include   #define LOG_D(fmt, args...) do\
                            {\
                                printf("<> ", __FILE__, __LINE__, __FUNCTION__);\
                                printf(fmt, ##args);\
                            }while(0) int main(int arc, char *argv[]) { char ch = 'a'; char str[10] = "ZhengN"; float float_val = 10.10; int num = 88; double double_val = 10.123456;
    LOG_D("字符為 %c \n", ch);
    LOG_D("字符串為 %s \n" , str);
    LOG_D("浮點(diǎn)數(shù)為 %f \n", float_val);
    LOG_D("整數(shù)為 %d\n" , num);
    LOG_D("雙精度值為 %lf \n", double_val);
    LOG_D("八進(jìn)制值為 %o \n", num);
    LOG_D("十六進(jìn)制值為 %x \n", num); return 0;
}

運(yùn)行結(jié)果:

可閱讀

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

全球半導(dǎo)體封裝市場(chǎng)正向PLP、ECP等先進(jìn)技術(shù)傾斜,以應(yīng)對(duì)5G和高性能計(jì)算需求。但國(guó)內(nèi)上規(guī)模的PLP廠商不超過五家,芯友微憑借技術(shù)創(chuàng)新和成本優(yōu)勢(shì)已占據(jù)一席之地。面對(duì)行業(yè)競(jìng)爭(zhēng)和終端需求波動(dòng),張博威認(rèn)為:“機(jī)會(huì)永遠(yuǎn)都在,關(guān)鍵...

關(guān)鍵字: PLP ECP 封裝 芯友微 XINYOUNG

在半導(dǎo)體封裝領(lǐng)域,BGA(球柵陣列)封裝技術(shù)憑借其高引腳密度、低電阻電感和優(yōu)異散熱性能,已成為高性能芯片的主流封裝形式。然而,隨著芯片集成度與功率密度的持續(xù)提升,BGA焊點(diǎn)中的裂紋與微孔缺陷逐漸成為制約產(chǎn)品可靠性的核心問...

關(guān)鍵字: BGA裂紋 半導(dǎo)體 封裝

上海2025年8月20日 /美通社/ -- 今日,全球領(lǐng)先的集成電路成品制造和技術(shù)服務(wù)提供商長(zhǎng)電科技(600584.SH)公布了2025年半年度報(bào)告。財(cái)報(bào)顯示,今年上半年長(zhǎng)電...

關(guān)鍵字: 封裝 長(zhǎng)電科技 系統(tǒng)集成 汽車電子

在嵌入式系統(tǒng)開發(fā)中,硬件抽象層(Hardware Abstraction Layer,HAL)起著至關(guān)重要的作用。它為上層軟件提供了統(tǒng)一的硬件訪問接口,隱藏了底層硬件的細(xì)節(jié),使得軟件具有更好的可移植性和可維護(hù)性。C++作...

關(guān)鍵字: 嵌入式C++ HAL 寄存器 封裝

在當(dāng)今科技飛速發(fā)展的時(shí)代,半導(dǎo)體產(chǎn)業(yè)無(wú)疑是全球經(jīng)濟(jì)和科技競(jìng)爭(zhēng)的核心領(lǐng)域。隨著摩爾定律逐漸逼近物理極限,傳統(tǒng)的芯片制程微縮面臨著巨大挑戰(zhàn),而先進(jìn)封裝技術(shù)卻異軍突起,成為推動(dòng)半導(dǎo)體產(chǎn)業(yè)持續(xù)發(fā)展的新引擎。尤其是國(guó)產(chǎn)先進(jìn)封裝技術(shù)...

關(guān)鍵字: 半導(dǎo)體 芯片 封裝

在IEDM2024上,英特爾代工的技術(shù)研究團(tuán)隊(duì)展示了晶體管和封裝技術(shù)的開拓性進(jìn)展,有助于滿足未來AI算力需求。

關(guān)鍵字: 晶體管 封裝 AI算力

由Manz亞智科技主辦,未來半導(dǎo)體協(xié)辦的“FOPLP、TGV、異質(zhì)整合結(jié)構(gòu)芯片封裝技術(shù)創(chuàng)新論壇”將于12月4日在蘇州尼盛萬(wàn)麗酒店召開。本次論壇將以“‘化圓為方’解鎖高效封裝 ? CoPoS賦能芯未來”為主題,全面探討當(dāng)前...

關(guān)鍵字: 封裝 半導(dǎo)體

一種集成FPGA(現(xiàn)場(chǎng)可編程門陣列)和DSP(數(shù)字信號(hào)處理器)芯粒的異構(gòu)系統(tǒng)級(jí)封裝(SiP)是一種具有創(chuàng)新性和實(shí)用性的技術(shù)解決方案。以下是對(duì)這種異構(gòu)系統(tǒng)級(jí)封裝的詳細(xì)解析:

關(guān)鍵字: FPGA DSP芯粒 封裝
關(guān)閉