Compare commits

...

6 Commits

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

@ -1,16 +1,24 @@
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, ip, gateway, subnet);
Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
// start listening for clients
server.begin();
web.begin();
//web.begin();
// Report address
Serial.print("MAC>>");
@ -28,36 +36,6 @@ 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,11 +1,38 @@
#include "Arduino.h"
#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"
#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 ---------- */
// Flags
bool T_1ms = false;
bool T_2ms = false;
bool T_4ms = false;
bool T_5ms = false;
bool T_10ms = false;
bool T_20ms = false;
bool T_50ms = false;
@ -19,7 +46,6 @@ bool T_5000ms = false;
// Datas
int msCnt = 0;
unsigned long timer = 0;
#define AI_AVG_SIZE 20
/* ---------- Arduino Mega 2560 Basic IO ---------- */
// Pins
@ -32,11 +58,12 @@ const int AiPin[] = { A0, A1, A2, A3, A4, A5, A6, A7,
// Data Storages
int Size_DO = 16;
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_AI[16];
int Recent_AI[16][AI_AVG_SIZE];
int Values_AI[AI_RANGE];
int Recent_AI[AI_RANGE][AI_AVG_SIZE];
/* ---------- I2C (Analog Output, DAC) ---------- */
// Addresses
@ -52,13 +79,10 @@ 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 (Ethernet Sheld2) ---------- */
// Ethernet Client
/* ---------- Ethernet (ENC28J60) ---------- */
EthernetClient client;
// SCPI defaults to port 5025
EthernetServer server(5025);
// HTTP defaults to port 5025
EthernetServer web(80);
EthernetServer server = EthernetServer(LISTENPORT);
unsigned long lastDataReceivedTime;
unsigned long timeoutPeriod = 5000; // 이더넷 타임아웃 시간 (5초)
@ -67,17 +91,21 @@ bool State_eth = false;
HardwareSerial* Serials[] = {&Serial1, &Serial2};
const int BUFF_SIZE = 1024;
const int BUFF_SIZE = 512;
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;
String latest_sent_msg_1;
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;
@ -92,9 +120,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];
bool RS485_2_Rcv_PV[2];
bool RS485_2_Rcv_SV[2];
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_Rcv_size = 8;
int RS485_2_Values_PV[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_PV_Read();
String Prcss_SV_Read();
String Prcss_SV_Write(unsigned int data[], int dataSize);
String Prcss_AT_Write(unsigned int data[], int dataSize);
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_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
void Ethernet_setup();
@ -121,8 +152,10 @@ int demuxNum(String rightPart, unsigned int data[]);
//RS485
void RS485_setup();
void send_485();
int recieve_485();
void send_485_1();
void send_485_2();
int recieve_485_1();
int recieve_485_2();
void recieve_485_0();
//GPIO
@ -132,10 +165,13 @@ void read_digital();
//MC9
void setupMC9_1(int i, int data);
String msg_MC9_PV(int addr);
String msg_MC9_SV(int addr);
int saveMC9(String message);
int timeoutMC9();
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();
int parseMC9(const String& message, int& addr, String& mode, int data[8], int& crc);
String sumMC9(String input);

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

@ -15,11 +15,17 @@ void read_analog(){
for(i = 0 ; i < Size_AI ; i++){
Values_AI[i] = analogRead(AiPin[i]);
/*
for(int j = 0; j < AI_AVG_SIZE - 1; j++) {
Recent_AI[i][j] = Recent_AI[i][j + 1];
}
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(){

@ -7,10 +7,15 @@ 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 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 = "";
if(addr < 10){
@ -24,7 +29,7 @@ String msg_MC9_PV(int addr){
return message;
}
String msg_MC9_SV(int addr){
String msg_MC9_SV_read(int addr){
String message = "";
if(addr < 10){
@ -38,10 +43,13 @@ String msg_MC9_SV(int addr){
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 = "";
int lp0, lp1;
if(dataSize > 16){
dataSize = 16;
}
if(dataSize > 8){
lp0 = 8;
lp1 = dataSize;
@ -49,7 +57,7 @@ int msg_MC9_SV_set(unsigned int data[], int dataSize){
lp0 = dataSize;
lp1 = 0;
}
if(RS485_1_Addr[0] != 0){
if(RS485_1_Addr[0] < 10){
message += "0";
@ -91,13 +99,14 @@ int msg_MC9_SV_set(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(unsigned int data[], int dataSize){
int msg_MC9_AT_set_1(unsigned int data[], int dataSize){
String message = "";
bool at[16];
@ -108,7 +117,7 @@ int msg_MC9_AT_set(unsigned int data[], int dataSize){
for (int i = 0; i < 16; i++) {
at[i] = (bitRead(data0, i) ? HIGH : LOW);
}
lp0 = 8;
lp1 = 8;
@ -126,7 +135,6 @@ int msg_MC9_AT_set(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.
@ -137,6 +145,7 @@ int msg_MC9_AT_set(unsigned int data[], int dataSize){
}
message += sumMC9(message);
message = "" + message + CRLF;
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;
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 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 idx = -1;
String mode;
@ -190,7 +334,7 @@ int saveMC9(String message){
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;
RS485_1_Rcv_PV[idx] = true;
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;
RS485_1_Rcv_SV[idx] = true;
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 idx = -1;
String msg, mode, cmd;
@ -222,12 +408,12 @@ int timeoutMC9(){
int crc;
// Message parsing
msg = latest_sent_msg.substring(1);
msg = latest_sent_msg_1.substring(1);
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
// Find idx of array
if(RS485_1_Addr[i] == addr){
@ -236,23 +422,38 @@ int timeoutMC9(){
}
}
// If not matched, return error
if(idx < 0){
return 0;
} else {
Serial.println();
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 @");
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);
}
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;
}
}
return 0;
} else {
@ -260,18 +461,6 @@ int timeoutMC9(){
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) {

@ -1,22 +1,31 @@
void Periodic_run(){
if(T_1ms){
// Read Arduino AI
read_analog();
// read_analog();
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){
//read_analog();
T_10ms = false;
}
if(T_20ms){
// send and recieve RS485
send_485();
recieve_485();
send_485_1();
recieve_485_1();
T_20ms = false;
}
if(T_50ms){
// Read Arduino DI
read_digital();
T_50ms = false;
}
@ -29,21 +38,23 @@ void Periodic_run(){
T_200ms = false;
}
if(T_500ms){
// RS485 recieve (for developing)
recieve_485_0();
recieve_485_0(); // RS485 recieve (for developing)
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(RS485_1_Addr[i]));
write_buff(Buff_485_1_Wr, msg_MC9_PV_read(RS485_1_Addr[i]));
}
}
T_1000ms = false;
}
if(T_2000ms){
if(numOf485 > 0){
if(numOf485 > 10){
Serial.print("----- remain 485 buff : "); // For
Serial.println(numOf485); // Debugging
}
@ -53,7 +64,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(RS485_1_Addr[i]));
//write_buff(Buff_485_1_Wr, msg_MC9_SV_read(RS485_1_Addr[i]));
}
}
T_5000ms = false;
@ -64,6 +75,15 @@ void timer_1ms(){
msCnt += 1;
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){
T_10ms = true;
}

@ -1,23 +1,27 @@
String Prcss_ALL_Read(){
String str = "";
char formattedNumber[5]; // 4자리 숫자 + 널 종료 문자
float factor = 1.0f / AI_AVG_SIZE;
str += "AI?:";
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++) {
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", sum_AI); // 4자리로 고정된 형식의 문자열 생성
sprintf(formattedNumber, "%04X", integer_part); // 4자리로 고정된 형식의 문자열 생성
str += formattedNumber; // 형식화된 문자열 추가
str += ',';
}
str += RcvOK;
str += "DI?:";
char formattedNumber[5];
sprintf(formattedNumber, "%04X", Values_DI);
str += formattedNumber;
str += ',';
@ -25,7 +29,6 @@ String Prcss_ALL_Read(){
str += "PV_1?:";
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]);
sprintf(formattedNumber, "%04X", RS485_1_Values_PV[i] * rcv);
@ -37,7 +40,6 @@ String Prcss_ALL_Read(){
str += "SV_1?:";
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]);
sprintf(formattedNumber, "%04X", RS485_1_Values_SV[i] * rcv);
@ -46,6 +48,11 @@ String Prcss_ALL_Read(){
}
str += RcvOK;
str += "INIT?:";
sprintf(formattedNumber, "%04X", ((unsigned int)(Init_AO | Init_MC9)));
str += formattedNumber;
str += ',';
str += RcvOK;
return str + FIN;
}
@ -79,44 +86,43 @@ String Prcss_AO_Write(unsigned int data[], int dataSize){
return str + FIN;
}
String Prcss_SV_Write(unsigned int data[], int dataSize){
String str = "SV!:";
String Prcss_SV_Write_1(unsigned int data[], int dataSize){
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;
return str + FIN;
}
String Prcss_AT_Write(unsigned int data[], int dataSize){
String str = "AT!:";
String Prcss_SV_Write_2(unsigned int data[], int dataSize){
String str = "SV_2!:";
msg_MC9_AT_set(data, dataSize);
msg_MC9_SV_set_2(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";
}
message = cmd;
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_Wr, message);
String Prcss_AT_Write_2(unsigned int data[], int dataSize){
String str = "AT_2!:";
msg_MC9_AT_set_2(data, dataSize);
str += RcvOK;
return str + FIN;
}
*/
String Prcss_RngAO(unsigned int data[], int dataSize){
String str = "RngAO!:";
int rng = 0;
@ -135,8 +141,8 @@ String Prcss_RngAO(unsigned int data[], int dataSize){
return str + FIN;
}
String Prcss_ChMC9(unsigned int data[], int dataSize){
String str = "ChMC9!:";
String Prcss_ChMC9_1(unsigned int data[], int dataSize){
String str = "ChMC9_1!:";
int d = 20;
for(int i=0 ; i<dataSize ; i++){
setupMC9_1(i, data[i]);
@ -144,4 +150,15 @@ String Prcss_ChMC9(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(){
void send_485_1(){
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 = message;
latest_sent_msg_1 = message;
message += CRLF;
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
if(Wait_485_1){
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)");
timeoutMC9();
//if((latest_sent_msg == MC9_10_PV) ||(latest_sent_msg == MC9_10_SV)){
/*
if((latest_sent_msg == msg_MC9_PV(10)) || (latest_sent_msg == msg_MC9_SV(10))){
timeoutMC9();
}
*/
latest_sent_msg = "";
timeoutMC9_1();
latest_sent_msg_1 = "";
Wait_485_1 = false;
Wait_485_1_cnt = 0;
numOf485--;
return -1;
}
}
@ -71,8 +85,8 @@ int recieve_485(){
String message = read_buff(Buff_485_1_Rd);
if(message != ""){
numOf485--;
if(latest_sent_msg.indexOf("DRS") != -1){
saveMC9(message);
if(latest_sent_msg_1.indexOf("DRS") != -1){
saveMC9_1(message);
}
else{
Serial.print("----- 485 rcv : ");
@ -85,6 +99,45 @@ int recieve_485(){
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(){
@ -102,3 +155,21 @@ 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

@ -1,77 +0,0 @@
{
"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": []
}
}

@ -1,490 +0,0 @@
{
"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

@ -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