[Linux] how to complete the actual project-- Summary of security monitoring system project


So far, I have also done 5 or 6 embedded projects, but in the past, I started from scratch, that is, I had no plan. If I wanted to do it there, I would implement it if I had an idea. This led to a lot of pitfalls and consumed me a lot of time. Of course, it's not bad, because I also got a good exercise and practice in it, but it's not applicable to doing it at work.

First of all, I would like to thank Huaqing Yuanjian for providing the teaching video of the security monitoring system project; It let me know how to complete a project in actual development from scratch. It helped me clarify the idea of project production, and also let me understand how important a good plan and agreement is for a project.

1, Personal perception

   1. Design idea of layered system framework

When designing the embedded project, try to design and draw the layered system framework of the project before;

Most embedded projects involve multi platform and multi task development;

For this project, it involves

  • The data communication between HTML and CGI is through boa server;
  • Communication between A9 server and CGI;
  • Communication between zigbee and A9;
  • Work of the platform itself and mutual access between multiple platforms

Then it is necessary to design the whole project hierarchically, and divide each platform into one for separate processing (multi process and multi thread can be considered). When formulating communication protocols and selecting communication methods, different platforms can be connected with each other. When a project has problems, it can quickly locate which layer and which task has problems, which not only facilitates the division of labor and cooperation of most people.

Take the layered design of the project as an example:

   2. Consideration of data flow

The ultimate goal of embedded design is to complete the correct data transmission. There are many transmission modes, such as Bluetooth, wifi, 3G/4G, serial port, etc;

Understanding the data flow of the project can help us correctly draw the software architecture, formulate reasonable communication contents and select appropriate communication methods.

Take this project as an example:

The data flow in this project is

  • Uplink data: ZigBee – >a9 – > Web page (obtain environmental information)
  • Downlink data: Web page – >a9 – >zigbee (issue command)

Communication mode:

  • Upload data: ZigBee ---- > shared memory + semaphore upload data ----> display and give it to the user
  • Data distribution: used to control hardware: ---- > message queue data distribution ----- > control hardware

   3. Necessity of unified communication content

Communication content, that is, the communication structure contains the data content we want to transfer

In this way, the information in the whole project is transmitted in the same way, which is convenient for us to unify the communication of the whole thread or process

For example, in this project
   data upload part:

Data type definition 	
typedef uint8_t  unsigned char;       
typedef uint16_t unsigned short;
typedef uint32_t unsigned int;

//Consider memory alignment
struct makeru_zigbee_info
		uint8_t head[3]; //Identification bit:'m''s''m'makeru security monitor  
		uint8_t type;	 //Data type'z'---zigbee'a'---a9
		------------->crc ...encryption algorithm  <--------------
		float temperature; //temperature
		float humidity;  //humidity
		float light;     //light intensity
		float tempMIN;  //Lower temperature limit
		float tempMAX;  //Upper temperature limit 
		float humidityMIN;   //Lower humidity limit
		float humidityMAX;   //Upper humidity limit
		float lightMIN; //Lower limit of light intensity
		float lightMAX; //Upper limit of light intensity  
		uint32_t reserved[2]; //Reserved extension bits, 0 filled by default
		//void *data;   Kernel reserved extension interface reference version

struct makeru_a9_info
	uint8_t head[3]; //Identification bit:'m''s''m'makeru security monitor  
	uint8_t type;	 //Data type'z'---zigbee'a'---a9
	uint32_t adc;    //adc voltage
	uint32_t reserved[2]; //Reserved extension bits, 0 filled by default
	//void *data;   Kernel reserved extension interface reference version
struct makeru_env_data
	struct makeru_a9_info a9_info;       //a9 uploading data    
	struct makeru_zigbee_info zigbee_info;   //zigbee uploading data

   data distribution: (send data to the lower computer in the form of message queue)

//Message queue structure
#define QUEUE_MSG_LEN 32                 
struct msg
	long type;   //Message type used to judge when receiving messages from message queue   
	long msgtype;//Specific message type = = = device type
	unsigned char text[QUEUE_MSG_LEN]; //Message body ====> CMD controls the specified device
long msgtype;//Specific message types
 Assignment of message types:
	1L: 		LED control
	2L:			Buzzer control
	3L:			Fan
	4L:			Setting of maximum temperature, humidity and light intensity
	5L-6L-7L-8L,Extensions for individuals
	9L: 		3G communication module -GPRS 
	case 1L: ...  break;
	default ....  break;
A9-ZIGBEE General instructions
 Command format: One byte,  unsigned char Corresponding to the type of body in the message queue: 

8 position
7	6	|  5	4	|	3	2	1	0
 Platform No |  Equipment No  |	Operating equipment
Platform No	
0x00		00-0 number-ZigBee platform 
0x40		01-1 number-A9 platform
0x80		10-2 number-STM32 platform(extend)
0xc0		11-3 number-retain(extend)
Equipment No		Operation mask	
0x00	LED		0x00	close all       0x40
				0x01	Open all       0x41
				0x02	Open LED2       0x42
				0x03	Open LED3       0x43
				0X04	Open LED4       0x44
				0x05	Open LED5       0x45
				0x06    closure LED2       0x46
				0x07    closure LED3       0x47
				0x08    closure LED4       0x48
				0x09    closure LED5       0x49
0x10	buzzer	0x00	closure           0x50 
				0x01	Open           0x51 
				0x02	Auto alarm off 0 x52 
				0x03	Automatic alarm on 0 x53
0x20	Fan	0x00	Turn off the fan       0x20
				0x01	Turn on the fan       0x21
0x30	extend	
control command: 		
	Platform number + Equipment number + Operation mask = command (Encapsulation of commands)
	for example: 
			0x00 + 0x20 + 0x01 = 0x21   Fan on
			0x40 + 0x10 + 0x01 = 0x51   Buzzer on		

2, Summary of project knowledge points

   1. HTML web page design and CGI

In the design of this project, html is used to draw web pages, CGI is used to process web page data, boa server is used to realize the communication between different languages, and form form is used to realize the communication between HTML and CGI; This is the development of user layer

   2. Communication between HTML webpage and A9

   send messages from web pages to A9, convert the data of web pages through CGI, and add the data to the message queue. Here we use the knowledge points of message queue, including the creation of message queue (msgget), receiving messages (msgrcv), sending messages (msgsnd);

   refreshing data from A9 to web pages is achieved by sharing memory. CGI gets the data of shared memory and sends it to web pages Here we use the knowledge points of shared memory, including the creation of shared memory (shmget), mapping (shmat), and unmapping (shmdt); At the same time, semaphores should be added to synchronize critical resources;

   3, the design idea of multithreading

   A9 platform is the core platform of the project. It uses multithreading to process and run multiple tasks separately, and uses mutually exclusive locks, semaphores, and conditional variables to complete the synchronization and mutual exclusion between threads

   the A9 platform controls the ZigBee coordinator downward through the serial port and interacts with the PC web page upward through the network cable, which requires separate threads for processing

   4,zigbee environment acquisition

   environmental acquisition needs to consider the content of acquisition, and then select the corresponding sensor to digitize the environmental information to be collected. This requires knowing the relevant knowledge of MCU development and reading the chip manual; And understand the usage of the sensor and the method of data processing; And master the principle of ZigBee wireless transmission

There may be a lot more to say, but the blogger's knowledge is limited and he can't say it comprehensively. Here is just a summary of my summary and perception from my project to the present I think the most important thing is to participate in the project production more and practice more. Only in this way can we have our own experience in the project production process. Thank you for seeing here

Tags: Linux IoT Single-Chip Microcomputer

Posted by JMair on Thu, 04 Aug 2022 02:10:28 +0930