123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.IO.Ports;
- namespace Basic_Terminal
- {
- enum DataSeq
- {
- UpdateResetOK = 0,
- UpdateStartOK,
- UpdateSendingOK,
- UpdateEndOK,
- }
- class FileDownload
- {
-
- Bluecell_BootProtocol Bluecell_BootProtocol = new Bluecell_BootProtocol();
- /***
- *Data File open
- */
- OpenFileDialog ofd;
- Serial serial;
- public string ShowFileOpenDialog(object serial,object ofd)
- {
- this.ofd = (OpenFileDialog)ofd;
- this.serial = (Serial)serial;
- this.ofd.Title = "업데이터 파일 탐색기";//파일오픈창 생성 및 설정
- this.ofd.FileName = "*.bin";
- //ofd.Filter = "bin 파일 (*.bin) | *.bin; | 모든 파일 (*.*) | *.*";
- this.ofd.Filter = "bin 파일 (*.bin) | *.bin;";
- DialogResult dr = this.ofd.ShowDialog(); //파일 오픈창 로드
- if (dr == DialogResult.OK)//OK버튼 클릭시
- {
- string fileName = this.ofd.SafeFileName; //File명과 확장자를 가지고 온다.
- string fileFullName = this.ofd.FileName;//File경로와 File명을 모두 가지고 온다.
- string filePath = fileFullName.Replace(fileName, "");//File경로만 가지고 온다.
- Bluecell_BootProtocol.Boot_Reset(serial);
- //UpdateFileSend(File.ReadAllBytes(this.ofd.FileName));
- return fileFullName;
- }
- else if (dr == DialogResult.Cancel)//취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우
- {
- return "";
- }
- return "";
- }
- #if false
- public void Recv_dataCheck(byte[] data)
- {
- Boolean HeaderCheck = Serial_HeaderCheck(data);
- int DataAckcnt = data[(int)Bluepro_t.bluecell_type + 1];
- if (HeaderCheck == false)
- {
- return;
- }
- else
- {
- DataSeq seq = DataSeq.UpdateResetOK;
- switch (seq)
- {
- case DataSeq.UpdateSendingOK:
- UpdateFileSend(data, DataAckcnt);
- break;
- case DataSeq.UpdateEndOK:
- break;
- default:
- break;
- }
- }
- }
- #endif
- private void UpdateFileSend(byte[] data,int cnt)
- {
- /*Define*/
- int Quotient = 0,remainder = 0;
- int sourceindex = 0;
- byte[] updatedata = new byte[Bluecell_BootProtocol.bluecell_Firmupdate_sendlength];
- /*Filse size */
- Quotient = data.Length / Bluecell_BootProtocol.bluecell_Firmupdate_sendlength;
- remainder = data.Length % Bluecell_BootProtocol.bluecell_Firmupdate_sendlength;
- /*file copy*/
- Array.Copy(data, sourceindex, updatedata, 0,Bluecell_BootProtocol.bluecell_Firmupdate_sendlength);
- /*file write*/
- if (remainder > 0 && cnt > Quotient)
- {
- this.serial.Serial_DataSend(data, remainder);
- }
- else
- {
- this.serial.Serial_DataSend(data, cnt * Bluecell_BootProtocol.bluecell_Firmupdate_sendlength);
- /*send index modify*/
- sourceindex = cnt * Bluecell_BootProtocol.bluecell_Firmupdate_sendlength;
- }
- }
- public Boolean Serial_HeaderCheck(byte[] data)
- {
- Boolean ret = false;
- if (data[(int)Bluepro_t.bluecell_header0] == Bluecell_BootProtocol.Bluecell_Header0
- && data[(int)Bluepro_t.bluecell_header1] == Bluecell_BootProtocol.Bluecell_Header1
- && data[(int)Bluepro_t.bluecell_header2] == Bluecell_BootProtocol.Bluecell_Header2
- && data[(int)Bluepro_t.bluecell_header3] == Bluecell_BootProtocol.Bluecell_Header3
- )/*모든 Header OK */
- {
- ret = true;
- }
- return ret;
- }
-
- }
- }
|