public string download(ShowProgressEvent progress) { byte[] page = new byte[130]; while (true) { node.status = NodeStatus.ST_IDLE; node["flag_enable"] = 0; Thread.Sleep(100); node["addr"] = null; Thread.Sleep(100); if (node["addr"].HasValue) { break; } } node.status = NodeStatus.ST_IDLE; node["board_id"] = null; Thread.Sleep(200); if ((node["board_id"] != null) && ('B' != node["board_id"].Value)) { /* we are in application firmware now*/ node.status = NodeStatus.ST_IDLE; node["flag_reset"] = 0xA0; /*force node to stay in bootloader after WDT reset*/ Thread.Sleep(2000); /* 2000ms is enough for node to reset and power up*/ node.status = NodeStatus.ST_IDLE; node["board_id"] = null; } while (true) { node.status = NodeStatus.ST_IDLE; node["board_id"] = null; Thread.Sleep(100); if (node["board_id"].HasValue) { break; } } if ((node["board_id"] == null) || ('B' != node["board_id"].Value)) { return("fail to enter bootloader mode"); } /* Node is waiting for firmware upgrade now*/ UInt16 page_addr = 0; try { Stream fs; if (File.Exists("C:\\MAIN.BIN")) { fs = new FileStream("C:\\MAIN.BIN", FileMode.Open, FileAccess.Read); } else { fs = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ioex_cs.Resources.MAIN.BIN"); } { progress((UInt16)(fs.Length >> 7 + 1)); int count; while (fs.CanRead) { count = fs.Read(page, 0, 128); if (count == 0) { break; } while (count < 128) { page[count++] = 0x1A; //filled up with eof char } //get crc UInt16 crc_ret = crc(page, count); page[count + 1] = (byte)(crc_ret); page[count] = (byte)(crc_ret >> 8); //write page_address node.writebyte_abs_reg(new byte[] { (byte)2, (byte)3 }, new byte[] { (byte)page_addr, (byte)(page_addr >> 8) }); Thread.Sleep(10); byte b; b = (byte)(page_addr >> 8); //send data to node node.writeseq_abs_reg(4, page, count + 2); Thread.Sleep(20); node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)2, (byte)0 });//BOOT_CMD_PGM_PAGE =2 Thread.Sleep(20); if (poll("addr", 2) != 0) { return("crc error"); } page_addr += (UInt16)count; progress((UInt16)(page_addr >> 7)); } } node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)3, (byte)0 }); //BOOT_CMD_UPGRADE = 3 Thread.Sleep(500); if (poll("addr", 3) != 0) { return("upgrade error"); } node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)4, (byte)0 }); //BOOT_CMD_RUN_APP = 4 Thread.Sleep(2000); /*update board_id*/ return((poll("board_id", (byte)('B')) != (byte)'B')?"":"reboot error"); } catch (System.Exception e) { return(e.Message); } }
public string download(ShowProgressEvent progress) { return ""; /* byte[] page = new byte[130]; while (true) { node.status = NodeStatus.ST_IDLE; node["flag_enable"] = 0; Thread.Sleep(100); node["addr"] = null; Thread.Sleep(100); if (node["addr"].HasValue) break; } node.status = NodeStatus.ST_IDLE; node["board_id"] = null; Thread.Sleep(200); if((node["board_id"] != null) && ('B' != node["board_id"].Value)) { // we are in application firmware now node.status = NodeStatus.ST_IDLE; node["flag_reset"] = 0xA0; //force node to stay in bootloader after WDT reset Thread.Sleep(2000); // 2000ms is enough for node to reset and power up node.status = NodeStatus.ST_IDLE; node["board_id"] = null; } while (true) { node.status = NodeStatus.ST_IDLE; node["board_id"] = null; Thread.Sleep(100); if (node["board_id"].HasValue) break; } if ((node["board_id"] == null) || ('B' != node["board_id"].Value)) return "fail to enter bootloader mode"; // Node is waiting for firmware upgrade now UInt16 page_addr = 0; try { Stream fs; if(File.Exists(ProdNum.baseDir + "\\MAIN.BIN")) fs = new FileStream(ProdNum.baseDir + "\\MAIN.BIN",FileMode.Open,FileAccess.Read); else fs = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ioex_cs.Resources.MAIN.BIN"); { progress((UInt16)(fs.Length >> 7 + 1)); int count; while(fs.CanRead) { count = fs.Read(page, 0, 128); if (count == 0) break; while (count < 128) { page[count++] = 0x1A; //filled up with eof char } //get crc UInt16 crc_ret = crc(page, count); page[count + 1] = (byte)(crc_ret); page[count] = (byte)(crc_ret>>8); //write page_address node.writebyte_abs_reg(new byte[] { (byte)2, (byte)3 }, new byte[] { (byte)page_addr, (byte)(page_addr >> 8) }); Thread.Sleep(10); byte b; b = (byte)(page_addr >> 8); //send data to node node.writeseq_abs_reg(4, page, count+2); Thread.Sleep(20); node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)2, (byte)0 });//BOOT_CMD_PGM_PAGE =2 Thread.Sleep(20); if (poll("addr",2) != 0) return "crc error"; page_addr += (UInt16)count; progress((UInt16)(page_addr>>7)); } } node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)3, (byte)0 }); //BOOT_CMD_UPGRADE = 3 Thread.Sleep(500); if (poll("addr",3) != 0) return "upgrade error"; node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)4, (byte)0 }); //BOOT_CMD_RUN_APP = 4 Thread.Sleep(2000); //update board_id return (poll("board_id", (byte)('B')) != (byte)'B')?"":"reboot error"; } catch (System.Exception e) { return e.Message; } */ }
public string download(ShowProgressEvent progress) { return(""); /* * byte[] page = new byte[130]; * * while (true) * { * node.status = NodeStatus.ST_IDLE; * node["flag_enable"] = 0; * Thread.Sleep(100); * node["addr"] = null; * Thread.Sleep(100); * if (node["addr"].HasValue) * break; * } * * node.status = NodeStatus.ST_IDLE; * node["board_id"] = null; * Thread.Sleep(200); * if((node["board_id"] != null) && ('B' != node["board_id"].Value)) * { * // we are in application firmware now * node.status = NodeStatus.ST_IDLE; * node["flag_reset"] = 0xA0; //force node to stay in bootloader after WDT reset * Thread.Sleep(2000); // 2000ms is enough for node to reset and power up * node.status = NodeStatus.ST_IDLE; * node["board_id"] = null; * } * while (true) * { * node.status = NodeStatus.ST_IDLE; * node["board_id"] = null; * Thread.Sleep(100); * if (node["board_id"].HasValue) * break; * } * if ((node["board_id"] == null) || ('B' != node["board_id"].Value)) * return "fail to enter bootloader mode"; * * * // Node is waiting for firmware upgrade now * UInt16 page_addr = 0; * try * { * Stream fs; * if(File.Exists(ProdNum.baseDir + "\\MAIN.BIN")) * fs = new FileStream(ProdNum.baseDir + "\\MAIN.BIN",FileMode.Open,FileAccess.Read); * else * fs = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ioex_cs.Resources.MAIN.BIN"); * { * progress((UInt16)(fs.Length >> 7 + 1)); * int count; * while(fs.CanRead) * { * count = fs.Read(page, 0, 128); * if (count == 0) * break; * while (count < 128) * { * page[count++] = 0x1A; //filled up with eof char * } * //get crc * UInt16 crc_ret = crc(page, count); * page[count + 1] = (byte)(crc_ret); * page[count] = (byte)(crc_ret>>8); * * //write page_address * node.writebyte_abs_reg(new byte[] { (byte)2, (byte)3 }, new byte[] { (byte)page_addr, (byte)(page_addr >> 8) }); * Thread.Sleep(10); * byte b; * b = (byte)(page_addr >> 8); * //send data to node * node.writeseq_abs_reg(4, page, count+2); * Thread.Sleep(20); * node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)2, (byte)0 });//BOOT_CMD_PGM_PAGE =2 * Thread.Sleep(20); * if (poll("addr",2) != 0) * return "crc error"; * * page_addr += (UInt16)count; * progress((UInt16)(page_addr>>7)); * } * } * node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)3, (byte)0 }); //BOOT_CMD_UPGRADE = 3 * Thread.Sleep(500); * if (poll("addr",3) != 0) * return "upgrade error"; * node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)4, (byte)0 }); //BOOT_CMD_RUN_APP = 4 * * * * Thread.Sleep(2000); //update board_id * return (poll("board_id", (byte)('B')) != (byte)'B')?"":"reboot error"; * } * * catch (System.Exception e) * { * return e.Message; * } * */ }
public string download(ShowProgressEvent progress,string fwpath) { if (!File.Exists(fwpath)) return "Not found"; byte[] page = new byte[130]; while (true) { node.status = NodeStatus.ST_IDLE; node["flag_enable"] = 0; Thread.Sleep(100); node["addr"] = null; Thread.Sleep(100); if (node["addr"].HasValue) break; } node.status = NodeStatus.ST_IDLE; node["board_id"] = null; Thread.Sleep(200); if((node["board_id"] != null) && ('B' != node["board_id"].Value)) { /* we are in application firmware now*/ node.status = NodeStatus.ST_IDLE; node["flag_reset"] = 0xA0; /*force node to stay in bootloader after WDT reset*/ Thread.Sleep(2000); /* 2000ms is enough for node to reset and power up*/ node.status = NodeStatus.ST_IDLE; node["board_id"] = null; } while (true) { node.status = NodeStatus.ST_IDLE; node["board_id"] = null; Thread.Sleep(100); if (node["board_id"].HasValue) break; } if ((node["board_id"] == null) || ('B' != node["board_id"].Value)) return "fail to enter bootloader mode"; /* Node is waiting for firmware upgrade now*/ UInt16 page_addr = 0; try { Stream fs; fs = new FileStream(Form1.fwpath, FileMode.Open, FileAccess.Read); { progress((UInt16)(fs.Length >> 7 + 1)); int count; while(fs.CanRead) { count = fs.Read(page, 0, 128); if (count == 0) break; while (count < 128) { page[count++] = 0x1A; //filled up with eof char } //get crc UInt16 crc_ret = crc(page, count); page[count + 1] = (byte)(crc_ret); page[count] = (byte)(crc_ret>>8); //write page_address node.writebyte_abs_reg(new byte[] { (byte)2, (byte)3 }, new byte[] { (byte)page_addr, (byte)(page_addr >> 8) }); Thread.Sleep(10); byte b; b = (byte)(page_addr >> 8); //send data to node node.writeseq_abs_reg(4, page, count+2); Thread.Sleep(20); node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)2, (byte)0 });//BOOT_CMD_PGM_PAGE =2 Thread.Sleep(20); if (poll("addr",2) != 0) return "crc error"; page_addr += (UInt16)count; progress((UInt16)(page_addr>>7)); } } node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)3, (byte)0 }); //BOOT_CMD_UPGRADE = 3 Thread.Sleep(500); if (poll("addr",3) != 0) return "upgrade error"; node.writebyte_abs_reg(new byte[] { (byte)0 }, new byte[] { (byte)4, (byte)0 }); //BOOT_CMD_RUN_APP = 4 Thread.Sleep(2000); /*update board_id*/ return (poll("board_id", (byte)('B')) != (byte)'B')?"":"reboot error"; } catch (System.Exception e) { return e.Message; } }