与其他字符相比,c++/Arduino 处理“?”的方式是否不同
Does c++/Arduino handle '?' differently compared with other chars
我有一个通过蓝牙与arduino板通信的Android应用程序
所有命令都很好地前后移动,直到我想发送该类型的 comand
"aT?bb"
从安卓应用程序,但是当我在 ardunio 中打印它时,我得到了
"aT%3F"
我正在 android 中记录命令并且它的格式正确 我的问题是 c++/Arduino 处理"?"的方式是否与普通字符不同?
这是我的Arduino代码>
while(bluetooth.available())
{
char toSend = (char)bluetooth.read();
if(toSend != ' '){
if (toSend == 'a'){ i=0 ;}
inMsg[i] = toSend;
i++;
}
}
if(i == 5 )
{
// mock sending queries
if(inMsg[2] == '?'){
if(inMsg[1] == 'T'){
bluetooth.write("ty1");Serial.println("");
}else if(inMsg[1] == 'x'){ //normal cycle
bluetooth.write("xx1");
}else if(inMsg[1] == 'X'){ Serial.println(""); //booter
bluetooth.write("XX0");
}else if(inMsg[1] == 'N'){Serial.println(""); //On time
bluetooth.write("on1");
}else if(inMsg[1] == 'F'){ Serial.println(""); //Off time
bluetooth.write("of30");
}else if(inMsg[1] == 'S'){ Serial.println(""); //Speed percent
bluetooth.write("sp30");
}
}
// write to console
for(int j = 0; j < 5; j++){
Serial.write(inMsg[j]);
}
// new line
if(i == 5){Serial.println("");}
i = 0; // reset buffer
}
aT%3F <- this is mal formed
aS133 <- all the other are as I sent them from android
aN169
aF192
aS200
aXXXX
aYYYY
ayYYY
axXXX
我的安卓代码 ... 命令 = "aT?bb"; writeCommand(command); ...
private void writeCommand(String command)
{
for (BluetoothGattCharacteristic characteristic : characteristics)
{
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) >0)
{
try {
characteristic.setValue(URLEncoder.encode(command, "utf-8"));
gatt.writeCharacteristic(characteristic);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
正如上面的评论中所指出的,是URLEncoder正在更改字符串。我现在已经将此方法更改为
private void writeCommand(String command)
{
for (BluetoothGattCharacteristic characteristic : characteristics)
{
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) >0)
{
characteristic.setValue(command);
gatt.writeCharacteristic(characteristic);
}else{
Log.i(TAG,"non write able");
}
}
}
相关文章:
- 不同/较旧的处理器运行c++代码的方式是否不同
- 并发/多线程:是否可以以这种方式生成相同的输出?
- 这种方式是否可以接受向向量添加unique_ptr?
- 在线程中读取无符号整数时,c++ 位是否以原子方式切换?
- 在 Eclipse 中添加库的工作方式是否与在 Visual Studio 中相同?
- VS2017 是否更改了 C++ 中访问 C# 命名空间的方式?
- size_t的大小和对齐方式是否与ptrdiff_t相同?
- 只需要知道我在c ++中打印模式的方式是否有效,或者有另一种方法可以有效地做到这一点
- 我的随机生成器是否不工作,或者我决定人/骨架是否击中对手的方式是否有错误
- clang实现char8_t的方式是否存在缺陷,或者标准的某个黑暗角落是否禁止优化?
- 在现代C++中初始化字符串的方式是否有不同
- 与 C++ 相比,C# 中的按引用传递的工作方式是否正确?
- 如果与未使用的库链接,可执行文件的构建方式是否不同?
- 类定义中定义的成员函数的编译方式是否与C++中其他位置定义的成员函数不同
- C(和C++)中字符的对齐方式是否保证为 1
- 我插入 STL 映射的方式是否正确?不会漏内存吗?
- 这种使用虚拟受保护方法扩展库的方式是否安全
- 与其他字符相比,c++/Arduino 处理“?”的方式是否不同
- 使用可变参数模板创建传递新对象的更安全方式是否是个好主意
- gcc对vla的sizeof操作符的计算方式是否不同