[原创] ST MEMS状态机和机器学习.ucf文件转c代码工具。

littleshrimp   2022-4-21 13:00 楼主

请问LSM6DSOX 的FSM 和MLC功能 配置好的ucf文件后续如何转换成C代码嵌入到MCU

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UcfFile2CCode
{
    public partial class MainWindow : Form
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "ucf files (*.ucf)|*.ucf|All files (*.*)|*.*";
            dialog.Title = "请选择要转换的.ucf文件";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string ccode = "typedef struct {\r\n" +
                                "\tuint8_t address;\r\n" +
                                "\tuint8_t data;\r\n" +
                                "}ucf_line_t;\r\n\r\n" +
                                "const ucf_line_t ucf_lines[] = {\r\n";
                string[] ucfTextLines = File.ReadAllLines(dialog.FileName);
                foreach (string ucfTextLine in ucfTextLines)
                {
                    if (ucfTextLine.IndexOf("Ac") == 0)
                    {
                        string[] sp = ucfTextLine.Split(' ');
                        ccode += string.Format("\t{{.address = {0}, .data = {1},}},\r\n", sp[1], sp[2]);
                    }
                }
                ccode = ccode.Substring(0, ccode.Length - 3) + "\r\n};";
                File.WriteAllText(dialog.FileName + ".h", ccode);
            }
        }
    }
}

UcfFile2CCode bin.zip (4.13 KB)
(下载次数: 2, 2022-4-21 12:57 上传)

UcfFile2CCode source.zip (14.87 KB)
(下载次数: 2, 2022-4-21 12:57 上传)

虾扯蛋,蛋扯虾,虾扯蛋扯虾

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复