示例#1
0
        /// <summary>
        /// Write the list of maintence Entries to the
        /// Maintence log.  This will convert the list
        /// to a JSON object.  It will then create a temp
        /// file and write the JSON data
        /// to the file.  It will then upload the data to the
        /// ADCP.
        ///
        /// Append will allow the maintence file to be complete
        /// overwritten.  If Append = false, only the data in list
        /// will be written to the maintence log and anything
        /// previously in the log will be lost.
        ///
        /// </summary>
        /// <param name="adcp">Connection to the ADCP.</param>
        /// <param name="list">List to write to the ADCP.</param>
        /// <param name="append">TRUE = Add to end of file.  False = Overwrite file.</param>
        public void WriteLog(AdcpSerialPort adcp, List <MaintenceEntry> list, bool append = true)
        {
            // Create a list
            var maintList = new List <MaintenceEntry>();

            // If we are appending, add the data already in the
            // log
            // If we are not appending, the entire log file will
            // be overwritten with the new list
            if (append)
            {
                // Get the current log and append to it
                // Get the log file
                string maintLog = DownloadLog(System.IO.Path.GetTempPath(), adcp);

                // Decode the log file of all its content
                // and add it to the list
                List <MaintenceEntry> decodedLog = DecodeLog(maintLog);
                if (decodedLog != null)
                {
                    maintList.AddRange(decodedLog);
                }
            }

            // Add the new list to the one from the file
            maintList.AddRange(list);

            // Generate a temp file
            // Then write the list a JSON object to the file
            string fileName = System.IO.Path.GetTempPath() + @"\" + MAINT_FILE_NAME;

            using (FileStream fs = File.Open(fileName, FileMode.OpenOrCreate))
                using (StreamWriter sw = new StreamWriter(fs))
                    using (JsonWriter jw = new JsonTextWriter(sw))
                    {
                        jw.Formatting = Formatting.Indented;
                        JsonSerializer serializer = new JsonSerializer();

                        serializer.Serialize(jw, maintList);
                    }

            // Upload the log to the ADCP
            adcp.XModemUpload(fileName);
        }
示例#2
0
        /// <summary>
        /// Execute the upload process.  This should be called
        /// from the async command.
        /// </summary>
        /// <param name="fileName">File name to upload.</param>
        private void ExecuteUpdateFirmware(object fileName)
        {
            // Convert the object to a string array
            var files = fileName as string[];

            if (files != null)
            {
                // Stop the ADCP pinging if its pinging
                AdcpSerialPort.StopPinging();

                // Upload all the selected files
                foreach (var file in files)
                {
                    // Upload the file to the ADCP
                    AdcpSerialPort.XModemUpload(file);

                    // Wait for the update to complete
                    Thread.Sleep(AdcpSerialPort.WAIT_STATE * 2);

                    // Load the firmware to NAND
                    if (file.ToLower().Contains("rtisys"))
                    {
                        AdcpSerialPort.SendDataWaitReply("FMCOPYS");
                    }

                    // Load the boot code to NAND
                    if (file.ToLower().Contains("boot"))
                    {
                        AdcpSerialPort.SendDataWaitReply("FMCOPYB");
                    }
                }


                // Reboot the ADCP to use the new firmware
                AdcpSerialPort.Reboot();

                // Validate the files uploaded
                // By downloading it and compairing it against
                // the original file
            }
        }