带缓冲时间的环形缓冲区 [英] Ring buffer with stamp time

查看:121
本文介绍了带缓冲时间的环形缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要一个环形缓冲区(C语言版)



我尝试了什么:



大家好,



我有需要一个环形缓冲区(在C语言中),它可以在运行时保存任何类型的对象(几乎数据将是不同的信号值,如电流(100ms和10ms)和temperature.etc)(我不确定它是否必须是固定大小或不是)它需要非常高的性能。虽然它处于多任务嵌入式环境中。



实际上我需要这个缓冲区作为备份,这意味着嵌入式软件将正常工作并将数据保存到环缓冲区,到目前为止由于任何原因和发生错误,然后我可能有一个测量值的参考,然后我将能够看看它们并确定问题。此外,我需要在环形缓冲区上创建一个时间戳,这意味着每个数据(信号值)存储在环形缓冲区中将与测量时间一起存储。



任何代码或想法将不胜感激。所需的一些操作是:



创建一个特定大小的环形缓冲区。将其与整个软件相关联。放在尾巴上。从头上得到。出错,读取数据及其发生时间(时间戳)。归还计数。当缓冲区已满时覆盖。

Hi everybody,

I have a need for a ring buffer (In C language)

What I have tried:

Hi everybody,

I have a need for a ring buffer (In C language) which can hold objects of any type at the run time (almost the data will be different signal's values like current (100ms and 10ms) and temperature.etc) ( I am not sure if it have to be a fixed size or not) and it needs to be very high performance. although it's in a multi-tasking embedded environment.

Actually i need this buffer as a back up, which mean the embedded software will work as normal and save the data into the ring buffer, so far for any reason and when an error occurred, then i could have like a reference for the measured values then i will be able to have a look on them and determine the problem. Also i need to make a time stamp on the ring buffer, which mean every data (Signal value) is stored on the ring buffer will stored with the measurement's time.

Any code or ideas would be greatly appreciated. some of the operations required are:

create a ring buffer with specific size. Link it with the whole software. put at the tail. get from the head. at error, read the data and when its happen (time stamp). return the count. overwrite when the buffer is being full.

推荐答案

它不是那样的工作。

我们不为你工作。

如果你想让别人写你的代码,你必须付钱 - 我建议你去Freelancer.com并在那里问。



但要注意:你得到了你付出的代价。支付花生,买猴子。



发展的概念就像这句话所暗示的那样:系统地运用科学和技术知识来满足特定的目标或要求。 BusinessDictionary.com [ ^ ]

这与有一个不一样快速谷歌并放弃,如果我找不到完全正确的代码。

所以要么付钱给别人去做,要么学会如何自己写。我们不是为你做的。
It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.


引用:

我需要一个环形缓冲区(在C语言中),它可以在运行时保存任何类型的对象

I have a need for a ring buffer (In C language) which can hold objects of any type at the run time



由于C是强类型的并且不是对象,因此可能很难。

您需要优化您的要求。

如果我理解,您需要一个缓冲区来记录最后n个条目,以便能够在错误后重新读取条目。

循环缓冲区 - 维基百科 [ ^ ]



我们不做你的HomeWork。

HomeWork未设置为测试你乞求别人做你的工作的技巧,它会让你思考并帮助你的老师检查你对你所学课程的理解,以及你应用它们时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。



作为程序员,您的工作是创建算法解决特定问题,你不能依赖别人永远为你做,所以有一段时间你必须学会​​如何。而且越快越好。

当你要求解决方案时,就像试图通过培训其他人来学习开车一样。

创建算法基本上是找到数学并进行必要的调整以适应你的实际问题。


It may be difficult since C is strongly typed and is not object.
You need to refine you requirement.
If I understand, you want a buffer to log last n entries to be able to reread entries after error.
Circular buffer - Wikipedia[^]

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.


创建一个存储在环形缓冲区中的结构:

Create a structure to be stored in the ring buffer:
typedef struct rbuf_data 
{
    time_t timestamp; /* or any other time type */
    int data_type; /* defines the type of data (and so also it's length) */
    void *data; /* with variable data size */
    /*char data[MAX_DATA_SIZE];*/ /* with fixed or limited data size */
};
rbuf_data rbuf[RBUF_SIZE];



当拥有可变大小的数据时,必须使用 malloc()在传递给put函数之前,当覆盖缓冲区溢出时释放。



否则使用 memcpy()复制数据在添加新数据时具有相应的大小。


When having data with variable size, the data must be allocated using malloc() before passing to the put function and freed when overwriting upon buffer overuns.

Otherwise copy the data using memcpy() with the corresponding size when adding new data.


这篇关于带缓冲时间的环形缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆