我正在编写一段arduino代码,它使用的是内置wifi的BlackWidow版本。通过使用WiServer.h库,我使用带有mods的SimpleClient.pde示例向red服务器发送一个调用,该调用将简单地返回一个整数- 0、1或2。最终目标是打开红灯、绿灯或黄灯的引脚。整数表示我们的Hudson CI的聚合状态。
我是个PHP懒惰的混蛋,指针吓到我了。我正在使用的代码是
// Function that prints data from the server
void printData(char* data, int len) {
// Print the data returned by the server
// Note that the data is not null-terminated, may be broken up into smaller packets, and
// includes the HTTP header.
while (len-- > 0) {
Serial.print(*(data++));
}
}printData()是对when服务器的调用的回调,运行时它会将以下内容发送到串行监视器(这是3个循环,在新输出之前没有换行符):
HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:37 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html
0HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:45 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html
0HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:58 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html
0我需要确定的部分是0,也可以是1或2。
这个函数将变成turnOnAppropriateLight(),而不是printData(),只需将引脚设置为高即可。这将激活继电器,为相应的LED阵列供电。
现在我已经写好了这段代码,看起来我只需要保留最后一个字符,并根据值进行切换。*(data++)是令人困惑的部分,尽管我知道它增加了一个指针索引……我只是不确定如何直接转到该索引中的最后一个字符。不需要这个循环来输出结果。


发布于 2011-02-11 01:57:36
这一点也不健壮,但是
Serial.print(data[len-1])看看这会给你带来什么
发布于 2011-02-11 01:58:58
这应该是您需要的全部内容:
data[len - 1]发布于 2011-02-11 02:05:38
您可能很神经质,会解析每一行,或者查找最后一个标记: Content-Type:。
我会将C样式的字符串转换为C++ std::string,然后使用find_first方法查找关键字。
std::istringstream可用于将文本" 0“转换为数字0。
https://stackoverflow.com/questions/4960757
复制相似问题