aboutsummaryrefslogtreecommitdiff
path: root/list.h
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2025-04-28 20:25:40 -0700
committerXiao Pan <xyz@flylightning.xyz>2025-04-28 20:25:40 -0700
commit10e19dab46407cb9cf23923d2431cef0f2a50733 (patch)
treeba315453a9fd8dcda9090bc8752866b0de377132 /list.h
parentea551f37cc03c691e7f2c002d1ca313fbca8793c (diff)
feat: read past data from remote pi
Using linked list so I can keep adding data without worrying about arrary max length. I also moved old code that can only read live data to old/remote_plot_live.c as an archive.
Diffstat (limited to 'list.h')
-rw-r--r--list.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/list.h b/list.h
new file mode 100644
index 0000000..88cd4f5
--- /dev/null
+++ b/list.h
@@ -0,0 +1,76 @@
+// "C Primer Plus" Chapter17 practice 17 practice problem 2
+
+/*list.h--简单列表类型的头文件*/
+#ifndef LIST_H_
+#define LIST_H_
+#include <stdbool.h>
+#include <stdint.h> //uint32_t
+
+/*特定与程序的声明*/
+#define VOLTLEN 96
+#define TEMPLEN 32
+
+typedef struct can
+{
+ uint32_t t;
+ double volt[VOLTLEN];
+ double temp[TEMPLEN];
+};
+
+/*一般类型定义*/
+typedef struct can Item;
+
+typedef struct node
+{
+ Item item;
+ struct node * next;
+}Node;
+
+typedef struct list
+{
+ Node * head;
+ Node * end;
+}List;
+/*函数原型*/
+/*操作: 初始化一个列表 */ //operation
+/*操作前: plist指向一个列表 */ //preconditions
+/*操作后: 该列表被初始化为空列表 */ //postconditions
+void InitializeList(List * plist);
+
+/*操作: 确定列表是否为空列表 */
+/*操作前: plist指向一个已经初始化的列表 */
+/*操作后: 如果该列表为空则返回true; 否则返回false*/
+bool ListIsEmpty(const List * plist);
+
+/*操作: 确定列表是否已满*/
+/*操作前: plist指向一个已初始化的列表*/
+/*操作后: 如果该列表为空则返回true; 否则返回false*/
+bool ListIsFull(const List * plist);
+
+/*操作: 确定列表中项目的个数*/
+/*操作前: plist指向一个已初始化的列表*/
+/*操作后: 返回该列表中项目的个数*/
+unsigned int ListItemCount(const List * plist);
+
+/*操作: 在列表尾部添加一个项目*/
+/*操作前: item是要被增加到列表的项目*/
+/* plist指向一个已初始化的列表*/
+/*操作后: 如果可能的话,在列表尾部添加一个新项目,*/
+/* 函数返回true;否则函数返回false*/
+bool AddItem(Item item, List * plist);
+
+/*操作: 把一个函数作用于列表中的每个项目*/
+/*操作前: plist指向一个已出书画的列表*/
+/* pfun指向一个函数,该函数接受*/
+/* 一个Item参数并且无返回值*/
+/*操作后: pfun指向的函数被作用到*/
+/* 列表中的每个项目一次*/
+void Traverse(const List * plist, void (* pfun)(Item item));
+
+/*操作: 释放已分配的内存(如果有)*/
+/*操作前: plist指向一个已初始化的列表*/
+/*操作后: 为该列表分配的内存已被释放*/
+/* 并且该列表被置为空列表*/
+void EmptyTheList(List * plist);
+
+#endif // LIST_H_