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

Files at this revision

API Documentation at this revision

Comitter:
masterkookus
Date:
Mon Sep 16 14:17:45 2019 +0000
Parent:
2:ec972966689e
Child:
4:98cdccfb17d6
Commit message:
Added basic system timer and moving devices to new file

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
netdevices.h Show annotated file Show diff for this revision Revisions of this file
nettime.cpp Show annotated file Show diff for this revision Revisions of this file
nettime.h Show annotated file Show diff for this revision Revisions of this file
--- 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(&eth);
             printf("Socket%d\r\n",ret);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netdevices.h	Mon Sep 16 14:17:45 2019 +0000
@@ -0,0 +1,11 @@
+
+struct netsys 
+{ 
+    TCPServer srv;
+    TCPSocket clt_sock;
+    SocketAddress clt_addr;
+    int tcpport;
+    bool isactive;
+    bool closeconnection;
+    int sockalivetime;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nettime.cpp	Mon Sep 16 14:17:45 2019 +0000
@@ -0,0 +1,24 @@
+#include "nettime.h"
+
+static volatile unsigned int timerval = 0;
+static volatile bool tickflag = false;
+
+int getTime(void)
+{
+    return timerval;
+}
+
+bool getTick(void)
+{
+    return tickflag;
+}
+
+void setTick(bool tickval)
+{
+    tickflag = tickval;
+}
+
+void incTime(void)
+{
+    timerval=timerval+1;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nettime.h	Mon Sep 16 14:17:45 2019 +0000
@@ -0,0 +1,4 @@
+int getTime(void);
+void incTime(void);
+bool getTick(void);
+void setTick(bool);
\ No newline at end of file