Stringification working with USERNAME:PASSWORD but not for SERIAL:TOKEN?

醉酒当歌 提交于 2019-12-25 02:31:06

问题


I have the following Makefile (If you are asking me why there's \" included you can refer to my previous question)

BOARD_TAG    = mega2560
CPPFLAGS     = -DUSERNAME=\"$(USERNAME)\" -DPASSWORD=\"$(PASSWORD)\"
include $(ARDMK_DIR)/Arduino.mk

and code:

void setup() {
  Serial.begin(9600);
  String auth_raw2(USERNAME ":" PASSWORD);
  Serial.println(auth_raw2);
}
void loop() {}

when I compile this with make USERNAME=hello PASSWORD=world, everything works and I see 'hello:world' being printed out.

However, if I substitute USERNAME to SERIAL and PASSWORD to TOKEN:

BOARD_TAG    = mega2560
CPPFLAGS     = -DSERIAL=\"$(SERIAL)\" -DTOKEN=\"$(TOKEN)\"
include $(ARDMK_DIR)/Arduino.mk

and

void setup() {
  Serial.begin(9600);
  String auth_raw2(SERIAL ":" TOKEN);
  Serial.println(auth_raw2);
}
void loop() {}

I am getting the error, macro.ino:5:27: error: expected ‘)’ before string constant

Note that $USERNAME is defined on my linux box as disappearedng while $PASSWORD, $SERIAL, and $TOKEN are undefined.

WHY does this work for USERNAME:PASSWORD but not for SERIAL:TOKEN?


回答1:


So it seems like Arduino overrides the $SERIAL parameter.

Switching SERIAL to DSERIAL makes compiling ok



来源:https://stackoverflow.com/questions/24966878/stringification-working-with-usernamepassword-but-not-for-serialtoken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!