Paso 2: WizFi250-CSI.h
Todas las funciones, estructura y valores estáticos se definen en "WizFi250-CSI.h".
Por lo tanto, el archivo de secuencia de comandos sólo debe incluir "WizFi250-CSI.h".
Usted no necesita incluir otros archivos de cabecera como stdio.h, string.h socket.h.
Al referirse a este "CSI.h WizFi250", puede escribir su propia aplicación (archivo de comandos de C).
Funciones más generales se basan en la "Biblioteca estándar de C".
int atoi(char *); int atol(char *); int printf(char *, ...); int scanf(char *, ...); void *memcpy(void *,void *,int); int strlen(char *); ..........................................
Toma funciones se basan en sockets BSD API.
int socket(int, int, int); int connect(int, struct sockaddr *, unsigned long); int recv(int, void *, unsigned long, int); int recvfrom(int, void *, unsigned long, int, struct sockaddr *, unsigned long *); int send(int, void *, unsigned long, int); ..........................................
Mayoría de las funciones de hardware de WizFi250 se basa en el estilo de Arduino.
void pinMode(int gpio, int type); void pinOut(int gpio, int value); int pinIn(int); int analogRead(int); void delay_ms(unsigned long milliseconds); ..........................................
Por favor, refiérase a la abajo completo "WizFi250 CSI.h".
<p>/*<br> * This file is part of the WizFi250-CSI(C Script Interpreter) project * By referring to this header file, you can write a C-Script-file of WizFi250-CSI. * * This is published under the "New BSD License". * <a href="http://www.opensource.org/licenses/bsd-license.php" rel="nofollow"> http://www.opensource.org/licenses/bsd-license.ph...</a> * * Copyright (C) 2015 Steve Kim (ssekim * * The WizFi250-CSI is based on picoc project. * <a href="https://github.com/zsaleeba/picoc" rel="nofollow"> http://www.opensource.org/licenses/bsd-license.ph...</a> * Copyright (c) 2009-2011, Zik Saleeba * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the Zik Saleeba nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *</p><p>/ WizFi250-CSI(C Script Interpreter) Header File for All</p><p>// Based on "ctype.h" of C standard library int isalnum(int); int isalpha(int); int isblank(int); int iscntrl(int); int isdigit(int); int isgraph(int); int islower(int); int isprint(int); int ispunct(int); int isspace(int); int isupper(int); int isxdigit(int); int tolower(int); int toupper(int);</p><p>// Based on "stdbool.h" of C standard library typedef int bool; #define true 1 #define false 0</p><p>// Based on "stdio.h" int puts(char *); char *gets(char *); int getchar(); int printf(char *, ...); int sprintf(char *, char *, ...); int snprintf(char *, int, char *, ...); int scanf(char *, ...); int sscanf(char *, char *, ...); int vprintf(char *, va_list); int vsprintf(char *, char *, va_list); int vsnprintf(char *, int, char *, va_list); int vscanf(char *, va_list); int vsscanf(char *, char *, va_list);</p><p>// Based on "stdlib.h" of C standard library #define NULL 0</p><p>int atoi(char *); int atol(char *); int strtol(char *,char **,int); int strtoul(char *,char **,int); void *malloc(int); void *calloc(int,int); void *realloc(void *,int); void free(void *); int rand(); void srand(int); void abort(); void exit(int); char *getenv(char *); int abs(int); int labs(int);</p><p>// Based on "string.h" of C standard library void *memcpy(void *,void *,int); void *memmove(void *,void *,int); void *memchr(char *,int,int); int memcmp(void *,void *,int); void *memset(void *,int,int); char *strcat(char *,char *); char *strncat(char *,char *,int); char *strchr(char *,int); char *strrchr(char *,int); int strcmp(char *,char *); int strncmp(char *,char *,int); int strcoll(char *,char *); char *strcpy(char *,char *); char *strncpy(char *,char *,int); char *strerror(int); int strlen(char *); int strspn(char *,char *); int strcspn(char *,char *); char *strpbrk(char *,char *); char *strstr(char *,char *); char *strtok(char *,char *); int strxfrm(char *,char *,int);</p><p>// Based on "time.h" of C standard library typedef int time_t; typedef int clock_t;</p><p>struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; };</p><p>char *asctime(struct tm *); char *ctime(int *); struct tm *gmtime(int *); struct tm *localtime(int *); int mktime(struct tm *ptm); int strftime(char *, int, char *, struct tm *);</p><p>// Based on "sockets.h" of lwIP #define AF_UNSPEC_networkLibrary 0 #define AF_INET_networkLibrary 2 #define SOCK_STREAM_networkLibrary 1 #define SOCK_DGRAM_networkLibrary 2 #define SOCK_RAW_networkLibrary 3 #define IPPROTO_IP_networkLibrary 0 #define IPPROTO_TCP_networkLibrary 6 #define IPPROTO_UDP_networkLibrary 17</p><p>#define O_NONBLOCK_networkLibrary 1 #define F_GETFL_networkLibrary 3 #define F_SETFL_networkLibrary 4</p><p>#define EAGAIN_networkLibrary 11</p><p>#define MSG_PEEK_networkLibrary 0x01 #define MSG_DONTWAIT_networkLibrary 0x08</p><p>struct in_addr { unsigned long s_addr; };</p><p>struct sockaddr_in { unsigned char sin_len; unsigned char sin_family; unsigned short sin_port; struct in_addr sin_addr; char sin_zero[8]; } sockaddr_in;</p><p>typedef struct fd_set { unsigned char fd_bits [(8+7)/8]; } fd_set;</p><p>int accept(int, struct sockaddr *, unsigned long *); int bind(int, struct sockaddr *, unsigned long); int shutdown(int, int); int getpeername(int, struct sockaddr *, unsigned long *); int getsockname(int, struct sockaddr *, unsigned long *); int getsockopt(int, int, int, void *, unsigned long *); int setsockopt(int, int, int, void *, unsigned long); int close(int); int connect(int, struct sockaddr *, unsigned long); int listen(int, int); int recv(int, void *, unsigned long, int); int recvfrom(int, void *, unsigned long, int, struct sockaddr *, unsigned long *); int send(int, void *, unsigned long, int); int sendto(int, void *, unsigned long, int, struct sockaddr *, unsigned long); int socket(int, int, int); int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); int fcntl(int, int, int); int inet_addr(char *); unsigned short htons(unsigned short);</p><p>// Regarding WizFi250-WiFi /** * Joins a Wi-Fi network * ssid : A null terminated string containing the SSID name of the network to join * auth_type : Authentication type: * open - Open Security * wep - WEP Security * wpa2_tkip - WPA2 Security using TKIP cipher * wpa2_aes - WPA2 Security using AES cipher * wpa2 - WPA2 Security using AES and/or TKIP ciphers * wpa_aes - WPA Security using AES cipher * wpa_tkip - WPA Security using TKIP ciphers * key : Security key * ip : String of IP address string (if 0, DHCP will be applied.) * netmask : String of netamsk string * gateway : String of gateway address string * 0(Success), the others(Fail) */ int wifi_join(char* ssid, char* auth_type, char* key, char* ip, char* netmask, char* gateway);</p><p>/** * Disassociates from a Wi-Fi network. * None */ int wifi_leave();</p><p>// Regarding WizFi250-Hardware /** * Initialises a GPIO pin * gpio : the gpio pin which should be initialised * GPIO1, GPIO6, GPIO7, GPIO8, GPIO9, GPIO12(LED), GPIO13(LED), GPIO14 * type : A structure containing the required gpio configuration 0 : INPUT_PULL_UP : Input with an internal pull-up resistor - use with devices that actively drive the signal low - e.g. button connected to ground 1 : INPUT_PULL_DOWN : Input with an internal pull-down resistor - use with devices that actively drive the signal high - e.g. button connected to a power rail 2 : INPUT_HIGH_IMPEDANCE : Input - must always be driven, either actively or by an external pullup resistor 3 : OUTPUT_PUSH_PULL : Output actively driven high and actively driven low - must not be connected to other active outputs - e.g. LED output 4 : OUTPUT_OPEN_DRAIN_NO_PULL : Output actively driven low but is high-impedance when set high - can be connected to other open-drain/open-collector outputs. Needs an external pull-up resistor 5 : OUTPUT_OPEN_DRAIN_PULL_UP : Output actively driven low and is pulled high with an internal resistor when set high - can be connected to other open-drain/open-collector outputs. * None */ void pinMode(int gpio, int type);</p><p>/** * Sets an output GPIO pin low or hign * gpio : the gpio pin which should be set * GPIO1, GPIO6, GPIO7, GPIO8, GPIO9, GPIO12, GPIO13, GPIO14 * value : 0(low) or 1(high) * None */ void pinOut(int gpio, int value);</p><p>/** * Get the state of an input GPIO pin * gpio : the gpio pin which should be read * GPIO1, GPIO6, GPIO7, GPIO8, GPIO9, GPIO12, GPIO13, GPIO14 * 0(low) or 1(high) */ int pinIn(int);</p><p>/** * Transmit data on a UART interface * uart : the UART interface. UART1, UART2. * data : pointer to the start of data * size : number of bytes to transmit * None */ void uart_tx(int uart, unsigned char* data, int size);</p><p>/** * Takes a single sample from an ADC interface * adc : the interface which should be sampled AD1(Currently, WizFi250-CSI support one ADC) * a variable which will receive the sample (0 ~ 4095) */ int analogRead(int adc);</p><p>/** * Receive data on a UART interface * uart : the UART interface. UART1, UART2. * data : pointer to the buffer which will store incoming data * size : number of bytes to receive * number of received bytes */ int uart_rx(int uart, unsigned char* data, int size);</p><p>/** * Sleep for a given period * milliseconds : the time to sleep in milliseconds * None */ void delay_ms(unsigned long milliseconds);</p>