mr_na 发表于 2014-11-7 14:22:55

arduino语法求助,求助,求助

使用IDE版本为0022,写的一个socket 的例子,项目中包含一个pde文件,一个C文件,如果在C文件中调用pde文件中的函数呢,或者在pde中调用C文件中的函数也行。
pde文件如下
/*
* Socket App
*
* A simple socket application example using the WiShield 1.0
*/

#include <WiShield.h>

#define WIRELESS_MODE_INFRA        1
#define WIRELESS_MODE_ADHOC        2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,20};        // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,200};        // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};        // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"mr`na"};                // max 32 bytes
unsigned char security_type = 2;        // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
const prog_char security_passphrase[] PROGMEM = {"19850227"};        // max 64 characters
prog_uchar wep_keys[] PROGMEM = {        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,        // Key 0
                                                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00,        // Key 1
                                                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00,        // Key 2
                                                                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00        // Key 3
                                                                };
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
void onCall(){//C文件中调用这个方法
digitalWrite(13,HIGH);
}
void setup()
{
        WiFi.init();
}
void loop()
{
        WiFi.run();
}
C文件如下

#include "socketapp.h"
#include "uip.h"
#include <string.h>


static int handle_connection(struct socket_app_state *s);

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

void socket_app_appcall(void)
{

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

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


handle_connection(s);
}

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

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

PSOCK_END(&s->p);
}
/*---------------------------------------------------------------------------*/

mr_na 发表于 2014-11-7 14:23:57

现在是会报这样的错误:undefined reference to `onCall'

Super169 发表于 2014-11-7 15:48:12

"C文件中调用pde文件中的函数" - 你知道自己在做什麼嗎?
pde 跟 c 文件的關係, 你應該要先攪清楚了.

carney 发表于 2014-11-7 16:01:26

是不是应该先声明下函数,extern声明好应该就能调用了

mr_na 发表于 2014-11-7 19:08:33

carney 发表于 2014-11-7 16:01 static/image/common/back.gif
是不是应该先声明下函数,extern声明好应该就能调用了

extern void onCall();
static int handle_connection(struct socket_app_state *s)
{
PSOCK_BEGIN(&s->p);

PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
int fi=0;
while(1==1){
    onCall();//我是这样声明的,问题依就啊,还请帮帮忙

mr_na 发表于 2014-11-7 19:09:38

Super169 发表于 2014-11-7 15:48 static/image/common/back.gif
"C文件中调用pde文件中的函数" - 你知道自己在做什麼嗎?
pde 跟 c 文件的關係, 你應該要先攪清楚了.

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

peanut 发表于 2014-11-7 21:48:32

本帖最后由 peanut 于 2014-11-7 21:51 编辑

请参考以下的链接:
http://www.visualmicro.com/page/User-Guide.aspx?doc=INOs-and-CPPs.html

http://forum.arduino.cc/index.php?topic=190990.0

http://www.geek-workshop.com/thread-7100-1-1.html
页: [1]
查看完整版本: arduino语法求助,求助,求助