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.

77 lines
1.9 KiB
C++

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;
// initialize the ethernet device
Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
// start listening for clients
server.begin();
//web.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());
}
String demuxCMD(String command, String* rightPart) {
// ":"를 기준으로 문자열을 분리
int separatorIndex = command.indexOf(":");
String leftPart = command.substring(0, separatorIndex);
*rightPart = command.substring(separatorIndex + 1);
leftPart.replace(" ", "");
return leftPart;
}
int demuxNum(String rightPart, unsigned int data[]) {
// 우측의 16진수 배열을 분리하여 추출
const char* delimiter = ",";
int startIndex = 0;
int endIndex = rightPart.indexOf(delimiter);
int index = 0;
while (endIndex >= 0) {
String hexValue = rightPart.substring(startIndex, endIndex);
// 16진수 문자열을 16진수 숫자로 변환하여 data 배열에 저장
data[index] = strtoul(hexValue.c_str(), NULL, 16);
index++;
startIndex = endIndex + 1;
endIndex = rightPart.indexOf(delimiter, startIndex);
}
// 남은 마지막 16진수 배열 원소 처리
String hexValue = rightPart.substring(startIndex);
data[index] = strtoul(hexValue.c_str(), NULL, 16);
index++;
return index;
}