Re: Arduino Mega Server
Добавлено: Чт апр 06, 2017 10:34 am
OFF TOP. Это еще раз к вопросу поиска по форуму ))).
Код: Выделить всё
// W5100
#include <Ethernet.h>
#include <EthernetUdp.h>
// W5500
//#include <Ethernet2.h>
//#include <EthernetUdp2.h> Код: Выделить всё
#define ETHERNET_LIBRARY Код: Выделить всё
// 0 - W5100
// 1 - W5500
switch (ETH) {
label 0:
#include <Ethernet.h>
#include <EthernetUdp.h>
break;
label 1:
#include <Ethernet2.h>
#include <EthernetUdp2.h>
break;
default:
#include <Ethernet.h>
#include <EthernetUdp.h>
}Значения можно хранить на SD. Можно просто поправить 0 на 1Alex писал(а):Ответ никуда не годится — если у человека не тот шилд, то он вообще никогда не получит доступа к веб-странице, потому что АМС просто не запустится.
Да честно говоря удивлен,#include то директива препроцессора,а switch это исполняемая инструкция,чувствуете разницу?switch (ETH) {
label 0:
#include <Ethernet.h>
#include <EthernetUdp.h>
break;
label 1:
#include <Ethernet2.h>
#include <EthernetUdp2.h>
break;
default:
#include <Ethernet.h>
#include <EthernetUdp.h>
}
Alex вы ведь писали код у Вас там прямо напичкано директивами условной компиляции,тогда у вас все работало,а почему сейчас нет?Наконец-то у знатоков С и системного программирования появилась возможность блеснуть своими знаниями и перейти от декларативных заявлений к делу.
#ifdef SD_INFO_FEATURE
sdInfoInit();
#endif
#define STACK_USE_REBOOT_SERVERвот пример включения целого файла через директиву
#if defined(STACK_USE_REBOOT_SERVER)
#include "TCPIP Stack/TCPIP.h"
#define REBOOT_PORT 69 // UDP TFTP port
// For improved security, you might want to limit reboot capabilities
// to only users on the same IP subnet. Define REBOOT_SAME_SUBNET_ONLY
// to enable this access restriction.
#define REBOOT_SAME_SUBNET_ONLY
extern NODE_INFO remoteNode;
/*********************************************************************
* Function: void RebootTask(void)
*
* PreCondition: Stack is initialized()
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: Checks for incomming traffic on port 69.
* Resets the PIC if a 'R' is received.
*
* Note: This module is primarily for use with the
* Ethernet bootloader. By resetting, the Ethernet
* bootloader can take control for a second and let
* a firmware upgrade take place.
********************************************************************/
void RebootTask(void)
{
static UDP_SOCKET MySocket = INVALID_UDP_SOCKET;
struct
{
BYTE vMACAddress[6];
DWORD dwIPAddress;
WORD wChecksum;
} BootloaderAddress;
if(MySocket == INVALID_UDP_SOCKET)
MySocket = UDPOpen(REBOOT_PORT, NULL, INVALID_UDP_PORT);
if(MySocket == INVALID_UDP_SOCKET)
return;
// Do nothing if no data is waiting
if(!UDPIsGetReady(MySocket))
return;
#if defined(REBOOT_SAME_SUBNET_ONLY)
// Respond only to name requests sent to us from nodes on the same subnet
if((remoteNode.IPAddr.Val & AppConfig.MyMask.Val) != (AppConfig.MyIPAddr.Val & AppConfig.MyMask.Val))
{
UDPDiscard();
return;
}
#endif
// Get our MAC address, IP address, and compute a checksum of them
memcpy((void*)&BootloaderAddress.vMACAddress[0], (void*)&AppConfig.MyMACAddr.v[0], sizeof(AppConfig.MyMACAddr));
BootloaderAddress.dwIPAddress = AppConfig.MyIPAddr.Val;
BootloaderAddress.wChecksum = CalcIPChecksum((BYTE*)&BootloaderAddress, sizeof(BootloaderAddress) - sizeof(BootloaderAddress.wChecksum));
// To enter the bootloader, we need to clear the /POR bit in RCON.
// Otherwise, the bootloader will immediately hand off execution
// to us.
#if defined(USE_LCD)
strcpypgm2ram((char*)LCDText, "Bootloader Reset");
LCDUpdate();
#endif
RCONbits.POR = 0;
#if defined(__18CXX)
{
WORD_VAL wvPROD;
wvPROD.Val = ((WORD)&BootloaderAddress);
PRODH = wvPROD.v[1];
PRODL = wvPROD.v[0];
}
#endif
Reset();
}
#endif //#if defined(STACK_USE_REBOOT_SERVER)