嵌入式C设计模式:命令设计模式

设计模式在软件开发中扮演着重要的角色,它们提供了一种在特定场景下解决常见问题的经验丰富的方法。在嵌入式C开发中,命令设计模式是一种常用的设计模式,它将请求封装为对象,从而允许我们根据不同的请求类型执行相应的操作。本文将详细介绍命令设计模式的概念和实现,并提供相应的源代码示例。

命令设计模式的核心思想是将请求封装为一个命令对象,该对象包含了执行该请求所需的所有信息。这样,我们可以将请求的执行延迟、排队或记录下来,以及支持可撤销的操作。命令模式由三个关键角色组成:命令接口、具体命令类和命令调用者。

首先,我们需要定义一个命令接口,该接口声明了执行命令的方法。以下是一个简单的命令接口的示例代码:

// 定义命令接口
typedef struct {
   
   
    void (*execute)(void
【C语言】如何优雅地进行嵌入式C开发?(万字总结) 如果当你听过很多大道理,依然写不好C代码,就来读读这篇文章吧!!! 关键词:代码质量、分层设计、设计模式、面向对象、防御式编程 阅读详情

相关推荐

嵌入式C设计模式---命令设计模式

将一个请求(行为)封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤销的操作。

weixin_42162924的博客 538

嵌入式C语言设计模式 --- 前言

重构嵌入式 C 语言开发的思维模式

EmbedIoT Studio 1604

嵌入式C设计模式---状态机设计模式

允许一个对象在其内部状态改变时改变它的行为。从而使对像看起来似乎修改了其行为。

weixin_42162924的博客 1515

嵌入式C语言设计模式 --- 单例模式

单例模式(Singleton Pattern)是软件程序设计中最简单的设计模式之一,单例模式在设计模式分类中,是属于创建型模式,它提供了一种创建对象(实例,变量)的最佳实践方式。顾名思义,单例(也叫单件),也就是在整个程序设计中,只存在一个单一的类(C语言中叫“类型”,通常用结构体类型表示),这个类负责创建一个对象(C语言中叫“定义变量”,通常是指结构体变量)

EmbedIoT Studio 2750

Verilog流水线CPU设计(超详细)

快把这一篇给更了

Ace Cheney的博客 7万+

常微分方程 (ODE) 和 随机微分方程 (SDE)

常微分方程(Ordinary Differential Equations, ODE)和随机微分方程(Stochastic Differential Equations, SDE)是数学中描述系统动态行为的重要工具。它们有一些相似之处,但在处理随机性方面存在显著差异。

weixin_39699362的博客 4384

【BAT32G113-仿真器及脱机烧录器教程-A3-2024/9/19】

提示:此壁纸收集于互联网,如有侵权,请联系作者!今日下班,闲来无事,就与生活中在乎的人闲日常,互相彼此增进一些友谊或爱意情愫!在座的朋友看到这里,有时间,抽抽空,多多联系一下,身边重要的人哟!四种指示灯和一个按钮:MODE->代表红色POWER->代表黄色ACTIVE->代表蓝色STATUS->代表XX(不记得了)黑色按钮:按键上电,会进入升级模式,这里我们一般默认不需要改变!仿真工具-ICE8-PRO介绍隶属于产品分支里。烧写工具-CMS-WRITER8 LITE介绍点击。

星新计划的博客 8274

ROS实践(四)机器人SLAM建图(gmapping)

本文介绍了SLAM技术及其实现方法。SLAM(同步定位与地图构建)让机器人在未知环境中通过传感器数据自主定位并构建地图。文章详细讲解了激光雷达、RGBD相机等常用传感器,以及gmapping和map_server这两个ROS功能包的使用方法。重点阐述了SLAM建图实验步骤:配置gmapping节点参数、启动机器人仿真、运行gmapping节点、使用rviz可视化工具、通过键盘遥控机器人完成地图构建并保存。实验结果表明,该方法能有效实现机器人自主建图功能,为后续导航等应用奠定基础。

qq_1033275663的博客 4343

c# 如何使用S7NET 读取汇川H5U的数据

本文介绍了两种使用C#读取汇川H5U PLC数据的方法。第一种通过ModbusTCP协议(推荐),使用NModbus库实现,步骤包括配置PLC的Modbus服务器功能、安装库及编写读取保持寄存器的代码。第二种针对兼容西门子S7协议的型号,使用S7NetPlus库直接读取。文章强调需注意地址映射关系、协议配置及网络设置,并建议优先采用ModbusTCP方案以确保稳定性。两种方法均提供了完整的代码示例,帮助开发者快速实现在C#环境下与汇川H5U PLC的通信。

StevenChen的博客 457

基于matlab实现的水果识别系统设计

本项目针对多种常见水果混合的图像,利用 Matlab 软件,对水果的识别进行研究。根据水果和背景的差别选取阈值,对去噪增强对比度后的图像进行二值化处理。再对图像进行边缘检测,选定连通区域,标记后再对不同种水果的颜色,形状,大小等特征进行快速识别水果,从而实现对水果的正确分拣。:水果识别、MATLAB、数字图像处理。

热情、奔放、快乐编程! 4863

【Simulink教程案例7】基于Simulink的滑模控制器设计与实现

欢迎订阅滑膜控制是一种变结构控制策略,其和常规控制方法的主要区别在于控制的不连续性,即一种使系统结构随时间变化的开关特性。所以,滑膜控制器也叫做变结构控制器,其本质是一类特殊的非线性控制器,并且这种非线性为不连续性。滑膜控制器和其他控制方式最大的区别在于其结构的不固定性,在其工作过程中,系统当前的状态会发生变化,使得系统按照预先设置的“滑动模态”的状态轨迹运动。正是由于这个特点,滑膜控制器具有快速响应的优点。滑模控制的基本定义如下所示:1).穿越切换面上的某个点;2).从切换面上的某个点离开;

FPGA/MATLAB学习教程/源码/项目合作开发 3244

大疆 2021 嵌入式笔试题

在深圳做嵌入式,大疆公司绝对是 Top 级别的,大疆的技术栈也很深。

qq_38769551的博客 2496

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 在ARXML中定义嵌入式XCP-PDU用于测量和标定
下一篇: Altium Designer 18中查看引脚数的方法
普通网友
博客等级 码龄3年 28粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值