📄 picnic.h
字号:
/*
* picnic.h
*
* Include file for picnic project
*
*/
//Auto checks the compiler type and select the device
//For total portability between 16f877 and 18f452
//STILL does not work for 16F877
//TODO: Make it fully workful under 16F877
//#fuses HS,NOWDT,NOPROTECT
#if defined(__PCM__)
#include <16F877.h>
#elif defined(__PCH__)
#include <18F452.h>
#endif
//If not using IRQs and using Ivar's Bootloader, uncomment this line not to overwrite the Bootloader
//#org 0x0004, 0x0008 {}
//Reserves PIC Flash not to overwrite Ivar's Bootloader
//#if defined(__PCM__)
// #ORG 0x3E98,0x3FFF {} //16F877
//#elif defined(__PCH__)
// #ORG 0x7D32,0x7FFF {} //18F452
//#endif
//If we're not using irqs we need those lines also too keep bootloader safe in flash memory
//#int_global
//void dummy() {}
//Tell the compiler to use 16 bit pointer and 8 bit resolution on the adc
#DEVICE *=16 ADC=8
//Set clock speed
#use delay(clock=CLOCK_SPEED)
//Turn the serial port on with 19200bps 8N1
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
//Para comunicar com o outro PIC
//#use rs232(baud=19200, xmit=PIN_B6, rcv=PIN_B7, invert, stream=GEOSHOW)
//invert usado pq eh pic a pic sem max232 no meio
//Enable functions for reading the temperature sensor, if the "user" wants
#ifdef ENABLE_TEMPERATURE
#include <1wire.c>
#include <ds1820.c>
#endif
//Turn compiler case sensivity on
#case
//Important definitions
#define byte int8
#define READ FALSE
#define WRITE TRUE
//Set I/O mode
#use fast_io(A)
#use fast_io(B)
#use fast_io(D)
#use fast_io(E)
//IP Address Structure
typedef struct {
int8 ip0;
int8 ip1;
int8 ip2;
int8 ip3;
} IP_ADDR;
//MAC Address Structure
typedef struct {
int8 mac0;
int8 mac1;
int8 mac2;
int8 mac3;
int8 mac4;
int8 mac5;
} MAC_ADDR;
//Node Structure (A host MAC Address + IP Address)
typedef struct {
MAC_ADDR MACAddr;
IP_ADDR IPAddr;
} NODE_INFO;
//A 16-Bit Word Type divided in Most Significant and Least Significant
typedef struct {
int8 LSB;
int8 MSB;
} WORD_VAL;
//Double Word Type
typedef struct _DWORD_VAL {
int8 LOLSB;
int8 LOMSB;
int8 HILSB;
int8 HIMSB;
} DWORD_VAL;
//14 Bytes Ethernet Header
struct _ETHERNET_HEADER {
int8 mac_dest[6];
int8 mac_source[6];
int16 type; //ip=0x8000, arp=0x0806, etc.
} ETHERNET_HEADER;
//COXAMBRA: Para casa do futuro
//14 Bytes Ethernet Header
struct __ETHERNET_HEADER {
int8 mac_dest[6];
int8 mac_source[6];
int16 type; //ip=0x8000, arp=0x0806, etc.
} SERVER_ETHERNET_HEADER;
//20 Bytes IP Header
typedef struct {
int8 VersionIHL;
int8 TypeOfService; //Tos
int16 TotalLength;
int16 Identification;
int16 FragmentInfo;
int8 TimeToLive; //TTL
int8 Protocol;
int16 HeaderChecksum;
IP_ADDR SourceAddress;
IP_ADDR DestAddress;
} _IP_HEADER;
//ARP Packet Structure
typedef struct {
int16 HardwareType;
int16 Protocol;
int8 MACAddrLen;
int8 ProtocolLen;
int16 Operation;
MAC_ADDR SenderMACAddr;
IP_ADDR SenderIPAddr;
MAC_ADDR TargetMACAddr;
IP_ADDR TargetIPAddr;
} _ARP_PACKET;
//TCP Header
typedef struct {
int16 SourcePort;
int16 DestPort;
int32 SeqNumber;
int32 AckNumber;
//int8 tcp_options;
//int8 offset;
struct _dataoffset {
int1 reserved3 :4;
int1 val :4;
} dataoffset;
struct _Flags {
int1 flagFIN : 1;
int1 flagSYN : 1;
int1 flagRST : 1;
int1 flagPSH : 1;
int1 flagACK : 1;
int1 flagURG : 1;
int1 Reserved2 : 2;
} Flags;
int16 Window;
int16 Checksum;
int16 UrgentPointer;
} _TCP_HEADER;
//Possible TCP States
enum tcp_states {
LISTEN,
SYN_SENT,
SYN_RCVD,
ESTAB,
FIN_WAIT_1,
FIN_WAIT_2,
CLOSING,
TIME_WAIT,
CLOSE_WAIT,
LAST_ACK,
CLOSED
};
//Protocols Definitions
//What the Ethernet Frame can carry
#define ARP 0x0806
#define IP 0x0800
//What the IP Packet can carry
#define ICMP 0x01
#define TCP 0x06
#define UDP 0x17
//ICMP Packet Flags
#define ECHO 0x08
#define REPLY 0x00
//TCP Packet Flags
#define TCP_FIN 0x01
#define TCP_SYN 0x02
#define TCP_RST 0x04
#define TCP_PSH 0x08
#define TCP_ACK 0x10
#define TCP_URG 0x20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -