<commit_before>// generates erase and write binaries for dfu
// takes in the dfu rom
var fs = require('fs'),
  path = require('path'),
  sys = require('sys'),
  exec = require('child_process').exec;

  var writeByte = 0x08;
  var eraseByte = 0x07;

function puts(error, stdout, stderr) { sys.puts(stdout) }

function BinGenerator (path){
  this.path = path;
  this.chunkSize = 2048;
  this.writeStart = [0x14, 0x00, 0x00, 0x00];
  this.eraseStat = [0x00, 0x02, 0x00, 0x00];
}

// check if erase file already exists
// todo clean this up
BinGenerator.prototype.fileExists = function (name) {
  if (fs.existsSync(name)) {
    console.log("Error didn't write file because ", name, " already exists");
    return true;
  }
  return false;
}

BinGenerator.prototype.writeFile = function (name, buff){
  var fd =  fs.openSync(name, 'w');
  fs.writeSync(fd, buff, 0, buff.length, 0);
  console.log("finished writing ", name);
  
  return path.basename(name, '.bin');
}

  // if it doesnt generate an erase file that looks like dis
  // unsigned char buf [] = {
    // 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 
    // 0x00, 0x00, 0x02, 0x00, 0x0B, 0x01, 0x43, 0x18}; // erase
    // 07 00 00 00 00 00 00 14 
    // 00 00 02 00 0b 01 43 18
BinGenerator.prototype.eraseCmd = function(size, name) {
  name = name || this.path;

  var eraseName = path.basename(name, '.bin') + '-erase.bin';
  if (this.fileExists(eraseName)) return;

  var buff = new Buffer([eraseByte, 0x00, 0x00, 0x00, this.writeStart[3], 
    this.writeStart[2], this.writeStart[1], this.writeStart[0], 
    this.eraseStat[3], this.eraseStat[2], this.eraseStat[1], 
    this.eraseStat[0], 0x0B, 0x01, 0x43, 0x18], 'binary');

  return this.writeFile(eraseName, buff);

  // var fd =  fs.openSync(eraseName, 'w');
  // fs.write(fd, buff, 0, buff.length, 0, function(err,written){
  //   console.log("finished writing ", eraseName);
  // });

  // return path.basename(this.path, '.bin') + '-erase';
}
<commit_msg>fixed erase size<commit_after>// generates erase and write binaries for dfu
// takes in the dfu rom
var fs = require('fs'),
  path = require('path'),
  sys = require('sys'),
  exec = require('child_process').exec;

  var writeByte = 0x08;
  var eraseByte = 0x07;

function puts(error, stdout, stderr) { sys.puts(stdout) }

function BinGenerator (path){
  this.path = path;
  this.chunkSize = 2048;
  this.writeStart = [0x14, 0x00, 0x00, 0x00];
  this.eraseStart = [0x00, 0x04, 0x00, 0x00];
}

// check if erase file already exists
// todo clean this up
BinGenerator.prototype.fileExists = function (name) {
  if (fs.existsSync(name)) {
    console.log("Error didn't write file because ", name, " already exists");
    return true;
  }
  return false;
}

BinGenerator.prototype.writeFile = function (name, buff){
  var fd =  fs.openSync(name, 'w');
  fs.writeSync(fd, buff, 0, buff.length, 0);
  console.log("finished writing ", name);
  
  return path.basename(name, '.bin');
}

  // if it doesnt generate an erase file that looks like dis
  // unsigned char buf [] = {
    // 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 
    // 0x00, 0x00, 0x02, 0x00, 0x0B, 0x01, 0x43, 0x18}; // erase
    // 07 00 00 00 00 00 00 14 
    // 00 00 02 00 0b 01 43 18
BinGenerator.prototype.eraseCmd = function(size, name) {
  name = name || this.path;

  var eraseName = path.basename(name, '.bin') + '-erase.bin';
  if (this.fileExists(eraseName)) return;

  var buff = new Buffer([eraseByte, 0x00, 0x00, 0x00, this.writeStart[3], 
    this.writeStart[2], this.writeStart[1], this.writeStart[0], 
    this.eraseStart[3], this.eraseStart[2], this.eraseStart[1], 
    this.eraseStart[0], 0x0B, 0x01, 0x43, 0x18], 'binary');

  return this.writeFile(eraseName, buff);

  // var fd =  fs.openSync(eraseName, 'w');
  // fs.write(fd, buff, 0, buff.length, 0, function(err,written){
  //   console.log("finished writing ", eraseName);
  // });

  // return path.basename(this.path, '.bin') + '-erase';
}

{'fraction_non_alphanumeric': 0.15951539626451286, 'fraction_numerical': 0.07269056032306916, 'mean_word_length': 3.477966101694915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7616615', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1458, 'n_words': 396}