├── README.md └── code └── card ├── Makefile ├── aboutbmp.c ├── card.c ├── databasse.c ├── head.h ├── main.c ├── park11 ├── rfid_gec_getId.c ├── sql_test ├── test ├── test.c └── test.db └── time.c /README.md: -------------------------------------------------------------------------------- 1 | ## 基于Linux平台下的私家车智能停车场计费系统的设计与实现 2 | --------------------- 3 | ## `Author:zhanxuegui` :apple: 4 | ## `Date:2017.07.04 - 2017.08.03` 5 | ----------------- 6 | ### 项目描述: 7 | - 功能: 8 | - 实现车辆进、出入停车场的自动识别; 9 | - 实现车辆的停车场计费功能; 10 | - 可以对非法车辆进行处理,通过报警器等方式告知管理员。 11 | - 方案: 12 | - 基于Linux平台开发的停车场计费系统,采用ARM Cotex-A53作为系统CPU,搭载Linux系统操作系统。 13 | - 采用sqlite3作为系统的数据库,实现车主信息和费用的增删查改等操作。 14 | - 通过RFID模块的识别实现对车辆出入车动作的识别。 15 | - 涉及的技术:Linux系统编程、嵌入式数据库sqlite3、RFID射频识别模块、多线程编程。 16 | 17 | 18 | 19 | ----------- 20 | ## 注:效果演示图未上传 21 | -------------------------------------------------------------------------------- /code/card/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CC=arm-none-linux-gnueabi-gcc 3 | 4 | TARGET=park 5 | 6 | SRCS=$(wildcard *.c) 7 | OBJS=$(patsubst %.c,%.o,$(SRCS)) 8 | 9 | $(TARGET):$(OBJS) 10 | $(CC) $(OBJS) -o $(TARGET) -I /home/gec/develop/yueqian/sqlite3/sqlite-autoconf-3240000 -L /home/gec/develop/yueqian/sqlite3/sqlite-autoconf-3240000/.lib -lsqlite3 11 | 12 | $(OBJS):%.o:%.c 13 | $(CC) -c $^ -o $@ 14 | 15 | clean: 16 | rm *.o $(TARGET) 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /code/card/aboutbmp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victory1355/Park/6c759c285b326d5066c55fca8ac5ea0c81b1bbdc/code/card/aboutbmp.c -------------------------------------------------------------------------------- /code/card/card.c: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | 3 | #define PICTURE_IN "/root/project/park/in.bmp" 4 | #define PICTURE_OUT "/root/project/park/out.bmp" 5 | 6 | /* 7 | 处理入库动作,成功返回0,失败返回-1 8 | 参数:要插入的信息,比如卡号 9 | */ 10 | int card_in(char *cardid,sqlite3 *car_owner_database) 11 | { 12 | 13 | if(cardid == NULL || car_owner_database == NULL) 14 | { 15 | return -1; 16 | } 17 | 18 | char insert_information[300]; 19 | memset(insert_information,0,sizeof(insert_information)); 20 | 21 | long int start_time; 22 | start_time = get_local_time(); 23 | char buffer[30]; 24 | bzero(buffer,30); 25 | 26 | sprintf(buffer,"%ld",start_time); 27 | 28 | sprintf(insert_information,"insert into owner_information_table values(\"%s\", \"%s\");",cardid, buffer); 29 | //打印调试信息 30 | //printf("insert information:%s\n", insert_information); 31 | 32 | 33 | int ret=sqlite3_exec(car_owner_database,insert_information,NULL,NULL,NULL); 34 | if(ret!=SQLITE_OK) 35 | { 36 | 37 | printf("insert action failed\n"); 38 | return -1; 39 | } 40 | else 41 | { 42 | printf("the car(%s) is coming >------> the park\n", cardid); 43 | 44 | //显示车位状态 45 | show_shapebmp(40,250,98,178,PICTURE_IN); 46 | return 0; 47 | } 48 | } 49 | 50 | 51 | /* 52 | 处理出库动作,成功返回0,失败返回-1 53 | 参数:要删除的信息,比如卡号 54 | */ 55 | int card_out(char *cardid, sqlite3 *car_owner_database) 56 | { 57 | 58 | if(cardid == NULL || car_owner_database == NULL) 59 | { 60 | return -1; 61 | } 62 | 63 | char delete_information[300]; 64 | 65 | memset(delete_information,0,sizeof(delete_information)); 66 | 67 | //删除之前打印费用和时间 68 | calculate_total_parking_time(cardid, car_owner_database); 69 | 70 | sprintf(delete_information,"delete from owner_information_table where card_id='%s';",cardid); 71 | //打印调试信息 72 | //printf("delete information:%s\n", delete_information); 73 | 74 | //删除车主信息 75 | int ret=sqlite3_exec(car_owner_database,delete_information,NULL,NULL,NULL); 76 | if(ret!=SQLITE_OK) 77 | { 78 | 79 | printf("delete action failed\n"); 80 | return -1; 81 | } 82 | else 83 | { 84 | printf("the car(%s) is leaving <------< the park\n", cardid); 85 | //显示车位状态 86 | //show_shapebmp(40,250,98,178,PICTURE_OUT); 87 | show_fullbmp(PICTURE_PATH); 88 | return 0; 89 | } 90 | } 91 | 92 | 93 | // 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /code/card/databasse.c: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | 3 | //查询结果 4 | int select_cardid_result(void *arg,int column,char **column_val,char **column_name) 5 | { 6 | 7 | //printf("one test\n"); 8 | flag = 1; 9 | return 0;//一定要写上 10 | } 11 | /* 12 | 创建数据库,成功返回数据库指针,失败返回NULL 13 | 参数:数据库名字 14 | */ 15 | sqlite3 *create_car_owner_database(char *databasename) 16 | { 17 | if(databasename == NULL) 18 | return NULL; 19 | 20 | 21 | sqlite3 *car_owner_database; 22 | int ret; 23 | 24 | //打开你要操作的数据库文件 25 | ret=sqlite3_open(databasename,&car_owner_database); 26 | if(ret!=SQLITE_OK) 27 | { 28 | printf("create database failed\n"); 29 | return NULL; 30 | } 31 | else 32 | printf("create database ok\n"); 33 | //执行相关的命令 34 | ret=sqlite3_exec(car_owner_database,"create table if not exists owner_information_table(card_id text unique,time text);",NULL,NULL,NULL); 35 | if(ret!=SQLITE_OK) 36 | { 37 | printf("create table owner_information_table failed\n"); 38 | return NULL; 39 | } 40 | else 41 | printf("create table ok\n"); 42 | 43 | return car_owner_database; 44 | 45 | } 46 | 47 | /* 48 | 查询数据库是否有该卡号,成功返回0,失败返回-1 49 | 参数:数据指针car_owner_database,卡号cardid, 50 | */ 51 | int select_cardid(char *cardid,sqlite3 *car_owner_database) 52 | { 53 | 54 | // 使用查询命令的时候一定要使用第三个参数,函数指针 55 | 56 | if(cardid == NULL || car_owner_database == NULL) 57 | { 58 | return -1; 59 | } 60 | 61 | char select_information[300]; 62 | 63 | //bzero(error_msg, 100); 64 | memset(select_information,0,sizeof(select_information)); 65 | sprintf(select_information,"select card_id from owner_information_table where card_id='%s';",cardid); 66 | //打印调试信息 67 | //printf("select information:%s\n", select_information); 68 | 69 | if(strlen(cardid) == 8) 70 | { 71 | int ret=sqlite3_exec(car_owner_database,select_information,select_cardid_result,NULL,NULL); 72 | //printf("flag = %d\n", flag); 73 | if(flag != 1) 74 | { 75 | //printf("the card_id not exist\n"); 76 | card_in(cardid,car_owner_database); 77 | } 78 | else 79 | { 80 | flag = 0; 81 | //printf("the card_id has existed\n"); 82 | card_out(cardid, car_owner_database); 83 | } 84 | } 85 | 86 | return 0; 87 | } 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /code/card/head.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEAD_H 2 | #define _HEAD_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "sqlite3.h" 19 | 20 | 21 | #define PICTURE_PATH "/root/project/park/ui.bmp" 22 | #define DATABASE_PATH "/root/project/park/car_owner_database.db" 23 | 24 | 25 | int flag; 26 | 27 | /* 28 | 打开串口设备并初始化 29 | 参数:串口的文件, 30 | */ 31 | 32 | int open_tty(int *fd); 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | // 自定义函数,专门用于显示800*480bmp格式的图片 41 | int show_fullbmp(char *bmpname); 42 | /* 43 | x,y是图片显示左上角的坐标 44 | w,h是图片本身的宽和高 像素 45 | */ 46 | int show_shapebmp(int x,int y,int w,int h,char *bmpname); 47 | /*将任意大小的图片缩小成某种比例 48 | 参数介绍:x ,y --》左上角x,y坐标 49 | w ---》图片的实际宽 50 | h ---》图片的实际高 51 | scale---》缩小的倍数 52 | bmpname---》图片的路径 53 | 代码重点提示:m相当于是缩小之后的图片的宽,n相当于是缩小之后的图片的高 54 | */ 55 | int show_shortbmp(int x,int y,int w,int h,int scale,char *bmpname); 56 | 57 | 58 | 59 | 60 | // 停车场计费标准:3元每个小时 61 | 62 | int select_time_result(void *arg,int column,char **column_val,char **column_name); 63 | /* 64 | 获取系统时间,成功返回进车的时间点,失败返回-1 65 | 参数:无 66 | */ 67 | int get_local_time(); 68 | /* 69 | 计算停车时间并打印停车费用, 70 | 参数:数据库指针 71 | */ 72 | 73 | int calculate_total_parking_time(char *cardid, sqlite3 *car_owner_database); 74 | /* 75 | 根据停车时间计算停车费用,返回停车费用 76 | 参数:停车总时间 77 | */ 78 | 79 | double calculate_charge_park(long int time); 80 | 81 | 82 | 83 | 84 | 85 | /* 设置窗口参数:9600速率 */ 86 | void init_tty(int fd); 87 | /*计算校验和*/ 88 | unsigned char CalBCC(unsigned char *buf, int n); 89 | // 发送A命令 90 | int PiccRequest(int fd); 91 | /*防碰撞,获取范围内最大ID*/ 92 | int PiccAnticoll(int fd); 93 | /* 94 | 实时检测串口的数据,判断进车还是出车动作,成功返回卡的ID,失败返回-1 95 | 参数:数据库指针 96 | */ 97 | char *carin_or_carout(sqlite3 *car_owner_database, int fd); 98 | 99 | 100 | 101 | 102 | int select_cardid_result(void *arg,int column,char **column_val,char **column_name); 103 | /* 104 | 创建数据库,成功返回数据库指针,失败返回NULL 105 | 参数:数据库名字 106 | */ 107 | sqlite3 *create_car_owner_database(char *databasename); 108 | /* 109 | 查询数据库是否有该卡号,成功返回0,失败返回-1 110 | 参数:数据指针car_owner_database,卡号cardid, 111 | */ 112 | int select_cardid(char *cardid,sqlite3 *car_owner_database); 113 | 114 | 115 | 116 | /* 117 | 处理入库动作,成功返回0,失败返回-1 118 | 参数:要插入的信息,比如卡号 119 | */ 120 | int card_in(char *cardid,sqlite3 *car_owner_database); 121 | 122 | /* 123 | 处理出库动作,成功返回0,失败返回-1 124 | 参数:要删除的信息,比如卡号 125 | */ 126 | int card_out(char *cardid,sqlite3 *car_owner_database); 127 | 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /code/card/main.c: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | 3 | 4 | 5 | 6 | int main(void) 7 | { 8 | int serial_fd; 9 | flag = 0; 10 | sqlite3 * car_owner_database = NULL; 11 | 12 | //初始化串口 13 | open_tty(&serial_fd); 14 | 15 | //显示停车场背景图 16 | show_fullbmp(PICTURE_PATH); 17 | 18 | 19 | //创建数据库 20 | car_owner_database = create_car_owner_database(DATABASE_PATH); 21 | if(car_owner_database == NULL) 22 | { 23 | return -1; 24 | } 25 | //检测进车或者出车动作 26 | char *p; 27 | char *pp = (char *)malloc(9); 28 | bzero(pp ,9); 29 | 30 | while(1) 31 | { 32 | if((p = carin_or_carout(car_owner_database, serial_fd)) != NULL) 33 | { 34 | if(strlen(p) == 8) 35 | { 36 | //printf("p values = %s ", p); 37 | sprintf(pp, "%s", p); 38 | //printf("pp values = %s\n", pp); 39 | if(strlen(pp) == 8) 40 | select_cardid(pp, car_owner_database); 41 | } 42 | } 43 | else 44 | sleep(3); 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /code/card/park11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victory1355/Park/6c759c285b326d5066c55fca8ac5ea0c81b1bbdc/code/card/park11 -------------------------------------------------------------------------------- /code/card/rfid_gec_getId.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victory1355/Park/6c759c285b326d5066c55fca8ac5ea0c81b1bbdc/code/card/rfid_gec_getId.c -------------------------------------------------------------------------------- /code/card/sql_test/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/victory1355/Park/6c759c285b326d5066c55fca8ac5ea0c81b1bbdc/code/card/sql_test/test -------------------------------------------------------------------------------- /code/card/sql_test/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "sqlite3.h" 15 | 16 | 17 | 18 | /*回调函数*/ 19 | int show_result(void *arg,int column,char **column_val,char **column_name) 20 | { 21 | int i; 22 | printf("test\n"); 23 | 24 | 25 | for(i=0; i