Compare commits

...

5 Commits

Author SHA1 Message Date
Changwoo Park 954d6d6ec0 [v2.1]
외부전원 블럭 추가 (Vin)
WatchDog printing
5 months ago
Changwoo Park fe95dbe67c AO / MC9 하나만 사용 가능 5 months ago
Changwoo Park 5b16385aa5 [IFB_v2]
- ENC28J60 Ethernet 기반 업데이트
- 485 두개 사용할 수 있도록 업데이트
- LabView 라이브러리는 두번째 485 사용함수 미작성
- LabView 의 글로벌 변수 별도 선언
11 months ago
Changwoo Park 2789e42c77 [IFB][ENC28J60]
- IFB v2.0 : JLCPCB 주문의 건
- ENC28J60 사용 test code
1 year ago
Changwoo Park acfcf8e030 [IFB v2] branch 1 year ago

@ -1,16 +1,24 @@
void Ethernet_setup(){ void Ethernet_setup(){
/*
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x00 }; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x00 };
IPAddress ip(192, 168, 20, 177); IPAddress ip(192, 168, 20, 177);
IPAddress gateway(192, 168, 20, 1); IPAddress gateway(192, 168, 20, 1);
IPAddress subnet(255, 255, 255, 0); 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 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 // initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet); Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
// start listening for clients // start listening for clients
server.begin(); server.begin();
web.begin(); //web.begin();
// Report address // Report address
Serial.print("MAC>>"); Serial.print("MAC>>");
@ -28,36 +36,6 @@ void Ethernet_setup(){
Serial.println(Ethernet.localIP()); 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) { String demuxCMD(String command, String* rightPart) {

@ -1,11 +1,38 @@
#include "Arduino.h" #include "Arduino.h"
#include <MsTimer2.h> // MsTimer2 v1.1 #include <MsTimer2.h> // MsTimer2 v1.1
#include <Ethernet2.h> // Ethernet2 v1.0.4 //#include <Ethernet2.h> // Ethernet2 v1.0.4
// for ENC28J60
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPClient.h>
// ------------------
#include "GP8403.h" #include "GP8403.h"
#define VERSION "240129 1044"
#define COMMENT "MC9 or AO init"
#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;
bool Init_MC9 = false;
/* ---------- Periodics ---------- */ /* ---------- Periodics ---------- */
// Flags // Flags
bool T_1ms = false; bool T_1ms = false;
bool T_2ms = false;
bool T_4ms = false;
bool T_5ms = false;
bool T_10ms = false; bool T_10ms = false;
bool T_20ms = false; bool T_20ms = false;
bool T_50ms = false; bool T_50ms = false;
@ -19,7 +46,6 @@ bool T_5000ms = false;
// Datas // Datas
int msCnt = 0; int msCnt = 0;
unsigned long timer = 0; unsigned long timer = 0;
#define AI_AVG_SIZE 20
/* ---------- Arduino Mega 2560 Basic IO ---------- */ /* ---------- Arduino Mega 2560 Basic IO ---------- */
// Pins // Pins
@ -32,11 +58,12 @@ const int AiPin[] = { A0, A1, A2, A3, A4, A5, A6, A7,
// Data Storages // Data Storages
int Size_DO = 16; int Size_DO = 16;
int Size_DI = 8; int Size_DI = 8;
int Size_AI = 16; int Size_AI = AI_RANGE;
int index_AI = 0;
int Values_DI; // digit values to a number int Values_DI; // digit values to a number
int Values_AI[16]; int Values_AI[AI_RANGE];
int Recent_AI[16][AI_AVG_SIZE]; int Recent_AI[AI_RANGE][AI_AVG_SIZE];
/* ---------- I2C (Analog Output, DAC) ---------- */ /* ---------- I2C (Analog Output, DAC) ---------- */
// Addresses // Addresses
@ -52,13 +79,10 @@ DFRobot_GP8403 AO_14(&Wire,0x5F);
// Data Storage // Data Storage
int RngAO[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int RngAO[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
/* ---------- Ethernet (Ethernet Sheld2) ---------- */ /* ---------- Ethernet (ENC28J60) ---------- */
// Ethernet Client
EthernetClient client; EthernetClient client;
// SCPI defaults to port 5025 EthernetServer server = EthernetServer(LISTENPORT);
EthernetServer server(5025);
// HTTP defaults to port 5025
EthernetServer web(80);
unsigned long lastDataReceivedTime; unsigned long lastDataReceivedTime;
unsigned long timeoutPeriod = 5000; // 이더넷 타임아웃 시간 (5초) unsigned long timeoutPeriod = 5000; // 이더넷 타임아웃 시간 (5초)
@ -67,17 +91,21 @@ bool State_eth = false;
HardwareSerial* Serials[] = {&Serial1, &Serial2}; HardwareSerial* Serials[] = {&Serial1, &Serial2};
const int BUFF_SIZE = 1024; const int BUFF_SIZE = 512;
char Buff_Eth_Rd[BUFF_SIZE] = {0}; char Buff_Eth_Rd[BUFF_SIZE] = {0};
char Buff_485_1_Wr[BUFF_SIZE] = {0}; char Buff_485_1_Wr[BUFF_SIZE] = {0};
char Buff_485_1_Rd[BUFF_SIZE] = {0}; char Buff_485_1_Rd[BUFF_SIZE] = {0};
char Buff_485_2_Wr[BUFF_SIZE] = {0}; char Buff_485_2_Wr[BUFF_SIZE] = {0};
char Buff_485_2_Rd[BUFF_SIZE] = {0}; char Buff_485_2_Rd[BUFF_SIZE] = {0};
String latest_sent_msg; String latest_sent_msg_1;
int numOf485 = 0; int numOf485 = 0;
int returnTime = 0; int returnTime = 0;
String latest_sent_msg_2;
int numOf485_2 = 0;
int returnTime_2 = 0;
/* ---------- RS485 ---------- */ /* ---------- RS485 ---------- */
// 485 CH 1 // 485 CH 1
bool Wait_485_1; bool Wait_485_1;
@ -92,9 +120,9 @@ int RS485_1_Values_SV[8*2];
// 485 CH 2 // 485 CH 2
bool Wait_485_2; bool Wait_485_2;
int Wait_485_2_cnt; int Wait_485_2_cnt;
int RS485_2_Addr[2]; int RS485_2_Addr[2] = {0,0};
bool RS485_2_Rcv_PV[2]; bool RS485_2_Rcv_PV[2] = {false, false};
bool RS485_2_Rcv_SV[2]; bool RS485_2_Rcv_SV[2] = {false, false};
int RS485_2_Rcv_size = 8; int RS485_2_Rcv_size = 8;
int RS485_2_Values_PV[8*2]; int RS485_2_Values_PV[8*2];
int RS485_2_Values_SV[8*2]; int RS485_2_Values_SV[8*2];
@ -108,10 +136,13 @@ String Prcss_AI_Read();
String Prcss_AO_Write(unsigned int data[], int dataSize); String Prcss_AO_Write(unsigned int data[], int dataSize);
String Prcss_PV_Read(); String Prcss_PV_Read();
String Prcss_SV_Read(); String Prcss_SV_Read();
String Prcss_SV_Write(unsigned int data[], int dataSize); String Prcss_SV_Write_1(unsigned int data[], int dataSize);
String Prcss_AT_Write(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_RngAO(unsigned int data[], int dataSize); String Prcss_RngAO(unsigned int data[], int dataSize);
String Prcss_ChMC9(unsigned int data[], int dataSize); String Prcss_ChMC9_1(unsigned int data[], int dataSize);
String Prcss_ChMC9_2(unsigned int data[], int dataSize);
//Ethernet //Ethernet
void Ethernet_setup(); void Ethernet_setup();
@ -121,8 +152,10 @@ int demuxNum(String rightPart, unsigned int data[]);
//RS485 //RS485
void RS485_setup(); void RS485_setup();
void send_485(); void send_485_1();
int recieve_485(); void send_485_2();
int recieve_485_1();
int recieve_485_2();
void recieve_485_0(); void recieve_485_0();
//GPIO //GPIO
@ -132,10 +165,13 @@ void read_digital();
//MC9 //MC9
void setupMC9_1(int i, int data); void setupMC9_1(int i, int data);
String msg_MC9_PV(int addr); void setupMC9_2(int i, int data);
String msg_MC9_SV(int addr); String msg_MC9_PV_read(int addr);
int saveMC9(String message); String msg_MC9_SV_read(int addr);
int timeoutMC9(); int saveMC9_1(String message);
int saveMC9_2(String message);
int timeoutMC9_1();
int timeoutMC9_2();
int parseMC9(const String& message, int& addr, String& mode, int data[8], int& crc); int parseMC9(const String& message, int& addr, String& mode, int data[8], int& crc);
String sumMC9(String input); String sumMC9(String input);

@ -1,8 +1,6 @@
#include "FC_InterfaceBoard.h" #include "FC_InterfaceBoard.h"
#define CR "\r" #define CR "\r"
#define FIN "\n" #define FIN "\n"
#define CRLF "\r\n" #define CRLF "\r\n"
@ -12,11 +10,16 @@
String IdeSerial; // for 485_0 String IdeSerial; // for 485_0
void setup() { void setup() {
// put your setup code here, to run once: // Serial setup (Debug)
Serial.begin(9600); Serial.begin(9600);
Serial.println("Start!"); Serial.print("Version ::: ");
Serial.println(VERSION);
Serial.print("Comment ::: ");
Serial.println(COMMENT);
// modules setup (init.) // modules setup (init.)
Ethernet_setup(); Ethernet_setup();
GPIO_setup(); GPIO_setup();
@ -89,22 +92,38 @@ void loop() {
// MC9 // MC9
else if(cmd=="SV_1!"){ else if(cmd=="SV_1!"){
dataSize = demuxNum(cmdData, data); dataSize = demuxNum(cmdData, data);
client.print(Prcss_SV_Write(data, dataSize)); client.print(Prcss_SV_Write_1(data, dataSize));
}else if(cmd=="AT_1!"){ }else if(cmd=="AT_1!"){
dataSize = demuxNum(cmdData, data); dataSize = demuxNum(cmdData, data);
client.print(Prcss_AT_Write(data, dataSize)); 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));
} }
// Init // Init
else if(cmd=="State?"){ else if(cmd=="State?"){
client.print(cmd + " " + RcvOK + FIN);
}else if(cmd=="RngAO!"){ }else if(cmd=="RngAO!"){
dataSize = demuxNum(cmdData, data); dataSize = demuxNum(cmdData, data);
client.print(Prcss_RngAO(data, dataSize)); client.print(Prcss_RngAO(data, dataSize));
Init_AO = true;
}else if(cmd=="ChMC9_1!"){ }else if(cmd=="ChMC9_1!"){
dataSize = demuxNum(cmdData, data); dataSize = demuxNum(cmdData, data);
client.print(Prcss_ChMC9(data, dataSize)); 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));
Init_MC9 = true;
} }
// Extra // Extra

@ -15,11 +15,17 @@ void read_analog(){
for(i = 0 ; i < Size_AI ; i++){ for(i = 0 ; i < Size_AI ; i++){
Values_AI[i] = analogRead(AiPin[i]); Values_AI[i] = analogRead(AiPin[i]);
/*
for(int j = 0; j < AI_AVG_SIZE - 1; j++) { for(int j = 0; j < AI_AVG_SIZE - 1; j++) {
Recent_AI[i][j] = Recent_AI[i][j + 1]; Recent_AI[i][j] = Recent_AI[i][j + 1];
} }
Recent_AI[i][AI_AVG_SIZE - 1] = Values_AI[i]; Recent_AI[i][AI_AVG_SIZE - 1] = Values_AI[i];
*/
// 현재 인덱스 위치에 값을 저장
Recent_AI[i][index_AI] = Values_AI[i];
} }
// 인덱스를 증가시키고, 필요한 경우 순환
index_AI = (index_AI + 1) % AI_AVG_SIZE;
} }
void read_digital(){ void read_digital(){

@ -7,10 +7,15 @@ const int MC9_CH[] = {1000, 1008, 1016, 1024, 1100, 1108, 1116, 1124};
void setupMC9_1(int i, int data){ void setupMC9_1(int i, int data){
RS485_1_Addr[i] = data; RS485_1_Addr[i] = data;
Serial.println("MC9 No."+ String(i) + " 's address set as " + String(data)); Serial.println("MC9_1 No."+ String(i) + " 's address set as " + String(data));
} }
void setupMC9_2(int i, int data){
RS485_2_Addr[i] = data;
String msg_MC9_PV(int addr){ Serial.println("MC9_2 No."+ String(i) + " 's address set as " + String(data));
}
String msg_MC9_PV_read(int addr){
String message = ""; String message = "";
if(addr < 10){ if(addr < 10){
@ -24,7 +29,7 @@ String msg_MC9_PV(int addr){
return message; return message;
} }
String msg_MC9_SV(int addr){ String msg_MC9_SV_read(int addr){
String message = ""; String message = "";
if(addr < 10){ if(addr < 10){
@ -38,10 +43,13 @@ String msg_MC9_SV(int addr){
return message; return message;
} }
int msg_MC9_SV_set(unsigned int data[], int dataSize){ int msg_MC9_SV_set_1(unsigned int data[], int dataSize){
String message = ""; String message = "";
int lp0, lp1; int lp0, lp1;
if(dataSize > 16){
dataSize = 16;
}
if(dataSize > 8){ if(dataSize > 8){
lp0 = 8; lp0 = 8;
lp1 = dataSize; lp1 = dataSize;
@ -49,7 +57,7 @@ int msg_MC9_SV_set(unsigned int data[], int dataSize){
lp0 = dataSize; lp0 = dataSize;
lp1 = 0; lp1 = 0;
} }
if(RS485_1_Addr[0] != 0){ if(RS485_1_Addr[0] != 0){
if(RS485_1_Addr[0] < 10){ if(RS485_1_Addr[0] < 10){
message += "0"; message += "0";
@ -91,13 +99,14 @@ int msg_MC9_SV_set(unsigned int data[], int dataSize){
} }
message += sumMC9(message); message += sumMC9(message);
message = "" + message + CRLF; message = "" + message + CRLF;
write_buff_first(Buff_485_1_Wr, message); write_buff_first(Buff_485_1_Wr, message);
} }
return 0; return 0;
} }
int msg_MC9_AT_set(unsigned int data[], int dataSize){ int msg_MC9_AT_set_1(unsigned int data[], int dataSize){
String message = ""; String message = "";
bool at[16]; bool at[16];
@ -108,7 +117,7 @@ int msg_MC9_AT_set(unsigned int data[], int dataSize){
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
at[i] = (bitRead(data0, i) ? HIGH : LOW); at[i] = (bitRead(data0, i) ? HIGH : LOW);
} }
lp0 = 8; lp0 = 8;
lp1 = 8; lp1 = 8;
@ -126,7 +135,6 @@ int msg_MC9_AT_set(unsigned int data[], int dataSize){
}else{ }else{
atFlag = "0000"; // Auto Tuen Off atFlag = "0000"; // Auto Tuen Off
} }
message += "0302,"; // Ch No cmd. message += "0302,"; // Ch No cmd.
message += "000" + String(i+1) + ","; // Ch No. message += "000" + String(i+1) + ","; // Ch No.
message += "0501,"; // AT cmd. message += "0501,"; // AT cmd.
@ -137,6 +145,7 @@ int msg_MC9_AT_set(unsigned int data[], int dataSize){
} }
message += sumMC9(message); message += sumMC9(message);
message = "" + message + CRLF; message = "" + message + CRLF;
write_buff_first(Buff_485_1_Wr, message); write_buff_first(Buff_485_1_Wr, message);
} }
@ -167,11 +176,146 @@ int msg_MC9_AT_set(unsigned int data[], int dataSize){
message = "" + message + CRLF; message = "" + message + CRLF;
write_buff_first(Buff_485_1_Wr, message); 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; return 0;
} }
int saveMC9(String message){ 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 addr; int addr;
int idx = -1; int idx = -1;
String mode; String mode;
@ -190,7 +334,7 @@ int saveMC9(String message){
return -1; return -1;
} }
if(latest_sent_msg.indexOf("DRS,08,0001") != -1){ // if sent message is PV CMD if(latest_sent_msg_1.indexOf("DRS,08,0001") != -1){ // if sent message is PV CMD
//rcv_10_PV = true; //rcv_10_PV = true;
RS485_1_Rcv_PV[idx] = true; RS485_1_Rcv_PV[idx] = true;
for(int i = 0 ; i < RS485_1_Rcv_size ; i++){ for(int i = 0 ; i < RS485_1_Rcv_size ; i++){
@ -198,7 +342,7 @@ int saveMC9(String message){
} }
} }
if(latest_sent_msg.indexOf("DRS,08,0011") != -1){ // if sent message is SV CMD if(latest_sent_msg_1.indexOf("DRS,08,0011") != -1){ // if sent message is SV CMD
//rcv_10_SV = true; //rcv_10_SV = true;
RS485_1_Rcv_SV[idx] = true; RS485_1_Rcv_SV[idx] = true;
for(int i = 0 ; i < RS485_1_Rcv_size ; i++){ for(int i = 0 ; i < RS485_1_Rcv_size ; i++){
@ -213,7 +357,49 @@ int saveMC9(String message){
} }
} }
int timeoutMC9(){ 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 addr; int addr;
int idx = -1; int idx = -1;
String msg, mode, cmd; String msg, mode, cmd;
@ -222,12 +408,12 @@ int timeoutMC9(){
int crc; int crc;
// Message parsing // Message parsing
msg = latest_sent_msg.substring(1); msg = latest_sent_msg_1.substring(1);
sscanf(msg.c_str(), "%2d%3s", &addr, &dummy); sscanf(msg.c_str(), "%2d%3s", &addr, &dummy);
Serial.print("485 not responced... (Timeout) Req msg : " + latest_sent_msg); //230721 Serial.print("485 not responced... (Timeout) Req msg : " + latest_sent_msg_1);
if (latest_sent_msg.indexOf("DRS") != -1) { if (latest_sent_msg_1.indexOf("DRS") != -1) {
for(int i=0 ; i < 2 ; i++){ // RS485_1 has two rooms for two MC9s for(int i=0 ; i < 2 ; i++){ // RS485_1 has two rooms for two MC9s
// Find idx of array // Find idx of array
if(RS485_1_Addr[i] == addr){ if(RS485_1_Addr[i] == addr){
@ -236,23 +422,38 @@ int timeoutMC9(){
} }
} }
// If not matched, return error return 0;
if(idx < 0){
} else {
Serial.println(); Serial.println();
return -1; return -1;
} }
if(latest_sent_msg.indexOf("DRS,08,0001") != -1){ // if sent message is PV CMD }
RS485_1_Rcv_PV[idx] = false;
Serial.print(" >> PV @"); int timeoutMC9_2(){
Serial.println(idx); int addr;
} int idx = -1;
if(latest_sent_msg.indexOf("DRS,08,0011") != -1){ // if sent message is SV CMD String msg, mode, cmd;
RS485_1_Rcv_SV[idx] = false; char dummy[4];
int data[8];
Serial.print(" >> SV @"); int crc;
Serial.println(idx); // 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;
}
} }
return 0; return 0;
} else { } else {
@ -260,18 +461,6 @@ int timeoutMC9(){
return -1; 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) { int parseMC9(const String& message, int& addr, String& mode, int data[8], int& crc) {

@ -1,22 +1,31 @@
void Periodic_run(){ void Periodic_run(){
if(T_1ms){ if(T_1ms){
// Read Arduino AI // read_analog();
read_analog();
T_1ms = false; T_1ms = false;
} }
if(T_2ms){
read_analog(); // runtime of 1.xxx ms @8ch
T_2ms = false;
}
if(T_4ms){
//read_analog();
T_4ms = false;
}
if(T_5ms){
//read_analog(); // runtime of 2.048012 ms @16ch
T_5ms = false;
}
if(T_10ms){ if(T_10ms){
//read_analog(); //read_analog();
T_10ms = false; T_10ms = false;
} }
if(T_20ms){ if(T_20ms){
// send and recieve RS485 send_485_1();
send_485(); recieve_485_1();
recieve_485();
T_20ms = false; T_20ms = false;
} }
if(T_50ms){ if(T_50ms){
// Read Arduino DI
read_digital(); read_digital();
T_50ms = false; T_50ms = false;
} }
@ -29,21 +38,23 @@ void Periodic_run(){
T_200ms = false; T_200ms = false;
} }
if(T_500ms){ if(T_500ms){
// RS485 recieve (for developing)
recieve_485_0(); recieve_485_0(); // RS485 recieve (for developing)
T_500ms = false; T_500ms = false;
} }
if(T_1000ms){ if(T_1000ms){
T_1000ms = false;
}
if(T_2000ms){
// Read MC9 PV // Read MC9 PV
for(int i=0 ; i < 2 ; i++){ for(int i=0 ; i < 2 ; i++){
if(RS485_1_Addr[i] > 0){ if(RS485_1_Addr[i] > 0){
write_buff(Buff_485_1_Wr, msg_MC9_PV(RS485_1_Addr[i])); write_buff(Buff_485_1_Wr, msg_MC9_PV_read(RS485_1_Addr[i]));
} }
} }
T_1000ms = false;
} if(numOf485 > 10){
if(T_2000ms){
if(numOf485 > 0){
Serial.print("----- remain 485 buff : "); // For Serial.print("----- remain 485 buff : "); // For
Serial.println(numOf485); // Debugging Serial.println(numOf485); // Debugging
} }
@ -53,7 +64,7 @@ void Periodic_run(){
// Read MC9 SV // Read MC9 SV
for(int i=0 ; i < 2 ; i++){ for(int i=0 ; i < 2 ; i++){
if(RS485_1_Addr[i] > 0){ if(RS485_1_Addr[i] > 0){
write_buff(Buff_485_1_Wr, msg_MC9_SV(RS485_1_Addr[i])); //write_buff(Buff_485_1_Wr, msg_MC9_SV_read(RS485_1_Addr[i]));
} }
} }
T_5000ms = false; T_5000ms = false;
@ -64,6 +75,15 @@ void timer_1ms(){
msCnt += 1; msCnt += 1;
T_1ms = true; T_1ms = true;
if (msCnt % 2 == 0){
T_2ms = true;
}
if (msCnt % 4 == 0){
T_4ms = true;
}
if (msCnt % 5 == 0){
T_5ms = true;
}
if (msCnt % 10 == 0){ if (msCnt % 10 == 0){
T_10ms = true; T_10ms = true;
} }

@ -1,23 +1,27 @@
String Prcss_ALL_Read(){ String Prcss_ALL_Read(){
String str = ""; String str = "";
char formattedNumber[5]; // 4자리 숫자 + 널 종료 문자
float factor = 1.0f / AI_AVG_SIZE;
str += "AI?:"; str += "AI?:";
for (int i = 0; i < Size_AI; i++) { for (int i = 0; i < Size_AI; i++) {
int sum_AI = 0; float sum_AI = 0;
for(int j = 0; j < AI_AVG_SIZE; j++) { for(int j = 0; j < AI_AVG_SIZE; j++) {
sum_AI += Recent_AI[i][j]; sum_AI += (float) Recent_AI[i][j] * factor;
} }
char formattedNumber[5]; // 4자리 숫자 + 널 종료 문자 sum_AI *= 50.0f; // convert the sum to an integer representation, Transfer data max(0xFFFF): 65,535. Each data max(10bit ADC): 1024. 1024 x 50 = 51,200
unsigned int integer_part = (unsigned int)sum_AI;
//sprintf(formattedNumber, "%04X", Values_AI[i]); // 4자리로 고정된 형식의 문자열 생성 //sprintf(formattedNumber, "%04X", Values_AI[i]); // 4자리로 고정된 형식의 문자열 생성
sprintf(formattedNumber, "%04X", sum_AI); // 4자리로 고정된 형식의 문자열 생성 sprintf(formattedNumber, "%04X", integer_part); // 4자리로 고정된 형식의 문자열 생성
str += formattedNumber; // 형식화된 문자열 추가 str += formattedNumber; // 형식화된 문자열 추가
str += ','; str += ',';
} }
str += RcvOK; str += RcvOK;
str += "DI?:"; str += "DI?:";
char formattedNumber[5];
sprintf(formattedNumber, "%04X", Values_DI); sprintf(formattedNumber, "%04X", Values_DI);
str += formattedNumber; str += formattedNumber;
str += ','; str += ',';
@ -25,7 +29,6 @@ String Prcss_ALL_Read(){
str += "PV_1?:"; str += "PV_1?:";
for (int i = 0; i < RS485_1_Rcv_size*2; i++) { for (int i = 0; i < RS485_1_Rcv_size*2; i++) {
char formattedNumber[5];
int rcv = int(RS485_1_Rcv_PV[i/RS485_1_Rcv_size]); int rcv = int(RS485_1_Rcv_PV[i/RS485_1_Rcv_size]);
sprintf(formattedNumber, "%04X", RS485_1_Values_PV[i] * rcv); sprintf(formattedNumber, "%04X", RS485_1_Values_PV[i] * rcv);
@ -37,7 +40,6 @@ String Prcss_ALL_Read(){
str += "SV_1?:"; str += "SV_1?:";
for (int i = 0; i < RS485_1_Rcv_size*2; i++) { for (int i = 0; i < RS485_1_Rcv_size*2; i++) {
char formattedNumber[5];
int rcv = int(RS485_1_Rcv_SV[i/RS485_1_Rcv_size]); int rcv = int(RS485_1_Rcv_SV[i/RS485_1_Rcv_size]);
sprintf(formattedNumber, "%04X", RS485_1_Values_SV[i] * rcv); sprintf(formattedNumber, "%04X", RS485_1_Values_SV[i] * rcv);
@ -46,6 +48,11 @@ String Prcss_ALL_Read(){
} }
str += RcvOK; str += RcvOK;
str += "INIT?:";
sprintf(formattedNumber, "%04X", ((unsigned int)(Init_AO | Init_MC9)));
str += formattedNumber;
str += ',';
str += RcvOK;
return str + FIN; return str + FIN;
} }
@ -79,44 +86,43 @@ String Prcss_AO_Write(unsigned int data[], int dataSize){
return str + FIN; return str + FIN;
} }
String Prcss_SV_Write(unsigned int data[], int dataSize){ String Prcss_SV_Write_1(unsigned int data[], int dataSize){
String str = "SV!:"; String str = "SV_1!:";
msg_MC9_SV_set(data, dataSize); msg_MC9_SV_set_1(data, dataSize);
str += RcvOK;
Serial.println(str);
return str + FIN;
}
String Prcss_AT_Write_1(unsigned int data[], int dataSize){
String str = "AT_1!:";
msg_MC9_AT_set_1(data, dataSize);
str += RcvOK; str += RcvOK;
return str + FIN; return str + FIN;
} }
String Prcss_AT_Write(unsigned int data[], int dataSize){ String Prcss_SV_Write_2(unsigned int data[], int dataSize){
String str = "AT!:"; String str = "SV_2!:";
msg_MC9_AT_set(data, dataSize); msg_MC9_SV_set_2(data, dataSize);
str += RcvOK; str += RcvOK;
return str + FIN; return str + FIN;
} }
/*
String Prcss_AT_Write(bool onOff){ String Prcss_AT_Write_2(unsigned int data[], int dataSize){
String str = "AT!:"; String str = "AT_2!:";
String message, cmd;
msg_MC9_AT_set_2(data, dataSize);
cmd = "10DWR,02,0302,0001,0501,";
if(onOff){
cmd += "0001";
}else{
cmd += "0000";
}
message = cmd;
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_Wr, message);
str += RcvOK; str += RcvOK;
return str + FIN; return str + FIN;
} }
*/
String Prcss_RngAO(unsigned int data[], int dataSize){ String Prcss_RngAO(unsigned int data[], int dataSize){
String str = "RngAO!:"; String str = "RngAO!:";
int rng = 0; int rng = 0;
@ -135,8 +141,8 @@ String Prcss_RngAO(unsigned int data[], int dataSize){
return str + FIN; return str + FIN;
} }
String Prcss_ChMC9(unsigned int data[], int dataSize){ String Prcss_ChMC9_1(unsigned int data[], int dataSize){
String str = "ChMC9!:"; String str = "ChMC9_1!:";
int d = 20; int d = 20;
for(int i=0 ; i<dataSize ; i++){ for(int i=0 ; i<dataSize ; i++){
setupMC9_1(i, data[i]); setupMC9_1(i, data[i]);
@ -144,4 +150,15 @@ String Prcss_ChMC9(unsigned int data[], int dataSize){
} }
str += RcvOK; str += RcvOK;
return str + FIN; 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); digitalWrite(RS485_OE_2, Rcv_485);
} }
void send_485(){ void send_485_1(){
if(!Wait_485_1){ if(!Wait_485_1){
String message = read_buff(Buff_485_1_Wr); String message = read_buff(Buff_485_1_Wr);
if(message != ""){ if(message != ""){
//save sent message info. for received data processing //save sent message info. for received data processing
latest_sent_msg = message; latest_sent_msg_1 = message;
message += CRLF; message += CRLF;
digitalWrite(RS485_OE_1, Snd_485); delay(5); digitalWrite(RS485_OE_1, Snd_485); delay(5);
@ -39,26 +39,40 @@ void send_485(){
} }
} }
int recieve_485(){ 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(){
// Timeout code // Timeout code
if(Wait_485_1){ if(Wait_485_1){
Wait_485_1_cnt++; Wait_485_1_cnt++;
if(Wait_485_1_cnt > 25){ // Timeout = periodic(20ms) x 25 = 500 msec if(Wait_485_1_cnt > 40){ // Timeout = periodic(20ms) x 25 = 500 msec
//Serial.println("485 not responced... (Timeout)"); //Serial.println("485 not responced... (Timeout)");
timeoutMC9(); timeoutMC9_1();
//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 = false;
Wait_485_1_cnt = 0; Wait_485_1_cnt = 0;
numOf485--; numOf485--;
return -1; return -1;
} }
} }
@ -71,8 +85,8 @@ int recieve_485(){
String message = read_buff(Buff_485_1_Rd); String message = read_buff(Buff_485_1_Rd);
if(message != ""){ if(message != ""){
numOf485--; numOf485--;
if(latest_sent_msg.indexOf("DRS") != -1){ if(latest_sent_msg_1.indexOf("DRS") != -1){
saveMC9(message); saveMC9_1(message);
} }
else{ else{
Serial.print("----- 485 rcv : "); Serial.print("----- 485 rcv : ");
@ -85,6 +99,45 @@ int recieve_485(){
return 0; 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 */ /* For Test from PC */
void recieve_485_0(){ void recieve_485_0(){
@ -102,3 +155,21 @@ void recieve_485_0(){
IdeSerial = ""; 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.

@ -1,4 +1,4 @@
37970046450706097 37988699897139129
Audio_Module Audio_Module
Reverb_BTDR-1H Reverb_BTDR-1H
Digital Reverberation Unit, http://www.belton.co.kr/inc/downfile.php?seq=17&file=pdf (footprint from http://www.uk-electronic.de/PDF/BTDR-1.pdf) Digital Reverberation Unit, http://www.belton.co.kr/inc/downfile.php?seq=17&file=pdf (footprint from http://www.uk-electronic.de/PDF/BTDR-1.pdf)
@ -150507,6 +150507,13 @@ rotary encoder
7 7
6 6
ScitechKorea ScitechKorea
74HC138
<b>Small Outline Integrated Circuit</b>
0
16
16
ScitechKorea
Holder5reg Holder5reg
@ -150521,6 +150528,20 @@ Holder485
8 8
8 8
ScitechKorea ScitechKorea
HolderEth
0
10
0
ScitechKorea
HolderEth_1
0
10
10
ScitechKorea
I2C_Socket I2C_Socket
@ -150528,6 +150549,20 @@ I2C_Socket
4 4
4 4
ScitechKorea ScitechKorea
R250
Resistor, Axial_DIN0204 series, Axial, Horizontal, pin pitch=7.62mm, 0.167W, length*diameter=3.6*1.6mm^2, http://cdn-reichelt.de/documents/datenblatt/B400/1_4W%23YAG.pdf
Resistor Axial_DIN0204 series Axial Horizontal pin pitch 7.62mm 0.167W length 3.6mm diameter 1.6mm
0
2
2
ScitechKorea
ScrewHole
0
0
0
ScitechKorea
Terminal_02 Terminal_02
@ -150549,12 +150584,33 @@ Terminal_16
16 16
16 16
ScitechKorea ScitechKorea
Terminal_24
0
24
24
ScitechKorea
mega_socket mega_socket
0 0
92 92
91 91
ScitechKorea
mega_socket_no_center
0
86
85
ScitechKorea
mega_socket_simplest
0
86
85
Sensor Sensor
Aosong_DHT11_5.5x12.0_P2.54mm Aosong_DHT11_5.5x12.0_P2.54mm
Temperature and humidity module, http://akizukidenshi.com/download/ds/aosong/DHT11.pdf Temperature and humidity module, http://akizukidenshi.com/download/ds/aosong/DHT11.pdf
@ -151017,6 +151073,27 @@ LEM Hall Effect Voltage transducer
0 0
5 5
5 5
Shocker
SOIC127P600X175-8N
D0008A
Integrated Circuit
0
8
8
Shocker
SOP40P640X120-16N
DGV (R-PDSO-G16)
Integrated Circuit
0
16
16
Shocker
SOP65P640X110-16N
SOT403-1
Integrated Circuit
0
16
16
Socket Socket
3M_Textool_240-1288-00-0602J_2x20_P2.54mm 3M_Textool_240-1288-00-0602J_2x20_P2.54mm
3M 40-pin zero insertion force socket, though-hole, row spacing 25.4 mm (1000 mils) 3M 40-pin zero insertion force socket, though-hole, row spacing 25.4 mm (1000 mils)

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
{ {
"board": { "board": {
"active_layer": 37, "active_layer": 31,
"active_layer_preset": "", "active_layer_preset": "",
"auto_track_width": true, "auto_track_width": true,
"hidden_netclasses": [], "hidden_netclasses": [],
@ -15,17 +15,17 @@
"zones": 0.6 "zones": 0.6
}, },
"selection_filter": { "selection_filter": {
"dimensions": false, "dimensions": true,
"footprints": false, "footprints": true,
"graphics": false, "graphics": true,
"keepouts": false, "keepouts": true,
"lockedItems": false, "lockedItems": false,
"otherItems": false, "otherItems": true,
"pads": false, "pads": true,
"text": true, "text": true,
"tracks": true, "tracks": true,
"vias": true, "vias": true,
"zones": false "zones": true
}, },
"visible_items": [ "visible_items": [
0, 0,

@ -34,9 +34,9 @@
"other_text_thickness": 0.15, "other_text_thickness": 0.15,
"other_text_upright": false, "other_text_upright": false,
"pads": { "pads": {
"drill": 0.7, "drill": 3.2,
"height": 1.4, "height": 3.2,
"width": 1.4 "width": 3.2
}, },
"silk_line_width": 0.15, "silk_line_width": 0.15,
"silk_text_italic": false, "silk_text_italic": false,
@ -439,7 +439,7 @@
"last_paths": { "last_paths": {
"gencad": "", "gencad": "",
"idf": "", "idf": "",
"netlist": "", "netlist": "./",
"specctra_dsn": "", "specctra_dsn": "",
"step": "", "step": "",
"vrml": "" "vrml": ""

File diff suppressed because it is too large Load Diff

@ -0,0 +1,97 @@
/*
* 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