Network Ethernet Library, error in example [OK]

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Network Ethernet Library, error in example [OK]

#1 Post by Dany » 03 Aug 2014 11:11

Addition 2014-08-06: see the next post for rectification. I misinterpreted the expression "memcmp(@getRequest, @tmp, 5)" when assumed as boolean.

--------------------------------------------------------------------------------------------------------------------

Hi, I found some wrong code I think in the Network Ethernet Library example for the ENC28J60 (but also present in the other 2 versions), in file HTTP_Demo_28j60.mpas, routine Net_Ethernet_28j60_UserTCP.

The code in the example is:

Code: Select all

// only GET method is supported here
if(memcmp(@getRequest, @tmp, 5)and(socket^.state <> 3)) then exit;
The above statement is only true (resulting in an exit of the routine) if, by any chance the result of expression "memcmp(@getRequest, @tmp, 5)" is 255! (=true in mP). Since the result of memcmp is the ascii code of the first different character discovered in the two strings compared, this chance is virtually non existant. So, the and function will also never be true...

The only correct statement here should be:

Code: Select all

if(socket^.state <> 3) then exit;
// leave out the getrequest compare statement
(the getrequest should not cause an exit because that would mean that only the first buffer of the webpage would be sent...)[/color][/i]
Last edited by Dany on 24 Aug 2014 19:13, edited 3 times in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Network Ethernet Library, error in example.

#2 Post by Dany » 06 Aug 2014 18:34

I discovered that my post above is wrong, the statement

Code: Select all

if(memcmp(@getRequest, @tmp, 5)and(socket^.state <> 3)) then exit;
is exactly the same as

Code: Select all

if((memcmp(@getRequest, @tmp, 5) <> 0) and (socket^.state <> 3)) then exit;
meaning:
if "string tmp is not "GET /" and "the socket is no longer open" then exit. I hope this makes sense.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

wisemanchifita
Posts: 5
Joined: 25 Jan 2017 16:06

Re: Network Ethernet Library

#3 Post by wisemanchifita » 11 Feb 2017 14:50

Guys i need help, Trying to use Net Ethernet library as a HTTP Client but it not responding........Code given below
////////////////////////////////////////////////////////////////////// C File
#include "__NetEthEnc28j60.h"

// mE ehternet NIC pinout
sfr sbit Net_Ethernet_28j60_Rst at LATB3_bit;
sfr sbit Net_Ethernet_28j60_CS at LATB2_bit;
sfr sbit Net_Ethernet_28j60_Rst_Direction at TRISB3_bit;
sfr sbit Net_Ethernet_28j60_CS_Direction at TRISB2_bit;
// end ethernet NIC definitions

unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f}; // my MAC address
unsigned char myIpAddr[4] = {10, 1, 1, 100 }; // my IP address
unsigned char gwIpAddr[4] = {10, 1, 1, 254 }; // gateway (router) IP address
unsigned char ipMask[4] = {255, 255, 255, 0 }; // network mask (for example : 255.255.255.0)
unsigned char dnsIpAddr[4] = {196, 12, 12, 65 }; // DNS server IP address

unsigned char ServerIpAddr[4] = {10, 1, 1, 4 }; // {160, 153, 128, 24 }

int mark = 0,
buffer = 0;
char sendF = 0;
unsigned char MessgaeBuffer[160],cnt = 0,i = 0;
SOCKET_28j60_Dsc *socketConnection; // HTTP request buffer
//unsigned char dyna[31] ;

////////////////////////////////////////////////////////////////////////////////
// // User musto set values of global variables in _Lib_NetEthEnc24j600_Defs.c file: !!!!!
/*
NUM_OF_SOCKET_28j60 = 7; // Max number of socket We can open.
TCP_TX_SIZE_28j60 = 256; // Size of Tx buffer in RAM.
MY_MSS_28j60 = 30; // Our maximum segment size.
SYN_FIN_WAIT_28j60 = 1; // Wait-time (in second) on remote SYN/FIN segment.
RETRANSMIT_WAIT_28j60 = 1; // Wait-time (in second) on ACK which we expect.
*/
////////////////////////////////////////////////////////////////////////////////
const code char dat[] = "This is simple TCP client example\nmikroElektronika\n ";

unsigned int dat_pos = 0,mark1;
char packetC = 0;
//void Net_Ethernet_28j60_UserTCP(SOCKET_28j60_Dsc *socket) {
void Net_Ethernet_28j60_UserTCP(SOCKET_28j60_Dsc *socket_28j60) {
if (sendF){
while(1){
if(Net_Ethernet_28j60_putByteTCP('m', socket_28j60) == 0) {
//OK
sendF = 0;
break;
}
}
}

}

////////////////////////////////////////////////////////////////////////////////

unsigned int Net_Ethernet_28j60_UserUDP(UDP_28j60_Dsc *udpDsc) {
return(0);
}
// Interrupt routine
void interrupt() {
if(TMR0IF_bit == 1)
{
cnt++;
if(cnt == 6) //1sec
{
cnt = 0;
Net_Ethernet_28j60_UserTimerSec++; //Makes SPI_Ethernet_sendUDP to work
//Net_Ethernet_28j60_timerTCP++;
//Flag = 1;
}
TMR0H = 0XE1;
TMR0L = 0X7D;
TMR0IF_bit = 0;

}
}


void main() {
Delay_ms(2000);
ADCON0 = 0X00; //A/D converter module is disabled
ADCON1 |= 0x0F ; //no analog inputs,Set all to digital
CMCON |= 0x07 ; //turn off comparators
CCP2CON = 0X00;
CCP1CON = 0X00; //Disable Pulse width modulation
UTRDIS_bit = 1; //On-chip transceiver disabled; Enable RC4 and RC5 as digital pins. NOTE!!!! in datasheet they can only be inputs
TRISA0_bit = 1;

T08BIT_bit = 0; //16 bit counter
T0CS_bit = 0;
PSA_bit = 0; //Timer0 clock input from prescaler
T0PS0_bit = 1; //
T0PS1_bit = 1; //Prescaler 1:256
T0PS2_bit = 1; //
TMR0H = 0XE1;
TMR0L = 0X7D;
INTCON = 0XC0;
TMR0IE_bit = 1;
TMR0ON_bit = 1; //Switch on TMR0


SPI1_Init();
SPI_Rd_Ptr = SPI1_Read;
Net_Ethernet_28j60_Init(myMacAddr, myIpAddr, 1); // init ethernet board
Net_Ethernet_28j60_confNetwork(ipMask, gwIpAddr, dnsIpAddr);
Delay_ms(1000);
Net_Ethernet_28j60_stackInitTCP();


while(1)
{
Net_Ethernet_28j60_doPacket();
if (PORTA.RA0 == 1 && mark == 0){
mark = 1;
Net_Ethernet_28j60_connectTCP(ServerIpAddr, 80, 80, &socketConnection);
//Lcd_Out(1, 1, "Connect");
sendF = 1;
}
if(( socketConnection->state == 3 ) && (mark==1)) {
mark = 0;
Net_Ethernet_28j60_startSendTCP(socketConnection);
//Lcd_Out(2, 1, "Send");
}
else{
mark = 0;
}
if (PORTA.RA0 == 1){
Net_Ethernet_28j60_startSendTCP(socketConnection);
sendF = 1;
}
}
}

/////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////__Lib_NetEthEnc28j60_Defs.c
#include "__NetEthEnc28j60.h"

const char ARPCACHESIZE_28j60 = 3; // Size of arpcache.
Net_Ethernet_28j60_arpCacheStruct Net_Ethernet_28j60_arpCache[ARPCACHESIZE_28j60];

const char NUM_OF_SOCKET_28j60 = 1; // Max number of socket We can open.
const unsigned int TCP_TX_SIZE_28j60 = 512; // Size of Tx buffer in RAM.
const unsigned int MY_MSS_28j60 = 1360; // Our maximum segment size.
const unsigned int SYN_FIN_WAIT_28j60 = 2; // Wait-time (in second) on remote SYN/FIN segment.
const unsigned int RETRANSMIT_WAIT_28j60 = 3; // Wait-time (in second) on ACK which we expect.

char tx_buffers_28j60[NUM_OF_SOCKET_28j60][TCP_TX_SIZE_28j60]; // Tx buffers. Every socket has its buffer.

UDP_28j60_Dsc udpRecord_28j60; // This record contains properties of last received UDP packet.

SOCKET_28j60_Dsc socket_28j60[NUM_OF_SOCKET_28j60]; // This record contains properties of each socket.

///////////////////////////////////////////////////////////////////////////////////////

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Network Ethernet Library, error in example [OK]

#4 Post by dusan.poluga » 13 Feb 2017 15:53

Hi,

What development system do you use this board with?

Regards,
Dusan Poluga.

wisemanchifita
Posts: 5
Joined: 25 Jan 2017 16:06

Re: Network Ethernet Library, error in example [OK]

#5 Post by wisemanchifita » 13 Feb 2017 16:53

I am using PIC18F2550 , MicroC for pic to program

wisemanchifita
Posts: 5
Joined: 25 Jan 2017 16:06

Re: Network Ethernet Library, error in example [OK]

#6 Post by wisemanchifita » 13 Feb 2017 16:54

i built my own development board

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Network Ethernet Library, error in example [OK]

#7 Post by dusan.poluga » 13 Feb 2017 17:14

Hi,

Please submit a ticket on our site.
Here is the link:
http://helpdesk.mikroe.com/

Regards,
Dusan Poluga.

Post Reply

Return to “mikroPascal PRO for PIC General”