#!/usr/bin/env python import os, sys, shutil import subprocess options_stock = [[("", "EXT=STD"), ("frsky", "EXT=FRSKY"), ("jeti", "EXT=JETI"), ("ardupilot", "EXT=ARDUPILOT"), ("nmea", "EXT=NMEA")], [("", "HELI=NO"), ("heli", "HELI=YES")], [("", "TEMPLATES=NO"), ("templates", "TEMPLATES=YES")], [("", "AUDIO=NO"), ("audio", "AUDIO=YES")], [("", "HAPTIC=NO"), ("haptic", "HAPTIC=YES")], [("", "DSM2=NO"), ("DSM2", "DSM2=PPM")], [("", "NAVIGATION=NO"), ("potscroll", "NAVIGATION=POTS")], # ("PXX", "PXX=NO", "PXX=YES"), ] options_v4 = [[("", "EXT=FRSKY")], [("", "HELI=NO"), ("heli", "HELI=YES")], [("", "TEMPLATES=NO"), ("templates", "TEMPLATES=YES")], [("", "LOGS=NO"), ("logs", "LOGS=YES")], [("", "SOMO=NO"), ("SOMO", "SOMO=YES")], ] languages = ["en", "fr", "se"] def generate(hex, arg, options,v4): result = [] states = [0] * len(options) count = len(languages) for option in options: count *= len(option) current = 0 while 1: # print index, states for language in languages: current += 1 hex_file = hex make_args = ["make", arg] for i, option in enumerate(options): state = states[len(options) - 1 - i] if option[state][0]: hex_file += "-" + option[state][0] make_args.append(option[state][1]) hex_file += "-" + language make_args.append("TRANSLATIONS=" + language.upper()) print "[%d/%d]" % (current, count), hex_file subprocess.check_output(["make", "clean"]) p = subprocess.Popen(make_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() stderr = p.stderr.read() if "error" in stderr: print stderr exit() for line in stderr.split("\n"): if "warning" in line: print " ", line size = 0 for line in p.stdout.readlines(): if line.startswith("Program:"): parts = line.split(" ") while "" in parts: parts.remove("") size = int(parts[1]) if ((size > 65530 and v4==0) or (size > 262000 and v4==1)): print " ", line[:-1], "[NOT RELEASED]" else: print " ", line, if line.startswith("Data:"): print " ", line, if ((size <= 65530 and v4==0) or (size <=262000 and v4==1)) : shutil.copyfile("open9x.hex", "../binaries/" + hex_file + ".hex") result.append(hex_file) for index, state in enumerate(states): if state < len(options[len(options) - 1 - index]) - 1: for i in range(index): states[i] = 0 states[index] += 1 break else: break return result def generate_c9x_list(filename, hexes, size): f = file(filename, "w") for hex in hexes: f.write('open9x->add_option(new Open9xFirmware("%s", new Open9xInterface(%s), OPEN9X_BIN_URL "%s.hex"));\n' % (hex, size, hex)) # stock board hexes = generate("open9x-stock", "PCB=STD", options_stock,0) generate_c9x_list("../../companion9x/src/open9x-stock-binaries.cpp", hexes, "EESIZE_STOCK") # v4 board hexes = generate("open9x-v4", "PCB=V4", options_v4,1) generate_c9x_list("../../companion9x/src/open9x-v4-binaries.cpp", hexes, "EESIZE_V4") # stamp subprocess.check_output(["make", "stamp"])