Beispiel #1
0
 public override void FinalEncode(ref byte[] buffer, ref int pos)
 {
     UrbetrackCodec.EncodeString(ref buffer, ref pos, Identifier);
     UrbetrackCodec.EncodeString(ref buffer, ref pos, Description);
     UrbetrackCodec.EncodeString(ref buffer, ref pos, File);
     UrbetrackCodec.EncodeInteger(ref buffer, ref pos, Revision);
     UrbetrackCodec.EncodeByte(ref buffer, ref pos, Flags);
 }
Beispiel #2
0
            void SendFile(string order, string signature, string src_file, string path)
            {
                var full_file = String.Format(@"{0}\{1}", path, src_file);
                var fota_file = String.Format(@"{0}\{1}.l4pnp", path, src_file);

                if (!File.Exists(full_file))
                {
                    send("E");
                    return;
                }

                IO.PadFile(full_file, fota_file, 512, 0x00, true);

                using (var fs = File.OpenRead(fota_file))
                {
                    var filesize = (int)fs.Length;
                    if (filesize % 512 != 0)
                    {
                        send("E");
                        return;
                    }
                    var filepages = filesize / 512;
                    var md5Hasher = MD5.Create();
                    var b         = md5Hasher.ComputeHash(fs);
                    if (b.GetLength(0) != 16)
                    {
                        throw new Exception("el hash md5 no retorna 16 bytes.");
                    }
                    var buffer = new byte[256];
                    var pos    = 0;
                    send("D");
                    UrbetrackCodec.EncodeByte(ref buffer, ref pos, (byte)(Convert.ToInt16(order) & 0xFF));
                    UrbetrackCodec.EncodeString(ref buffer, ref pos, signature);
                    UrbetrackCodec.EncodeInteger(ref buffer, ref pos, filepages);
                    UrbetrackCodec.EncodeBytes(ref buffer, ref pos, b);
                    send(buffer, pos);
                }

                using (var fs = File.OpenRead(fota_file))
                {
                    var b = new byte[512];
                    while (fs.Read(b, 0, 512) > 0)
                    {
                        send(b, 512);
                    }
                }

                var cpos   = 0;
                var commit = new byte[3];

                UrbetrackCodec.EncodeByte(ref commit, ref cpos, (byte)'A');
                UrbetrackCodec.EncodeByte(ref commit, ref cpos, (byte)(Convert.ToInt16(order) & 0xFF));
                UrbetrackCodec.EncodeByte(ref commit, ref cpos, (byte)'R');
                send(commit, 3);
            }
Beispiel #3
0
            bool SendFile(Device d, string name, string src_file, string path)
            {
                // var path = Process.GetApplicationFolder("temp");
                var full_file = String.Format(@"{0}\{1}", path, src_file);
                var fota_file = String.Format(@"{0}\{1}.l4pnp", path, src_file);

                if (!File.Exists(full_file))
                {
                    Send("E");
                    //T.ERROR("DEVICE[{0}]/FOTA: el archivo '{1}' no existe o no hay permisos.", d.LogId, full_file);
                    return(false);
                }

                IO.PadFile(full_file, fota_file, 512, 0x00, true);

                using (var fs = File.OpenRead(fota_file))
                {
                    var filesize = (int)fs.Length;
                    if (filesize % 512 != 0)
                    {
                        //T.ERROR("DEVICE[{0}]/FOTA: el archivo '{1}' no existe o no hay permisos.", d.LogId, full_file);
                        Send("C");
                        return(false);
                    }
                    var filepages = filesize / 512;
                    var md5Hasher = MD5.Create();
                    var b         = md5Hasher.ComputeHash(fs);
                    if (b.GetLength(0) != 16)
                    {
                        throw new Exception("el hash md5 no retorna 16 bytes.");
                    }
                    var buffer = new byte[256];
                    var pos    = 0;
                    Send("D");
                    UrbetrackCodec.EncodeString(ref buffer, ref pos, name);
                    UrbetrackCodec.EncodeInteger(ref buffer, ref pos, filepages);
                    UrbetrackCodec.EncodeBytes(ref buffer, ref pos, b);
                    Send(buffer, pos);
                }

                using (var fs = File.OpenRead(fota_file))
                {
                    var b = new byte[512];
                    while (fs.Read(b, 0, 512) > 0)
                    {
                        Send(b, 512);
                    }
                }

                return(true);
            }
Beispiel #4
0
 public override void FinalEncode(ref byte[] buffer, ref int pos)
 {
     UrbetrackCodec.EncodeShort(ref buffer, ref pos, IdAsignado);
     if (CL == 0x01)
     {
         UrbetrackCodec.EncodeByte(ref buffer, ref pos, MaxPDUSamples);
         UrbetrackCodec.EncodeByte(ref buffer, ref pos, FlushTimeout);
         UrbetrackCodec.EncodeShort(ref buffer, ref pos, RetrieveFlags);
     }
     if (CL == 0x02)
     {
         UrbetrackCodec.EncodeByte(ref buffer, ref pos, MaxPDUSamples);
         UrbetrackCodec.EncodeByte(ref buffer, ref pos, FlushTimeout);
         UrbetrackCodec.EncodeShort(ref buffer, ref pos, RetrieveFlags);
         UrbetrackCodec.EncodeInteger(ref buffer, ref pos, ResetToSample);
     }
 }
Beispiel #5
0
 public override void FinalEncode(ref byte[] buffer, ref int pos)
 {
     switch (CL)
     {
     case 0x00:     // SET/MODIFY
     case 0x01:     // DELETE
     case 0x02:     // DELETE ALL
     case 0x03:     // SET LOGISTIC STATE
     case 0x04:     // SHOW DRAFT
     case 0x05:     // SHOW CUSTOM
     case 0x06:     // DELIVER
     case 0x07:     // READ RECEIPT
         UrbetrackCodec.EncodeInteger(ref buffer, ref pos, Revision);
         UrbetrackCodec.EncodeByte(ref buffer, ref pos, Convert.ToByte(Code & 0xFF));
         UrbetrackCodec.EncodeByte(ref buffer, ref pos, Convert.ToByte((Source == 'M' ? 0x1 : 0) & (Destination == 'M' ? 0x02 : 0)));
         UrbetrackCodec.EncodeString(ref buffer, ref pos, Message);
         UrbetrackCodec.EncodeString(ref buffer, ref pos, ReplyFilter);
         UrbetrackCodec.EncodeInteger(ref buffer, ref pos, Session);
         break;
     }
 }
Beispiel #6
0
        //public Queue<byte[]> GetQTreeCompressed(int frame_limit, int from_revision)

        public Queue <byte[]> GetQTreeCompressed(int frame_limit, int from_revision)
        {
            frame_limit--; // reservo el espacio para el 0xAC (cierre)
            var       result              = new Queue <byte[]>();
            var       dataset             = GetActionsQueue(from_revision);
            var       data_buffer         = new byte[frame_limit + 1];
            var       db_cursor           = 0;
            var       pagina              = 0;
            var       huffman_sectors     = 0;
            var       rle_sectors         = 0;
            var       uncompresed_sectors = 0;
            var       total_sectors       = 0;
            const int adds                  = 0;
            byte      operaciones           = 0;
            var       operaciones_en_pagina = 0;
            var       source_size           = 0;

            // preparo el espacio pata operaciones.
            UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0);
            var total_de_pasos = dataset.Count;
            var pasos          = 0;

            foreach (var action in dataset)
            {
                pasos++;
                var completado = pasos * 100.0 / total_de_pasos;
                if (pasos % 5000 == 0)
                {
                    STrace.Debug(GetType().FullName, String.Format("QTREE/GETQTREECOMPRESSED: {0:0.0}% completado.", completado));
                }
                if (operaciones_en_pagina > Hacker.QTree.OperacionesPorPagina)
                {
                    UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0xAC); // Cierre del bloque
                    source_size++;
                    operaciones++;
                    operaciones_en_pagina = 0;
                    pagina++;
                    //Marshall.User("QTREE: un OPERACIONXPAGINA cerro msg {0} de {1} bytes y {2} operaciones", pagina, db_cursor, operaciones);

                    var transient = new byte[db_cursor];
                    var dummy     = 0;
                    Array.Copy(data_buffer, transient, db_cursor);
                    // Actualizo las operaciones en el bloque.
                    UrbetrackCodec.EncodeByte(ref transient, ref dummy, operaciones);
                    result.Enqueue(transient);
                    db_cursor   = 0;
                    operaciones = 0;
                    // preparo el espacio pata operaciones.
                    UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0);
                }
                switch (action.Action)
                {
                case QtreeAction.Actions.START_UPDATE:
                    //Marshall.User(String.Format("QTREE:MSG={0}/START={1}/SIZE={2}: FULL FORMAT", pagina, db_cursor, 5));
                    source_size += 5;
                    operaciones_en_pagina++;
                    // 0xFF es Full Format.
                    UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0xFF);
                    // Patron de Seguridad.
                    UrbetrackCodec.EncodeInteger(ref data_buffer, ref db_cursor, action.Sector);
                    operaciones++;
                    break;

                case QtreeAction.Actions.SET_GR2_DEFAULTS:
                    if (db_cursor + 8 > frame_limit)
                    {
                        //Marshall.User(String.Format("QTREE:MSG={0}/START={1}/SIZE={2}: CLOSE PAGE", pagina, db_cursor, 1));
                        UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0xAC);     // Cierre del bloque
                        source_size++;
                        operaciones++;
                        operaciones_en_pagina = 0;
                        pagina++;
                        //Marshall.User("QTREE: un UPDATE_REVISION cerro msg {0} de {1} bytes y {2} operaciones", pagina, db_cursor, operaciones);
                        var transient = new byte[db_cursor];
                        var dummy     = 0;
                        Array.Copy(data_buffer, transient, db_cursor);
                        // Actualizo las operaciones en el bloque.
                        UrbetrackCodec.EncodeByte(ref transient, ref dummy, operaciones);
                        result.Enqueue(transient);
                        db_cursor   = 0;
                        operaciones = 0;
                        // preparo el espacio pata operaciones.
                        UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0);
                    }
                    // 0xDF es DeFaults
                    UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0xDF);
                    UrbetrackCodec.EncodeShort(ref data_buffer, ref db_cursor, action.FileLat);
                    UrbetrackCodec.EncodeShort(ref data_buffer, ref db_cursor, action.FileLon);
                    UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, (byte)action.Sector);
                    operaciones++;
                    break;

                case QtreeAction.Actions.SET_M2:
                {
                    byte repeated_byte = 0;
                    var  sector        = GetSector(action.Filename, action.Sector, ref repeated_byte);
                    var  file_class    = (byte)matrix[action.Filename][5000];
                    if (repeated_byte != 0 && repeated_byte == file_class)
                    {
                        STrace.Debug(GetType().FullName, String.Format("QTREE/FILE[{0}]: saltando sector x defecto {1} class={2}", action.Filename,
                                                                       action.Sector, file_class));
                        continue;
                    }
                    source_size += 512;
                    var page_buffer = new byte[512];
                    var page_cursor = 0;

                    UrbetrackCodec.EncodeByte(ref page_buffer, ref page_cursor, 0x01);
                    UrbetrackCodec.EncodeShort(ref page_buffer, ref page_cursor, action.FileLat);
                    UrbetrackCodec.EncodeShort(ref page_buffer, ref page_cursor, action.FileLon);
                    UrbetrackCodec.EncodeInteger(ref page_buffer, ref page_cursor, action.Sector);


                    var    huff           = new Huffman();
                    var    result_huffman = huff.Compress(sector, 0, 512);
                    var    rle            = new RLE();
                    var    result_rle     = rle.Compress(sector, 0, 512);
                    byte[] compressed_data;

                    if (sector.GetLength(0) <= result_huffman.GetLength(0) && sector.GetLength(0) <= result_rle.GetLength(0))
                    {
                        uncompresed_sectors++;
                        compressed_data = sector;
                        UrbetrackCodec.EncodeShort(ref page_buffer, ref page_cursor, (short)compressed_data.GetLength(0));
                        UrbetrackCodec.EncodeByte(ref page_buffer, ref page_cursor, 0x00);         // indicador de algoritmo (Sin compresion)
                    }
                    else
                    if (result_huffman.GetLength(0) <= sector.GetLength(0) && result_huffman.GetLength(0) <= result_rle.GetLength(0))
                    {
                        huffman_sectors++;
                        compressed_data = result_huffman;
                        UrbetrackCodec.EncodeShort(ref page_buffer, ref page_cursor, (short)compressed_data.GetLength(0));
                        UrbetrackCodec.EncodeByte(ref page_buffer, ref page_cursor, 0x02);             // indicador de algoritmo (Huffman)
                    }
                    else
                    if (result_rle.GetLength(0) <= result_huffman.GetLength(0) && result_rle.GetLength(0) <= sector.GetLength(0))
                    {
                        rle_sectors++;
                        compressed_data = result_rle;
                        UrbetrackCodec.EncodeShort(ref page_buffer, ref page_cursor, (short)compressed_data.GetLength(0));
                        UrbetrackCodec.EncodeByte(ref page_buffer, ref page_cursor, 0x01);                 // indicador de algoritmo (RLE)
                    }
                    else
                    {
                        STrace.Debug(GetType().FullName, "QTREE: imposible elijir algoritmo.");
                        return(null);
                    }
                    // agrego el buffer de datos...
                    UrbetrackCodec.EncodeBytes(ref page_buffer, ref page_cursor, compressed_data);
                    // valido si es posible meter el buffer en una sola pagina al menos.
                    if (page_cursor > frame_limit)
                    {
                        STrace.Debug(GetType().FullName, "QTREE: el resultado de una pagina no entra en el buffer completo.");
                        STrace.Debug(GetType().FullName, "QTREE: el resultado de una pagina no entra en el buffer completo.");
                        return(null);
                    }
                    // ahora tengo que validar si me entra en esta pagina, o la cierro y empiezo otra.
                    if (db_cursor + page_cursor > frame_limit)
                    {
                        //Marshall.User(String.Format("QTREE:MSG={0}/START={1}/SIZE={2}: CLOSE PAGE", pagina, db_cursor, 1));
                        UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0xAC);         // Cierre del bloque
                        source_size++;
                        operaciones++;
                        operaciones_en_pagina = 0;
                        pagina++;
                        //Marshall.User("QTREE: un SET_M2 cerro msg {0} de {1} bytes y {2} operaciones", pagina, db_cursor, operaciones);

                        var transient = new byte[db_cursor];
                        var dummy     = 0;
                        Array.Copy(data_buffer, transient, db_cursor);
                        // Actualizo las operaciones en el bloque.
                        UrbetrackCodec.EncodeByte(ref transient, ref dummy, operaciones);
                        result.Enqueue(transient);
                        db_cursor   = 0;
                        operaciones = 0;
                        // preparo el espacio pata operaciones.
                        UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0);
                    }
                    Array.Copy(page_buffer, 0, data_buffer, db_cursor, page_cursor);
                    //Marshall.User(String.Format("QTREE:MSG={0}/START={1}/SIZE={2}: SET {3};{4} PAGE:{5}", pagina, db_cursor, page_cursor, action.FileLat, action.FileLon, action.Sector));
                    db_cursor += page_cursor;
                    total_sectors++;
                    operaciones++;
                    operaciones_en_pagina++;
                }
                break;

                case QtreeAction.Actions.UPDATE_REVISION:
                    if (db_cursor + 5 > frame_limit)
                    {
                        //Marshall.User(String.Format("QTREE:MSG={0}/START={1}/SIZE={2}: CLOSE PAGE", pagina, db_cursor, 1));
                        UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0xAC);     // Cierre del bloque
                        source_size++;
                        operaciones++;
                        operaciones_en_pagina = 0;
                        pagina++;
                        //Marshall.User("QTREE: un UPDATE_REVISION cerro msg {0} de {1} bytes y {2} operaciones", pagina, db_cursor, operaciones);
                        var transient = new byte[db_cursor];
                        var dummy     = 0;
                        Array.Copy(data_buffer, transient, db_cursor);
                        // Actualizo las operaciones en el bloque.
                        UrbetrackCodec.EncodeByte(ref transient, ref dummy, operaciones);
                        result.Enqueue(transient);
                        db_cursor   = 0;
                        operaciones = 0;
                        // preparo el espacio pata operaciones.
                        UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0);
                    }
                    //Marshall.User(String.Format("QTREE:MSG={0}/START={1}/SIZE={2}: UPDATE REVISION {3}", pagina, db_cursor, 5, action.Sector));
                    UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0x02);
                    UrbetrackCodec.EncodeInteger(ref data_buffer, ref db_cursor, action.Sector);
                    source_size += 5;
                    operaciones++;
                    operaciones_en_pagina++;
                    break;
                }
            }

            {
                //Marshall.User(String.Format("QTREE:MSG={0}/START={1}/SIZE={2}: UPDATE FINISH", pagina, db_cursor, 1));
                UrbetrackCodec.EncodeByte(ref data_buffer, ref db_cursor, 0xDC); // Fin de la actualizacion.
                var transient = new byte[db_cursor];
                var dummy     = 0;
                operaciones++;
                source_size += 1;
                //Marshall.User("QTREE: cerro la ultima pagina {0} de {1} bytes y {2} operaciones", pagina, db_cursor, operaciones);
                Array.Copy(data_buffer, transient, db_cursor);
                // Actualizo las operaciones en el bloque.
                UrbetrackCodec.EncodeByte(ref transient, ref dummy, operaciones);
                result.Enqueue(transient);
            }
            if (pagina == 0)
            {
                STrace.Debug(GetType().FullName, String.Format("QRTEE NO SE REQUIERE UPDATE revision {0}", from_revision));
                return(null);
            }
            var suma_total = result.Sum(tmp => tmp.GetLength(0));

            STrace.Debug(GetType().FullName, String.Format("QRTEE COMPRIMIDO entre revisiones {0} y {1}", from_revision, Revision));
            STrace.Debug(GetType().FullName, "===================================================================================");
            STrace.Debug(GetType().FullName, String.Format("  Tamaño Origninal:   {0} bytes en {1} paginas.", source_size, total_sectors));
            STrace.Debug(GetType().FullName, String.Format("  Tamaño Final:       {0} bytes en {1} paginas. ({2} bytes pormedio por pagina)", suma_total, pagina, (pagina > 0 ? suma_total / pagina : 0)));
            STrace.Debug(GetType().FullName, String.Format("  Tasa de Compresion: {0}%", suma_total * 100 / source_size));
            STrace.Debug(GetType().FullName, String.Format("  Paginas RAW:        {0} ({1}%)", uncompresed_sectors, uncompresed_sectors * 100 / total_sectors));
            STrace.Debug(GetType().FullName, String.Format("  Paginas RLE:        {0} ({1}%)", rle_sectors, rle_sectors * 100 / total_sectors));
            STrace.Debug(GetType().FullName, String.Format("  Paginas HUFFMAN:    {0} ({1}%)", huffman_sectors, huffman_sectors * 100 / total_sectors));
            STrace.Debug(GetType().FullName, String.Format("  GR2 Agreagados:     {0}", adds));

            return(result);
        }
Beispiel #7
0
 public override void FinalEncode(ref byte[] buffer, ref int pos)
 {
     UrbetrackCodec.EncodeInteger(ref buffer, ref pos, Order);
     UrbetrackCodec.EncodeString(ref buffer, ref pos, CommandLine);
 }
Beispiel #8
0
 public override void FinalEncode(ref byte[] buffer, ref int pos)
 {
     UrbetrackCodec.EncodeInteger(ref buffer, ref pos, Revision);
     UrbetrackCodec.EncodeString(ref buffer, ref pos, Parameter);
     UrbetrackCodec.EncodeString(ref buffer, ref pos, Value);
 }
Beispiel #9
0
        void WriterProc()
        {
            var remote_result = false;

            try
            {
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: Thread de escritura iniciada.", device.LogId));
                socket = new TcpClient();
                socket.Connect(endPoint);
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: Thread de escritura conectada.", device.LogId));
                var buff = new byte[71];
                // ponemos a cero.
                for (var i = 0; i < 71; ++i)
                {
                    buff[i] = 0x00;
                }
                var pos = 0;
                UrbetrackCodec.EncodeShort(ref buff, ref pos, device.Id_short);
                UrbetrackCodec.EncodeByte(ref buff, ref pos, op);
                UrbetrackCodec.EncodeInteger(ref buff, ref pos, filesize);
                var b = Encoding.ASCII.GetBytes(filename);
                Array.Copy(b, 0, buff, pos, b.GetLength(0));
                socket.Client.Send(buff);
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: Cabeceras Enviadas.", device.LogId));
                var total = 0;
                var r     = socket.Client.Send(mensaje, mensaje.GetLength(0), SocketFlags.None);
                total += r;
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{2}]: Termino el envio de archivo de {0} bytes. total={1}", total, total + 71, device.LogId));
                var ack = new byte[1];
                ack[0] = Convert.ToByte('N');
                try
                {
                    if (socket.Client.Receive(ack, 0, 1, SocketFlags.None) == 1)
                    {
                        try
                        {
                            socket.Client.Shutdown(SocketShutdown.Send);
                            socket.Client.Close();
                        }
                        catch (Exception)
                        {
                        }
                        if (ack[0] == 'A')
                        {
                            STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: ACK Recibido", endPoint));
                            remote_result = true;
                        }
                        else
                        {
                            STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: NACK Recibido", endPoint));
                        }
                    }
                }
                catch (Exception e)
                {
                    STrace.Exception(typeof(FileClient).FullName, e, "FileClient.BeginPush WAIT FOR ACK/NACK PHASE");
                }
                //socket.Client.Shutdown(SocketShutdown.Both);
                //socket.Client.Close();
            } catch (Exception e)
            {
                STrace.Exception(typeof(FileClient).FullName, e, String.Format("FileClient[{0}]", device.LogId));
            }
            finally
            {
                if (SendMessageResult != null)
                {
                    SendMessageResult(device.Id_short, filename, remote_result);
                }
                else
                {
                    throw new ApplicationException(String.Format("FileClient[{0}]: Finalizo operacion desconocida.", device.LogId));
                }
            }
        }
Beispiel #10
0
        public static bool SendMessage(IPEndPoint endPoint, short idDispositivo, byte op, byte[] mensaje, string filename)
        {
            var filesize = mensaje.GetLength(0);

            try
            {
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: === inciando cliente ===", endPoint));
                var socket = new TcpClient();
                socket.Connect(endPoint);
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: Se ha conectado el socket TCP/IP", endPoint));
                var buff = new byte[71];
                // ponemos a cero.
                for (var i = 0; i < 71; ++i)
                {
                    buff[i] = 0x00;
                }
                var pos = 0;
                UrbetrackCodec.EncodeShort(ref buff, ref pos, idDispositivo);
                UrbetrackCodec.EncodeByte(ref buff, ref pos, op);
                UrbetrackCodec.EncodeInteger(ref buff, ref pos, filesize);
                var b = Encoding.ASCII.GetBytes(filename);
                Array.Copy(b, 0, buff, pos, b.GetLength(0));
                socket.Client.Send(buff);
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: Cabeceras enviadas", endPoint));
                var total = 0;
                var r     = socket.Client.Send(mensaje, mensaje.GetLength(0), SocketFlags.None);
                total += r;
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: Cabeceras enviadas", endPoint));
                STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: {1} byte enviados.", endPoint, total));
                var ack = new byte[1];
                ack[0] = Convert.ToByte('N');
                try
                {
                    if (socket.Client.Receive(ack, 0, 1, SocketFlags.None) == 1)
                    {
                        try
                        {
                            socket.Client.Shutdown(SocketShutdown.Send);
                            socket.Client.Close();
                        }
                        catch (Exception)
                        {
                        }

                        if (ack[0] == 'A')
                        {
                            STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: ACK Recibido", endPoint));
                            return(true);
                        }
                        STrace.Debug(typeof(FileClient).FullName, String.Format("FileClient[{0}]: NACK Recibido", endPoint));
                    }
                    return(false);
                }
                catch (Exception e)
                {
                    STrace.Exception(typeof(FileClient).FullName, e, "FileClient.BeginPush WAIT FOR ACK/NACK PHASE");
                }
            }
            catch (Exception e)
            {
                STrace.Debug(typeof(FileClient).FullName, String.Format("Exception en FileClient: txt={0}", e.Message));
            }
            return(false);
        }
Beispiel #11
0
 public override void FinalEncode(ref byte[] buffer, ref int pos)
 {
     UrbetrackCodec.EncodeInteger(ref buffer, ref pos, Sensor);
     UrbetrackCodec.EncodeDateTime(ref buffer, ref pos, StartTime);
     UrbetrackCodec.EncodeDateTime(ref buffer, ref pos, EndTime);
 }
Beispiel #12
0
 public override void FinalEncode(ref byte[] buffer, ref int pos)
 {
     UrbetrackCodec.EncodeGPSPoint(ref buffer, ref pos, Posicion);
     UrbetrackCodec.EncodeShort(ref buffer, ref pos, CodigoEvento);
     UrbetrackCodec.EncodeInteger(ref buffer, ref pos, Datos);
 }