-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheISCP_Interface.ino
More file actions
93 lines (82 loc) · 2.59 KB
/
eISCP_Interface.ino
File metadata and controls
93 lines (82 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#define PIONEER true //false = Onkyo
#define DEBUG true
//******WIFI******
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif
WiFiClient client;
bool clientConnected = false;
const char* ssid = "MyWiFi";
const char* password = "Secret :)";
IPAddress host = IPAddress(192, 168, 2, 104); //Will automatically be set
IPAddress udpHost = IPAddress(192, 168, 2, 255);
const int port = 60128;
const unsigned int WiFiTimeout = 15000; //15 Sec
const uint16_t TcpTimeout = 5000; //5 Sec
const uint16_t UdpTimeout = 5000; //5 Sec
//******ISCP******
static const uint8_t packetHeader[] = {0x49, 0x53, 0x43, 0x50, //ISCP
0x00, 0x00, 0x00, 0x10, //HeaderSize (Bigendian)
0x00, 0x00, 0x00, 0xFF, //DataSize (Bigendian) replace last with length
0x01, 0x00, 0x00, 0x00 //Version + Reserved
};
const uint8_t packetFooterOutgoing[] = {0x0D};//CR
const uint8_t packetFooterIncoming[] = {0x1A, 0x0D, 0x0A}; //EOF, CR, LF
static const uint8_t lenghtBytePosHeader = 7; //Header Length
static const uint8_t lenghtBytePosHigh = 10; //Message Length 1/2
static const uint8_t lenghtBytePosLow = 11; //Message Length 2/2
static const char commandPrefix[] = "!1"; //Start Character + Destination Unit (Receiver)
const unsigned int IncomingBufferSize = 300;
unsigned char IncomingBuffer[IncomingBufferSize];
uint8_t IncomingBufferCounter = 0;
const char* incoming = "Incoming";
String MessageText = "";
bool MessageBool = false;
int MessageInt = 0;
char MessageCmd[4];//Null Terminated
void setup() {
Serial.begin(115200);
if (SetupWiFi()) {
GetUdpAdress();
if (ConnectToDevice())
RadioBob();
}
}
void loop() {
//Submit Message via Serial: (f.e. !1PWRQSTN or PWRQSTN)
if (Serial.available()) {
String cmdString;
while (Serial.available()) {
char c = Serial.read();
if (c == 0x0D) //CarriageReturn
SendCommand(cmdString);
else
cmdString += c;
}
}
//Constantly read from receiver:
Read();
}
bool SetupWiFi() {
WiFi.begin(ssid, password);
// Wait for connection
unsigned long timeout = millis();
while (WiFi.status() != WL_CONNECTED) {
delay(500);
#if DEBUG
Serial.print(".");
#endif DEBUG
if (millis() - timeout > WiFiTimeout){
SetText("WiFi", "Timeout!");
return false;
}
}
udpHost = WiFi.localIP();
//change to broadcast adress
udpHost[3] = 255;
return true;
}