|
|
@ -3,13 +3,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <avr/wdt.h> // ??
|
|
|
|
#include <avr/wdt.h> // ??
|
|
|
|
|
|
|
|
|
|
|
|
#include "SC_AI.h" // Differential analog input collector
|
|
|
|
//#include "SC_AI.h" // Differential analog input collector
|
|
|
|
#include "SC_MC9.h" // MC9 Tempreture Controller
|
|
|
|
//#include "SC_MC9.h" // MC9 Tempreture Controller
|
|
|
|
|
|
|
|
|
|
|
|
#define RcvOK "OK\r\n"
|
|
|
|
#define RcvOK "OK\r\n"
|
|
|
|
#define RcvErr "ER\r\n"
|
|
|
|
#define RcvErr "ER\r\n"
|
|
|
|
#define MODE_DEBUG false
|
|
|
|
#define MODE_DEBUG false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String demuxCMD(String command, String* rightPart);
|
|
|
|
|
|
|
|
int demuxNum(String rightPart, unsigned int data[]);
|
|
|
|
|
|
|
|
|
|
|
|
// Enter a MAC address and IP address for your controller below.
|
|
|
|
// Enter a MAC address and IP address for your controller below.
|
|
|
|
// The IP address will be dependent on your local network.
|
|
|
|
// The IP address will be dependent on your local network.
|
|
|
|
// gateway and subnet are optional:
|
|
|
|
// gateway and subnet are optional:
|
|
|
@ -33,9 +36,14 @@ bool connection = false;
|
|
|
|
char buffer[1024];
|
|
|
|
char buffer[1024];
|
|
|
|
|
|
|
|
|
|
|
|
int Size_AI = 16;
|
|
|
|
int Size_AI = 16;
|
|
|
|
int AI_VALUES[] = {
|
|
|
|
int Values_AI[16];
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
int Size_PV = 8;
|
|
|
|
};
|
|
|
|
int Values_PV[8];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String Buf_485;
|
|
|
|
|
|
|
|
bool Wait_485;
|
|
|
|
|
|
|
|
int Wait_485_cnt;
|
|
|
|
|
|
|
|
|
|
|
|
int msCnt = 0;
|
|
|
|
int msCnt = 0;
|
|
|
|
unsigned long timer = 0;
|
|
|
|
unsigned long timer = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -47,8 +55,8 @@ void setup() {
|
|
|
|
TCPIP_setup(mac, ip, gateway, subnet);
|
|
|
|
TCPIP_setup(mac, ip, gateway, subnet);
|
|
|
|
|
|
|
|
|
|
|
|
// scitech korea Library
|
|
|
|
// scitech korea Library
|
|
|
|
SC_AI_setup();
|
|
|
|
GPIO_setup();
|
|
|
|
SC_MC9_setup();
|
|
|
|
MC9_setup();
|
|
|
|
|
|
|
|
|
|
|
|
// Timer set
|
|
|
|
// Timer set
|
|
|
|
MsTimer2::set(10, periodic_10ms);
|
|
|
|
MsTimer2::set(10, periodic_10ms);
|
|
|
@ -77,7 +85,8 @@ void loop() {
|
|
|
|
webReponse();
|
|
|
|
webReponse();
|
|
|
|
client = server.available();
|
|
|
|
client = server.available();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Prcss_SV();
|
|
|
|
|
|
|
|
//delay(100);
|
|
|
|
if (client) {
|
|
|
|
if (client) {
|
|
|
|
// check if client is connected
|
|
|
|
// check if client is connected
|
|
|
|
Serial.println("Client Connected!!!");
|
|
|
|
Serial.println("Client Connected!!!");
|
|
|
@ -90,31 +99,49 @@ void loop() {
|
|
|
|
// check for command byte
|
|
|
|
// check for command byte
|
|
|
|
if (client.available() > 0) {
|
|
|
|
if (client.available() > 0) {
|
|
|
|
char c;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
bool cr = false;
|
|
|
|
|
|
|
|
|
|
|
|
String command;
|
|
|
|
String command;
|
|
|
|
String cmd;
|
|
|
|
String cmd;
|
|
|
|
unsigned int data[32];
|
|
|
|
unsigned int data[32];
|
|
|
|
|
|
|
|
String message;
|
|
|
|
int dataSize;
|
|
|
|
int dataSize;
|
|
|
|
|
|
|
|
|
|
|
|
busy = true;
|
|
|
|
busy = true;
|
|
|
|
// Read message by byte
|
|
|
|
// Read message by byte
|
|
|
|
while ((c = client.read())) {
|
|
|
|
while ((c = client.read())) {
|
|
|
|
// Read data until LF or CR
|
|
|
|
|
|
|
|
if((c != 10) && (c != 13)){
|
|
|
|
// Read data until CR or LF
|
|
|
|
command += c;
|
|
|
|
if((c != 13) && (c != 10)){
|
|
|
|
|
|
|
|
command += c;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd = demuxCMD(command, data, &dataSize);
|
|
|
|
// -------------------- Process CMD -------------------- //
|
|
|
|
|
|
|
|
cmd = demuxCMD(command, &message);
|
|
|
|
|
|
|
|
|
|
|
|
if(cmd=="AI"){
|
|
|
|
if(cmd=="AI"){
|
|
|
|
client.print(Prcss_AI());
|
|
|
|
client.print(Prcss_AI());
|
|
|
|
|
|
|
|
|
|
|
|
}else if(cmd=="AO"){
|
|
|
|
}else if(cmd=="AO"){
|
|
|
|
|
|
|
|
dataSize = demuxNum(message, data);
|
|
|
|
client.print(Prcss_AO(data, dataSize));
|
|
|
|
client.print(Prcss_AO(data, dataSize));
|
|
|
|
}else{
|
|
|
|
}else if(cmd=="PV"){
|
|
|
|
client.print(RcvErr);
|
|
|
|
client.print(Prcss_PV());
|
|
|
|
|
|
|
|
}else if(cmd=="SV"){
|
|
|
|
|
|
|
|
client.print(Prcss_SV());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else if(cmd=="RS"){
|
|
|
|
|
|
|
|
client.print(Prcss_RS(message));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}//else if(cmd==""){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
client.print(cmd + " " + RcvErr);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -141,7 +168,7 @@ void loop() {
|
|
|
|
Serial.println("Client Disconnected...");
|
|
|
|
Serial.println("Client Disconnected...");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -154,32 +181,10 @@ void TCPIP_setup(byte mac[], IPAddress ip, IPAddress gateway, IPAddress subnet){
|
|
|
|
web.begin();
|
|
|
|
web.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void periodic_10ms(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msCnt += 10;
|
|
|
|
|
|
|
|
if(!busy){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SC_AI(AI_VALUES, Size_AI);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// periodic_1s
|
|
|
|
|
|
|
|
if (msCnt > 1000){
|
|
|
|
|
|
|
|
msCnt = 0;
|
|
|
|
|
|
|
|
periodic_1s();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void periodic_1s(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//AnalogIn_Print();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AnalogIn_Print(){
|
|
|
|
void AnalogIn_Print(){
|
|
|
|
for (int i = 0; i < Size_AI; i++) {
|
|
|
|
for (int i = 0; i < Size_AI; i++) {
|
|
|
|
Serial.print(AI_VALUES[i]);
|
|
|
|
Serial.print(Values_AI[i]);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print("\t");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|