Embedded and satellite navigation and positioning host computer software development (based on MFC framework)

Embedded and satellite navigation and positioning host computer software development (based on MFC framework)

The professional course requires real-time single-point positioning program calculation on the SEED-DEC6713 development board, and the results are encoded in a custom format and output sequentially through the serial port.

Then, develop a PC host software similar to the serial port assistant, which is used to receive the navigation and positioning results output by the development board from the serial port, and complete the data decoding and positioning result display interface.

To be honest, my knowledge of embedded systems is really messed up, and I started interface development almost from scratch. It took me several weeks to write the PC software, and I encountered countless pitfalls, so I will summarize it here.


The final rendering is as follows:

Insert image description here

Insert image description here


Regarding the development of the host computer software, I downloaded a serial port debugging assistant written by others, modified it on this basis, realized the decoding of binary navigation and positioning results, and then developed a real-time dynamic drawing interface.

In general, under the MFC interface development framework, the MSComm control is used to complete serial port communication programming, and real-time drawing operations are realized based on the ChartCtrl source code library.

Download link: Serial port debugging assistant source code (MFC+SComm)


1 Serial communication - MSComm control

The serial communication programming ActiveX control provided by the VS2017 development platform - MSComm
(Microsoft Communications Control) is used to complete the data transmission and data reception of the serial port.

Like interrupts, the MSComm control handles serial port interactions through event-driven communication.

When there are characters in the serial port receiving buffer or the character length reaches the set threshold limit, you can use the OnComm event of the MSComm control to capture and process these communication events.


2 Data drawing——ChartCtrl

The ChartCtrl library is a C++-based MFC extended control that can be used for interface chart drawing.

The basic property functions of the ChartCtrl library include: drawing line charts and bar charts, setting coordinate axes, titles, legends, labels, setting axes background color, grid, line type, etc.

Insert image description here

Initialize the drawing interface through the ChartCtrlInit() function, set the coordinate axis value range, etc.

As shown below, taking the X coordinate result change chart as an example, the interface is initialized to set the title "X coordinate" and the drawing background color RGB (255, 255, 255), which is white; the SetAutomatic mode is used for the coordinate axis XY, which is automatically set according to the calculated value. Coordinate scale range.

m_chartctrl.EnableRefresh(true);
m_chartctrlX.GetTitle()->AddString(_T("X 坐标"));//设置标题
m_chartctrlX.SetBackColor(RGB(255, 255, 255));//设置背景色

//设置 XY 坐标轴
pAxis = m_chartctrlX.CreateStandardAxis(CChartCtrl::BottomAxis);
pAxis->SetAutomatic(true);
pAxis = m_chartctrlX.CreateStandardAxis(CChartCtrl::LeftAxis);
pAxis->SetAutomatic(true);

Line chart drawing is implemented through the DataShow () function. The code is as follows: the input arrays xb and yb are the horizontal and vertical coordinate data, and len corresponds to the number of drawing points.

void DataShow(double *xb, double *yb, int len, CChartCtrl* m_chartctrl) {
    
    
	m_chartctrl->EnableRefresh(false);
	CChartLineSerie *pLineSerie;
	m_chartctrl->RemoveAllSeries();
	pLineSerie = m_chartctrl->CreateLineSerie();
	pLineSerie->SetSeriesOrdering(poNoOrdering);//设置为无序
	pLineSerie->AddPoints(xb, yb, len);
	pLineSerie->SetWidth(3);
	UpdateWindow();
	m_chartctrl->EnableRefresh(true);
}

3 Summary

Generally speaking, the workload of developing this PC software is quite large. I wrote it by myself for maybe three weeks? Mainly Thai dishes, almost all made from scratch.

At first, I tried a lot of existing serial port debugging assistant codes. Some versions were too old and incompatible with the VS environment. Some functions were too simple... I suggest you learn more about C# or Qt in the future. The development interface is still easy to use. some.

Regarding serial port communication operations, I tried to use the MSComm control, CSerialPort serial port class, and Windows API to perform serial port operations. The latter two were really unclear, so I finally used the MSComm control. The triggering mechanism is similar to an interrupt and is easier to understand.

Regarding chart drawing operations, there are many libraries available, such as ChartCtrl, TeeChart, Mschart, etc. There are actually relatively few tutorials on ChartCtrl, but I didn’t understand the latter two. Fortunately, I finished it after two weeks of hard work.

At present, the PC software I wrote still has many problems:

  1. The original serial port debugging assistant cannot automatically identify the port number. I went to the computer room to connect the development board to test. Once the port number is not among the options, there is nothing I can do. I can only change the code manually;
  2. Positioning result output and drawing cannot be guaranteed to be completely synchronized. The positioning result obtained by the drawing interface is continuously refreshed at fixed intervals through a timer, and new data is drawn when new data is available. I have no idea how to achieve synchronization;
  3. How to solve the problem of legend position in ChartCtrl drawing? I found some code that uses GetLegend()->UndockLegend(). The strange thing is that nothing happens when I use this function.
  4. Regarding the problem of how to dynamically display GPS week seconds on the abscissa, it was not solved in the end.

Reference blog:

  1. VS2010 dialog-based MFC serial communication concise routine
  2. MFC-based serial port assistant
  3. VC++ MFC uses ChartCtrl to quickly realize waveform display
  4. C++ Part 44 – MFC uses ChartCtrl to draw dynamic curves
  5. MFC uses ChartCtrl to draw curves
  6. Data transfer between two dialog boxes in MFC
  7. The definition and use of global variables in MFC

Guess you like

Origin blog.csdn.net/slender_1031/article/details/109787305