This demonstrates the process of communicating through ethernet to a SEL-2431 Voltage Regulator Control Panel using SEL Fast Message. Basic device commands and data cna be requested and displayed over a connected serial port. This is a basic version and full testing and documentation has yet to be completed.
Dependencies: BufferedSerial analogAverager voltageRegulator netStatReg analogMinMax CounterMinMax
Diff: main.cpp
- Revision:
- 3:ac1f2af8bd0f
- Parent:
- 2:ec972966689e
- Child:
- 4:98cdccfb17d6
--- a/main.cpp Wed Sep 11 19:02:43 2019 +0000 +++ b/main.cpp Mon Sep 16 14:17:45 2019 +0000 @@ -7,6 +7,8 @@ #include "TCPServer.h" #include "TCPSocket.h" #include "BufferedSerial.h" +#include "nettime.h" +#include "netdevices.h" #define HTTP_STATUS_LINE "HTTP/1.0 200 OK" #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" @@ -31,16 +33,7 @@ Ticker nettimer[2]; -struct netsys -{ - TCPServer srv; - TCPSocket clt_sock; - SocketAddress clt_addr; - int tcpport; - bool isactive; - bool closeconnection; - int sockalivetime; -} net1,nets,http1; +struct netsys net1,nets,http1; bool polltick; @@ -52,7 +45,8 @@ //Provides the deivce poll timing void heartbeat() { - polltick=true; + //polltick=true; + setTick(true); } //Provides the timeout for ethernet to serial communications @@ -60,7 +54,7 @@ { if (net2->isactive==true) { - if (net2->sockalivetime==30) + if (net2->sockalivetime==300) { net2->closeconnection=true; net2->sockalivetime=0; @@ -177,9 +171,9 @@ /* Setup Ethernet to Serial Connection Thread */ conchkthread[0].start(callback(conchk,&net1)); /* Setup Ethernet to Serial Timeout Ticker */ - nettimer[0].attach(callback(nettimeout,&net1),1); + nettimer[0].attach_us(callback(nettimeout,&net1),100000); /* Setup polltick Ticker */ - nettimer[1].attach(heartbeat,10); + nettimer[1].attach_us(heartbeat,10000); /* Setup Ethernet to Serial transmit data Thread */ rxtxdatathread[0].start(callback(datanrx,&net1)); /* Setup Ethernet to Serial receive data Thread */ @@ -187,7 +181,22 @@ /* Setup Web Server Connection Thread */ conchkthread[1].start(callback(conchk,&http1)); + unsigned int polltime=200; + unsigned int currenttime=0; + unsigned int polltimeout=200; + while (true) { + + polltick=getTick(); + //polltime=getTime(); + + if (polltick) + { + setTick(false); + incTime(); + currenttime=getTime(); + } + if (net1.isactive) { if (net1.closeconnection==true) @@ -199,9 +208,11 @@ } } - if (polltick) + //if (polltick) + if (polltime==currenttime) { - polltick=false; + //polltick=false; + polltime=getTime()+polltimeout; printf("Enter_Tick\r\n"); ret = nets.clt_sock.open(ð); printf("Socket%d\r\n",ret);