mirror of https://github.com/sfeakes/AqualinkD.git
Updates
parent
69f9a5c176
commit
6768ca5d90
19
aqualinkd.c
19
aqualinkd.c
|
@ -1848,20 +1848,15 @@ void main_loop()
|
|||
caculate_ack_packet(rs_fd, packet_buffer, SIMULATOR);
|
||||
DEBUG_TIMER_STOP(_rs_packet_timer,AQUA_LOG,"Simulator Emulation Processed packet in");
|
||||
}
|
||||
else if ( _aqualink_data.simulator_id == NUL
|
||||
&& packet_buffer[PKT_CMD] == CMD_PROBE
|
||||
&& packet_buffer[PKT_DEST] != _aqconfig_.device_id
|
||||
else if ( _aqualink_data.simulator_id == NUL
|
||||
&& packet_buffer[PKT_CMD] == CMD_PROBE
|
||||
&& packet_buffer[PKT_DEST] != _aqconfig_.device_id // Check no conflicting id's
|
||||
#if defined AQ_ONETOUCH || defined AQ_IAQTOUCH
|
||||
&& packet_buffer[PKT_DEST] != _aqconfig_.extended_device_id
|
||||
&& packet_buffer[PKT_DEST] != _aqconfig_.extended_device_id // Check no conflicting id's
|
||||
#endif
|
||||
) {
|
||||
// Check it's a probe we are after
|
||||
//if (_aqualink_data.simulator_active == ONETOUCH && packet_buffer[PKT_DEST] >= 0x40 && packet_buffer[PKT_DEST] <= 0x43 && packet_buffer[PKT_DEST] != _aqconfig_.extended_device_id) {
|
||||
if ( (_aqualink_data.simulator_active == ONETOUCH && packet_buffer[PKT_DEST] >= 0x40 && packet_buffer[PKT_DEST] <= 0x43) ||
|
||||
(_aqualink_data.simulator_active == ALLBUTTON && packet_buffer[PKT_DEST] >= 0x08 && packet_buffer[PKT_DEST] <= 0x0a) ||
|
||||
(_aqualink_data.simulator_active == IAQTOUCH && packet_buffer[PKT_DEST] >= 0x30 && packet_buffer[PKT_DEST] <= 0x33) ||
|
||||
(_aqualink_data.simulator_active == AQUAPDA && packet_buffer[PKT_DEST] >= 0x60 && packet_buffer[PKT_DEST] <= 0x63)
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (is_simulator_packet(&_aqualink_data, packet_buffer, packet_length)) {
|
||||
_aqualink_data.simulator_id = packet_buffer[PKT_DEST];
|
||||
// reply to probe
|
||||
LOG(SIM_LOG,LOG_NOTICE, "Got probe on '0x%02hhx', using for simulator ID\n",packet_buffer[PKT_DEST]);
|
||||
|
|
|
@ -155,7 +155,7 @@ void _broadcast_simulator_message(struct mg_connection *nc) {
|
|||
}
|
||||
}
|
||||
|
||||
LOG(NET_LOG,LOG_DEBUG, "Sent to simulator '%s'\n",data);
|
||||
//LOG(NET_LOG,LOG_DEBUG, "Sent to simulator '%s'\n",data);
|
||||
|
||||
_aqualink_data->simulator_packet_updated = false;
|
||||
}
|
||||
|
@ -985,25 +985,19 @@ uriAtype action_URI(request_source from, const char *URI, int uri_length, float
|
|||
return uSetSchedules;
|
||||
} else if (strncmp(ri1, "schedules", 9) == 0) {
|
||||
return uSchedules;
|
||||
} else if (strncmp(ri1, "simulator/onetouch", 18) == 0 && from == NET_WS) { // Only valid from websocket.
|
||||
LOG(NET_LOG,LOG_NOTICE, "Received request to start Onetouch Simulator!\n");
|
||||
_aqualink_data->simulator_active = ONETOUCH;
|
||||
return uSimulator;
|
||||
} else if (strncmp(ri1, "simulator/allbutton", 19) == 0 && from == NET_WS) { // Only valid from websocket.
|
||||
LOG(NET_LOG,LOG_NOTICE, "Received request to start AllButton Simulator!\n");
|
||||
_aqualink_data->simulator_active = ALLBUTTON;
|
||||
return uSimulator;
|
||||
} else if (strncmp(ri1, "simulator/aquapda", 17) == 0 && from == NET_WS) { // Only valid from websocket.
|
||||
LOG(NET_LOG,LOG_NOTICE, "Received request to start PDA Simulator!\n");
|
||||
_aqualink_data->simulator_active = AQUAPDA;
|
||||
return uSimulator;
|
||||
} else if (strncmp(ri1, "simulator/iaqtouch", 18) == 0 && from == NET_WS) { // Only valid from websocket.
|
||||
LOG(NET_LOG,LOG_NOTICE, "Received request to start iAqualinkTouch Simulator!\n");
|
||||
_aqualink_data->simulator_active = IAQTOUCH;
|
||||
return uSimulator;
|
||||
/*
|
||||
} else if (strncmp(ri1, "simulator", 9) == 0 && from == NET_WS) { // Only valid from websocket.
|
||||
return uSimulator;*/
|
||||
if (ri2 != NULL && strncmp(ri2, "onetouch", 8) == 0) {
|
||||
start_simulator(_aqualink_data, ONETOUCH);
|
||||
} else if (ri2 != NULL && strncmp(ri2, "allbutton", 9) == 0) {
|
||||
start_simulator(_aqualink_data, ALLBUTTON);
|
||||
} else if (ri2 != NULL && strncmp(ri2, "aquapda", 7) == 0) {
|
||||
start_simulator(_aqualink_data, AQUAPDA);
|
||||
} else if (ri2 != NULL && strncmp(ri2, "iaqtouch", 8) == 0) {
|
||||
start_simulator(_aqualink_data, IAQTOUCH);
|
||||
} else {
|
||||
return uBad;
|
||||
}
|
||||
return uSimulator;
|
||||
} else if (strncmp(ri1, "simcmd", 10) == 0 && from == NET_WS) { // Only valid from websocket.
|
||||
simulator_send_cmd((unsigned char)value);
|
||||
return uActioned;
|
||||
|
@ -1610,13 +1604,11 @@ void action_websocket_request(struct mg_connection *nc, struct websocket_message
|
|||
break;
|
||||
case uSimulator:
|
||||
{
|
||||
LOG(NET_LOG,LOG_DEBUG, "Started Simulator Mode\n");
|
||||
LOG(NET_LOG,LOG_DEBUG, "Request to start Simulator\n");
|
||||
set_websocket_simulator(nc);
|
||||
//_aqualink_data->simulate_panel = true;
|
||||
// Clear simulator ID incase sim type changes
|
||||
_aqualink_data->simulator_id = NUL;
|
||||
//LOG(NET_LOG,LOG_ERR, "Started Simulator Mode, code removed for dubug, put back in\n");
|
||||
|
||||
//_aqualink_data->simulator_id = NUL;
|
||||
DEBUG_TIMER_START(&tid);
|
||||
char message[JSON_BUFFER_SIZE];
|
||||
build_aqualink_status_JSON(_aqualink_data, message, JSON_BUFFER_SIZE);
|
||||
|
@ -1759,8 +1751,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
|||
_aqualink_data->open_websockets--;
|
||||
LOG(NET_LOG,LOG_DEBUG, "-- Websocket left\n");
|
||||
if (is_websocket_simulator(nc)) {
|
||||
_aqualink_data->simulator_active = SIM_NONE;
|
||||
_aqualink_data->simulator_id = NUL;
|
||||
stop_simulator(_aqualink_data);
|
||||
LOG(NET_LOG,LOG_DEBUG, "Stoped Simulator Mode\n");
|
||||
} else if (is_websocket_aqmanager(nc)) {
|
||||
_aqualink_data->aqManagerActive = false;
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -41,7 +41,7 @@
|
|||
#define SLOG_MAX 80
|
||||
#define PACKET_MAX 600
|
||||
|
||||
#define VERSION "serial_logger V2.0"
|
||||
#define VERSION "serial_logger V2.1"
|
||||
|
||||
/*
|
||||
typedef enum used {
|
||||
|
@ -86,7 +86,7 @@ bool _playback_file = false;
|
|||
|
||||
int sl_timespec_subtract (struct timespec *result, const struct timespec *x, const struct timespec *y);
|
||||
|
||||
int _serial_logger(int rs_fd, char *port_name, int logPackets, int logLevel, bool panleProbe, bool rsSerialSpeedTest, bool errorMonitor);
|
||||
int _serial_logger(int rs_fd, char *port_name, int logPackets, int logLevel, bool panleProbe, bool rsSerialSpeedTest, bool errorMonitor, bool printAllIDs);
|
||||
|
||||
|
||||
#ifdef SERIAL_LOGGER
|
||||
|
@ -101,7 +101,7 @@ void intHandler(int dummy) {
|
|||
}
|
||||
#else
|
||||
int serial_logger (int rs_fd, char *port_name, int logLevel) {
|
||||
return _serial_logger(rs_fd, port_name, PACKET_MAX, (logLevel>=LOG_NOTICE?logLevel:LOG_NOTICE), true, false, false);
|
||||
return _serial_logger(rs_fd, port_name, PACKET_MAX, (logLevel>=LOG_NOTICE?logLevel:LOG_NOTICE), true, false, false, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -362,6 +362,7 @@ int main(int argc, char *argv[]) {
|
|||
bool rsSerialSpeedTest = false;
|
||||
bool serialBlocking = true;
|
||||
bool errorMonitor = false;
|
||||
bool printAllIDs = false;
|
||||
|
||||
// aq_serial.c uses the following
|
||||
_aqconfig_.log_protocol_packets = false;
|
||||
|
@ -388,6 +389,7 @@ int main(int argc, char *argv[]) {
|
|||
fprintf(stderr, "\t-lpack (log RS packets to %s)\n",RS485LOGFILE);
|
||||
fprintf(stderr, "\t-lrawb (log raw RS bytes to %s)\n",RS485BYTELOGFILE);
|
||||
fprintf(stderr, "\t-e (monitor errors)\n");
|
||||
fprintf(stderr, "\t-a (Print all ID's the panel queried)\n");
|
||||
fprintf(stderr, "\nie:\t%s /dev/ttyUSB0 -d -p 1000 -i 0x08 -i 0x0a\n\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
@ -421,6 +423,8 @@ int main(int argc, char *argv[]) {
|
|||
serialBlocking = false;
|
||||
} else if (strcmp(argv[i], "-e") == 0) {
|
||||
errorMonitor = true;
|
||||
} else if (strcmp(argv[i], "-a") == 0) {
|
||||
printAllIDs = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,7 +472,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
startPacketLogger();
|
||||
|
||||
_serial_logger(rs_fd, argv[1], logPackets, logLevel, panleProbe, rsSerialSpeedTest, errorMonitor);
|
||||
_serial_logger(rs_fd, argv[1], logPackets, logLevel, panleProbe, rsSerialSpeedTest, errorMonitor, printAllIDs);
|
||||
|
||||
stopPacketLogger();
|
||||
|
||||
|
@ -480,7 +484,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
|
||||
|
||||
int _serial_logger(int rs_fd, char *port_name, int logPackets, int logLevel, bool panleProbe, bool rsSerialSpeedTest, bool errorMonitor) {
|
||||
int _serial_logger(int rs_fd, char *port_name, int logPackets, int logLevel, bool panleProbe, bool rsSerialSpeedTest, bool errorMonitor, bool printAllIDs) {
|
||||
int packet_length;
|
||||
int last_packet_length = 0;
|
||||
unsigned char packet_buffer[AQ_MAXPKTLEN];
|
||||
|
@ -566,6 +570,7 @@ int _serial_logger(int rs_fd, char *port_name, int logPackets, int logLevel, boo
|
|||
}
|
||||
}
|
||||
if (found != true && sindex < SLOG_MAX) {
|
||||
//printf("Added id 0x%02hhx\n",packet_buffer[PKT_DEST]);
|
||||
slog[sindex].ID = packet_buffer[PKT_DEST];
|
||||
slog[sindex].inuse = false;
|
||||
sindex++;
|
||||
|
@ -651,7 +656,8 @@ int _serial_logger(int rs_fd, char *port_name, int logPackets, int logLevel, boo
|
|||
for (i = 0; i < sindex; i++) {
|
||||
//LOG(RSSD_LOG, LOG_NOTICE, "ID 0x%02hhx is %s %s\n", slog[i].ID, (slog[i].inuse == true) ? "in use" : "not used",
|
||||
// (slog[i].inuse == false && canUse(slog[i].ID) == true)? " <-- can use for Aqualinkd" : "");
|
||||
if (logLevel >= LOG_DEBUG || slog[i].inuse == true || canUse(slog[i].ID) == true) {
|
||||
//if (logLevel >= LOG_DEBUG || slog[i].inuse == true || canUse(slog[i].ID) == true) {
|
||||
if (logLevel >= LOG_DEBUG || slog[i].inuse == true || canUse(slog[i].ID) == true || printAllIDs == true) {
|
||||
LOG(RSSD_LOG, LOG_NOTICE, "ID 0x%02hhx is %s %s\n", slog[i].ID, (slog[i].inuse == true) ? "in use " : "not used",
|
||||
(slog[i].inuse == false)?canUseExtended(slog[i].ID):getDevice(slog[i].ID));
|
||||
}
|
||||
|
|
61
simulator.c
61
simulator.c
|
@ -68,4 +68,65 @@ bool processSimulatorPacket(unsigned char *packet, int packet_length, struct aqu
|
|||
broadcast_simulator_message();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_simulator(struct aqualinkdata *aqdata, emulation_type type) {
|
||||
|
||||
// if type is same AND id is valid, sim is already started, their is nothing to do.
|
||||
if (aqdata->simulator_active == type) {
|
||||
if (aqdata->simulator_id >= 0x40 && aqdata->simulator_id <= 0x43) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "OneTouch Simulator already active!\n");
|
||||
return true;
|
||||
} else if (aqdata->simulator_id >= 0x08 && aqdata->simulator_id <= 0x0a) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "AllButton Simulator already active!\n");
|
||||
return true;
|
||||
} else if (aqdata->simulator_id >= 0x30 && aqdata->simulator_id <= 0x33) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "iAqualinkTouch Simulator already active!\n");
|
||||
return true;
|
||||
} else if (aqdata->simulator_id >= 0x60 && aqdata->simulator_id <= 0x63) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "PDA Simulator already active!\n");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check it's a valid request
|
||||
if (type == ALLBUTTON) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "Starting AllButton Simulator!\n");
|
||||
} else if (type == ONETOUCH) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "Starting OneTouch Simulator!\n");
|
||||
} else if (type == AQUAPDA ) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "Starting PDA Simulator!\n");
|
||||
} else if (type == IAQTOUCH) {
|
||||
LOG(SIM_LOG,LOG_NOTICE, "Starting iAqualinkTouch Simulator!\n");
|
||||
} else {
|
||||
LOG(SIM_LOG,LOG_ERR, "Request to start simulator of unknown type : %d", type);
|
||||
return false;
|
||||
}
|
||||
|
||||
// start the simulator
|
||||
aqdata->simulator_active = type;
|
||||
aqdata->simulator_id = NUL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stop_simulator(struct aqualinkdata *aqdata) {
|
||||
aqdata->simulator_active = SIM_NONE;
|
||||
aqdata->simulator_id = NUL;
|
||||
|
||||
LOG(SIM_LOG,LOG_DEBUG, "Stoped Simulator Mode\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_simulator_packet(struct aqualinkdata *aqdata, unsigned char *packet, int packet_length) {
|
||||
|
||||
if ( (aqdata->simulator_active == ONETOUCH && packet[PKT_DEST] >= 0x40 && packet[PKT_DEST] <= 0x43) ||
|
||||
(aqdata->simulator_active == ALLBUTTON && packet[PKT_DEST] >= 0x08 && packet[PKT_DEST] <= 0x0a) ||
|
||||
(aqdata->simulator_active == IAQTOUCH && packet[PKT_DEST] >= 0x30 && packet[PKT_DEST] <= 0x33) ||
|
||||
(aqdata->simulator_active == AQUAPDA && packet[PKT_DEST] >= 0x60 && packet[PKT_DEST] <= 0x63) ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -10,4 +10,9 @@ int simulator_cmd_length();
|
|||
//bool push_simulator_cmd(unsigned char cmd);
|
||||
void simulator_send_cmd(unsigned char cmd);
|
||||
|
||||
bool start_simulator(struct aqualinkdata *aqdata, emulation_type type);
|
||||
bool stop_simulator(struct aqualinkdata *aqdata);
|
||||
|
||||
bool is_simulator_packet(struct aqualinkdata *aqdata, unsigned char *packet, int packet_length);
|
||||
|
||||
#endif // SIMULATOR_H_
|
|
@ -134,6 +134,27 @@
|
|||
|
||||
var _panel_size = 6;
|
||||
var _panel_set = 0;
|
||||
var _keep_socket_alive=true;
|
||||
|
||||
// See if we are in an iframe and capture focus
|
||||
function capture_iframe_focus() {
|
||||
var targetNode = parent.document.getElementById('allbutton_iframe');
|
||||
if (targetNode != null) {
|
||||
var observer = new MutationObserver(function(){
|
||||
if(targetNode.style.display != 'none'){
|
||||
console.log("AllButton sim Displaying");
|
||||
startWebsockets();
|
||||
} else {
|
||||
console.log("AllButton sim Hiding");
|
||||
stopWebsockets();
|
||||
}
|
||||
});
|
||||
observer.observe(targetNode, { attributes: true, childList: true });
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function send(source) {
|
||||
console.log("from" + source.id);
|
||||
|
@ -404,6 +425,7 @@
|
|||
const PKT_CMD = 3;
|
||||
const PKT_DATA1 = 4;
|
||||
|
||||
const CMD_PROBE = 0;
|
||||
const CMD_STATUS = 2
|
||||
const CMD_MSG = 3 // message
|
||||
const CMD_MSG_LONG = 4
|
||||
|
@ -416,12 +438,15 @@
|
|||
}
|
||||
|
||||
switch(data.dec[PKT_CMD]) {
|
||||
case CMD_PROBE:
|
||||
// We are about to start
|
||||
break;
|
||||
case CMD_MSG: // Message
|
||||
console.log("Received Line "+data.dec[PKT_DATA1]+" = "+packet_to_ascii(data.dec));
|
||||
//console.log("Received Line "+data.dec[PKT_DATA1]+" = "+packet_to_ascii(data.dec));
|
||||
lcd_display(data.dec[PKT_DATA1], packet_to_ascii(data.dec));
|
||||
break;
|
||||
case CMD_MSG_LONG: // Message
|
||||
console.log("Received Line long "+data.dec[PKT_DATA1]+" = "+packet_to_ascii(data.dec));
|
||||
//console.log("Received Line long "+data.dec[PKT_DATA1]+" = "+packet_to_ascii(data.dec));
|
||||
lcd_display_append(data.dec[PKT_DATA1], packet_to_ascii(data.dec));
|
||||
break;
|
||||
|
||||
|
@ -460,6 +485,7 @@
|
|||
|
||||
function startWebsockets() {
|
||||
socket_di = new WebSocket(get_appropriate_ws_url());
|
||||
_keep_socket_alive = true;
|
||||
try {
|
||||
socket_di.onopen = function () {
|
||||
// success!
|
||||
|
@ -488,7 +514,9 @@
|
|||
update_status_message(' !!! Connection error !!! ', true);
|
||||
// Try to reconnect every 5 seconds.
|
||||
setTimeout(function () {
|
||||
startWebsockets();
|
||||
if (_keep_socket_alive == true) {
|
||||
startWebsockets();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
} catch (exception) {
|
||||
|
@ -496,6 +524,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
function stopWebsockets() {
|
||||
if (socket_di) {
|
||||
socket_di.close();
|
||||
}
|
||||
_keep_socket_alive = false;
|
||||
}
|
||||
|
||||
function start_simulator() {
|
||||
var msg = {
|
||||
//command: "simulator"
|
||||
|
@ -520,8 +555,14 @@
|
|||
socket_di.send("reset\n");
|
||||
}
|
||||
*/
|
||||
|
||||
function init() {
|
||||
startWebsockets();
|
||||
if ( capture_iframe_focus() ) {
|
||||
// In iframe wait for focus event to start
|
||||
} else {
|
||||
//update_status_message();
|
||||
startWebsockets();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -136,12 +136,14 @@
|
|||
<script type='text/javascript'>
|
||||
|
||||
var _socket_di;
|
||||
var _keep_socket_alive=true;
|
||||
|
||||
const PKT_CMD = 3;
|
||||
const PKT_DATA1 = 4;
|
||||
const PKT_DATA2 = 5;
|
||||
const PKT_DATA3 = 6;
|
||||
|
||||
const CMD_PROBE = 0;
|
||||
const CMD_MSG_LONG = 4;
|
||||
const CMD_PDA_CLEAR = 9;
|
||||
const CMD_PDA_HIGHLIGHT = 8;
|
||||
|
@ -155,6 +157,25 @@
|
|||
var _hlightcharstart = -1;
|
||||
var _hlightcharend = -1;
|
||||
|
||||
// See if we are in an iframe and capture focus
|
||||
function capture_iframe_focus() {
|
||||
var targetNode = parent.document.getElementById('aquapda_iframe');
|
||||
if (targetNode != null) {
|
||||
var observer = new MutationObserver(function(){
|
||||
if(targetNode.style.display != 'none'){
|
||||
console.log("AquaPDA sim Displaying");
|
||||
startWebsockets();
|
||||
} else {
|
||||
console.log("AquaPDA sim Hiding");
|
||||
stopWebsockets();
|
||||
}
|
||||
});
|
||||
observer.observe(targetNode, { attributes: true, childList: true });
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function send(source) {
|
||||
console.log("from" + source.id);
|
||||
|
@ -239,18 +260,18 @@
|
|||
check_rehighlight_chrs(lineno);
|
||||
}
|
||||
|
||||
function lcd_display_shiftlines(first, last, shift) {
|
||||
function lcd_display_shiftlines(first, last, direction) {
|
||||
|
||||
if (shift < 0) {
|
||||
for (i = first-shift; i <= line; i++) {
|
||||
var line1 = document.getElementById("lcd-l" + (i + shift) );
|
||||
var line2 = document.getElementById("lcd-l" + last);
|
||||
if (direction == 255) {
|
||||
for (i = first; i <= last; i++) {
|
||||
var line1 = document.getElementById("lcd-l" + i);
|
||||
var line2 = document.getElementById("lcd-l" + (i + 1));
|
||||
line1.innerHTML = line2.innerHTML;
|
||||
}
|
||||
} else {
|
||||
for (i = last; i >= first+shift; i--) {
|
||||
} else if (direction == 1) {
|
||||
for (i = last; i >= first; i--) {
|
||||
var line1 = document.getElementById("lcd-l" + i);
|
||||
var line2 = document.getElementById("lcd-l" + (i - shift) );
|
||||
var line2 = document.getElementById("lcd-l" + (i - 1) );
|
||||
line1.innerHTML = line2.innerHTML;
|
||||
}
|
||||
}
|
||||
|
@ -346,25 +367,29 @@
|
|||
}
|
||||
|
||||
switch (data.dec[PKT_CMD]) {
|
||||
case CMD_PROBE:
|
||||
// We are about to start
|
||||
break;
|
||||
case CMD_PDA_CLEAR: // Clear
|
||||
console.log("Received Clear");
|
||||
//console.log("Received Clear");
|
||||
lcd_clear();
|
||||
_shift_lines = false;
|
||||
break;
|
||||
case CMD_MSG_LONG: // Message
|
||||
console.log("Received Line " + data.dec[PKT_DATA1] + " = " + packet_to_ascii(data.dec));
|
||||
//console.log("Received Line " + data.dec[PKT_DATA1] + " = " + packet_to_ascii(data.dec));
|
||||
lcd_display(data.dec[PKT_DATA1], packet_to_ascii(data.dec));
|
||||
break;
|
||||
case CMD_PDA_HIGHLIGHT:
|
||||
console.log("Received Highlight " + data.dec[PKT_DATA1]);
|
||||
//console.log("Received Highlight " + data.dec[PKT_DATA1]);
|
||||
// We sometimes get 255 for line number, need to find out why
|
||||
lcd_display_highlight(data.dec[PKT_DATA1]);
|
||||
break;
|
||||
case CMD_PDA_HIGHLIGHTCHARS:
|
||||
console.log("Received Highlight chars, Line=" + data.dec[PKT_DATA1] + ", Start=" + data.dec[PKT_DATA2] + ", Stop=" + data.dec[PKT_DATA3]);
|
||||
//console.log("Received Highlight chars, Line=" + data.dec[PKT_DATA1] + ", Start=" + data.dec[PKT_DATA2] + ", Stop=" + data.dec[PKT_DATA3]);
|
||||
lcd_display_highlight_chrs(data.dec[PKT_DATA1], data.dec[PKT_DATA2], data.dec[PKT_DATA3]);
|
||||
break;
|
||||
case CMD_PDA_SHIFTLINES:
|
||||
//console.log("Received shift lines, Start=" + data.dec[PKT_DATA1] + ", End=" + data.dec[PKT_DATA2] + ", Direction=" + data.dec[PKT_DATA3]);
|
||||
lcd_display_shiftlines(data.dec[PKT_DATA1], data.dec[PKT_DATA2], data.dec[PKT_DATA3]);
|
||||
break;
|
||||
default:
|
||||
|
@ -432,6 +457,7 @@
|
|||
|
||||
function startWebsockets() {
|
||||
_socket_di = new WebSocket(get_appropriate_ws_url());
|
||||
_keep_socket_alive = true;
|
||||
try {
|
||||
_socket_di.onopen = function () {
|
||||
// success!
|
||||
|
@ -454,7 +480,9 @@
|
|||
update_status_message("!!! Connection error !!!", true);
|
||||
// Try to reconnect every 5 seconds.
|
||||
setTimeout(function () {
|
||||
startWebsockets();
|
||||
if (_keep_socket_alive == true) {
|
||||
startWebsockets();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
} catch (exception) {
|
||||
|
@ -462,6 +490,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
function stopWebsockets() {
|
||||
if (_socket_di) {
|
||||
_socket_di.close();
|
||||
}
|
||||
_keep_socket_alive = false;
|
||||
}
|
||||
|
||||
function start_simulator() {
|
||||
var msg = {
|
||||
//command: "simulator"
|
||||
|
@ -490,8 +525,12 @@
|
|||
}
|
||||
*/
|
||||
function init() {
|
||||
update_status_message();
|
||||
startWebsockets();
|
||||
if ( capture_iframe_focus() ) {
|
||||
// In iframe wait for focus event to start
|
||||
} else {
|
||||
update_status_message();
|
||||
startWebsockets();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
@ -603,9 +642,9 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td align="center"><input class="button_s" id="One" type="button" onclick="send(this);" value="1"></td>
|
||||
<td align="center"><input class="button_s" id="Page_up" type="button" onclick="send(this);" value="1"></td>
|
||||
<td align="center"><input class="button_s" id="Down" type="button" onclick="send(this);"value="↓"></td>
|
||||
<td align="center"><input class="button_s" id="Two" type="button" onclick="send(this);" value="2">
|
||||
<td align="center"><input class="button_s" id="Page_down" type="button" onclick="send(this);" value="2">
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
|
|
@ -135,24 +135,48 @@
|
|||
<script type='text/javascript'>
|
||||
|
||||
var _socket_di;
|
||||
var _keep_socket_alive=true;
|
||||
|
||||
const PKT_CMD = 3;
|
||||
const PKT_DATA1 = 4;
|
||||
const PKT_DATA2 = 5;
|
||||
const PKT_DATA3 = 6;
|
||||
|
||||
const CMD_PROBE = 0;
|
||||
const CMD_MSG_LONG = 4;
|
||||
const CMD_PDA_CLEAR = 9;
|
||||
const CMD_PDA_HIGHLIGHT = 8;
|
||||
const CMD_PDA_HIGHLIGHTCHARS = 16;
|
||||
const CMD_PDA_SHIFTLINES = 15;
|
||||
|
||||
const ONET_LINES = 11; // 0 to 11
|
||||
|
||||
var _hlightcharlineno = -1;
|
||||
var _hlightcharline = "";
|
||||
var _hlightcharstart = -1;
|
||||
var _hlightcharend = -1;
|
||||
|
||||
// See if we are in an iframe and capture focus
|
||||
function capture_iframe_focus() {
|
||||
var targetNode = parent.document.getElementById('onetouch_iframe');
|
||||
if (targetNode != null) {
|
||||
var observer = new MutationObserver(function(){
|
||||
if(targetNode.style.display != 'none'){
|
||||
console.log("OneTouch sim Displaying");
|
||||
startWebsockets();
|
||||
} else {
|
||||
console.log("OneTouch sim Hiding");
|
||||
stopWebsockets();
|
||||
}
|
||||
});
|
||||
observer.observe(targetNode, { attributes: true, childList: true });
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function send(source) {
|
||||
console.log("from" + source.id);
|
||||
|
@ -205,7 +229,7 @@
|
|||
|
||||
function lcd_clear() {
|
||||
//var container = document.getElementById("lcd_display");
|
||||
for (i=1; i <= 12; i++) {
|
||||
for (i=0; i <= ONET_LINES; i++) {
|
||||
//container.lastElementChild.remove();
|
||||
//child = container.children[i];
|
||||
//console.log("Line "+i+" replacing "+child.innerHTML)
|
||||
|
@ -222,7 +246,7 @@
|
|||
|
||||
function lcd_display(lineno, message) {
|
||||
// We get lines 0,2,3,4,5,6.... no line 1. (so using 0 as 1)
|
||||
if (lineno == 0){lineno=1;}
|
||||
//if (lineno == 0){lineno=1;}
|
||||
var line = document.getElementById("lcd-l"+lineno);
|
||||
//console.log("Line "+lineno+" replacing '"+line.innerHTML+"' with '"+message+"'");
|
||||
line.innerHTML = message;
|
||||
|
@ -231,11 +255,28 @@
|
|||
check_rehighlight_chrs(lineno);
|
||||
}
|
||||
|
||||
function lcd_display_shiftlines(first, last, direction) {
|
||||
// Add 1 to first & last we get 0 to 10 not 1 to 11
|
||||
if (direction == 255) {
|
||||
for (i = first; i <= last; i++) {
|
||||
var line1 = document.getElementById("lcd-l" + i);
|
||||
var line2 = document.getElementById("lcd-l" + (i + 1));
|
||||
line1.innerHTML = line2.innerHTML;
|
||||
}
|
||||
} else if (direction == 1) {
|
||||
for (i = last; i >= first; i--) {
|
||||
var line1 = document.getElementById("lcd-l" + i);
|
||||
var line2 = document.getElementById("lcd-l" + (i - 1) );
|
||||
line1.innerHTML = line2.innerHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lcd_display_highlight(lineno) {
|
||||
// We get lines 0,2,3,4,5,6.... no line 1. (so using 0 as 1)
|
||||
if (lineno == 0){lineno=1;}
|
||||
|
||||
for (i=1; i <= 12; i++) {
|
||||
//if (lineno == 0){lineno=1;}
|
||||
|
||||
for (i=0; i <= ONET_LINES; i++) {
|
||||
var line = document.getElementById("lcd-l"+i);
|
||||
if (i != lineno) {
|
||||
line.classList.remove("lcd_highlight");
|
||||
|
@ -321,26 +362,35 @@
|
|||
}
|
||||
|
||||
switch(data.dec[PKT_CMD]) {
|
||||
case CMD_PROBE:
|
||||
// We are about to start
|
||||
document.getElementById("lcd-l2").innerHTML = " Connected ";
|
||||
document.getElementById("lcd-l3").innerHTML = "";
|
||||
break;
|
||||
case CMD_PDA_CLEAR: // Clear
|
||||
console.log("Received Clear");
|
||||
//console.log("Received Clear");
|
||||
lcd_clear();
|
||||
break;
|
||||
case CMD_MSG_LONG: // Message
|
||||
console.log("Received Line "+data.dec[PKT_DATA1]+" = "+packet_to_ascii(data.dec));
|
||||
//console.log("Received Line "+data.dec[PKT_DATA1]+" = "+packet_to_ascii(data.dec));
|
||||
lcd_display(data.dec[PKT_DATA1], packet_to_ascii(data.dec));
|
||||
break;
|
||||
case CMD_PDA_HIGHLIGHT:
|
||||
console.log("Received Highlight "+data.dec[PKT_DATA1]);
|
||||
//console.log("Received Highlight "+data.dec[PKT_DATA1]);
|
||||
// We sometimes get 255 for line number, need to find out why
|
||||
lcd_display_highlight(data.dec[PKT_DATA1]);
|
||||
break;
|
||||
case CMD_PDA_HIGHLIGHTCHARS:
|
||||
console.log("Received Highlight chars, Line="+data.dec[PKT_DATA1]+", Start="+data.dec[PKT_DATA2]+", Stop="+data.dec[PKT_DATA3]);
|
||||
//console.log("Received Highlight chars, Line="+data.dec[PKT_DATA1]+", Start="+data.dec[PKT_DATA2]+", Stop="+data.dec[PKT_DATA3]);
|
||||
lcd_display_highlight_chrs(data.dec[PKT_DATA1], data.dec[PKT_DATA2], data.dec[PKT_DATA3]);
|
||||
break;
|
||||
case CMD_PDA_SHIFTLINES:
|
||||
//console.log("Received shift lines, Start=" + data.dec[PKT_DATA1] + ", End=" + data.dec[PKT_DATA2] + ", Direction=" + data.dec[PKT_DATA3]);
|
||||
lcd_display_shiftlines(data.dec[PKT_DATA1], data.dec[PKT_DATA2], data.dec[PKT_DATA3]);
|
||||
break;
|
||||
default:
|
||||
// 2 is READY for commands
|
||||
console.log("Received unknown command "+data.dec[PKT_CMD]+" "+tohex(data.dec[PKT_CMD]));
|
||||
console.log("Received unknown command "+data.dec[PKT_CMD]+" "+tohex(data.dec[PKT_CMD]));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -403,6 +453,7 @@
|
|||
|
||||
function startWebsockets() {
|
||||
_socket_di = new WebSocket(get_appropriate_ws_url());
|
||||
_keep_socket_alive = true;
|
||||
try {
|
||||
_socket_di.onopen = function () {
|
||||
// success!
|
||||
|
@ -425,7 +476,9 @@
|
|||
update_status_message("!!! Connection error !!!", true);
|
||||
// Try to reconnect every 5 seconds.
|
||||
setTimeout(function () {
|
||||
startWebsockets();
|
||||
if (_keep_socket_alive == true) {
|
||||
startWebsockets();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
} catch (exception) {
|
||||
|
@ -433,6 +486,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
function stopWebsockets() {
|
||||
if (_socket_di) {
|
||||
_socket_di.close();
|
||||
}
|
||||
_keep_socket_alive = false;
|
||||
}
|
||||
|
||||
function start_simulator() {
|
||||
var msg = {
|
||||
//command: "simulator"
|
||||
|
@ -461,8 +521,12 @@
|
|||
}
|
||||
*/
|
||||
function init() {
|
||||
update_status_message();
|
||||
startWebsockets();
|
||||
if ( capture_iframe_focus() ) {
|
||||
// In iframe wait for focus event to start
|
||||
} else {
|
||||
update_status_message();
|
||||
startWebsockets();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
@ -480,7 +544,12 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td class="lcd_display" id="lcd-l1"> </td>
|
||||
<td class="lcd_display" id="lcd-l0"> </td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td class="lcd_display" id="lcd-l1"></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -533,11 +602,13 @@
|
|||
<td class="lcd_display"id="lcd-l11"> </td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<!--
|
||||
<tr>
|
||||
<td></td>
|
||||
<td class="lcd_display" id="lcd-l12"> </td>
|
||||
<td></td>
|
||||
</tr>
|
||||
-->
|
||||
<tr>
|
||||
<td></td>
|
||||
<th align="center"><input id="Select" type="button" onclick="send(this);" value="Select"></th>
|
||||
|
|
|
@ -10,590 +10,111 @@
|
|||
<meta name='apple-mobile-web-app-status-bar-style' content='black'>
|
||||
<link href="aqualinkd.png" rel="apple-touch-icon">
|
||||
<link href="aqualinkd.png" rel="icon">
|
||||
|
||||
<style>
|
||||
html {}
|
||||
|
||||
body {
|
||||
font-family: 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
|
||||
font-weight: 300;
|
||||
background-color: white;
|
||||
color: #000000;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
/* Style the tab */
|
||||
.tab {
|
||||
overflow: hidden;
|
||||
border: 1px solid #ccc;
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
/*position: absolute;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;*/
|
||||
}
|
||||
|
||||
table {
|
||||
background-color: rgb(221, 221, 221);
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#title {
|
||||
background-color: rgb(200, 200, 200);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
input[type=button],
|
||||
input[type=submit],
|
||||
input[type=reset] {
|
||||
background-color: rgb(165, 165, 165);
|
||||
/* Style the buttons that are used to open the tab content */
|
||||
.tab button {
|
||||
background-color: inherit;
|
||||
float: left;
|
||||
border: none;
|
||||
color: rgb(0, 0, 0);
|
||||
padding: 2px 2px;
|
||||
text-decoration: none;
|
||||
margin: 0px 0px;
|
||||
min-width: 70px;
|
||||
border-radius: 70px;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
padding: 14px 16px;
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.led {
|
||||
border-radius: calc(var(--tile_icon-height) / 2);
|
||||
border-radius: 20px;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
filter: alpha(opacity=100);
|
||||
opacity: 1.0;
|
||||
/* Change background color of buttons on hover */
|
||||
.tab button:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.on {
|
||||
background-color: rgb(255, 0, 0);
|
||||
/* Create an active/current tablink class */
|
||||
.tab button.active {
|
||||
background-color: #ccc;
|
||||
}
|
||||
|
||||
.off {
|
||||
background-color: rgb(116, 116, 116);
|
||||
/* Style the tab content */
|
||||
.tabcontent {
|
||||
display: none;
|
||||
/*padding: 6px 12px;*/
|
||||
border: 1px solid #ccc;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.error {
|
||||
background-color: rgb(255, 0, 0) !important;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
.tabiframe {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type='text/javascript'>
|
||||
function openPage(evt, pageName) {
|
||||
// Declare all variables
|
||||
var i, tabcontent, tablinks;
|
||||
|
||||
var _panel_size = 6;
|
||||
var _panel_set = 0;
|
||||
|
||||
function send(source) {
|
||||
console.log("from" + source.id);
|
||||
|
||||
var cmd = {};
|
||||
cmd.uri = "rawcommand"
|
||||
switch (source.id) {
|
||||
case "Filter_Pump_button":
|
||||
cmd.value = "0x02";
|
||||
break;
|
||||
case "Spa_Mode_button":
|
||||
cmd.value = "0x01";
|
||||
break;
|
||||
case "Aux_1_button":
|
||||
cmd.value = "0x05";
|
||||
break;
|
||||
case "Aux_2_button":
|
||||
cmd.value = "0x0a";
|
||||
break;
|
||||
case "Aux_3_button":
|
||||
cmd.value = "0x0f";
|
||||
break;
|
||||
case "Aux_4_button":
|
||||
if (_panel_size < 12)
|
||||
cmd.value = "0x06";
|
||||
else
|
||||
cmd.value = "0x14"; //Different on RS12+ (0x14)
|
||||
break;
|
||||
case "Aux_5_button":
|
||||
if (_panel_size < 12)
|
||||
cmd.value = "0x0b";
|
||||
else
|
||||
cmd.value = "0x03"; //Different on RS12+ (0x03)
|
||||
break;
|
||||
case "Aux_6_button":
|
||||
if (_panel_size < 12)
|
||||
cmd.value = "0x10";
|
||||
else
|
||||
cmd.value = "0x07"; //Different on RS12+ (0x07)
|
||||
break;
|
||||
case "Aux_7_button":
|
||||
if (_panel_size < 12)
|
||||
cmd.value = "0x15";
|
||||
else
|
||||
cmd.value = "0x06"; //Different on RS12+ (0x06)
|
||||
break;
|
||||
case "Aux_B1_button":
|
||||
cmd.value = "0x0b";
|
||||
break;
|
||||
case "Aux_B2_button":
|
||||
cmd.value = "0x10";
|
||||
break;
|
||||
case "Aux_B3_button":
|
||||
cmd.value = "0x15";
|
||||
break;
|
||||
case "Aux_B4_button":
|
||||
cmd.value = "0x1a";
|
||||
break;
|
||||
case "Aux_B5_button":
|
||||
cmd.value = "0x04";
|
||||
break;
|
||||
case "Aux_B6_button":
|
||||
cmd.value = "0x08";
|
||||
break;
|
||||
case "Aux_B7_button":
|
||||
cmd.value = "0x0d";
|
||||
break;
|
||||
case "Aux_B8_button":
|
||||
cmd.value = "0x0c";
|
||||
break;
|
||||
case "Pool_Heater_button":
|
||||
cmd.value = "0x12";
|
||||
break;
|
||||
case "Spa_Heater_button":
|
||||
cmd.value = "0x17";
|
||||
break;
|
||||
case "Solar_Heater_button":
|
||||
cmd.value = "0x1c";
|
||||
break;
|
||||
case "B_menu":
|
||||
cmd.value = "0x09";
|
||||
break;
|
||||
case "B_cancel":
|
||||
cmd.value = "0x0e";
|
||||
break;
|
||||
case "B_back":
|
||||
cmd.value = "0x13";
|
||||
break;
|
||||
case "B_forward":
|
||||
cmd.value = "0x18";
|
||||
break;
|
||||
case "B_enter":
|
||||
cmd.value = "0x1d";
|
||||
break;
|
||||
case "B_hold":
|
||||
cmd.value = "0x19";
|
||||
break;
|
||||
case "B_overide":
|
||||
cmd.value = "0x1c";
|
||||
break;
|
||||
default:
|
||||
alert("Unknown button");
|
||||
return;
|
||||
break;
|
||||
// Get all elements with class="tabcontent" and hide them
|
||||
tabcontent = document.getElementsByClassName("tabcontent");
|
||||
for (i = 0; i < tabcontent.length; i++) {
|
||||
tabcontent[i].style.display = "none";
|
||||
}
|
||||
|
||||
cmd.value = todec(cmd.value);
|
||||
send_command(cmd);
|
||||
|
||||
// I know we are converting hex to dec and back to hex, but here for checking.
|
||||
document.getElementById("messages").innerHTML = "Sent "+tohex(cmd.value)+" please wait for response!";
|
||||
}
|
||||
|
||||
function tohex(value) {
|
||||
var rtn = parseInt(value).toString(16);
|
||||
if (rtn.length <= 1)
|
||||
return "0x0"+rtn;
|
||||
else
|
||||
return "0x"+rtn;
|
||||
}
|
||||
function todec(value) {
|
||||
let number = parseInt(value, 16);
|
||||
return number;
|
||||
}
|
||||
|
||||
function set_panel_size(size)
|
||||
{
|
||||
if (_panel_set == size){
|
||||
return;
|
||||
// Get all elements with class="tablinks" and remove the class "active"
|
||||
tablinks = document.getElementsByClassName("tablinks");
|
||||
for (i = 0; i < tablinks.length; i++) {
|
||||
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
||||
}
|
||||
|
||||
_panel_set = size;
|
||||
// Show the current tab, and add an "active" class to the button that opened the tab
|
||||
document.getElementById(pageName).style.display = "block";
|
||||
|
||||
switch(size){
|
||||
case 6:
|
||||
document.getElementById("Aux_6_led").classList.add("hidden");
|
||||
document.getElementById("Aux_6_button").classList.add("hidden");
|
||||
document.getElementById("Aux_7_led").classList.add("hidden");
|
||||
document.getElementById("Aux_7_button").classList.add("hidden");
|
||||
case 8:
|
||||
document.getElementById("Aux_B1_led").classList.add("hidden");
|
||||
document.getElementById("Aux_B1_button").classList.add("hidden");
|
||||
document.getElementById("Aux_B2_led").classList.add("hidden");
|
||||
document.getElementById("Aux_B2_button").classList.add("hidden");
|
||||
document.getElementById("Aux_B3_led").classList.add("hidden");
|
||||
document.getElementById("Aux_B3_button").classList.add("hidden");
|
||||
document.getElementById("Aux_B4_led").classList.add("hidden");
|
||||
document.getElementById("Aux_B4_button").classList.add("hidden");
|
||||
case 12:
|
||||
document.getElementById("Aux_B5_button").classList.add("hidden");
|
||||
document.getElementById("Aux_B6_button").classList.add("hidden");
|
||||
document.getElementById("Aux_B7_button").classList.add("hidden");
|
||||
document.getElementById("Aux_B8_button").classList.add("hidden");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function update_status(data) {
|
||||
// Some form of error if PDA only panel.
|
||||
if (data.panel_type.startsWith("PDA")) {
|
||||
document.getElementById("title").innerHTML = ' !!! PDA only panels are not Supported !!! '
|
||||
document.getElementById("title").classList.add("error");
|
||||
document.getElementById("messages").innerHTML = ' !!! PDA Not Supported !!! '
|
||||
document.getElementById("messages").classList.add("error");
|
||||
}
|
||||
|
||||
if (document.getElementById("status").getAttribute("raw") != data.panel_message) {
|
||||
document.getElementById("status_three").innerHTML = document.getElementById("status_two").innerHTML;
|
||||
document.getElementById("status_two").innerHTML = document.getElementById("status").innerHTML;
|
||||
if (data.panel_message == "") {
|
||||
document.getElementById("status").innerHTML = " ";
|
||||
} else {
|
||||
document.getElementById("status").innerHTML = data.panel_message;
|
||||
}
|
||||
document.getElementById("status").setAttribute("raw", data.panel_message);
|
||||
document.getElementById("messages").innerHTML = " ";
|
||||
}
|
||||
|
||||
for (var obj in data.leds) {
|
||||
if ((led = document.getElementById(obj.toString() + "_led")) == null) {
|
||||
//console.log("Error " + obj.toString() + " LED not found");
|
||||
//return;
|
||||
} else {
|
||||
if (data.leds[obj] == "on" || data.leds[obj] == "enabled" || data.leds[obj] == "flash") {
|
||||
//console.log("Set " + obj.toString() + " LED on");
|
||||
led.classList.add("on");
|
||||
led.classList.remove("off");
|
||||
} else {
|
||||
//console.log("Set " + obj.toString() + " LED off");
|
||||
led.classList.add("off");
|
||||
led.classList.remove("on");
|
||||
}
|
||||
}
|
||||
if (obj.toString() == "Aux_4" && _panel_size < 6)
|
||||
_panel_size=6;
|
||||
if (obj.toString() == "Aux_6" && _panel_size < 8)
|
||||
_panel_size=8;
|
||||
if (obj.toString() == "Aux_B1" && _panel_size < 12)
|
||||
_panel_size=12;
|
||||
if (obj.toString() == "Aux_B4")
|
||||
_panel_size=16;
|
||||
}
|
||||
|
||||
set_panel_size(_panel_size);
|
||||
}
|
||||
|
||||
function update_device(data) {
|
||||
for (var obj in data['devices']) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function set_labels(data) {
|
||||
for (var obj in data) {
|
||||
if ((button = document.getElementById(obj + "_button")) != null && data[obj] != "NONE") {
|
||||
button.value = data[obj];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_appropriate_ws_url() {
|
||||
var pcol;
|
||||
var u = document.URL;
|
||||
/*
|
||||
* We open the websocket encrypted if this page came on an
|
||||
* https:// url itself, otherwise unencrypted
|
||||
*/
|
||||
if (u.substring(0, 5) == "https") {
|
||||
pcol = "wss://";
|
||||
u = u.substr(8);
|
||||
if (evt != null) {
|
||||
evt.currentTarget.className += " active";
|
||||
} else {
|
||||
pcol = "ws://";
|
||||
if (u.substring(0, 4) == "http")
|
||||
u = u.substr(7);
|
||||
document.getElementById('opentab').className += " active";
|
||||
}
|
||||
u = u.split('/');
|
||||
//alert (pcol + u[0] + ":6500");
|
||||
return pcol + u[0];
|
||||
}
|
||||
/* dumb increment protocol */
|
||||
var socket_di;
|
||||
|
||||
function startWebsockets() {
|
||||
socket_di = new WebSocket(get_appropriate_ws_url());
|
||||
try {
|
||||
socket_di.onopen = function () {
|
||||
// success!
|
||||
start_simulator();
|
||||
get_devices();
|
||||
}
|
||||
socket_di.onmessage = function got_packet(msg) {
|
||||
document.getElementById("status").classList.remove("error");
|
||||
var data = JSON.parse(msg.data);
|
||||
if (data.type == 'status') {
|
||||
update_status(data);
|
||||
} else if (data.type == 'devices') {
|
||||
//update_status(data);
|
||||
update_device(data);
|
||||
} else if (data.type == 'aux_labels') {
|
||||
set_labels(data);
|
||||
}
|
||||
}
|
||||
socket_di.onclose = function () {
|
||||
// something went wrong
|
||||
document.getElementById("status").innerHTML = ' !!! Connection error !!! '
|
||||
document.getElementById("status").classList.add("error");
|
||||
// Try to reconnect every 5 seconds.
|
||||
setTimeout(function () {
|
||||
startWebsockets();
|
||||
}, 5000);
|
||||
}
|
||||
} catch (exception) {
|
||||
alert('<p>Error' + exception);
|
||||
}
|
||||
}
|
||||
|
||||
function start_simulator() {
|
||||
var msg = {
|
||||
//command: "simulator"
|
||||
uri: "simulator"
|
||||
};
|
||||
socket_di.send(JSON.stringify(msg));
|
||||
}
|
||||
|
||||
function get_devices() {
|
||||
var msg = {
|
||||
uri: "devices"
|
||||
};
|
||||
socket_di.send(JSON.stringify(msg));
|
||||
}
|
||||
|
||||
function send_command(cmd) {
|
||||
socket_di.send(JSON.stringify(cmd));
|
||||
}
|
||||
/*
|
||||
function reset() {
|
||||
socket_di.send("reset\n");
|
||||
}
|
||||
*/
|
||||
function init() {
|
||||
startWebsockets();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<body onload="init();">
|
||||
<div class="wrapper">
|
||||
|
||||
<table border='0' id="deviceList">
|
||||
<tr style="title">
|
||||
<td style="title" colspan="12" align="center"><label id="title"> AqualinkD All Button Simulator </label></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="12" align="center"><label id="status_three"> </label></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="12" align="center"><label id="status_two"> </label></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th colspan="12"><label id="status">AqualinkD</label></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<div id="Filter_Pump_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Filter_Pump_button" type="button" onclick="send(this);" value="Filter Pump">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Spa_Mode_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Spa_Mode_button" type="button" onclick="send(this);" value="Spa Mode">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_1_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_1_button" type="button" onclick="send(this);" value="AUX1">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_2_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_2_button" type="button" onclick="send(this);" value="AUX2">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_3_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_3_button" type="button" onclick="send(this);" value="AUX3">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_4_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_4_button" type="button" onclick="send(this);" value="AUX4">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<div id="Aux_5_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_5_button" type="button" onclick="send(this);" value="AUX5">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_6_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_6_button" type="button" onclick="send(this);" value="AUX6">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_7_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_7_button" type="button" onclick="send(this);" value="AUX7">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_B1_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B1_button" type="button" onclick="send(this);" value="AUXB1">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_B2_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B2_button" type="button" onclick="send(this);" value="AUXB2">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Aux_B3_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B3_button" type="button" onclick="send(this);" value="AUXB3">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<div id="Aux_B4_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B4_button" type="button" onclick="send(this);" value="AUXB4">
|
||||
</td>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B5_button" type="button" onclick="send(this);" value="AUXB5">
|
||||
</td>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B6_button" type="button" onclick="send(this);" value="AUXB6">
|
||||
</td>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B7_button" type="button" onclick="send(this);" value="AUXB7">
|
||||
</td>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Aux_B8_button" type="button" onclick="send(this);" value="AUXB8">
|
||||
</td>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
|
||||
</td>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
|
||||
</td>
|
||||
<td align="right">
|
||||
|
||||
</td>
|
||||
<td align="left">
|
||||
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Pool_Heater_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Pool_Heater_button" type="button" onclick="send(this);" value="Pool Heater">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Spa_Heater_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Spa_Heater_button" type="button" onclick="send(this);" value="Spa Heater">
|
||||
</td>
|
||||
<td align="right">
|
||||
<div id="Solar_Heater_led" class="led off"></div>
|
||||
</td>
|
||||
<td align="left">
|
||||
<input id="Solar_Heater_button" type="button" onclick="send(this);" value="Solar Heater">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<TD> </TD>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" colspan="2">
|
||||
<input type="button" onclick="send(this);" id="B_menu" value="Menu">
|
||||
</td>
|
||||
<td align="center" colspan="2">
|
||||
<input type="button" onclick="send(this);" id="B_cancel" value="Cancel">
|
||||
</td>
|
||||
<td align="center" colspan="2">
|
||||
<input type="button" onclick="send(this);" id="B_back" value="Back <">
|
||||
</td>
|
||||
<td align="center" colspan="2">
|
||||
<input type="button" onclick="send(this);" id="B_forward" value="Forward >">
|
||||
</td>
|
||||
<td align="center" colspan="2">
|
||||
<input type="button" onclick="send(this);" id="B_enter" value="Enter *">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="12" align="center"><label id="messages"> </label></td>
|
||||
</tr>
|
||||
</table>
|
||||
<body onload="openPage(null, 'aqualinka_iframe');">
|
||||
<div class="wrapper">
|
||||
<div class="tab">
|
||||
<button id="opentab" class="tablinks" onclick="openPage(event, 'aqualinka_iframe')">AqualinkD</button>
|
||||
<button class="tablinks" onclick="openPage(event, 'allbutton_iframe')">Allbutton Simulator</button>
|
||||
<button class="tablinks" onclick="openPage(event, 'onetouch_iframe')">One Touch Simulator</button>
|
||||
<!--<button class="tablinks" onclick="openPage(event, 'iaqtouch')">iAqualink Touch Simulator</button>-->
|
||||
<button class="tablinks" onclick="openPage(event, 'aquapda_iframe')">PDA Simulator</button>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<!-- Tab content -->
|
||||
<div id="aqualinka_iframe" class="tabcontent">
|
||||
<iframe id="aqd" src="/" class="tabiframe"></iframe>
|
||||
</div>
|
||||
|
||||
<div id="allbutton_iframe" class="tabcontent">
|
||||
<iframe id="aqd" src="/allbutton_sim.html" class="tabiframe"></iframe>
|
||||
</div>
|
||||
|
||||
<div id="onetouch_iframe" class="tabcontent">
|
||||
<iframe id="aqd" src="/onetouch_sim.html" class="tabiframe"></iframe>
|
||||
</div>
|
||||
|
||||
<div id="aquapda_iframe" class="tabcontent">
|
||||
<iframe id="aqd" src="/aquapda_sim.html" class="tabiframe"></iframe>
|
||||
</div>
|
||||
|
||||
<div id="iaqtouch_iframe" class="tabcontent">
|
||||
<iframe id="aqd" src="/iaqtouch_sim.html" class="tabiframe"></iframe>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue