static public int get_aline_checksum(string aline){
int checksum=0;
int i;
for(i=9;i<aline.Length-1-2;i+=2){
checksum = checksum + Convert.ToInt32(aline.Substring(i, 2), 16);
}
return(checksum);
}
static public void write_extraEP_area_IDRenesas(string input_file_name, string output_file_name){
StreamReader src_file = new StreamReader(input_file_name, System.Text.Encoding.GetEncoding("utf-8"));
StreamWriter dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
string Save_Data = "";
int checksum_all = 0;
//F1100-
while(src_file.Peek()>-1){
//空読み
Save_Data = src_file.ReakLine();
if(Convert.ToInt32(Save_Data.Substring(3,4),16)>0x)
get_aline_checksum(Save_Data);
break;
}
}
static public void copy_flash_area(int start_address, int end_address, string micom, string input_file_name, string output_file_name){
int itmp = 0;
string record_type = "";
string Save_Data = "";
StreamReader src_file = new StreamReader(input_file_name, System.Text.Encoding.GetEncoding("utf-8"));
StreamWriter dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
while(src_file.Peek()>-1) //空読み
{
Save_Data = src_file.ReadLine();
switch(micom){
case "IDRenesas":
itmp = 0x0;
break;
}
if(itmp >= start_address) //先頭までスキップして、先頭を書き出して、2行目からは次のwhileで
{
dst_file.WriteLine(Save_Data);
break;
}
}
while(src_file.Peek()>-1)
{
Save_Data = src_file.ReadLine();
switch(micom){
case "IDRenesas":
itmp = end_address - 1;
record_type = Save_Data.Substring(7,2);
if(record_type=="02"){
if(Save_Data.Substring(9,4)=="F000"){
itmp = end_address + 1;
}
}
break;
}
if((itmp > end_address)||((micom=="Renesas")&&(Save_Data==":00000001FF"))){
break;
}
dst_file.WriteLine(Save_Data);
}
src_file.Close();
dst_file.Close();
}
DataGridViewにexcelの行列をコピペ
private void DataGridView1_KeyDown(object sender, KeyEventArgs e)
{
string[] clipboardEpLines;
string[] clipboardEpValues;
int i, j;
if(e.Control && e.KeyCode == Keys.V)
{
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text))
{
//get strings from clipboard
string s = Clipboard.GetText();
clipboardEpLines = s.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
//count number of j and number of i
if (((s.Length - s.Replace("\n", "").Length) == 16)
&& ((s.Length - s.Replace("\t", "").Length) == 15 * 16))
{
for (j = 0; j < 16; j++)
{
clipboardEpValues = clipboardEpLines[j].Split(new char[] { '\t' });
for (i = 0; i < 16; i++)
{
this.DataGridView1[i, j].Value = clipboardEpValues[i];
}
}
}
}
}
}
private void EepButton_Click(object sender, EventArgs e)
{
string[] clipboardEpLines;
string[] clipboardEpValues;
int i, j;
string s;
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text))
{
//get strings from clipboard
s = Clipboard.GetText();
//count number of j and number of i
if (((s.Length - s.Replace("\n", "").Length) == 16)
&& ((s.Length - s.Replace("\t", "").Length) == 15 * 16))
{
clipboardEpLines = s.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
for (j = 0; j < 16; j++)
{
clipboardEpValues = clipboardEpLines[j].Split(new char[] { '\t' });
for (i = 0; i < 16; i++)
{
this.DataGridView1[i, j].Value = clipboardEpValues[i];
}
}
}
}
}
pot.cs
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
public class Hello
{
// static void Save_Hex(string[] DataGridView1);
static public int Main()
{
Save_Hex();
return(0);
}
static void Save_Hex()
{
string input_file_name = "src_srec.srec";
string output_file_name = "out_srec.srec";
StreamWriter dst_file;
string micom = "Renesas";//"Toshiba";
string ep_offset_address = "";
int start_address_MainEP = 0;
int end_address_MainEP = 0;
int start_address_InEP = 0;
int end_address_InEP = 0;
int start_address_POT = 0;
int end_address_POT = 0;
int start_address_FlashROM1 = 0;
int end_address_FlashROM1 = 0;
int start_address_FlashROM2 = 0;
int end_address_FlashROM2 = 0;
bool isMainEP = true;
bool isInEP = true;
bool isPOT = true;
bool keepMainEP = false;
bool keepInEP = false;
switch(micom){
case "Cypress":
//srecではアドレス飛び石で作れない??
// ep_offset_address = "200C";
// start_address_MainEP = 0x0000;
// end_address_MainEP = 0x0000+0xFF;
// start_address_InEP = 0x2000;
// end_address_InEP = 0x2000+0xFF;
// start_address_POT = 0x4000;
// end_address_POT = 0x4000+0x1FFF;
start_address_FlashROM1 = 0x0;
end_address_FlashROM1 = 0x3FFF;
start_address_FlashROM2 = 0x8000;
end_address_FlashROM2 = 0x3FFFF;
break;
case "Renesas":
input_file_name = "src_hex.hex";
output_file_name = "out_hex.hex";
ep_offset_address = "0010";
start_address_MainEP = 0x0000;
end_address_MainEP = 0x0000+0xFF;
start_address_InEP = 0x0400;
end_address_InEP = 0x0400+0xFF;
start_address_POT = 0x0800;
end_address_POT = 0x0BFF;
start_address_FlashROM1 = 0x0;
end_address_FlashROM1 = 0xFFFFF;
start_address_FlashROM2 = 0x0; //NOP: all copy about Renesas
end_address_FlashROM2 = 0xFFFFF; //NOP: all copy about Renesas
break;
case "Toshiba": //goto default;
default:
ep_offset_address = "";
start_address_MainEP = 0x4000;
end_address_MainEP = 0x4000+0xFF;
start_address_InEP = 0x6000;
end_address_InEP = 0x6000+0xFF;
start_address_POT = 0x7000;
end_address_POT = 0x7000+0xFFF;
start_address_FlashROM1 = 0x0;
end_address_FlashROM1 = 0x3FFF;
start_address_FlashROM2 = 0x8000;
end_address_FlashROM2 = 0x3FFFF;
break;
}
switch(micom){
case "Cypress":
//srecではアドレス飛び石で作れない??
dst_file = new StreamWriter(output_file_name, false, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
dst_file.Close();
// プログラム領域
copy_flash_area(start_address_FlashROM1, end_address_FlashROM2, micom, input_file_name, output_file_name);
break;
case "Renesas":
dst_file = new StreamWriter(output_file_name, false, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
dst_file.Close();
// // プログラム領域
// copy_flash_area(start_address_Flash, end_address_FlashROM2, micom, input_file_name, output_file_name);
//MainEP
if(!keepMainEP){
write_Renesas_EP_area_header(ep_offset_address, output_file_name);
if(isMainEP){
write_EP_area(start_address_MainEP, ep_offset_address, micom, "src_eep.eep", output_file_name);
fill_FF_area(end_address_MainEP+1, start_address_InEP-1, micom, output_file_name);
}
else{
fill_FF_area(start_address_MainEP, start_address_InEP-1, micom, output_file_name);
}
}
//InEP
if(!keepInEP){
// if(keepMainEP){
//よく考えたら別にオフセットあってもいいんじゃないかと思うから保持時以外はありにしてみる
write_Renesas_EP_area_header(ep_offset_address, output_file_name);
// }
if(isInEP){
write_EP_area(start_address_InEP, "", micom, "src_ineep.eep", output_file_name);
fill_FF_area(end_address_InEP+1, start_address_POT-1, micom, output_file_name);
}
else{
fill_FF_area(end_address_MainEP+1, start_address_POT-1, micom, output_file_name);
}
}
//通電時間
// if(keepMainEP && keepInEP){ //POTは保持とかなく基本的にクリアでいいか
//MainEPとPOT変更でInEP保持のとき、POT前にオフセットいるかもだから、もうPOT前は常にオフセットありにする
write_Renesas_EP_area_header(ep_offset_address, output_file_name);
// }
if(isPOT){//if(comboBoxPOT.Text!="")
write_POT_area(start_address_POT, end_address_POT, micom, output_file_name);
}
else{
fill_FF_area(start_address_POT, end_address_POT, micom, output_file_name);
}
// プログラム領域
copy_flash_area(start_address_FlashROM1, end_address_FlashROM1-1, micom, input_file_name, output_file_name);
dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
dst_file.WriteLine(":00000001FF");
dst_file.Close();
// copy_flash_area(start_address_Flash, end_address_FlashROM2, micom, input_file_name, output_file_name);
break;
case "Toshiba":
dst_file = new StreamWriter(output_file_name, false, System.Text.Encoding.GetEncoding("utf-8"));
dst_file.Close();
// プログラム領域
copy_flash_area(start_address_FlashROM1, end_address_FlashROM1, micom, input_file_name, output_file_name);
//MainEP
write_EP_area(start_address_MainEP, ep_offset_address, micom, "src_eep.eep", output_file_name);
fill_FF_area(end_address_MainEP+1, start_address_InEP-1, micom, output_file_name);
//InEP
if(isInEP){
write_EP_area(start_address_InEP, ep_offset_address, micom, "src_ineep.eep", output_file_name);
fill_FF_area(end_address_InEP+1, start_address_POT-1, micom, output_file_name);
}
else{
fill_FF_area(start_address_InEP, start_address_POT-1, micom, output_file_name);
}
//通電時間
if(isPOT){//if(comboBoxPOT.Text!="")
write_POT_area(start_address_POT, start_address_FlashROM2-1, micom, output_file_name);
}
else{
fill_FF_area(start_address_POT, start_address_FlashROM2-1, micom, output_file_name);
}
// プログラム領域
copy_flash_area(start_address_FlashROM2, end_address_FlashROM2, micom, input_file_name, output_file_name);
break;
default:
break;
}
}
////////////////////////////////////////////////
///////////////////// 関数 /////////////////////
////////////////////////////////////////////////
static public void fill_FF_area(int start_address, int end_address, string micom, string output_file_name){
string tmp;
string Save_Data = "";
StreamWriter dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
int i, j;
int checksum = 0;
int checksum_complement = 0xFF;
for(j=(start_address/16);j<=(end_address/16);j++){
switch(micom){
case "Renesas":
checksum_complement = 0x100;
Save_Data = ":10";
checksum = 0x10;
break;
case "Cypress":
checksum_complement = 0xFF;
Save_Data = "";
checksum = 0;
break;
case "Toshiba": //goto default;
default:
checksum_complement = 0xFF;
Save_Data = "S113";
checksum = 0x13;
break;
}
//eep address
tmp = (j*16).ToString("X4");
Save_Data = Save_Data + tmp;
checksum = checksum + Convert.ToInt32(tmp.Substring(tmp.Length-4,2), 16) + Convert.ToInt32(tmp.Substring(tmp.Length-2), 16);
if(micom=="Renesas"){
//record type
Save_Data = Save_Data + "00";
checksum = checksum + 0x00;
}
//eep data
for(i=0;i<16;i++)
{
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
}
//checksum
tmp = checksum.ToString("X2");
tmp = tmp.Substring(tmp.Length-2);
checksum = checksum_complement - Convert.ToInt32(tmp, 16);
tmp = "00" + checksum.ToString("X2");
Save_Data = Save_Data + tmp.Substring(tmp.Length-2);
dst_file.WriteLine(Save_Data);
}
dst_file.Close();
}
static public void write_Renesas_EP_area_header(string ep_offset_address, string output_file_name){
string tmp;
string Save_Data = "";
int checksum = 0;
StreamWriter dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
int checksum_complement = 0x100;
Save_Data = ":";
//data size
Save_Data = Save_Data + "02";
checksum = 0x02;
//address
Save_Data = Save_Data + "0000";
checksum = checksum + 0x00 + 0x00;
//record type
Save_Data = Save_Data + "04";
checksum = checksum + 0x04;
//offset address
Save_Data = Save_Data + ep_offset_address;
checksum = checksum + Convert.ToInt32(ep_offset_address.Substring(ep_offset_address.Length-4,2), 16) + Convert.ToInt32(ep_offset_address.Substring(ep_offset_address.Length-2), 16);
//checksum
tmp = checksum.ToString("X2");
tmp = tmp.Substring(tmp.Length-2);
checksum = checksum_complement - Convert.ToInt32(tmp, 16);
tmp = "00" + checksum.ToString("X2");
Save_Data = Save_Data + tmp.Substring(tmp.Length-2);
dst_file.WriteLine(Save_Data);
dst_file.Close();
}
static public void write_EP_area(int start_address, string ep_offset_address, string micom, string input_file_name, string output_file_name){
string tmp;
string Save_Data = "";
StreamWriter dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
int checksum = 0;
int i, j;
string[,] DataGridView1 = new string[16,16];
int checksum_complement = 0xFF;
DataGridView1 = read_EP(input_file_name);
switch(micom){
case "Renesas":
checksum_complement = 0x100;
break;
case "Cypress":
checksum_complement = 0xFF;
Save_Data = "";
break;
case "Toshiba": //goto default;
default:
checksum_complement = 0xFF;
break;
}
for(j=0;j<16;j++){
switch(micom){
case "Renesas":
//data size
Save_Data = ":10";
checksum = 0x10;
break;
case "Cypress":
Save_Data = "";
break;
case "Toshiba": //goto default;
default:
//record type and byte size
Save_Data = "S113";
checksum = 0x13;
break;
}
//eep address
tmp = (start_address+(j*16)).ToString("X4");
Save_Data = Save_Data + tmp;
checksum = checksum + Convert.ToInt32(tmp.Substring(tmp.Length-4,2), 16) + Convert.ToInt32(tmp.Substring(tmp.Length-2), 16);
if(micom=="Renesas"){
//record type
Save_Data = Save_Data + "00";
checksum = checksum + 0x00;
}
//eep data
for(i=0;i<16;i++)
{
tmp = DataGridView1[i,j];
Save_Data = Save_Data + DataGridView1[i,j];
checksum = checksum + Convert.ToInt32(DataGridView1[i,j], 16);
}
//checksum
tmp = checksum.ToString("X2");
tmp = tmp.Substring(tmp.Length-2);
checksum = checksum_complement - Convert.ToInt32(tmp, 16);
tmp = "00" + checksum.ToString("X2");
Save_Data = Save_Data + tmp.Substring(tmp.Length-2);
dst_file.WriteLine(Save_Data);
}
dst_file.Close();
}
static public void copy_flash_area(int start_address, int end_address, string micom, string input_file_name, string output_file_name){
int itmp = 0;
string record_type = "";
string Save_Data = "";
StreamReader src_file = new StreamReader(input_file_name, System.Text.Encoding.GetEncoding("utf-8"));
StreamWriter dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
while(src_file.Peek()>-1) //空読み
{
Save_Data = src_file.ReadLine();
switch(micom){
case "Renesas":
itmp = 0x0;
break;
case "Cypress":
record_type = Save_Data.Substring(1,1);
switch(record_type){
case "1":
itmp = Convert.ToInt32(Save_Data.Substring(4,4),16);
break;
case "2":
itmp = Convert.ToInt32(Save_Data.Substring(4,6),16);
break;
case "3":
itmp = Convert.ToInt32(Save_Data.Substring(4,8),16);
break;
case "9":
default:
itmp = start_address - 1; //pass
break;
}
break;
case "Toshiba": //goto default;
default:
record_type = Save_Data.Substring(1,1);
switch(record_type){
case "1":
itmp = Convert.ToInt32(Save_Data.Substring(4,4),16);
break;
case "2":
itmp = Convert.ToInt32(Save_Data.Substring(4,6),16);
break;
case "3":
itmp = Convert.ToInt32(Save_Data.Substring(4,8),16);
break;
case "9":
default:
itmp = start_address - 1; //pass
break;
}
break;
}
if(itmp >= start_address) //先頭までスキップして、先頭を書き出して、2行目からは次のwhileで
{
dst_file.WriteLine(Save_Data);
break;
}
}
while(src_file.Peek()>-1)
{
Save_Data = src_file.ReadLine();
switch(micom){
case "Renesas":
itmp = 0; //Renesasは全部コピーで
break;
case "Cypress":
record_type = Save_Data.Substring(1,1);
switch(record_type){
case "1":
itmp = Convert.ToInt32(Save_Data.Substring(4,4),16);
break;
case "2":
itmp = Convert.ToInt32(Save_Data.Substring(4,6),16);
break;
case "3":
itmp = Convert.ToInt32(Save_Data.Substring(4,8),16);
break;
case "9":
default:
itmp = end_address - 1; //write&pass
break;
}
break;
case "Toshiba": //goto default;
default:
record_type = Save_Data.Substring(1,1);
switch(record_type){
case "1":
itmp = Convert.ToInt32(Save_Data.Substring(4,4),16);
break;
case "2":
itmp = Convert.ToInt32(Save_Data.Substring(4,6),16);
break;
case "3":
itmp = Convert.ToInt32(Save_Data.Substring(4,8),16);
break;
case "9":
default:
itmp = end_address - 1; //write&pass
break;
}
break;
}
if((itmp > end_address)||((micom=="Renesas")&&(Save_Data==":00000001FF"))){
break;
}
dst_file.WriteLine(Save_Data);
}
src_file.Close();
dst_file.Close();
}
// EEPROM読み出し
static public string[,] read_EP(string input_file_name){
int i, j;
string line_buff;
int data;
string[,] DataGridView1 = new string[16,16];
StreamReader file;
file = new StreamReader(input_file_name, System.Text.Encoding.GetEncoding("utf-8")); //ファイル名
for (j = 0; j < 16; j++){
for (i = 0; i < 16; i++){
line_buff = file.ReadLine();
//flag set
data = Convert.ToInt32(line_buff.Substring(0, 2), 16);
DataGridView1[i, j] = data.ToString("X2"); //hex(data);
}
//textBox2.Text = Path.GetFileName(file_name);
}
file.Close();
return(DataGridView1);
}
static public void write_POT_area(int start_address_POT, int end_address_POT, string micom, string output_file_name){
string Save_Data = "";
int i, k;
int checksum = 0;
int pot_k;
int powerOnTime;
string pot_str = "28";
string tmp = "";
int checksum_complement = 0xFF;
StreamWriter dst_file;
powerOnTime = Convert.ToInt32(pot_str, 10);
switch(micom){
case "Renesas":
case "Cypress":
dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
//1行目
if(micom=="Renesas"){
checksum_complement = 0x100;
//data size
Save_Data = ":10";
checksum = 0x10;
}
else if(micom=="Cypress"){
checksum_complement = 0xFF;
//byte size
Save_Data = "S113";
checksum = 0x13;
}
//POT address
tmp = start_address_POT.ToString("X4");
Save_Data = Save_Data + tmp;
checksum = checksum + Convert.ToInt32(tmp.Substring(tmp.Length-4,2), 16) + Convert.ToInt32(tmp.Substring(tmp.Length-2), 16);
if(micom=="Renesas"){
//record type
Save_Data = Save_Data + "00";
checksum = checksum + 0x00;
}
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
for(i=1;i<16;i++){ //16byteを埋める 1行目
if(i<=powerOnTime){
if((i<=4)||((powerOnTime>=16)&&(i==15))){ //16時間以上のとき、1行目の最後の1byteの01を埋める
Save_Data = Save_Data + "01";
checksum = checksum + 0x1;
}
else if((powerOnTime<=28)&&(i%2==0)){
Save_Data = Save_Data + "01" + "01";
checksum = checksum + 0x1 + 0x1;
}
}
else{
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
}
}
//checksum
tmp = checksum.ToString("X2");
tmp = tmp.Substring(tmp.Length-2);
checksum = checksum_complement - Convert.ToInt32(tmp, 16);
tmp = "00" + checksum.ToString("X2");
Save_Data = Save_Data + tmp.Substring(tmp.Length-2);
dst_file.WriteLine(Save_Data);
//2行目
if(micom=="Renesas"){
//data size
Save_Data = ":10";
checksum = 0x10;
}
else if(micom=="Cypress"){
//byte size
Save_Data = "S113";
checksum = 0x13;
}
//POT address
tmp = (start_address_POT+0x10).ToString("X4");
Save_Data = Save_Data + tmp;
checksum = checksum + Convert.ToInt32(tmp.Substring(tmp.Length-4,2), 16) + Convert.ToInt32(tmp.Substring(tmp.Length-2), 16);
if(micom=="Renesas"){
//record type
Save_Data = Save_Data + "00";
checksum = checksum + 0x00;
}
if(powerOnTime>=16) {
Save_Data = Save_Data + "01";
checksum = checksum + 0x1;
}
else{
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
}
for(i=1;i<16;i++){ //16byteを埋める 2行目
if(i<=(powerOnTime-16)){ //28時間以下って条件は必要ないかな。comboBoxが28時間までだから
if(i%2==0){
Save_Data = Save_Data + "01" + "01";
checksum = checksum + 0x1 + 0x1;
}
}
else
{
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
}
}
//checksum
tmp = checksum.ToString("X2");
tmp = tmp.Substring(tmp.Length-2);
checksum = checksum_complement - Convert.ToInt32(tmp, 16);
tmp = "00" + checksum.ToString("X2");
Save_Data = Save_Data + tmp.Substring(tmp.Length-2);
dst_file.WriteLine(Save_Data);
dst_file.Close();
//残りの領域を埋める
fill_FF_area(start_address_POT+0x20, end_address_POT, micom, output_file_name);
break;
case "Toshiba": //goto default;
default:
for(k=0;k<16;k++) //0x100ごとに、0x7000~0x7F00。kが1で256byte
{
dst_file = new StreamWriter(output_file_name, true, System.Text.Encoding.GetEncoding("utf-8")); //出力ファイル名
pot_k = k + 1; //pot_kは1時間からだから? 合ってるかな
if(pot_k>=4)
{
pot_k = pot_k + (pot_k-4);
//4 5 6 7 8 9 10 11 12 13 14 15 16 k+1
//4 6 8 10 12 14 16 18 20 22 24 26 28 pot
//0 1 2 3 4 5 6 7 8 9 10 11 12 minus
//(k+1) + (k+1 -4)
}
if(pot_k > powerOnTime)
{
pot_k = 0;
}
//1行目
if(micom=="Renesas"){
checksum_complement = 0x100;
// Save_Data = ":020000040100F9"; //eep area start address
Save_Data = ":10";
checksum = 0x10;
}
else if(micom=="Cypress"){
checksum_complement = 0xFF;
Save_Data = "S113";
checksum = 0x13;
}
else{// if(micom=="Toshiba"){
checksum_complement = 0xFF;
Save_Data = "S113";
checksum = 0x13;
}
tmp = (start_address_POT+(k*16*16)).ToString("X2");
Save_Data = Save_Data + tmp;
checksum = checksum + Convert.ToInt32(tmp.Substring(tmp.Length-4,2), 16) + Convert.ToInt32(tmp.Substring(tmp.Length-2), 16);
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
for(i=1;i<16;i++) //16byteを埋める 1行目
{
if(i<=pot_k) //if(i<=pot)
{
if((i<=4)||((pot_k>=16)&&(i==15))) //16時間以上のとき、1行目の最後の1byteの01を埋める
{
Save_Data = Save_Data + "01";
checksum = checksum + 0x1;
}
else if((pot_k<=28)&&(i%2==0))
{
Save_Data = Save_Data + "01" + "01";
checksum = checksum + 0x1 + 0x1;
}
}
else
{
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
}
}
tmp = checksum.ToString("X2");
tmp = tmp.Substring(tmp.Length-2);
checksum = checksum_complement - Convert.ToInt32(tmp, 16);
tmp = "00" + checksum.ToString("X2");
Save_Data = Save_Data + tmp.Substring(tmp.Length-2);
dst_file.WriteLine(Save_Data);
//2行目
if(micom=="Renesas"){
Save_Data = ":10";
checksum = 0x10;
}
else if(micom=="Cypress"){
Save_Data = "S113";
checksum = 0x13;
}
else{// if(micom=="Toshiba"){
Save_Data = "S113";
checksum = 0x13;
}
tmp = (start_address_POT+(k*16*16)+16).ToString("X2");
Save_Data = Save_Data + tmp;
checksum = checksum + Convert.ToInt32(tmp.Substring(tmp.Length-4,2), 16) + Convert.ToInt32(tmp.Substring(tmp.Length-2), 16);
if(pot_k>=16)
{
Save_Data = Save_Data + "01";
checksum = checksum + 0x1;
}
else
{
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
}
for(i=1;i<16;i++) //16byteを埋める 2行目
{
if(i<=(pot_k-16)) //28時間以下って条件は必要ないかな。comboBoxが28時間までだから
{
if(i%2==0)
{
Save_Data = Save_Data + "01" + "01";
checksum = checksum + 0x1 + 0x1;
}
}
else
{
Save_Data = Save_Data + "FF";
checksum = checksum + Convert.ToInt32("FF", 16);
}
}
tmp = checksum.ToString("X2");
tmp = tmp.Substring(tmp.Length-2);
checksum = checksum_complement - Convert.ToInt32(tmp, 16);
tmp = "00" + checksum.ToString("X2");
Save_Data = Save_Data + tmp.Substring(tmp.Length-2);
dst_file.WriteLine(Save_Data);
dst_file.Close();
//0x100の256byteを埋める。jが1で16byte
fill_FF_area(start_address_POT+(k*16*16)+0x20, start_address_POT+(k*16*16)+0xFF, micom, output_file_name);
}
break;
}
}
}
MainWindow.Designer.cs
namespace EepromExchangerODU
{
partial class MainWindow
{
/// <summary>
/// 必要なデザイナー変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows フォーム デザイナーで生成されたコード
/// <summary>
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
/// コード エディターで変更しないでください。
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
this.DataGridView1 = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column12 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column13 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column14 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column15 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.EepButton = new System.Windows.Forms.Button();
this.TextBox2 = new System.Windows.Forms.TextBox();
this.HexButton = new System.Windows.Forms.Button();
this.Label1 = new System.Windows.Forms.Label();
this.CheckBox1 = new System.Windows.Forms.CheckBox();
this.Label2 = new System.Windows.Forms.Label();
this.TextBox1 = new System.Windows.Forms.TextBox();
this.RadioButton1 = new System.Windows.Forms.RadioButton();
this.RadioButton2 = new System.Windows.Forms.RadioButton();
this.GroupBox1 = new System.Windows.Forms.GroupBox();
this.GroupBox2 = new System.Windows.Forms.GroupBox();
this.GroupBox3 = new System.Windows.Forms.GroupBox();
this.Label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.DataGridView1)).BeginInit();
this.GroupBox1.SuspendLayout();
this.GroupBox2.SuspendLayout();
this.GroupBox3.SuspendLayout();
this.SuspendLayout();
//
// DataGridView1
//
this.DataGridView1.AllowDrop = true;
this.DataGridView1.AllowUserToAddRows = false;
this.DataGridView1.AllowUserToDeleteRows = false;
this.DataGridView1.AllowUserToResizeColumns = false;
this.DataGridView1.AllowUserToResizeRows = false;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.DataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle2.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
this.DataGridView1.ColumnHeadersHeight = 20;
this.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.DataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
this.Column3,
this.Column4,
this.Column5,
this.Column6,
this.Column7,
this.Column8,
this.Column9,
this.Column10,
this.Column11,
this.Column12,
this.Column13,
this.Column14,
this.Column15});
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.DataGridView1.DefaultCellStyle = dataGridViewCellStyle3;
this.DataGridView1.Location = new System.Drawing.Point(42, 21);
this.DataGridView1.Margin = new System.Windows.Forms.Padding(0);
this.DataGridView1.Name = "DataGridView1";
this.DataGridView1.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
this.DataGridView1.RowHeadersWidth = 50;
this.DataGridView1.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Window;
this.DataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle4;
this.DataGridView1.RowTemplate.DefaultCellStyle.BackColor = System.Drawing.SystemColors.Window;
this.DataGridView1.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Arial Narrow", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.DataGridView1.RowTemplate.Height = 20;
this.DataGridView1.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.DataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
this.DataGridView1.Size = new System.Drawing.Size(370, 340);
this.DataGridView1.TabIndex = 294;
this.DataGridView1.Visible = false;
this.DataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1_CellContentClick);
//
// Column1
//
this.Column1.HeaderText = "00";
this.Column1.MinimumWidth = 8;
this.Column1.Name = "Column1";
this.Column1.Width = 20;
//
// Column2
//
this.Column2.HeaderText = "02";
this.Column2.MinimumWidth = 8;
this.Column2.Name = "Column2";
this.Column2.Width = 20;
//
// Column3
//
this.Column3.HeaderText = "03";
this.Column3.MinimumWidth = 8;
this.Column3.Name = "Column3";
this.Column3.Width = 20;
//
// Column4
//
this.Column4.HeaderText = "04";
this.Column4.MinimumWidth = 8;
this.Column4.Name = "Column4";
this.Column4.Width = 20;
//
// Column5
//
this.Column5.HeaderText = "05";
this.Column5.MinimumWidth = 8;
this.Column5.Name = "Column5";
this.Column5.Width = 20;
//
// Column6
//
this.Column6.HeaderText = "06";
this.Column6.MinimumWidth = 8;
this.Column6.Name = "Column6";
this.Column6.Width = 20;
//
// Column7
//
this.Column7.HeaderText = "07";
this.Column7.MinimumWidth = 8;
this.Column7.Name = "Column7";
this.Column7.Width = 20;
//
// Column8
//
this.Column8.HeaderText = "08";
this.Column8.MinimumWidth = 8;
this.Column8.Name = "Column8";
this.Column8.Width = 20;
//
// Column9
//
this.Column9.HeaderText = "09";
this.Column9.MinimumWidth = 8;
this.Column9.Name = "Column9";
this.Column9.Width = 20;
//
// Column10
//
this.Column10.HeaderText = "0A";
this.Column10.MinimumWidth = 8;
this.Column10.Name = "Column10";
this.Column10.Width = 20;
//
// Column11
//
this.Column11.HeaderText = "0B";
this.Column11.MinimumWidth = 8;
this.Column11.Name = "Column11";
this.Column11.Width = 20;
//
// Column12
//
this.Column12.HeaderText = "0C";
this.Column12.MinimumWidth = 8;
this.Column12.Name = "Column12";
this.Column12.Width = 20;
//
// Column13
//
this.Column13.HeaderText = "0D";
this.Column13.MinimumWidth = 8;
this.Column13.Name = "Column13";
this.Column13.Width = 20;
//
// Column14
//
this.Column14.HeaderText = "0E";
this.Column14.MinimumWidth = 8;
this.Column14.Name = "Column14";
this.Column14.Width = 20;
//
// Column15
//
this.Column15.HeaderText = "0F";
this.Column15.MinimumWidth = 8;
this.Column15.Name = "Column15";
this.Column15.Width = 20;
//
// EepButton
//
this.EepButton.AllowDrop = true;
this.EepButton.Font = new System.Drawing.Font("HGP創英角ポップ体", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
this.EepButton.Location = new System.Drawing.Point(12, 280);
this.EepButton.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.EepButton.Name = "EepButton";
this.EepButton.Size = new System.Drawing.Size(300, 50);
this.EepButton.TabIndex = 297;
this.EepButton.Text = "EEPをここにドロップ";
this.EepButton.UseVisualStyleBackColor = true;
this.EepButton.Click += new System.EventHandler(this.EepButton_Click);
this.EepButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.EepButton_DragDrop);
this.EepButton.DragEnter += new System.Windows.Forms.DragEventHandler(this.EepButton_DragEnter);
//
// TextBox2
//
this.TextBox2.Location = new System.Drawing.Point(57, 86);
this.TextBox2.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.TextBox2.Name = "TextBox2";
this.TextBox2.ReadOnly = true;
this.TextBox2.Size = new System.Drawing.Size(255, 25);
this.TextBox2.TabIndex = 298;
//
// HexButton
//
this.HexButton.AllowDrop = true;
this.HexButton.Font = new System.Drawing.Font("HGS創英角ポップ体", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
this.HexButton.Location = new System.Drawing.Point(12, 30);
this.HexButton.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.HexButton.Name = "HexButton";
this.HexButton.Size = new System.Drawing.Size(300, 50);
this.HexButton.TabIndex = 301;
this.HexButton.Text = "HEXをここにドロップ";
this.HexButton.UseVisualStyleBackColor = true;
this.HexButton.Click += new System.EventHandler(this.HexButton_Click);
this.HexButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.HexButton_DragDrop);
this.HexButton.DragEnter += new System.Windows.Forms.DragEventHandler(this.HexButton_DragEnter);
//
// Label1
//
this.Label1.AutoSize = true;
this.Label1.Location = new System.Drawing.Point(0, 0);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(87, 18);
this.Label1.TabIndex = 4;
this.Label1.Text = "Write Data";
//
// CheckBox1
//
this.CheckBox1.AutoSize = true;
this.CheckBox1.Location = new System.Drawing.Point(15, 24);
this.CheckBox1.Name = "CheckBox1";
this.CheckBox1.Size = new System.Drawing.Size(106, 22);
this.CheckBox1.TabIndex = 6;
this.CheckBox1.Text = "mp";
this.CheckBox1.UseVisualStyleBackColor = true;
//
// Label2
//
this.Label2.AutoSize = true;
this.Label2.Font = new System.Drawing.Font("MS UI Gothic", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
this.Label2.Location = new System.Drawing.Point(12, 89);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(45, 20);
this.Label2.TabIndex = 299;
this.Label2.Text = "HEX";
//
// TextBox1
//
this.TextBox1.Location = new System.Drawing.Point(21, 26);
this.TextBox1.Name = "TextBox1";
this.TextBox1.Size = new System.Drawing.Size(100, 25);
this.TextBox1.TabIndex = 296;
//
// RadioButton1
//
this.RadioButton1.Font = new System.Drawing.Font("MS UI Gothic", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
this.RadioButton1.Location = new System.Drawing.Point(6, 18);
this.RadioButton1.Name = "RadioButton1";
this.RadioButton1.Size = new System.Drawing.Size(202, 24);
this.RadioButton1.TabIndex = 0;
this.RadioButton1.TabStop = true;
this.RadioButton1.Text = "エリア1";
this.RadioButton1.UseVisualStyleBackColor = true;
//
// RadioButton2
//
this.RadioButton2.Font = new System.Drawing.Font("MS UI Gothic", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
this.RadioButton2.Location = new System.Drawing.Point(6, 40);
this.RadioButton2.Name = "RadioButton2";
this.RadioButton2.Size = new System.Drawing.Size(202, 28);
this.RadioButton2.TabIndex = 1;
this.RadioButton2.TabStop = true;
this.RadioButton2.Text = "エリア2";
this.RadioButton2.UseVisualStyleBackColor = true;
//
// GroupBox1
//
this.GroupBox1.Controls.Add(this.DataGridView1);
this.GroupBox1.Controls.Add(this.TextBox1);
this.GroupBox1.Controls.Add(this.Label1);
this.GroupBox1.Location = new System.Drawing.Point(446, 22);
this.GroupBox1.Name = "GroupBox1";
this.GroupBox1.Size = new System.Drawing.Size(412, 411);
this.GroupBox1.TabIndex = 11;
this.GroupBox1.TabStop = false;
this.GroupBox1.Text = "groupBox1";
this.GroupBox1.Visible = false;
//
// GroupBox2
//
this.GroupBox2.Controls.Add(this.RadioButton1);
this.GroupBox2.Controls.Add(this.RadioButton2);
this.GroupBox2.Location = new System.Drawing.Point(12, 115);
this.GroupBox2.Name = "GroupBox2";
this.GroupBox2.Size = new System.Drawing.Size(300, 83);
this.GroupBox2.TabIndex = 302;
this.GroupBox2.TabStop = false;
this.GroupBox2.Text = "EEPROMエリア選択";
//
// GroupBox3
//
this.GroupBox3.Controls.Add(this.CheckBox1);
this.GroupBox3.Location = new System.Drawing.Point(12, 204);
this.GroupBox3.Name = "GroupBox3";
this.GroupBox3.Size = new System.Drawing.Size(300, 63);
this.GroupBox3.TabIndex = 13;
this.GroupBox3.TabStop = false;
this.GroupBox3.Text = "記憶領域 情報付加";
//
// Label3
//
this.Label3.AutoSize = true;
this.Label3.Location = new System.Drawing.Point(95, 9);
this.Label3.Name = "Label3";
this.Label3.Size = new System.Drawing.Size(47, 18);
this.Label3.TabIndex = 14;
this.Label3.Text = "Ver.1";
//
// MainWindow
//
this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(340, 340);
this.Controls.Add(this.Label3);
this.Controls.Add(this.GroupBox3);
this.Controls.Add(this.GroupBox1);
this.Controls.Add(this.GroupBox2);
this.Controls.Add(this.Label2);
this.Controls.Add(this.TextBox2);
this.Controls.Add(this.EepButton);
this.Controls.Add(this.HexButton);
this.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.Name = "MainWindow";
this.Text = "EepromExchanger";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView1)).EndInit();
this.GroupBox1.ResumeLayout(false);
this.GroupBox1.PerformLayout();
this.GroupBox2.ResumeLayout(false);
this.GroupBox3.ResumeLayout(false);
this.GroupBox3.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button HexButton;
private System.Windows.Forms.Button EepButton;
private System.Windows.Forms.DataGridView DataGridView1;
private System.Windows.Forms.TextBox TextBox2;
private System.Windows.Forms.Label Label1;
private System.Windows.Forms.CheckBox CheckBox1;
private System.Windows.Forms.Label Label2;
private System.Windows.Forms.TextBox TextBox1;
private System.Windows.Forms.RadioButton RadioButton1;
private System.Windows.Forms.RadioButton RadioButton2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
private System.Windows.Forms.DataGridViewTextBoxColumn Column6;
private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
private System.Windows.Forms.DataGridViewTextBoxColumn Column8;
private System.Windows.Forms.DataGridViewTextBoxColumn Column9;
private System.Windows.Forms.DataGridViewTextBoxColumn Column10;
private System.Windows.Forms.DataGridViewTextBoxColumn Column11;
private System.Windows.Forms.DataGridViewTextBoxColumn Column12;
private System.Windows.Forms.DataGridViewTextBoxColumn Column13;
private System.Windows.Forms.DataGridViewTextBoxColumn Column14;
private System.Windows.Forms.DataGridViewTextBoxColumn Column15;
private System.Windows.Forms.GroupBox GroupBox1;
private System.Windows.Forms.GroupBox GroupBox2;
private System.Windows.Forms.GroupBox GroupBox3;
private System.Windows.Forms.Label Label3;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EepromExchangerODU
{
static class Program
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainWindow());
}
}
}