VoiletEmbTools/ui/js/file_board_h.js
2024-09-09 17:45:53 +08:00

461 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//最大GPIO组,应该根据芯片进行区分
var MAX_GPIO_NUM = 7
//每一组的最大GPIO口PIN数量
var MAX_GPIO_PIN_NUM = 15
//最大ADC数量
var MAX_ADC_NUM = 8
//最大485数量
var MAX_RS485_NUM = 2
//最大ADC采样值
var MAX_ADC_VALUE = 4096
//最大CAN数量
var MAX_CAN_NUM = 2
//最大串口数量
var MAX_COM_NUM = 6
//最大DO数量
var MAX_DO_NUM = 30
//最大DI数量
var MAX_DI_NUM = 30
//获取整个文件空间的id
var board_h = document.querySelector("#board_h")
//获取CPU类型
var mcu_type = document.querySelector("#mcu_type")
//获取串口
var com0 = document.querySelector("#com0")
var com1 = document.querySelector("#com1")
var com2 = document.querySelector("#com2")
var com3 = document.querySelector("#com3")
var com4 = document.querySelector("#com4")
var com5 = document.querySelector("#com5")
let comIndex = ["com0","com1","com2","com3","com4","com5"]
let canIndex = ["can0","can1"]
let comIndexSwitch = []
var rs4851 = document.querySelector("#rs4851_com")
var rs4852 = document.querySelector("#rs4852_com")
//获取一键生成按钮
var click_button = document.querySelector("#board_h_click");
function addHead(mcu_type){
//头标记
board_h.textContent += "/* 存放板子的资源配置文件 */\n"
board_h.textContent += "#ifndef __BOARD_H_\n"
board_h.textContent += "#define __BOARD_H_\n\n"
board_h.textContent += "/* 不同的CPU 选择不同的头文件 */\n"
//引入头文件
board_h.textContent += "#include "
board_h.textContent += "\"" + mcu_type.value + "\"" + "\n"
//版本号
//软件名称
board_h.textContent += "\n"
board_h.textContent += "/* 软件名称" + " */\n"
board_h.textContent += "#define SOFTWARE_NAME \"" + document.querySelector("#software_name").value + "\"\n"
board_h.textContent += "/* 硬件版本" + " */\n"
board_h.textContent += "#define HARDWARE_VER \"" + document.querySelector("#hardware_ver").value + "\"\n"
board_h.textContent += "/* 软件版本" + " */\n"
board_h.textContent += "#define SOFTWARE_VER \"" + document.querySelector("#softwar_ver").value + "\"\n"
}
function addCom()
{
for(var i = 0;i < MAX_COM_NUM;i++)
{
var canid = document.querySelector("#com" + i)
if (canid.checked == true)
{
board_h.textContent += "\n"
board_h.textContent += "/* 添加串口" + i + " */\n"
board_h.textContent += "#define INCLUDE_COM" + i + "\n"
board_h.textContent += "#ifdef " + "INCLUDE_COM" + i + "\n"
board_h.textContent += " #define COM" + i + "_PORT " + document.querySelector("#com" + i + "_GPIO").value + "\n"
board_h.textContent += " #define COM" + i + "_TX_PIN " + "GPIO_" +document.querySelector("#com" + i + "_TX").value + "\n"
board_h.textContent += " #define COM" + i + "_RX_PIN " + "GPIO_" +document.querySelector("#com" + i + "_RX").value + "\n"
board_h.textContent += "#endif\n"
}
}
}
function addShell()
{
if (document.querySelector("#shell_com").checked == true)
{
board_h.textContent += "\n"
board_h.textContent += "/* 添加SHELL口" + " */\n"
board_h.textContent += "#define INCLUDE_SHELL\n"
board_h.textContent += "#ifdef INCLUDE_SHELL\n"
board_h.textContent += " #define SHELL_COM " + document.querySelector("#shell_com_COM").value + "\n"
board_h.textContent += "#endif\n"
}
}
function addRs485(rs485_com,index)
{
if (rs485_com.checked == true)
{
board_h.textContent += "\n"
board_h.textContent += "/* RS485" + index + " */\n"
board_h.textContent += "#define INCLUDE_RS485" + index + "\n"
board_h.textContent += "#ifdef INCLUDE_RS485" + index + "\n"
board_h.textContent += " #define RS485" + index + "_COM " + document.querySelector("#rs485" + index + "_com" + "_COM").value + "\n"
board_h.textContent += "#endif\n"
}
}
function addEndif(){
board_h.textContent += "\n"
board_h.textContent += "#endif\n"
}
function getRs485EnNum()
{
var en_id
var en_SUM = 0
for(var i = 1;i < MAX_RS485_NUM + 1;i++)
{
en_id = document.querySelector("#rs485" + i + "_EN_gpio")
if(en_id.value != "NONE")
{
en_SUM++
}
}
return en_SUM
}
function getDoNum(){
var do_id
var do_SUM = 0
var en_id
for(var i = 1;i < MAX_DO_NUM + 1;i++)
{
do_id = document.querySelector("#do_" + i)
if(do_id.checked == true)
{
do_SUM++
}
}
for(var i = 1;i < MAX_RS485_NUM + 1;i++)
{
en_id = document.querySelector("#rs485" + i + "_EN_gpio")
if(en_id.value != "NONE")
{
do_SUM++
}
}
return do_SUM
}
function getDiNum(){
var di_id
var di_SUM = 0
for(var i = 1;i < MAX_DI_NUM + 1;i++)
{
di_id = document.querySelector("#di_" + i)
if(di_id.checked == true)
{
di_SUM++
}
}
return di_SUM
}
function addDo(){
var do_id
var do_gpio
var do_pin
var do_index = 0
var en_id
var en_pin
var do_num = getDoNum()
var en_index = 0
board_h.textContent += "\n"
board_h.textContent += "#define INCLUDE_GPIO\n"
board_h.textContent += "#ifdef INCLUDE_GPIO\n"
board_h.textContent += "#define GPIO_OUTPUT_NUM " + do_num + "\n"
for(var i = 1;i < MAX_DO_NUM + 1;i++)
{
do_id = document.querySelector("#do_" + i)
if(do_id.checked == true)
{
do_index++
do_gpio = document.querySelector("#do_" + i + "_GPIO").value
do_pin = document.querySelector("#do_" + i + "_PIN").value
board_h.textContent += " #define DO" + i + " " + (do_index -1)
board_h.textContent += " /* P" + do_gpio[do_gpio.length - 1] + "_" + do_pin[do_pin.length - 1] + " */\n"
}
}
for(var i = 1;i < MAX_RS485_NUM + 1;i++)
{
en_id = document.querySelector("#rs485" + i + "_EN_gpio").value
en_pin = document.querySelector("#rs485" + i + "_EN_pin").value
if(en_id != "NONE")
{
board_h.textContent += " #define rs485" + i +"_TX_EN" + " " + (do_num - getRs485EnNum() + en_index)
board_h.textContent += " /* P" + en_id[en_id.length - 1] + "_" + en_pin[en_pin.length - 1] + " */\n"
en_index++
}
}
}
function addDi(){
var di_id
var di_gpio
var di_pin
var di_index = 0
board_h.textContent += "\n"
board_h.textContent += "#define GPIO_INPUT_NUM " + getDiNum() + "\n"
for(var i = 1;i < MAX_DI_NUM + 1;i++)
{
di_id = document.querySelector("#di_" + i)
if(di_id.checked == true)
{
di_index++
di_gpio = document.querySelector("#di_" + i + "_GPIO").value
di_pin = document.querySelector("#di_" + i + "_PIN").value
board_h.textContent += " #define DI" + i + " " + (di_index -1)
board_h.textContent += " /* P" + di_gpio[di_gpio.length - 1] + "_" + di_pin[di_pin.length - 1] + " */\n"
}
}
board_h.textContent += "#endif\n"
}
function getAdcNum()
{
var adcNum = 0
var adc_id
for(var i = 1;i < MAX_ADC_NUM + 1;i++)
{
adc_id = document.querySelector("#ai_" + i)
if(adc_id.checked == true)
{
adcNum++
}
}
return adcNum
}
function addAdc(){
var adc_id
var adc_index = 0
board_h.textContent += "\n"
board_h.textContent += "#define INCLUDE_ADC\n"
board_h.textContent += "#ifdef INCLUDE_ADC\n"
board_h.textContent += " #define ADC_CHANNEL_NUM " + getAdcNum() + "\n"
board_h.textContent += " #define ADC_MAX_VALUE " + MAX_ADC_VALUE + ".0f\n"
for (var i = 1;i < MAX_ADC_NUM + 1;i++)
{
adc_id = document.querySelector("#ai_" + i)
if (adc_id.checked == true)
{
adc_gpio = document.querySelector("#ai_" + i + "_GPIO").value
adc_pin = document.querySelector("#ai_" + i + "_PIN").value
board_h.textContent += " #define AI" + adc_index + " " + adc_index + " "
board_h.textContent += "/* P" + adc_gpio[adc_gpio.length - 1] + "_" + adc_pin[adc_pin.length - 1] + " */" + "\n"
adc_index++
}
}
board_h.textContent += "#endif\n"
}
function getCanNum()
{
var canNum = 0
var can_id
for(var i = 1;i < MAX_ADC_NUM + 1;i++)
{
can_id = document.querySelector("#can" + i)
if(can_id.checked == true)
{
canNum++
}
}
return canNum
}
function addCan()
{
for(var i = 0;i < MAX_CAN_NUM;i++)
{
var canid = document.querySelector("#can" + i)
if (canid.checked == true)
{
board_h.textContent += "\n"
board_h.textContent += "/* 添加CAN" + i + " */\n"
board_h.textContent += "#define INCLUDE_CAN" + i + "\n"
board_h.textContent += "#ifdef " + "INCLUDE_CAN" + i + "\n"
board_h.textContent += " #define CAN" + i + "_PORT " + document.querySelector("#can" + i + "_GPIO").value + "\n"
board_h.textContent += " #define CAN" + i + "_TX_PIN " + "GPIO_" +document.querySelector("#can" + i + "_TX").value + "\n"
board_h.textContent += " #define CAN" + i + "_RX_PIN " + "GPIO_" +document.querySelector("#can" + i + "_RX").value + "\n"
board_h.textContent += "#endif\n"
}
}
}
function addGpioOptions(gpio,index)
{
// GOIO组的数量应该根据芯片决定后续会修改
var option_gpio = document.createElement('option')
option_gpio.value = "GPIO" + String.fromCharCode(65 + index)
option_gpio.text = "GPIO" + String.fromCharCode(65 + index)
gpio.appendChild(option_gpio);
}
function addPinOptions(pin,index)
{
var option_pin = document.createElement('option')
option_pin.value = "PIN_" + index
option_pin.text = "PIN_" + index
pin.appendChild(option_pin);
}
//启动之后的进程
function startProcess()
{
//添加COM口的GPIO选择元素
for(var i = 0;i < MAX_COM_NUM;i++)
{
var com_gpio = document.querySelector("#" + "com" + i + "_GPIO")
for(var j = 0;j < MAX_GPIO_NUM;j++)
{
addGpioOptions(com_gpio,j)
}
}
//添加COM口的pin脚选择
for(var i = 0;i < MAX_COM_NUM;i++)
{
var com_pin = document.querySelector("#" + "com" + i + "_TX")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(com_pin,j)
}
}
for(var i = 0;i < MAX_COM_NUM;i++)
{
var com_pin = document.querySelector("#" + "com" + i + "_RX")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(com_pin,j)
}
}
//添加30路DO的管脚
var do_gpio
var do_pin
for(var i = 1;i < MAX_DO_NUM + 1;i++)
{
//添加GPIO组
do_gpio = document.querySelector("#do_" + i + "_GPIO")
for(var j = 0;j < MAX_GPIO_NUM;j++)
{
addGpioOptions(do_gpio,j)
}
//添加GPIO引脚
do_pin = document.querySelector("#do_" + i + "_PIN")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(do_pin,j)
}
}
//添加30路DI的管脚
var di_gpio
var di_pin
for(var i = 1;i < MAX_DI_NUM + 1;i++)
{
//添加GPIO组
di_gpio = document.querySelector("#di_" + i + "_GPIO")
for(var j = 0;j < MAX_GPIO_NUM;j++)
{
addGpioOptions(di_gpio,j)
}
//添加GPIO引脚
di_pin = document.querySelector("#di_" + i + "_PIN")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(di_pin,j)
}
}
//添加EN引脚
var rs485_EN
var rs485_EN_PIN
for(var i = 1;i < MAX_RS485_NUM + 1;i++)
{
rs485_EN = document.querySelector("#rs485" + i + "_EN_gpio")
var option_gpio = document.createElement('option')
option_gpio.value = "NONE"
option_gpio.text = "NONE"
rs485_EN.appendChild(option_gpio);
for(var j = 0;j < MAX_GPIO_NUM;j++)
{
addGpioOptions(rs485_EN,j)
}
rs485_EN_PIN = document.querySelector("#rs485" + i + "_EN_pin")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(rs485_EN_PIN,j)
}
}
//添加ADC的GPIO和PIN
var adc_gpio
var adc_pin
for(var i = 1;i < MAX_ADC_NUM + 1;i++)
{
adc_gpio = document.querySelector("#ai_" + i + "_GPIO")
for(var j = 0;j < MAX_GPIO_NUM;j++)
{
addGpioOptions(adc_gpio,j)
}
adc_pin = document.querySelector("#ai_" + i + "_PIN")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(adc_pin,j)
}
}
//添加CAN
for(var i = 0;i < MAX_CAN_NUM;i++)
{
var can_gpio = document.querySelector("#" + "can" + i + "_GPIO")
for(var j = 0;j < MAX_GPIO_NUM;j++)
{
addGpioOptions(can_gpio,j)
}
var can_pin = document.querySelector("#" + "can" + i + "_TX")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(can_pin,j)
}
var can_pin = document.querySelector("#" + "can" + i + "_RX")
for(var j = 0;j < MAX_GPIO_PIN_NUM;j++)
{
addPinOptions(can_pin,j)
}
}
//添加SPI
//添加IIC
}
startProcess()
//一键生成
click_button.addEventListener("click", function() {
board_h.textContent = ""
//添加固定头和头文件
addHead(mcu_type)
//添加串口
addCom()
//添加shell
addShell()
//添加RS485
addRs485(rs4851,1)
addRs485(rs4852,2)
//添加30路DO
addDo()
//添加30路DI
addDi()
//添加ADC
addAdc()
//添加CAn
addCan()
//添加结尾
addEndif()
});