完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HI论坛,我想知道是否有可能在编译的代码中获得构建版本。有没有办法在预构建命令中获得这个值,然后将它保存在UC的ROM中(γ定义、变量、常数、……)?这个话题对我来说绝对是新的…对你们来说可能没有意义;-非常感谢你们的帮助。问候,朱利安。
以上来自于百度翻译 以下为原文 Hi forum, I was wondering if it would be possible to get the build version in my compiled code. Is there any way to get this value in a pre-build command and then save it in the ROM of the uC (#define, variable, constante, ...)? This topic is absolutely new for me... It maybe makes no sense for you guys ;-) Thank you very much for you help. Regards, Julien |
|
相关推荐
13个回答
|
|
|
|
|
|
如果有日期和时间符号可用,那就太好了。我也不记得了,有人知道吗?${De}}似乎是nul.gP
以上来自于百度翻译 以下为原文 It would be nice if there were date and time symbols available. I don't recall either, does anyone know for sure? ${DATE} seems to be null. GP |
|
|
|
您可以在源代码(这里是XC16)中执行,但这当然不是一个“构建”版本,它必须有一些“原点”。你不会真的想为每个编译器运行(我假设)增加你的构建号。&编辑:忘了说:如果你不指定你想“显示”或稍后检索它,你的构建版本是相当无用的。
以上来自于百度翻译 以下为原文 You could do that within the source code (here xc16), #ifdef __XC16__ dbgPuts("XC16-"); dbgPutDec(__XC16_VERSION__); dbgPutc(':'); #else dbgPuts("C30: "); #endif dbgPuts("Compiled "); // output Build Date and Time dbgPuts(__DATE__); dbgPutc(','); dbgPuts(__TIME__); but that's of course not a "Build" version, which must have some "origin". You would not really want to increment your build number just for each compiler run (I assume). |
|
|
|
在G.CMD文件中使用Git作为预构建选项。
以上来自于百度翻译 以下为原文 I use this with git in a .cmd file as a prebuild option. git rev-list --full-history --all --abbrev-commit | wc -l | "D:Program Files (x86)GnuWin32binsed.exe" -e "s/^ *//" >>AppConfiguration.h echo|set /p="#define GIT_HASH " >>AppConfiguration.h git rev-list --full-history --all --abbrev-commit | head -1 >>AppConfiguration.h |
|
|
|
我使用一个简单的Windows控制台应用程序,它运行为一个预构建步骤:-它创建一个文件(BuffdNo..h作为默认值,但接受一个文件名作为参数),其中生成号既定义为整数又是String宏,每次运行时都增加它。不管怎样,你需要它。邮政1000![/OT ]
以上来自于百度翻译 以下为原文 I use a simple Windows console app which runs as a pre-build step:- // BuildNumber.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "string.h" #include "ctype.h" #include "stdlib.h" int main(int argc, char* argv[]) { char filename[1024]; strcpy(filename,"buildnumber.h"); char linebuf[1024]; int nBuild=1; if (argc>1) { char *cmd=argv[1]; strncpy(filename,cmd,1023); } printf("BuildNumber 1.0n"); printf("© S. Gregory 2016n"); FILE *fp=fopen(filename,"r+"); if (fp) { memset(linebuf,0,sizeof(linebuf)); int ctr=0; while(fgets(linebuf,1023,fp)) { char *cctr; for(cctr=linebuf;*cctr;cctr++) *cctr=tolower(*cctr); char *pctr=linebuf; while((*pctr)&&(isspace(*pctr))) pctr++; if (strncmp(pctr,"#define buildnumber",19)==0) { nBuild=atol(pctr+19)+1; fclose(fp); fp=fopen(filename,"w"); if (fp) { fprintf(fp,"/* Generated by BuildNumber Version 1.0 */rnrn"); fprintf(fp,"#ifndef BUILD_NUMBER_H_rn"); fprintf(fp,"#define BUILD_NUMBER_H_rnrn"); fprintf(fp,"#define BUILDNUMBER %drn",nBuild); fprintf(fp,"#define BUILDNUMBER_STR "%04d"rn",nBuild); fprintf(fp,"#endif /* BUILD_NUMBER_H_ */rn"); printf("Build %dn",nBuild); fclose(fp); return 0; } else { printf("File Open Errorrn"); } return -1; } } printf("%s not validrn",filename); fclose(fp); return -2; } else { fp=fopen(filename,"w"); if (fp) { fprintf(fp,"/* Generated by BuildNumber Version 1.0 */rnrn"); fprintf(fp,"#ifndef BUILD_NUMBER_H_rn"); fprintf(fp,"#define BUILD_NUMBER_H_rnrn"); fprintf(fp,"#define BUILDNUMBER %drn",nBuild); fprintf(fp,"#define BUILDNUMBER_STR "%04d"rn",nBuild); fprintf(fp,"#endif /* BUILD_NUMBER_H_ */rn"); } else { printf("File Open Errorrn"); return -1; } fclose(fp); printf("Build %dn",nBuild); return 0; } return -3; } It creates a file (buildnumber.h as default, but accepts a filename as a parameter), in which the build number is defined both as integer and string macros, and is incremented each time it is run. You can then include buildnumber.h wherever you need it. [ OT ]WooHoo! post #1000! [ /OT ] |
|
|
|
大家好,首先感谢大家的回答。实际上,我想做的是保存在UC内存中的构建版本(有效地增加每个代码的构建),以便在程序运行时使用它(通过UART发送)。我发现了关于这个主题的有趣文章(link)。它可能是第一个输入,但是我如何修改这个代码来保存UC内存中的值呢?谢谢你的帮助。问候,朱利安。
以上来自于百度翻译 以下为原文 Hi everyone, First, thanks to all for your answers. Actually, what I want to do is to save the build version (effectively a number, which will be incremented for each build of the code) in the uC memory to be able to use it when the program is running (send it over UART). I found this interesting article regarding this topic (link). It could be a first input, but how could I modify this code to save the value in the uC's memory? Thank you in advance for your help. Regards, Julien |
|
|
|
几年前我在C中也做了同样的事情,正义命令行版本看起来不错。
以上来自于百度翻译 以下为原文 I did the same thing in C some many years ago; also the just-command-line version looks nice |
|
|
|
I(在XC32项目中)将预定义的α-DATEYSY显示为字符串,而对于我使用的版本,将其定义为“2.30”或任何内容。复制粘贴代码;我不假装理解C的预处理器!没有做任何自动递增的构建号(但是)。这两个值(字符串,在这种情况下)被保存在微控制器程序存储器中,所以可以像任何其他常量一样使用——在这种情况下,我在电源UP.DOM上显示一个漂亮的小OLED。
以上来自于百度翻译 以下为原文 I (in an XC32 project) display the predefined __DATE__ as a string, and for version I use #define versionmaj 2 #define versionmin 30 // from https://gcc.gnu.org/onlinedocs/cpp/Stringification.html #define xstr(s) str(s) #define str(s) #s #define version xstr(versionmaj)"."xstr(versionmin) which defines version as "2.30" or whatever. Copy-pasted code; I don't pretend to understand C's pre-processor! Not done any auto-incrementing build numbers (yet). Both values (strings, in this case) are saved in the microcontrollers program memory so can be used like any other constant - in this case I show them on a nice little OLED on power up. dom. |
|
|
|
对于PIC18设备,您可以在项目构建上插入信息,使其出现在Flash中的已知位置,并且可以在HEX文件中看到:这是因为内存被组织成16位字。对于PIC16F设备中的14位内存字来说,它不太好用。
以上来自于百度翻译 以下为原文 For PIC18 devices, you can insert information on the project build such that it appears at a known location in flash and it can be seen in the hex file: const char PROJECT[] @ 0x100 = "SCRPCB1"; //__attribute__((address(0x100))) const char PROJECT[] = "SCRPCB1"; __attribute__((address(0x110))) const char VERSION[] = "1.40"; __attribute__((address(0x120))) const char DATE[] = "10/26/2016"; :0600000000F00BEF00F020 ---- :10000800F3CF04F096EC03F004C0F3FF110021EFE6 ---- ! :0200180007F0EF ---- :08010000534352504342310009 ---- SCRPCB1 :06011000312E3430000026 ---- 1.40 :0C01200031302F32362F323031360000E3 ---- 10/26/2016 This works because the memory is organized as 16 bit words. It doesn't work so well for 14 bit memory words in PIC16F devices. |
|
|
|
关于这个主题的其他线程:AutoDelpValueAutoDelphi版本增加了一个关于添加Git提交号的线程,但是我再也找不到它了。
以上来自于百度翻译 以下为原文 Other threads about this topic: Auto Increment Version Automatic version increment There was even a thread about adding Git commit numbers, but I can't find it anymore. |
|
|
|
这与上面的Jim Nickersons邮局有什么不同吗?
以上来自于百度翻译 以下为原文 Is this different to Jim Nickersons post above? |
|
|
|
您好论坛,非常感谢您的帮助。我真的很感激!我会看看你的解决方案,并会在这里贴上我的“定制”一个!再次感谢!问候,朱利安
以上来自于百度翻译 以下为原文 Hi forum, Thank you very much for your help. I really appreciate it! I will have a look to your solutions and will post here my "customized" one! Thanks again! Regards, Julien |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
636浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 16:14 , Processed in 1.920646 second(s), Total 103, Slave 86 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号