极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13907|回复: 6

arduino语法求助,求助,求助

[复制链接]
发表于 2014-11-7 14:22:55 | 显示全部楼层 |阅读模式
使用IDE版本为0022,写的一个socket 的例子,项目中包含一个pde文件,一个C文件,如果在C文件中调用pde文件中的函数呢,或者在pde中调用C文件中的函数也行。
pde文件如下
  1. /*
  2. * Socket App
  3. *
  4. * A simple socket application example using the WiShield 1.0
  5. */

  6. #include <WiShield.h>

  7. #define WIRELESS_MODE_INFRA        1
  8. #define WIRELESS_MODE_ADHOC        2

  9. // Wireless configuration parameters ----------------------------------------
  10. unsigned char local_ip[] = {192,168,1,20};        // IP address of WiShield
  11. unsigned char gateway_ip[] = {192,168,1,200};        // router or gateway IP address
  12. unsigned char subnet_mask[] = {255,255,255,0};        // subnet mask for the local network
  13. const prog_char ssid[] PROGMEM = {"mr`na"};                // max 32 bytes
  14. unsigned char security_type = 2;        // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
  15. const prog_char security_passphrase[] PROGMEM = {"19850227"};        // max 64 characters
  16. prog_uchar wep_keys[] PROGMEM = {        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,        // Key 0
  17.                                                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00,        // Key 1
  18.                                                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00,        // Key 2
  19.                                                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00        // Key 3
  20.                                                                 };
  21. unsigned char wireless_mode = WIRELESS_MODE_INFRA;
  22. unsigned char ssid_len;
  23. unsigned char security_passphrase_len;
  24. //---------------------------------------------------------------------------
  25. void onCall(){//C文件中调用这个方法
  26.   digitalWrite(13,HIGH);
  27. }
  28. void setup()
  29. {
  30.         WiFi.init();
  31. }
  32. void loop()
  33. {
  34.         WiFi.run();
  35. }
复制代码

C文件如下

  1. #include "socketapp.h"
  2. #include "uip.h"
  3. #include <string.h>


  4. static int handle_connection(struct socket_app_state *s);

  5. void socket_app_init(void)
  6. {
  7.   /* We start to listen for connections on TCP port 1000. */
  8.   uip_listen(HTONS(1000));
  9. }

  10. void socket_app_appcall(void)
  11. {

  12.   struct socket_app_state *s = &(uip_conn->appstate);

  13.   if(uip_connected()) {
  14.     PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
  15.   }


  16.   handle_connection(s);
  17. }

  18. static int handle_connection(struct socket_app_state *s)
  19. {
  20.   PSOCK_BEGIN(&s->p);

  21.   PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
  22.   while(1==1){
  23.     onCall();//调用pde文件中的函数
  24.     PSOCK_READTO(&s->p, '\n');
  25.     PSOCK_SEND_STR(&s->p, "Hello ");
  26.     PSOCK_SEND_STR(&s->p, s->inputbuffer);
  27.   }
  28.   memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  29.   PSOCK_CLOSE(&s->p);

  30.   PSOCK_END(&s->p);
  31. }
  32. /*---------------------------------------------------------------------------*/
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-11-7 14:23:57 | 显示全部楼层
现在是会报这样的错误:
  1. undefined reference to `onCall'
复制代码
回复 支持 反对

使用道具 举报

发表于 2014-11-7 15:48:12 | 显示全部楼层
"C文件中调用pde文件中的函数" - 你知道自己在做什麼嗎?
pde 跟 c 文件的關係, 你應該要先攪清楚了.

回复 支持 反对

使用道具 举报

发表于 2014-11-7 16:01:26 | 显示全部楼层
是不是应该先声明下函数,extern声明好应该就能调用了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-7 19:08:33 | 显示全部楼层
carney 发表于 2014-11-7 16:01
是不是应该先声明下函数,extern声明好应该就能调用了
  1. extern void onCall();
  2. static int handle_connection(struct socket_app_state *s)
  3. {
  4.   PSOCK_BEGIN(&s->p);

  5.   PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
  6.   int fi=0;
  7.   while(1==1){
  8.     onCall();//
复制代码
我是这样声明的,问题依就啊,还请帮帮忙
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-7 19:09:38 | 显示全部楼层
Super169 发表于 2014-11-7 15:48
"C文件中调用pde文件中的函数" - 你知道自己在做什麼嗎?
pde 跟 c 文件的關係, 你應該要先攪清楚了.

pde 跟 c 文件的關係,我是不清楚,我以为就相当于两个C文件,是吗,还请帮我搞清楚
回复 支持 反对

使用道具 举报

发表于 2014-11-7 21:48:32 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-18 05:38 , Processed in 0.037967 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表