Ci/Co rooms & Listening for calls in HOTEL mode
Re: Ci/Co rooms & Listening for calls in HOTEL mode
Hi,
My only doubt is related to OXO version and i am not OXO expert.
According to the doc, the OXO release must be 8.2 or above. Is that the case?
If not, for the check-in you must use the type A message and not the type B msg
My only doubt is related to OXO version and i am not OXO expert.
According to the doc, the OXO release must be 8.2 or above. Is that the case?
If not, for the check-in you must use the type A message and not the type B msg
Re: Ci/Co rooms & Listening for calls in HOTEL mode
Hi,
I was advised to use the B frame by the TelCo supplier as "They (their client) use 6 digit passwords, hence the need for a “B” frame."
I don't know the OXO version, but If an can bee advised on Hoe to find this out, then I will endeavour to get this information.
I was advised to use the B frame by the TelCo supplier as "They (their client) use 6 digit passwords, hence the need for a “B” frame."
I don't know the OXO version, but If an can bee advised on Hoe to find this out, then I will endeavour to get this information.
Re: Ci/Co rooms & Listening for calls in HOTEL mode
From your output "OmniPCX Office Version : 3EH30582BPAA ONEGB051/027.001" it seems to be a release 5.1 but once again, i am not a OXO expert.
What you can also try, is to test with a type A frame and check the behaviour.
What you can also try, is to test with a type A frame and check the behaviour.
Re: Ci/Co rooms & Listening for calls in HOTEL mode
Hi, I have replaced "b" with "a" when sending a message, but I get the same error in the O.L.D. log
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x40 0x46 0x46 0x46 0x46 0x03 .@FFFF.
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type @ (7 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : @FFFF
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : ACK
Fri Mar 03 11:22:45 2023 DEBUG 15780 AlcAHLDataLayer::GetConnectionState : GetConnectionState
Fri Mar 03 11:22:45 2023 DEBUG 15780 AlcAHLDataLayer::SetConnectionState : SetConnectionState to 1
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x24 0x46 0x46 0x46 0x46 0x03 .$FFFF.
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type $ (7 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : $FFFF
Fri Mar 03 11:22:45 2023 DEBUG 12708 AlcAHLLinkLayer::restartKeepAliveTimer : Timer 0 started
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : type $ (7 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL : $0001
Fri Mar 03 11:22:45 2023 INFO 15780 AlcAHLConfig::getStr : Parameter GLOBAL_LOG_FILE = C:\Users\Public\Documents\log.txt
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x44 0x20 0x20 0x20 0x20 0x20 0x32 .D 2
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x38 0x33 0x35 0x44 0x03 835D.
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type D (13 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : D 2835D
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : ACK
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLSocket::read : apr_socket_recv() failed (error = 70014)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : AHL link disconnected by the peer application
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : Reset the AHL layers
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer : AHL link reset
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::stopAckTimer : Can't stop the Ack timer : it is not running
Fri Mar 03 11:22:45 2023 DEBUG 12708 AlcAHLLinkLayer::stopKeepAliveTimer : Timer 0 stopped
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : @FFFF
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : $FFFF
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : D 2835D
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x40 0x46 0x46 0x46 0x46 0x03 .@FFFF.
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type @ (7 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : @FFFF
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : ACK
Fri Mar 03 11:22:45 2023 DEBUG 15780 AlcAHLDataLayer::GetConnectionState : GetConnectionState
Fri Mar 03 11:22:45 2023 DEBUG 15780 AlcAHLDataLayer::SetConnectionState : SetConnectionState to 1
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x24 0x46 0x46 0x46 0x46 0x03 .$FFFF.
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type $ (7 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : $FFFF
Fri Mar 03 11:22:45 2023 DEBUG 12708 AlcAHLLinkLayer::restartKeepAliveTimer : Timer 0 started
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : type $ (7 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL : $0001
Fri Mar 03 11:22:45 2023 INFO 15780 AlcAHLConfig::getStr : Parameter GLOBAL_LOG_FILE = C:\Users\Public\Documents\log.txt
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x44 0x20 0x20 0x20 0x20 0x20 0x32 .D 2
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x38 0x33 0x35 0x44 0x03 835D.
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type D (13 bytes)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : D 2835D
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : ACK
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLSocket::read : apr_socket_recv() failed (error = 70014)
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : AHL link disconnected by the peer application
Fri Mar 03 11:22:45 2023 INFO 12708 AlcAHLLinkLayer::Run : Reset the AHL layers
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer : AHL link reset
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::stopAckTimer : Can't stop the Ack timer : it is not running
Fri Mar 03 11:22:45 2023 DEBUG 12708 AlcAHLLinkLayer::stopKeepAliveTimer : Timer 0 stopped
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : @FFFF
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : $FFFF
Fri Mar 03 11:22:45 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : D 2835D
Re: Ci/Co rooms & Listening for calls in HOTEL mode
I do not see any type A frame on the log. The message that i see is a D frame and also for that one the error appears despiste the message its ok.
Are you sure that on the OXO site the setup is done? is it configured for hotel, does the room 283 and 212 exists, are the length configured for 6 digits, ...
Are you sure that on the OXO site the setup is done? is it configured for hotel, does the room 283 and 212 exists, are the length configured for 6 digits, ...
Re: Ci/Co rooms & Listening for calls in HOTEL mode
Also on the old there is the possibility to make a checkin test. Try making a checkin directly from the old and check the behaviour
Re: Ci/Co rooms & Listening for calls in HOTEL mode
In addition, in the sockets docs, the error seems to be due a connection lost. After sending the frames are you closing the connection ?
perhabs you can launch a wireshark capture and check what is going on
perhabs you can launch a wireshark capture and check what is going on
Re: Ci/Co rooms & Listening for calls in HOTEL mode
Hi,
The previous data was for the last response from the system that showed the error. This happened to be a departure, hence the D. Apologies.
Arrivals with an A prefix instead of a B looks like this (and returns the same message ).
I was advised to use the B prefix a while ago after Telco remembered that the system was set up for 6-digit passwords, not four.
They do not use the passwords anyway, hence that section being blank.
Extension Numbers have been confirmed by the TelCo.
The message sent looks correct (to me) re: OXOConnect_OHL_API_Developer-Guide_ed4.0pdf ( pg 35 and 40 )
Thanks
The previous data was for the last response from the system that showed the error. This happened to be a departure, hence the D. Apologies.
Arrivals with an A prefix instead of a B looks like this (and returns the same message ).
Code: Select all
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x40 0x46 0x46 0x46 0x46 0x03 .@FFFF.
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type @ (7 bytes)
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : @FFFF
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : ACK
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x24 0x46 0x46 0x46 0x46 0x03 .$FFFF.
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type $ (7 bytes)
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : $FFFF
Sun Mar 05 17:26:02 2023 DEBUG 12708 AlcAHLLinkLayer::restartKeepAliveTimer : Timer 0 started
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : type $ (7 bytes)
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL : $0001
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x02 0x41 0x20 0x20 0x20 0x20 0x20 0x32 .A 2
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x33 0x34 0x20 0x57 0x69 0x6c 0x64 0x20 34 Wild
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x4c 0x69 0x6e 0x64 0x61 0x20 0x20 0x20 Linda
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x31 1
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x20 0x20 0x30 0x33 0x20 0x20 0x20 0x20 03
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : 0x20 0x20 0x20 0x30 0x30 0x45 0x03 00E.
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL msg : type A (63 bytes)
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::linkLayerFsm : RX AHL : A 234 Wild Linda 1 03 00E
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::sendMessage : TX AHL msg : ACK
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLSocket::read : apr_socket_recv() failed (error = 70014)
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : AHL link disconnected by the peer application
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : Reset the AHL layers
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer : AHL link reset
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLLinkLayer::stopAckTimer : Can't stop the Ack timer : it is not running
Sun Mar 05 17:26:02 2023 DEBUG 12708 AlcAHLLinkLayer::stopKeepAliveTimer : Timer 0 stopped
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : @FFFF
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : $FFFF
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLLinkLayer::resetAHLLinkLayer
Untreated messages in m_RxDataQueue: : A 234 Wild Linda 1 03 00E
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLMetering::resetInterface : Interface reset
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLThread::stopThread : Thread not started or already stopped
Sun Mar 05 17:26:02 2023 WARN 12708 AlcAHLMetering::resetInterface : End of function
Sun Mar 05 17:26:02 2023 DEBUG 12708 AlcAHLDataLayer::SetConnectionState : SetConnectionState to 0
Sun Mar 05 17:26:02 2023 DEBUG 12708 AlcAHLDataLayer::resetAHLDataLayer : resetAHLDataLayer
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLManagement::resetAHLLayers : Stops AlcAHLManagement() thread
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLThread::stopThread : Thread not started or already stopped
Sun Mar 05 17:26:02 2023 INFO 12708 AlcAHLLinkLayer::Run : state = LINK_STATE_DISCONNECTED
They do not use the passwords anyway, hence that section being blank.
Extension Numbers have been confirmed by the TelCo.
The message sent looks correct (to me) re: OXOConnect_OHL_API_Developer-Guide_ed4.0pdf ( pg 35 and 40 )
Thanks
Re: Ci/Co rooms & Listening for calls in HOTEL mode
I think it's wrong. I think you are sending 6 characters in the password field and in the type A frame it should only be 4. The length of a A frame is 61 (with stx, etx and crc)
Either way, this shouldn't be what causes the error = 70014
You bore my remaining comments:
.the error seems to be due a connection lost. After sending the frames are you closing the connection ?
.Also on the OLD there is the possibility to make a checkin test. Try making a checkin directly from the OLD and check the behaviour
Either way, this shouldn't be what causes the error = 70014
You bore my remaining comments:
.the error seems to be due a connection lost. After sending the frames are you closing the connection ?
.Also on the OLD there is the possibility to make a checkin test. Try making a checkin directly from the OLD and check the behaviour
Re: Ci/Co rooms & Listening for calls in HOTEL mode
Hi sadmin, thank you very much for your help and advice. I would just like to say I have an initial interface now working, and it all seems to be working.
Lots of redundant code, but I'll let it work for a while before I tinker.
Incase anyone else is looking to do this, or I forget in the future , here is my code ATM.
Thank you so much again.
Lots of redundant code, but I'll let it work for a while before I tinker.
Incase anyone else is looking to do this, or I forget in the future , here is my code ATM.
Thank you so much again.
Code: Select all
/// This program uses the following additional packages
/// https://github.com/dyatchenko/ServiceBrokerListener
/// Manage Nuget packages, search for SqlServiceBrokerListener (v2 by Sebastian Huebener)
using RestSharp;
using SqlServiceBrokerListener;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using Telnet;
namespace ProVargoInterface
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs eg)
{
// Create a cancellation token source to stop the tasks
CancellationTokenSource cts = new CancellationTokenSource();
string errorpath = (@"error.log");
try
{
/// Default O.L.D driver connection details
Int32 port = 2561;
IPAddress ipAddr = IPAddress.Parse("127.0.0.1");
/// Establish the remote endpoint for the socket.
IPEndPoint localEndPoint = new IPEndPoint(ipAddr, port);
/// Creation TCP/IP Socket using Socket Class Constructor
Socket alcaltelSocket = new Socket(ipAddr.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
/// Connect Socket to the remote endpoint using the method Connect()
alcaltelSocket.Connect(localEndPoint);
ListenForCiCo(alcaltelSocket);
}
catch (Exception ex)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + ex.InnerException + Environment.NewLine);
}
}
static void keepAlive(Socket alcaltelSocket)
{
/// connection Keepalive string
string KeepAlive = "$FFFF";
string errorpath = (@"error.log");
try
{
sendMessage(KeepAlive, errorpath, alcaltelSocket, "y");
}
catch (Exception KAex)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + KAex.InnerException + Environment.NewLine);
}
}
void ListenForCiCo(Socket alcaltelSocket)
{
//// Create Global Variables
string _reservation_id, _extension_no = null, _phase = null, _room_id = null, _room_no = null, _full_guest_name = null, _guest_name = null, _dummy_id = "";
string errorpath = (@"error.log");
string inputCI = "";
string inputCO = "";
/// connection Keepalive string
string KeepAlive = "$FFFF";
/// connection handshake string
string handshake = "@FFFF";
/// Default O.L.D driver connection details
Int32 port = 2561;
IPAddress ipAddr = IPAddress.Parse("127.0.0.1");
//// Create a cancellation token source to stop the tasks
CancellationTokenSource cts = new CancellationTokenSource();
Task task1 = Task.Run(() =>
{
while (!cts.IsCancellationRequested)
{
try
{
keepAlive( alcaltelSocket);
Thread.Sleep(25000);
/// Repeat task1 every 25000 milliseconds (25 seconds) to test if the keepalive is intercepting call data.
}
catch (Exception ex)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (W) - Unable to open connection to Alcatel system - " + ex.ToString() + Environment.NewLine);
}
}
}, cts.Token);
try
{
var connectionString = @"Data Source=127.0.0.1,12345;Integrated Security=False;user id=sa;password=yourSApassword;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Initial Catalog=DBname;";
// See optional constructor parameters to configure it according to your needs
var listener = new SqlDependencyEx(connectionString, "dbName", "TabletoWatch", listenerType: SqlDependencyEx.NotificationTypes.Insert); // Listen to INSERTS to the table
// e.Data contains actual changed data in the XML format
listener.TableChanged += (o, e) =>
{
var tableChange = e.Data.ToString();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(tableChange);
XmlNodeList availChangeINS = xmlDoc.FirstChild.SelectNodes("inserted");
foreach (XmlNode changedRow in availChangeINS)
{
XmlNodeList rowList = availChangeINS[0].SelectNodes("row");
foreach (XmlNode availDataINS in rowList)
{
_dummy_id = availDataINS["dummy_id"].InnerText.TrimEnd();
_reservation_id = availDataINS["reservation_id"].InnerText.TrimEnd();
_extension_no = availDataINS["extension_no"].InnerText.TrimEnd();
_phase = availDataINS["phase"].InnerText.TrimEnd();
_full_guest_name = availDataINS["guest_name"].InnerText.TrimEnd();
_guest_name = _full_guest_name.Substring(0, 10);
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
/// Find room_id from db
/// Find room number from db
}
if (_phase == "I")
{
SetText1("Check IN >>> " + DateTime.Now.ToString() + " - " + _full_guest_name + " in to room " + _room_no + " (Ext: " + _extension_no + " )" + Environment.NewLine);
try
{
try
{
inputCI = "B " + _extension_no + " " + _guest_name + " 1 03 0";
//Calculate CRC based on the above string
var crcCI = XorAscii(inputCI).ToString("X2");
inputCI = inputCI + crcCI.ToString();
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - Sending handshake to Alcatel System." + Environment.NewLine);
sendMessage(handshake, errorpath, alcaltelSocket,"n");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - Sending KeepAlive to Alcatel System." + Environment.NewLine);
sendMessage(KeepAlive, errorpath, alcaltelSocket, "n");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - Sending " + inputCI + " to Alcatel System." + Environment.NewLine);
sendMessage(inputCI, errorpath, alcaltelSocket, "n");
}
catch (Exception ex1)
{
if (ex1.Message.Contains("existing connection was forcibly closed"))
{
/// Establish the remote endpoint for the socket.
IPEndPoint localEndPoint2 = new IPEndPoint(ipAddr, port);
/// Creation TCP/IP Socket using Socket Class Constructor
Socket alcaltelSocket2 = new Socket(ipAddr.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
/// Connect Socket to the remote endpoint using the method Connect()
alcaltelSocket2.Connect(localEndPoint2);
try
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - ReSending handshake to Alcatel System." + Environment.NewLine);
sendMessage(handshake, errorpath, alcaltelSocket2, "n");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - ReSending KeepAlive to Alcatel System." + Environment.NewLine);
sendMessage(KeepAlive, errorpath, alcaltelSocket2, "n");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - ReSending " +inputCI+ " to Alcatel System." + Environment.NewLine);
sendMessage(inputCI, errorpath, alcaltelSocket2, "n");
}
catch (Exception KAex1)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + KAex1.InnerException + Environment.NewLine);
}
}
else
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (W) - Unable to open connection to Alcatel system - " + ex1.ToString() + Environment.NewLine);
}
}
}
catch (Exception ciex)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (W) - CI issue- ArgumentNullException -" + ciex.Message + " at line " + Convert.ToInt32(ciex.StackTrace.Substring(ciex.StackTrace.LastIndexOf(' '))) + " - " + _guest_name + " - " + _room_no + " - " + _extension_no + Environment.NewLine);
}
}
else if (_phase == "O")
{
SetText1("Check OUT <<< " + DateTime.Now.ToString() + " - " + _full_guest_name + " from room " + _room_no + " (Ext: " + _extension_no + " )" + Environment.NewLine);
try
{
try
{
inputCO = "D " + _extension_no;
//Calculate CRC based on the above string
var crcCO = XorAscii(inputCO).ToString("X2");
inputCO = inputCO + crcCO.ToString();
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - Sending handshake to Alcatel System." + Environment.NewLine);
sendMessage(handshake, errorpath, alcaltelSocket, "y");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - Sending KeepAlive to Alcatel System." + Environment.NewLine);
sendMessage(KeepAlive, errorpath, alcaltelSocket, "y");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - Sending " + inputCO +" to Alcatel System." + Environment.NewLine);
sendMessage(inputCO, errorpath, alcaltelSocket, "y");
}
catch (Exception ex1)
{
if (ex1.Message.Contains("existing connection was forcibly closed"))
{
/// Establish the remote endpoint for the socket.
IPEndPoint localEndPoint1 = new IPEndPoint(ipAddr, port);
/// Creation TCP/IP Socket using Socket Class Constructor
Socket alcaltelSocket1 = new Socket(ipAddr.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
/// Connect Socket to the remote endpoint using the method Connect()
alcaltelSocket1.Connect(localEndPoint1);
try
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - ReSending handshake to Alcatel System." + Environment.NewLine);
sendMessage(handshake, errorpath, alcaltelSocket1, "y");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - ReSending KeepAlive to Alcatel System." + Environment.NewLine);
sendMessage(KeepAlive, errorpath, alcaltelSocket1, "y");
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (i) - ReSending " + inputCO +" to Alcatel System." + Environment.NewLine);
sendMessage(inputCO, errorpath, alcaltelSocket1, "y");
}
catch (Exception KAex1)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + KAex1.InnerException + Environment.NewLine);
}
}
else
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (W) - Unable to open connection to Alcatel system - " + ex1.ToString() + Environment.NewLine);
}
}
}
catch (Exception coex)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (W) - CO issue - ArgumentNullException -" + coex.Message + " at line " + Convert.ToInt32(coex.StackTrace.Substring(coex.StackTrace.LastIndexOf(' '))) + " - " + _guest_name + " - " + _room_no + " - " + _extension_no + Environment.NewLine);
}
}
//Delete the Line after use
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
try
{
//del line from the watched table
}
catch (SqlException sqlex)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - (W) - SQL Exception - " + sqlex.Message + Environment.NewLine);
SetText1("!!! Issue removing id " + _dummy_id + ". Check Error.log for more information. " + Environment.NewLine);
}
connection.Close();
}
}
};
listener.Start();
}
catch (Exception ex)
{
System.IO.File.AppendAllText(errorpath, DateTime.Now.ToString() + " - " + ex.Message + Environment.NewLine);
}
}
/// FUNCTIONS
private void SetText1(string text)
{
if (this.richTextBox2.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText1);
this.Invoke(d, new object[] { text });
this.richTextBox2.SelectionLength = 0;
this.richTextBox2.SelectionStart = this.richTextBox2.Text.Length;
this.richTextBox2.Focus();
this.richTextBox2.ScrollToCaret();
}
else
{
this.richTextBox2.AppendText(text);
this.richTextBox2.SelectionLength = 0;
this.richTextBox2.SelectionStart = this.richTextBox2.Text.Length;
this.richTextBox2.Focus();
this.richTextBox2.ScrollToCaret();
}
}
public static void sendMessage(string input, string errorlog, Socket alcaltelSocket, string keepAlive)
{
/// Create dictionary for PABX non-printable char replies
IDictionary<string, string> asciiConvert = new Dictionary<string, string>();
asciiConvert.Add("00", "(nul)"); //adding a key/value using the Add() method
asciiConvert.Add("01", "(soh)");
asciiConvert.Add("02", "(stx)");
asciiConvert.Add("03", "(etx)");
asciiConvert.Add("04", "(eot)");
asciiConvert.Add("05", "(enq)");
asciiConvert.Add("06", "(ack)");
asciiConvert.Add("07", "(bel)");
asciiConvert.Add("08", "(bs)");
asciiConvert.Add("09", "(ht)");
asciiConvert.Add("10", "(nl)");
asciiConvert.Add("11", "(vt)");
asciiConvert.Add("12", "(np)");
asciiConvert.Add("13", "(cr)");
asciiConvert.Add("14", "(so)");
//asciiConvert.Add("15", "(si)");
asciiConvert.Add("15", "(nack)");
asciiConvert.Add("16", "(dle)");
asciiConvert.Add("17", "(dc1)");
asciiConvert.Add("18", "(dc2)");
asciiConvert.Add("19", "(dc3)");
asciiConvert.Add("20", "(dc4)");
asciiConvert.Add("21", "(nak)");
asciiConvert.Add("22", "(syn)");
asciiConvert.Add("23", "(etb)");
asciiConvert.Add("24", "(can)");
asciiConvert.Add("25", "(em)");
asciiConvert.Add("26", "(sub)");
asciiConvert.Add("27", "(esc)");
asciiConvert.Add("28", "(fs)");
asciiConvert.Add("29", "(gs)");
asciiConvert.Add("30", "(rs)");
asciiConvert.Add("31", "(us)");
asciiConvert.Add("32", "(sp)");
/// Convert String into bytes as bytes need to be sent to socket
byte[] inputbytes = Encoding.Default.GetBytes(input);
/// Create prefix (nul, (sfx) ) and suffix ((etx)) bytes
byte[] prefix = { 0x02 };
byte[] suffix = { 0x03 };
/// join stx, message, etx bytes together
byte[] combined = prefix.Concat(inputbytes).Concat(suffix).ToArray();
byte[] ack = new byte[] { 6 };
string hexString = BitConverter.ToString(combined);
hexString = "0X" + hexString;
///// ^ add (STX) and 0x to being on 1st num
hexString = hexString.Replace("-", ", 0x");
///// ^ replace the - with ", 0x" for rest of nums
int byteSent = alcaltelSocket.Send(combined);
/// Data buffer
byte[] messageReceived = new byte[1024];
/// We receive the message using the method Receive(). This method returns the number of bytes received, which we'll use to convert them to string
int byteRecv = alcaltelSocket.Receive(messageReceived);
/// decimal value of returned CHAR
string returndata = BitConverter.ToString(messageReceived, 0, byteRecv);
/// String to store dictionary value of returndata
string pabxReply ="";
if (returndata == "02-24-30-30-30-31-03")
{
}
else if(returndata.Trim().StartsWith("02-4A-20"))
{ // IF RETURNED MESSAGE IS PHONE CALL DATA, ACK IT
returndata = returndata.Replace("-", "");
// Convert the hex string to ASCII using a StringBuilder
StringBuilder sb = new StringBuilder();
for (int i = 0; i < returndata.Length; i += 2)
{
// Get two characters from the hex string
string hs = returndata.Substring(i, 2);
// Convert them to an integer using base 16
int decval = Convert.ToInt32(hs, 16);
// Convert the integer to a char using ASCII encoding
char c = (char)decval;
// Append the char to the StringBuilder
sb.Append(c);
}
// Get the final ASCII string from the StringBuilder
string asciiString = sb.ToString();
int ACKbyteSent = alcaltelSocket.Send(ack);
// Data buffer
byte[] ACKmessageReceived = new byte[1024];
/// We receive the message using the method Receive(). This method returns the number of bytes received, which we'll use to convert them to string
int ACKbyteRecv = alcaltelSocket.Receive(ACKmessageReceived);
/// decimal value of returned CHAR
string ACKreturndata = BitConverter.ToString(ACKmessageReceived, 0, byteRecv);
System.IO.File.AppendAllText(errorlog, DateTime.Now.ToString() + " - (C) - Phone Message from Server -> " + asciiString + Environment.NewLine);
Array.Clear(ACKmessageReceived, 0, ACKmessageReceived.Length);
}
else if (returndata.Trim().StartsWith("02-53"))
{ // IF THE MESSAGE STARTS WITH AN S (REPLY TYPE), ACK IT
returndata = returndata.Replace("-", "");
// Convert the hex string to ASCII using a StringBuilder
StringBuilder sb = new StringBuilder();
for (int i = 0; i < returndata.Length; i += 2)
{
// Get two characters from the hex string
string hs = returndata.Substring(i, 2);
// Convert them to an integer using base 16
int decval = Convert.ToInt32(hs, 16);
// Convert the integer to a char using ASCII encoding
char c = (char)decval;
// Append the char to the StringBuilder
sb.Append(c);
}
// Get the final ASCII string from the StringBuilder
string asciiString = sb.ToString();
int ACKbyteSent = alcaltelSocket.Send(ack);
// Data buffer
byte[] ACKmessageReceived = new byte[1024];
/// We receive the message using the method Receive(). This method returns the number of bytes received, which we'll use to convert them to string
int ACKbyteRecv = alcaltelSocket.Receive(ACKmessageReceived);
/// decimal value of returned CHAR
string ACKreturndata = BitConverter.ToString(ACKmessageReceived, 0, byteRecv);
System.IO.File.AppendAllText(errorlog, DateTime.Now.ToString() + " - (i) - Response from Server -> " + asciiString + Environment.NewLine);
Array.Clear(ACKmessageReceived, 0, ACKmessageReceived.Length);
}
else
{
if (returndata =="06")
{
returndata = "ack";
}
else if (returndata =="15")
{
returndata = "nack";
}
System.IO.File.AppendAllText(errorlog, DateTime.Now.ToString() + " - (i) - Reply from Server -> (" + returndata + ")" + Environment.NewLine);
}
}
/// XOR HEX byte values to create CRC
static int XorAscii(String str)
{
int ans = (str[0]);
for (int i = 1; i < str.Length; i++)
{
ans = (ans ^ ((str[i])));
}
return ans;
}
delegate void SetTextCallback(string text);
}
}