Exemplo n.º 1
0
    void send(packet pck)
    {
        //print("sending " + pck.generateRawPacketData().Count + "bytes");
        try
        {
            //m_socket.Send(pck.generateRawPacketData().ToArray());
            byte[] pckData = pck.generateRawPacketData().ToArray();
            int sent = 0;
            int toBeSent = pckData.Length;
            while (sent < toBeSent)
                sent += m_socket.Send(pckData, sent, pckData.Length, SocketFlags.None);

        }
        catch (Exception e)
        {
            print(e.Message);
            callDisconnect();
        }
    }
Exemplo n.º 2
0
 void parseSocketUpdate(packet pck)
 {
     List<byte> raw = pck.generateRawPacketData();
     short sockId = (short)(raw[1] << 8 | raw[2]);
     byte newstate = raw[3];
     wallSocket sock;
     for (int i = 0; i < m_Wallsockets.Count; i++)
     {
         if (m_Wallsockets[i].id == sockId)
         {
             sock = m_Wallsockets[i];
             sock.state = (WALLSOCKET_STATE)newstate;
             try
             {
                 m_updateCallback(sock);
             }
             catch (System.Exception e)
             {
                 print(e.Message);
             }
             break;
         }
     }
 }
Exemplo n.º 3
0
 void parsePowerInfo(packet pck)
 {
     List<byte> raw = pck.generateRawPacketData();
     short sockId = (short)(raw[1] << 8 | raw[2]);
     byte state = raw[3];
     int totalUptime = toInt(raw, 4);
     int dailyUptime = toInt(raw, 8);
     int dailyDowntime = toInt(raw, 12);
     int watt = toInt(raw, 16);
     for (int i = 0; i < m_Wallsockets.Count; i++)
     {
         wallSocket sock = m_Wallsockets[i];
         if (sock.id == sockId)
         {
             sock.dailyDowntime = dailyDowntime;
             sock.dailyUptime = dailyUptime;
             sock.state = (WALLSOCKET_STATE)state;
             sock.totalUptime = totalUptime;
             sock.watt = watt;
             try
             {
                 m_socketInfoCallback(sock);
             }
             catch (System.Exception e)
             {
                 print(e.Message);
             }
             m_Wallsockets[i] = sock;
             break;
         }
     }
 }
Exemplo n.º 4
0
 void parsePowerUpdate(packet pck)
 {
     List<byte> raw = pck.generateRawPacketData();
     short sockId = (short)(raw[1] << 8 | raw[2]);
     int watt = toInt(raw, 3);
     for (int i = 0; i < m_Wallsockets.Count; i++)
     {
         wallSocket sock = m_Wallsockets[i];
         if (sock.id == sockId)
         {
             sock.watt = watt;
             m_Wallsockets[i] = sock;
             try
             {
                 m_updateWattCallback(sock);
             }
             catch (System.Exception e)
             {
                 print(e.Message);
             }
             break;
         }
     }
 }
Exemplo n.º 5
0
 void parseOnlineClientsPacket(packet pck)
 {
     List<byte> raw = pck.generateRawPacketData();
     for (int i = 3; i < raw.Count; i += 19)
     {
         //print(raw.Count);
         wallSocket wsock = new wallSocket();
         wsock.id = (short)((raw[i] << 8) | raw[i + 1]);
         wsock.state = (WALLSOCKET_STATE)raw[2 + i];
         wsock.totalUptime = toInt(raw, 3 + i);
         wsock.dailyUptime = toInt(raw, 7 + i);
         wsock.dailyDowntime = toInt(raw, 11 + i);
         wsock.watt = toInt(raw, 15 + i);
         m_Wallsockets.Add(wsock);
     }
     try
     {
         m_infocallback(m_Wallsockets);
     }
     catch (System.Exception e)
     {
         print(e.Message);
     }
 }