Compare commits

..

2 Commits

Author SHA1 Message Date
Changwoo Park a4f7011864 AI read : 10ms x 20 samples 2 years ago
Changwoo Park 5834e23263 [Periodics][Init]
- Periodics
  ㄴ Analog read:  0 to 9 pin, 100ms x 50 samples = 500ms time window
- Analog read value
  ㄴ 평균을 위한 복수의 Analog read data를 링 형태로 저장 (기존에는 배열 재정렬, 연산속도 향상 필요)
  ㄴ 평균에 의한 정밀도 향상으로 floating 연산 후 factor 곱하여 송신
- MC9
  ㄴ not responsed 디버그 메시지 주석 (추후 디버그 모드 개발 예정)
- Init
  ㄴ AO, MC9 중복 초기화 방지를 위한 리턴 값 추가
2 years ago

@ -1,24 +1,16 @@
void Ethernet_setup(){
/*
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x00 };
IPAddress ip(192, 168, 20, 177);
IPAddress gateway(192, 168, 20, 1);
IPAddress subnet(255, 255, 255, 0);
*/
uint8_t mac[6] = {MACADDRESS};
uint8_t myIP[4] = {MYIPADDR};
uint8_t myMASK[4] = {MYIPMASK};
uint8_t myDNS[4] = {MYDNS};
uint8_t myGW[4] = {MYGW};
// Mac as unique value by change last byte from ip last value.
//mac[5] = ip[3] & 0xFF;
mac[5] = ip[3] & 0xFF;
// initialize the ethernet device
Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
//web.begin();
web.begin();
// Report address
Serial.print("MAC>>");
@ -36,6 +28,36 @@ void Ethernet_setup(){
Serial.println(Ethernet.localIP());
}
void webReponse(){
EthernetClient webClient = web.available();
if (webClient) {
Serial.println("Web client connected");
while (webClient.connected()) {
if (webClient.available()) {
// 웹 브라우저에서 요청이 도착한 경우
String request = webClient.readStringUntil('\r');
//Serial.println(request);
webClient.flush();
// 웹 브라우저에 출력할 문구 작성
String response = "HTTP/1.1 200 OK\r\n";
response += "Content-Type: text/html\r\n\r\n";
response += "<html><body>";
response += Prcss_AI_Read();
//response += "<h1>Hello, World!</h1>";
response += "</body></html>";
// 문구를 웹 브라우저로 전송
webClient.print(response);
delay(1);
// 클라이언트 연결 종료
webClient.stop();
}
}
}
}
String demuxCMD(String command, String* rightPart) {

@ -1,27 +1,14 @@
#include "Arduino.h"
#include <MsTimer2.h> // MsTimer2 v1.1
//#include <Ethernet2.h> // Ethernet2 v1.0.4
// for ENC28J60
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPClient.h>
// ------------------
#include <Ethernet2.h> // Ethernet2 v1.0.4
#include "GP8403.h"
#define VERSION "240129 1044"
#define COMMENT "MC9 or AO init"
#define VERSION "23-08-08 09:37"
#define COMMENT "AI 10ms x 20"
#define AI_RANGE 10
#define AI_AVG_SIZE 20
/* ---------- Ethernet (ENC) ---------- */
#define MACADDRESS 0x00,0x01,0x02,0x03,0x04,0x05
#define MYIPADDR 192,168,20,177
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,20,1
#define MYGW 192,168,20,1
#define LISTENPORT 5025
/* ---------- Init ---------- */
bool Init_AO = false;
@ -79,10 +66,13 @@ DFRobot_GP8403 AO_14(&Wire,0x5F);
// Data Storage
int RngAO[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
/* ---------- Ethernet (ENC28J60) ---------- */
/* ---------- Ethernet (Ethernet Sheld2) ---------- */
// Ethernet Client
EthernetClient client;
EthernetServer server = EthernetServer(LISTENPORT);
// SCPI defaults to port 5025
EthernetServer server(5025);
// HTTP defaults to port 5025
EthernetServer web(80);
unsigned long lastDataReceivedTime;
unsigned long timeoutPeriod = 5000; // 이더넷 타임아웃 시간 (5초)
@ -91,21 +81,17 @@ bool State_eth = false;
HardwareSerial* Serials[] = {&Serial1, &Serial2};
const int BUFF_SIZE = 512;
const int BUFF_SIZE = 1024;
char Buff_Eth_Rd[BUFF_SIZE] = {0};
char Buff_485_1_Wr[BUFF_SIZE] = {0};
char Buff_485_1_Rd[BUFF_SIZE] = {0};
char Buff_485_2_Wr[BUFF_SIZE] = {0};
char Buff_485_2_Rd[BUFF_SIZE] = {0};
String latest_sent_msg_1;
String latest_sent_msg;
int numOf485 = 0;
int returnTime = 0;
String latest_sent_msg_2;
int numOf485_2 = 0;
int returnTime_2 = 0;
/* ---------- RS485 ---------- */
// 485 CH 1
bool Wait_485_1;
@ -120,9 +106,9 @@ int RS485_1_Values_SV[8*2];
// 485 CH 2
bool Wait_485_2;
int Wait_485_2_cnt;
int RS485_2_Addr[2] = {0,0};
bool RS485_2_Rcv_PV[2] = {false, false};
bool RS485_2_Rcv_SV[2] = {false, false};
int RS485_2_Addr[2];
bool RS485_2_Rcv_PV[2];
bool RS485_2_Rcv_SV[2];
int RS485_2_Rcv_size = 8;
int RS485_2_Values_PV[8*2];
int RS485_2_Values_SV[8*2];
@ -136,13 +122,10 @@ String Prcss_AI_Read();
String Prcss_AO_Write(unsigned int data[], int dataSize);
String Prcss_PV_Read();
String Prcss_SV_Read();
String Prcss_SV_Write_1(unsigned int data[], int dataSize);
String Prcss_AT_Write_1(unsigned int data[], int dataSize);
String Prcss_SV_Write_2(unsigned int data[], int dataSize);
String Prcss_AT_Write_2(unsigned int data[], int dataSize);
String Prcss_SV_Write(unsigned int data[], int dataSize);
String Prcss_AT_Write(unsigned int data[], int dataSize);
String Prcss_RngAO(unsigned int data[], int dataSize);
String Prcss_ChMC9_1(unsigned int data[], int dataSize);
String Prcss_ChMC9_2(unsigned int data[], int dataSize);
String Prcss_ChMC9(unsigned int data[], int dataSize);
//Ethernet
void Ethernet_setup();
@ -152,10 +135,8 @@ int demuxNum(String rightPart, unsigned int data[]);
//RS485
void RS485_setup();
void send_485_1();
void send_485_2();
int recieve_485_1();
int recieve_485_2();
void send_485();
int recieve_485();
void recieve_485_0();
//GPIO
@ -165,13 +146,10 @@ void read_digital();
//MC9
void setupMC9_1(int i, int data);
void setupMC9_2(int i, int data);
String msg_MC9_PV_read(int addr);
String msg_MC9_SV_read(int addr);
int saveMC9_1(String message);
int saveMC9_2(String message);
int timeoutMC9_1();
int timeoutMC9_2();
String msg_MC9_PV(int addr);
String msg_MC9_SV(int addr);
int saveMC9(String message);
int timeoutMC9();
int parseMC9(const String& message, int& addr, String& mode, int data[8], int& crc);
String sumMC9(String input);

@ -10,9 +10,6 @@
String IdeSerial; // for 485_0
void setup() {
// Serial setup (Debug)
Serial.begin(9600);
@ -92,20 +89,11 @@ void loop() {
// MC9
else if(cmd=="SV_1!"){
dataSize = demuxNum(cmdData, data);
client.print(Prcss_SV_Write_1(data, dataSize));
client.print(Prcss_SV_Write(data, dataSize));
}else if(cmd=="AT_1!"){
dataSize = demuxNum(cmdData, data);
client.print(Prcss_AT_Write_1(data, dataSize));
}
else if(cmd=="SV_2!"){
dataSize = demuxNum(cmdData, data);
client.print(Prcss_SV_Write_2(data, dataSize));
}else if(cmd=="AT_2!"){
dataSize = demuxNum(cmdData, data);
client.print(Prcss_AT_Write_2(data, dataSize));
client.print(Prcss_AT_Write(data, dataSize));
}
// Init
@ -118,11 +106,7 @@ void loop() {
Init_AO = true;
}else if(cmd=="ChMC9_1!"){
dataSize = demuxNum(cmdData, data);
client.print(Prcss_ChMC9_1(data, dataSize));
Init_MC9 = true;
}else if(cmd=="ChMC9_2!"){
dataSize = demuxNum(cmdData, data);
client.print(Prcss_ChMC9_2(data, dataSize));
client.print(Prcss_ChMC9(data, dataSize));
Init_MC9 = true;
}

@ -7,15 +7,10 @@ const int MC9_CH[] = {1000, 1008, 1016, 1024, 1100, 1108, 1116, 1124};
void setupMC9_1(int i, int data){
RS485_1_Addr[i] = data;
Serial.println("MC9_1 No."+ String(i) + " 's address set as " + String(data));
Serial.println("MC9 No."+ String(i) + " 's address set as " + String(data));
}
void setupMC9_2(int i, int data){
RS485_2_Addr[i] = data;
Serial.println("MC9_2 No."+ String(i) + " 's address set as " + String(data));
}
String msg_MC9_PV_read(int addr){
String msg_MC9_PV(int addr){
String message = "";
if(addr < 10){
@ -29,7 +24,7 @@ String msg_MC9_PV_read(int addr){
return message;
}
String msg_MC9_SV_read(int addr){
String msg_MC9_SV(int addr){
String message = "";
if(addr < 10){
@ -43,13 +38,10 @@ String msg_MC9_SV_read(int addr){
return message;
}
int msg_MC9_SV_set_1(unsigned int data[], int dataSize){
int msg_MC9_SV_set(unsigned int data[], int dataSize){
String message = "";
int lp0, lp1;
if(dataSize > 16){
dataSize = 16;
}
if(dataSize > 8){
lp0 = 8;
lp1 = dataSize;
@ -99,14 +91,13 @@ int msg_MC9_SV_set_1(unsigned int data[], int dataSize){
}
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_1_Wr, message);
}
return 0;
}
int msg_MC9_AT_set_1(unsigned int data[], int dataSize){
int msg_MC9_AT_set(unsigned int data[], int dataSize){
String message = "";
bool at[16];
@ -135,6 +126,7 @@ int msg_MC9_AT_set_1(unsigned int data[], int dataSize){
}else{
atFlag = "0000"; // Auto Tuen Off
}
message += "0302,"; // Ch No cmd.
message += "000" + String(i+1) + ","; // Ch No.
message += "0501,"; // AT cmd.
@ -145,7 +137,6 @@ int msg_MC9_AT_set_1(unsigned int data[], int dataSize){
}
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_1_Wr, message);
}
@ -176,146 +167,11 @@ int msg_MC9_AT_set_1(unsigned int data[], int dataSize){
message = "" + message + CRLF;
write_buff_first(Buff_485_1_Wr, message);
}
return 0;
}
int msg_MC9_SV_set_2(unsigned int data[], int dataSize){
String message = "";
int lp0, lp1;
if(dataSize > 16){
dataSize = 16;
}
if(dataSize > 8){
lp0 = 8;
lp1 = dataSize;
}else{
lp0 = dataSize;
lp1 = 0;
}
if(RS485_2_Addr[0] != 0){
if(RS485_2_Addr[0] < 10){
message += "0";
}
message = String(RS485_2_Addr[0]);
message += "DWR,0" + String(lp0) + ",";
for(int i=0 ; i<lp0 ; i++){
char hexStr[5]; // Buffer to hold the hexadecimal string (4 characters + null terminator)
sprintf(hexStr, "%04X", data[i]); // Format as 4 digit uppercase hexadecimal
message += MC9_CH[i] + 1; // ZONE 1
message += ",";
message += String(hexStr);
if(i != (lp0-1)){
message += ",";
}
}
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_2_Wr, message);
}
if((RS485_2_Addr[1] != 0) && (lp1>0)){
if(RS485_2_Addr[1] < 10){
message += "0";
}
message = String(RS485_2_Addr[1]);
message += "DWR,0" + String(lp1-8) + ",";
for(int i=8 ; i<lp1 ; i++){
char hexStr[5]; // Buffer to hold the hexadecimal string (4 characters + null terminator)
sprintf(hexStr, "%04X", data[i]); // Format as 4 digit uppercase hexadecimal
message += MC9_CH[i%8] + 1; // ZONE 1
message += ",";
message += String(hexStr);
if(i != (lp1-1)){
message += ",";
}
}
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_2_Wr, message);
}
return 0;
}
int msg_MC9_AT_set_2(unsigned int data[], int dataSize){
String message = "";
bool at[16];
int lp0, lp1;
// Number to boolean array
unsigned int data0 = data[0];
for (int i = 0; i < 16; i++) {
at[i] = (bitRead(data0, i) ? HIGH : LOW);
}
lp0 = 8;
lp1 = 8;
message = "";
if(RS485_2_Addr[0] != 0){
if(RS485_2_Addr[0] < 10){
message += "0";
}
message += String(RS485_2_Addr[0]);
message += "DWR,16,";
for(int i=0 ; i<8 ; i++){
String atFlag;
if(at[i]){
atFlag = "0001"; // Auto Tuen On
}else{
atFlag = "0000"; // Auto Tuen Off
}
message += "0302,"; // Ch No cmd.
message += "000" + String(i+1) + ","; // Ch No.
message += "0501,"; // AT cmd.
message += atFlag; // AT flag
if(i != 7){
message += ",";
}
}
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_2_Wr, message);
}
message = "";
if((RS485_2_Addr[1] != 0) && (lp1>0)){
if(RS485_1_Addr[1] < 10){
message += "0";
}
message += String(RS485_2_Addr[1]);
message += "DWR,16,";
for(int i=0 ; i<8 ; i++){
String atFlag;
if(at[i+8]){
atFlag = "0001";
}else{
atFlag = "0000";
}
message += "0302,"; // Ch No cmd.
message += "000" + String(i+1) + ","; // Ch No.
message += "0501,"; // AT cmd.
message += atFlag; // AT flag
if(i != 7){
message += ",";
}
}
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_2_Wr, message);
}
return 0;
}
int saveMC9_1(String message){
int saveMC9(String message){
int addr;
int idx = -1;
String mode;
@ -334,7 +190,7 @@ int saveMC9_1(String message){
return -1;
}
if(latest_sent_msg_1.indexOf("DRS,08,0001") != -1){ // if sent message is PV CMD
if(latest_sent_msg.indexOf("DRS,08,0001") != -1){ // if sent message is PV CMD
//rcv_10_PV = true;
RS485_1_Rcv_PV[idx] = true;
for(int i = 0 ; i < RS485_1_Rcv_size ; i++){
@ -342,7 +198,7 @@ int saveMC9_1(String message){
}
}
if(latest_sent_msg_1.indexOf("DRS,08,0011") != -1){ // if sent message is SV CMD
if(latest_sent_msg.indexOf("DRS,08,0011") != -1){ // if sent message is SV CMD
//rcv_10_SV = true;
RS485_1_Rcv_SV[idx] = true;
for(int i = 0 ; i < RS485_1_Rcv_size ; i++){
@ -357,49 +213,7 @@ int saveMC9_1(String message){
}
}
int saveMC9_2(String message){
int addr;
int idx = -1;
String mode;
int data[8];
int crc;
if (!parseMC9(message, addr, mode, data, crc)) {
for(int i=0 ; i < 2 ; i++){ // RS485_1 has two rooms for two MC9s
if(RS485_2_Addr[i] == addr){
idx = i;
break;
}
}
if(idx < 0){
return -1;
}
if(latest_sent_msg_2.indexOf("DRS,08,0001") != -1){ // if sent message is PV CMD
//rcv_10_PV = true;
RS485_2_Rcv_PV[idx] = true;
for(int i = 0 ; i < RS485_1_Rcv_size ; i++){
RS485_2_Values_PV[i + idx*8] = data[i];
}
}
if(latest_sent_msg_2.indexOf("DRS,08,0011") != -1){ // if sent message is SV CMD
//rcv_10_SV = true;
RS485_2_Rcv_SV[idx] = true;
for(int i = 0 ; i < RS485_1_Rcv_size ; i++){
RS485_2_Values_SV[i + idx*8] = data[i];
}
}
return 0;
} else {
Serial.println("error 485 read");
return -1;
}
}
int timeoutMC9_1(){
int timeoutMC9(){
int addr;
int idx = -1;
String msg, mode, cmd;
@ -408,12 +222,12 @@ int timeoutMC9_1(){
int crc;
// Message parsing
msg = latest_sent_msg_1.substring(1);
msg = latest_sent_msg.substring(1);
sscanf(msg.c_str(), "%2d%3s", &addr, &dummy);
//230721 Serial.print("485 not responced... (Timeout) Req msg : " + latest_sent_msg_1);
//230721 Serial.print("485 not responced... (Timeout) Req msg : " + latest_sent_msg);
if (latest_sent_msg_1.indexOf("DRS") != -1) {
if (latest_sent_msg.indexOf("DRS") != -1) {
for(int i=0 ; i < 2 ; i++){ // RS485_1 has two rooms for two MC9s
// Find idx of array
if(RS485_1_Addr[i] == addr){
@ -421,39 +235,25 @@ int timeoutMC9_1(){
break;
}
}
return 0;
} else {
/* 230721
// If not matched, return error
if(idx < 0){
Serial.println();
return -1;
}
}
int timeoutMC9_2(){
int addr;
int idx = -1;
String msg, mode, cmd;
char dummy[4];
int data[8];
int crc;
// Message parsing
msg = latest_sent_msg_2.substring(1);
sscanf(msg.c_str(), "%2d%3s", &addr, &dummy);
//230721 Serial.print("485 not responced... (Timeout) Req msg : " + latest_sent_msg_1);
if (latest_sent_msg_2.indexOf("DRS") != -1) {
for(int i=0 ; i < 2 ; i++){ // RS485_1 has two rooms for two MC9s
// Find idx of array
if(RS485_2_Addr[i] == addr){
idx = i;
break;
}
if(latest_sent_msg.indexOf("DRS,08,0001") != -1){ // if sent message is PV CMD
RS485_1_Rcv_PV[idx] = false;
Serial.print(" >> PV @");
Serial.println(idx);
}
if(latest_sent_msg.indexOf("DRS,08,0011") != -1){ // if sent message is SV CMD
RS485_1_Rcv_SV[idx] = false;
Serial.print(" >> SV @");
Serial.println(idx);
}
*/
return 0;
} else {
@ -461,6 +261,18 @@ int timeoutMC9_2(){
return -1;
}
/*
if(latest_sent_msg == MC9_10_PV){
//rcv_10_PV = false;
}
if(latest_sent_msg == MC9_10_SV){
//rcv_10_SV = false;
}else {
Serial.println("error 485 read");
return -1;
}
*/
}
int parseMC9(const String& message, int& addr, String& mode, int data[8], int& crc) {

@ -5,7 +5,7 @@ void Periodic_run(){
T_1ms = false;
}
if(T_2ms){
read_analog(); // runtime of 1.xxx ms @8ch
//read_analog(); // runtime of 1.xxx ms @8ch
T_2ms = false;
}
if(T_4ms){
@ -17,12 +17,12 @@ void Periodic_run(){
T_5ms = false;
}
if(T_10ms){
//read_analog();
read_analog();
T_10ms = false;
}
if(T_20ms){
send_485_1();
recieve_485_1();
send_485();
recieve_485();
T_20ms = false;
}
if(T_50ms){
@ -43,17 +43,15 @@ void Periodic_run(){
T_500ms = false;
}
if(T_1000ms){
T_1000ms = false;
}
if(T_2000ms){
// Read MC9 PV
for(int i=0 ; i < 2 ; i++){
if(RS485_1_Addr[i] > 0){
write_buff(Buff_485_1_Wr, msg_MC9_PV_read(RS485_1_Addr[i]));
write_buff(Buff_485_1_Wr, msg_MC9_PV(RS485_1_Addr[i]));
}
}
T_1000ms = false;
}
if(T_2000ms){
if(numOf485 > 10){
Serial.print("----- remain 485 buff : "); // For
Serial.println(numOf485); // Debugging
@ -64,7 +62,7 @@ void Periodic_run(){
// Read MC9 SV
for(int i=0 ; i < 2 ; i++){
if(RS485_1_Addr[i] > 0){
//write_buff(Buff_485_1_Wr, msg_MC9_SV_read(RS485_1_Addr[i]));
write_buff(Buff_485_1_Wr, msg_MC9_SV(RS485_1_Addr[i]));
}
}
T_5000ms = false;

@ -49,7 +49,7 @@ String Prcss_ALL_Read(){
str += RcvOK;
str += "INIT?:";
sprintf(formattedNumber, "%04X", ((unsigned int)(Init_AO | Init_MC9)));
sprintf(formattedNumber, "%04X", ((unsigned int)(Init_AO & Init_MC9)));
str += formattedNumber;
str += ',';
str += RcvOK;
@ -86,43 +86,44 @@ String Prcss_AO_Write(unsigned int data[], int dataSize){
return str + FIN;
}
String Prcss_SV_Write_1(unsigned int data[], int dataSize){
String str = "SV_1!:";
String Prcss_SV_Write(unsigned int data[], int dataSize){
String str = "SV!:";
msg_MC9_SV_set_1(data, dataSize);
msg_MC9_SV_set(data, dataSize);
str += RcvOK;
Serial.println(str);
return str + FIN;
}
String Prcss_AT_Write_1(unsigned int data[], int dataSize){
String str = "AT_1!:";
String Prcss_AT_Write(unsigned int data[], int dataSize){
String str = "AT!:";
msg_MC9_AT_set_1(data, dataSize);
msg_MC9_AT_set(data, dataSize);
str += RcvOK;
return str + FIN;
}
/*
String Prcss_AT_Write(bool onOff){
String str = "AT!:";
String message, cmd;
cmd = "10DWR,02,0302,0001,0501,";
if(onOff){
cmd += "0001";
}else{
cmd += "0000";
}
String Prcss_SV_Write_2(unsigned int data[], int dataSize){
String str = "SV_2!:";
msg_MC9_SV_set_2(data, dataSize);
str += RcvOK;
return str + FIN;
}
String Prcss_AT_Write_2(unsigned int data[], int dataSize){
String str = "AT_2!:";
msg_MC9_AT_set_2(data, dataSize);
message = cmd;
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_Wr, message);
str += RcvOK;
return str + FIN;
}
*/
String Prcss_RngAO(unsigned int data[], int dataSize){
String str = "RngAO!:";
int rng = 0;
@ -141,8 +142,8 @@ String Prcss_RngAO(unsigned int data[], int dataSize){
return str + FIN;
}
String Prcss_ChMC9_1(unsigned int data[], int dataSize){
String str = "ChMC9_1!:";
String Prcss_ChMC9(unsigned int data[], int dataSize){
String str = "ChMC9!:";
int d = 20;
for(int i=0 ; i<dataSize ; i++){
setupMC9_1(i, data[i]);
@ -151,14 +152,3 @@ String Prcss_ChMC9_1(unsigned int data[], int dataSize){
str += RcvOK;
return str + FIN;
}
String Prcss_ChMC9_2(unsigned int data[], int dataSize){
String str = "ChMC9_2!:";
int d = 20;
for(int i=0 ; i<dataSize ; i++){
setupMC9_2(i, data[i]);
delay(d);
}
str += RcvOK;
return str + FIN;
}

@ -18,13 +18,13 @@ void RS485_setup(){
digitalWrite(RS485_OE_2, Rcv_485);
}
void send_485_1(){
void send_485(){
if(!Wait_485_1){
String message = read_buff(Buff_485_1_Wr);
if(message != ""){
//save sent message info. for received data processing
latest_sent_msg_1 = message;
latest_sent_msg = message;
message += CRLF;
digitalWrite(RS485_OE_1, Snd_485); delay(5);
@ -39,40 +39,26 @@ void send_485_1(){
}
}
void send_485_2(){
if(!Wait_485_2){
String message = read_buff(Buff_485_2_Wr);
if(message != ""){
//save sent message info. for received data processing
latest_sent_msg_2 = message;
message += CRLF;
digitalWrite(RS485_OE_2, Snd_485); delay(5);
Serial2.print(message);
returnTime = millis();
Serial2.flush();
digitalWrite(RS485_OE_2, Rcv_485); delay(5);
Wait_485_2 = true;
Wait_485_2_cnt = 0;
}
}
}
int recieve_485_1(){
int recieve_485(){
// Timeout code
if(Wait_485_1){
Wait_485_1_cnt++;
if(Wait_485_1_cnt > 40){ // Timeout = periodic(20ms) x 25 = 500 msec
if(Wait_485_1_cnt > 25){ // Timeout = periodic(20ms) x 20 = 400 msec
//Serial.println("485 not responced... (Timeout)");
timeoutMC9_1();
timeoutMC9();
//if((latest_sent_msg == MC9_10_PV) ||(latest_sent_msg == MC9_10_SV)){
latest_sent_msg_1 = "";
/*
if((latest_sent_msg == msg_MC9_PV(10)) || (latest_sent_msg == msg_MC9_SV(10))){
timeoutMC9();
}
*/
latest_sent_msg = "";
Wait_485_1 = false;
Wait_485_1_cnt = 0;
numOf485--;
return -1;
}
}
@ -85,8 +71,8 @@ int recieve_485_1(){
String message = read_buff(Buff_485_1_Rd);
if(message != ""){
numOf485--;
if(latest_sent_msg_1.indexOf("DRS") != -1){
saveMC9_1(message);
if(latest_sent_msg.indexOf("DRS") != -1){
saveMC9(message);
}
else{
Serial.print("----- 485 rcv : ");
@ -99,45 +85,6 @@ int recieve_485_1(){
return 0;
}
int recieve_485_2(){
// Timeout code
if(Wait_485_2){
Wait_485_2_cnt++;
if(Wait_485_2_cnt > 40){ // Timeout = periodic(20ms) x 25 = 500 msec
//Serial.println("485 not responced... (Timeout)");
timeoutMC9_2();
latest_sent_msg_2 = "";
Wait_485_2 = false;
Wait_485_2_cnt = 0;
numOf485--;
return -1;
}
}
// Receive pv data
while(Wait_485_2 && (Serial2.available() > 0)) {
char c = Serial2.read();
write_buff_c(Buff_485_2_Rd, c);
}
String message = read_buff(Buff_485_2_Rd);
if(message != ""){
numOf485--;
if(latest_sent_msg_2.indexOf("DRS") != -1){
saveMC9_2(message);
}
else{
Serial.print("----- 485 rcv : ");
Serial.println(message);
}
Wait_485_2 = false;
Wait_485_2_cnt = 0;
}
return 0;
}
/* For Test from PC */
void recieve_485_0(){
@ -155,21 +102,3 @@ void recieve_485_0(){
IdeSerial = "";
}
}
void send_temp(bool F){
String message = "TEST";
if(F) {
message += CRLF;
message += " with CRLF";
message += CRLF;
}
digitalWrite(RS485_OE_1, Snd_485); delay(5);
Serial1.print(message);
returnTime = millis();
Serial1.flush();
digitalWrite(RS485_OE_1, Rcv_485); delay(5);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,77 @@
{
"board": {
"active_layer": 37,
"active_layer_preset": "",
"auto_track_width": true,
"hidden_netclasses": [],
"hidden_nets": [],
"high_contrast_mode": 0,
"net_color_mode": 1,
"opacity": {
"images": 0.6,
"pads": 1.0,
"tracks": 1.0,
"vias": 1.0,
"zones": 0.6
},
"selection_filter": {
"dimensions": false,
"footprints": false,
"graphics": false,
"keepouts": false,
"lockedItems": false,
"otherItems": false,
"pads": false,
"text": true,
"tracks": true,
"vias": true,
"zones": false
},
"visible_items": [
0,
1,
2,
3,
4,
5,
8,
9,
10,
11,
12,
13,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
32,
33,
34,
35,
36,
39,
40
],
"visible_layers": "ffcffff_ffffffff",
"zone_display_mode": 0
},
"meta": {
"filename": "megaPCB.kicad_prl",
"version": 3
},
"project": {
"files": []
}
}

@ -0,0 +1,490 @@
{
"board": {
"3dviewports": [],
"design_settings": {
"defaults": {
"board_outline_line_width": 0.09999999999999999,
"copper_line_width": 0.19999999999999998,
"copper_text_italic": false,
"copper_text_size_h": 1.5,
"copper_text_size_v": 1.5,
"copper_text_thickness": 0.3,
"copper_text_upright": false,
"courtyard_line_width": 0.049999999999999996,
"dimension_precision": 4,
"dimension_units": 3,
"dimensions": {
"arrow_length": 1270000,
"extension_offset": 500000,
"keep_text_aligned": true,
"suppress_zeroes": false,
"text_position": 0,
"units_format": 1
},
"fab_line_width": 0.09999999999999999,
"fab_text_italic": false,
"fab_text_size_h": 1.0,
"fab_text_size_v": 1.0,
"fab_text_thickness": 0.15,
"fab_text_upright": false,
"other_line_width": 0.15,
"other_text_italic": false,
"other_text_size_h": 1.0,
"other_text_size_v": 1.0,
"other_text_thickness": 0.15,
"other_text_upright": false,
"pads": {
"drill": 0.7,
"height": 1.4,
"width": 1.4
},
"silk_line_width": 0.15,
"silk_text_italic": false,
"silk_text_size_h": 1.0,
"silk_text_size_v": 1.0,
"silk_text_thickness": 0.15,
"silk_text_upright": false,
"zones": {
"min_clearance": 0.5
}
},
"diff_pair_dimensions": [
{
"gap": 0.0,
"via_gap": 0.0,
"width": 0.0
}
],
"drc_exclusions": [],
"meta": {
"version": 2
},
"rule_severities": {
"annular_width": "error",
"clearance": "error",
"connection_width": "warning",
"copper_edge_clearance": "error",
"copper_sliver": "warning",
"courtyards_overlap": "error",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint": "error",
"footprint_type_mismatch": "ignore",
"hole_clearance": "error",
"hole_near_hole": "error",
"invalid_outline": "error",
"isolated_copper": "warning",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"lib_footprint_issues": "warning",
"lib_footprint_mismatch": "warning",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
"missing_footprint": "warning",
"net_conflict": "warning",
"npth_inside_courtyard": "ignore",
"padstack": "warning",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_edge_clearance": "warning",
"silk_over_copper": "warning",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"solder_mask_bridge": "error",
"starved_thermal": "warning",
"text_height": "warning",
"text_thickness": "warning",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_dangling": "warning",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zones_intersect": "error"
},
"rules": {
"max_error": 0.005,
"min_clearance": 0.0,
"min_connection": 0.0,
"min_copper_edge_clearance": 0.0,
"min_hole_clearance": 0.25,
"min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.19999999999999998,
"min_microvia_drill": 0.09999999999999999,
"min_resolved_spokes": 2,
"min_silk_clearance": 0.0,
"min_text_height": 0.7999999999999999,
"min_text_thickness": 0.08,
"min_through_hole_diameter": 0.3,
"min_track_width": 0.0,
"min_via_annular_width": 0.09999999999999999,
"min_via_diameter": 0.5,
"solder_mask_clearance": 0.0,
"solder_mask_min_width": 0.0,
"solder_mask_to_copper_clearance": 0.0,
"use_height_for_length_calcs": true
},
"teardrop_options": [
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 5,
"td_on_pad_in_zone": false,
"td_onpadsmd": true,
"td_onroundshapesonly": false,
"td_ontrackend": false,
"td_onviapad": true
}
],
"teardrop_parameters": [
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_round_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_rect_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_track_end",
"td_width_to_size_filter_ratio": 0.9
}
],
"track_widths": [
0.0
],
"via_dimensions": [
{
"diameter": 0.0,
"drill": 0.0
}
],
"zones_allow_external_fillets": false
},
"layer_presets": [],
"viewports": []
},
"boards": [],
"cvpcb": {
"equivalence_files": []
},
"erc": {
"erc_exclusions": [],
"meta": {
"version": 0
},
"pin_map": [
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
1,
2
],
[
0,
1,
0,
0,
0,
0,
1,
1,
2,
1,
1,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2
],
[
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
2
],
[
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
1,
2,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
0,
2,
1,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2
]
],
"rule_severities": {
"bus_definition_conflict": "error",
"bus_entry_needed": "error",
"bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error",
"conflicting_netclasses": "error",
"different_unit_footprint": "error",
"different_unit_net": "error",
"duplicate_reference": "error",
"duplicate_sheet_names": "error",
"endpoint_off_grid": "warning",
"extra_units": "error",
"global_label_dangling": "warning",
"hier_label_mismatch": "error",
"label_dangling": "error",
"lib_symbol_issues": "warning",
"missing_bidi_pin": "warning",
"missing_input_pin": "warning",
"missing_power_pin": "error",
"missing_unit": "warning",
"multiple_net_names": "warning",
"net_not_bus_member": "warning",
"no_connect_connected": "warning",
"no_connect_dangling": "warning",
"pin_not_connected": "error",
"pin_not_driven": "error",
"pin_to_pin": "warning",
"power_pin_not_driven": "error",
"similar_labels": "warning",
"simulation_model_issue": "ignore",
"unannotated": "error",
"unit_value_mismatch": "error",
"unresolved_variable": "error",
"wire_dangling": "error"
}
},
"libraries": {
"pinned_footprint_libs": [],
"pinned_symbol_libs": []
},
"meta": {
"filename": "megaPCB.kicad_pro",
"version": 1
},
"net_settings": {
"classes": [
{
"bus_width": 12,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.25,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6
}
],
"meta": {
"version": 3
},
"net_colors": null,
"netclass_assignments": null,
"netclass_patterns": []
},
"pcbnew": {
"last_paths": {
"gencad": "",
"idf": "",
"netlist": "",
"specctra_dsn": "",
"step": "",
"vrml": ""
},
"page_layout_descr_file": ""
},
"schematic": {
"annotate_start_num": 0,
"drawing": {
"dashed_lines_dash_length_ratio": 12.0,
"dashed_lines_gap_length_ratio": 3.0,
"default_line_thickness": 6.0,
"default_text_size": 50.0,
"field_names": [],
"intersheets_ref_own_page": false,
"intersheets_ref_prefix": "",
"intersheets_ref_short": false,
"intersheets_ref_show": false,
"intersheets_ref_suffix": "",
"junction_size_choice": 3,
"label_size_ratio": 0.375,
"pin_symbol_size": 25.0,
"text_offset_ratio": 0.15
},
"legacy_lib_dir": "",
"legacy_lib_list": [],
"meta": {
"version": 1
},
"net_format_name": "",
"page_layout_descr_file": "",
"plot_directory": "",
"spice_current_sheet_as_root": false,
"spice_external_command": "spice \"%I\"",
"spice_model_current_sheet_as_root": true,
"spice_save_all_currents": false,
"spice_save_all_voltages": false,
"subpart_first_id": 65,
"subpart_id_separator": 0
},
"sheets": [
[
"6969f8a3-205d-401c-ae37-2e26183a6afa",
""
]
],
"text_variables": {}
}

File diff suppressed because it is too large Load Diff

@ -1,97 +0,0 @@
/*
* Modifed from UIPEthernet EchoServer example.
*
* UIPEthernet is a TCP/IP stack that can be used with a enc28j60 based
* Ethernet-shield.
*
*/
#define DEBUG 1
#define MACADDRESS 0x00,0x01,0x02,0x03,0x04,0x05
#define MYIPADDR 192,168,20,177
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,20,1
#define MYGW 192,168,20,1
#define LISTENPORT 5025
#define UARTBAUD 115200
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPClient.h>
#include "utility/logging.h"
uint8_t mac[6] = {MACADDRESS};
uint8_t myIP[4] = {MYIPADDR};
uint8_t myMASK[4] = {MYIPMASK};
uint8_t myDNS[4] = {MYDNS};
uint8_t myGW[4] = {MYGW};
EthernetClient client;
EthernetServer server = EthernetServer(LISTENPORT);
void setup() {
Serial.begin(9600);
Serial.println("Serial Done");
Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
// start listening for clients
server.begin();
// Report address
Serial.print("MAC>>");
for (int i = 0; i < 6; i++) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i < 5) {
Serial.print(":");
}
}
Serial.println();
Serial.print("IP >>");
Serial.println(Ethernet.localIP());
}
void loop() {
size_t size;
String message = "";
client = server.available();
if (client){
Serial.println("Client Connected!!!");
while(client.connected()){
// Recive Command
if((size = client.available()) > 0){
uint8_t* msg = (uint8_t*)malloc(size);
size = client.read(msg,size);
for(int i = 0 ; i < size ; i++){
message += (char)msg[i];
}
if(size > 2){
if((msg[size-1] == '\n') && (msg[size-2] == '\r')){
#if DEBUG
Serial.print(size);
Serial.println(" >> " + message);
#endif
//cmd = demuxCMD(message, &cmdData); // for IFB
client.print(message);
message = "";
}
}
free(msg);
}
// Action by Command
//if(cmd)
}
Serial.println("Client Disconnected...");
}
}
Loading…
Cancel
Save