You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
3.6 KiB
C++

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++) {
float sum_AI = 0;
for(int j = 0; j < AI_AVG_SIZE; j++) {
sum_AI += (float) Recent_AI[i][j] * factor;
}
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", integer_part); // 4자리로 고정된 형식의 문자열 생성
str += formattedNumber; // 형식화된 문자열 추가
str += ',';
}
str += RcvOK;
str += "DI?:";
sprintf(formattedNumber, "%04X", Values_DI);
str += formattedNumber;
str += ',';
str += RcvOK;
str += "PV_1?:";
for (int i = 0; i < RS485_1_Rcv_size*2; i++) {
int rcv = int(RS485_1_Rcv_PV[i/RS485_1_Rcv_size]);
sprintf(formattedNumber, "%04X", RS485_1_Values_PV[i] * rcv);
str += formattedNumber;
str += ',';
}
str += RcvOK;
str += "SV_1?:";
for (int i = 0; i < RS485_1_Rcv_size*2; i++) {
int rcv = int(RS485_1_Rcv_SV[i/RS485_1_Rcv_size]);
sprintf(formattedNumber, "%04X", RS485_1_Values_SV[i] * rcv);
str += formattedNumber;
str += ',';
}
str += RcvOK;
str += "INIT?:";
sprintf(formattedNumber, "%04X", ((unsigned int)(Init_AO | Init_MC9)));
str += formattedNumber;
str += ',';
str += RcvOK;
return str + FIN;
}
String Prcss_DO_Write(unsigned int data[], int dataSize){
String str = "DO!:";
if(dataSize != 1){
str += RcvErr;
return str + FIN;
}
unsigned int data0 = data[0];
for (int bit = 0; bit < 16; bit++) {
digitalWrite(DoPin[bit], bitRead(data0, bit) ? HIGH : LOW);
}
str += RcvOK;
return str + FIN;
}
String Prcss_AO_Write(unsigned int data[], int dataSize){
String str = "AO!:";
int d = 2;
for(int i=0 ; i<dataSize ; i++){
AO_Write(i, data[i]);
}
str += RcvOK;
return str + FIN;
}
String Prcss_SV_Write_1(unsigned int data[], int dataSize){
String str = "SV_1!:";
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_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);
str += RcvOK;
return str + FIN;
}
String Prcss_RngAO(unsigned int data[], int dataSize){
String str = "RngAO!:";
int rng = 0;
int d = 10;
for(int i=0 ; i<dataSize ; i++){
if(i+1 < dataSize){
rng = (data[i] > data[i+1]) ? data[i] : data[i+1];
}else{
rng = data[i];
}
AO_setup(i, rng);
delay(d);
i++; // every 0 ch, not 1 ch.
}
str += RcvOK;
return str + FIN;
}
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]);
delay(d);
}
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;
}