使用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);
- }
- /*---------------------------------------------------------------------------*/
复制代码 |