在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            博客專欄

            EEPW首頁 > 博客 > ubuntu安裝asn1c編譯器

            ubuntu安裝asn1c編譯器

            發(fā)布人:電子禪石 時(shí)間:2022-03-05 來源:工程師 發(fā)布文章

            最近在搞一個(gè)分布式控制系統(tǒng),所有控制器通過以太網(wǎng)鏈接,考慮到系統(tǒng)的方便擴(kuò)展(將來可能有不同平臺(tái)的控制器接入到控制網(wǎng)絡(luò))以及網(wǎng)絡(luò)傳輸?shù)陌踩?,?duì)通訊內(nèi)容分進(jìn)行asn.1編碼。這里做一個(gè)筆記以便以后偷懶。

                    首先是安裝asn.1編譯器,目前的編譯器有好幾種,這里選用了免費(fèi)開源的asn1c編譯器(http://lionet.info/asn1c/basics.html),步驟如下:

                    1、下載asn1c的源碼(http://lionet.info/asn1c/download.html或者h(yuǎn)ttps://github.com/vlm/asn1c)

                    2、解壓源碼:tar -zxvf asn1c-0.9.27.tar.gz

                    3、進(jìn)入源碼目錄:cd asn1c-0.9.27/

                    4、配置:./configure

                    5、編譯:make

                    6、安裝:sudo make install(注意需要管理員權(quán)限)

                    至此安裝結(jié)束,可以用asn1c命令做一下測(cè)試,接下來做一個(gè)例子,例子見使用說明文檔

                    1、新建一個(gè)rectangle.asn1文件并編輯如下文本:

            RectangleTest DEFINITIONS ::=
            BEGIN
             
            Rectangle ::= SEQUENCE {
              height INTEGER, -- Height of the rectangle
              width INTEGER -- Width of the rectangle
            }
             
            END


                      2、對(duì)rectangle.asn1進(jìn)行編譯:asn1c -fnative-types rectangle.asn1    ,執(zhí)行完畢后會(huì)在該目錄下生成跟編碼相關(guān)的c語言文件
               

                      3、使用eclipse新建一個(gè)c工程并將上一步生成的c文件加入到工程中,新建一個(gè)main.c,編輯如下代碼

            #include <stdio.h>#include <sys/types.h>#include <Rectangle.h> /* Rectangle ASN.1 type *//* * This is a custom function which writes the * encoded output into some FILE stream. */static int write_out(const void *buffer, size_t size, void *app_key){	FILE *out_fp = app_key;	size_t wrote;	wrote = fwrite(buffer, 1, size, out_fp);	return (wrote == size) ? 0 : -1;}int main(int ac, char **av){	Rectangle_t *rectangle; /* Type to encode */	asn_enc_rval_t ec; /* Encoder return value */	/* Allocate the Rectangle_t */	rectangle = calloc(1, sizeof(Rectangle_t)); /* not malloc! */	if (!rectangle)	{		perror("calloc() failed");		exit(71); /* better, EX_OSERR */	}	/* Initialize the Rectangle members */	rectangle->height = 42; /* any random value */	rectangle->width = 23; /* any random value */	/* BER encode the data if filename is given */	if (ac < 2)	{		fprintf(stderr, "Specify filename for BER output\n");	}	else	{		const char *filename = av[1];		FILE *fp = fopen(filename, "wb"); /* for BER output */		if (!fp)		{			perror(filename);			exit(71); /* better, EX_OSERR */		}		/* Encode the Rectangle type as BER (DER) */		ec = der_encode(&asn_DEF_Rectangle, rectangle, write_out, fp);		fclose(fp);		if (ec.encoded == -1)		{			fprintf(stderr, "Could not encode Rectangle (at %s)\n",					ec.failed_type ? ec.failed_type->name : "unknown");			exit(65); /* better, EX_DATAERR */		}		else		{			fprintf(stderr, "Created %s with BER encoded Rectangle\n",					filename);		}	}	/* Also print the constructed Rectangle XER encoded (XML) */	xer_fprint(stdout, &asn_DEF_Rectangle, rectangle);	return 0; /* Encoding finished successfully */}

                        4、將編碼文件夾中的converter-sample.c文件刪除

                        5、編譯運(yùn)行,Console會(huì)打印如下內(nèi)容:

            Specify filename for BER output<Rectangle><height>42</height><width>23</width></Rectangle>

                        如果需要在arm平臺(tái)運(yùn)行的話,直接將工程中的編譯器換成交叉編譯器即可

            轉(zhuǎn)載于:https://my.oschina.net/Cw6PKk/blog/749153


            *博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。



            關(guān)鍵詞: asn1c

            技術(shù)專區(qū)

            關(guān)閉