什么是BlackBox以及它如何使用。

Microcontrollers are ubiquitous in transportation, in industry, in medicine, and in everyday life.

The earliest electronic components "a lot of welding," thanks to the current programming can replace the 'welding era'. Yesterday everything needed welding. Reprogramming today is all right. A simple multivibrator, another buzzer project implemented on a microcontroller, will in many ways be cheaper to assemble than the basic electronics. So I think this trend will be more and more widespread.

Microcontrollers are components of non-complex projects, such as light switches or level sensors, which, once commissioned, eliminate the need for any additional setup. However, most projects also involve interaction with the outside world. For example, thermostats or timers require the ability to manage, adjust, and control setpoints. In most cases, this is done by adding control mechanisms and equipment to the project. So, the easiest item to start over is screen, button, encoder. The components of the microcontroller are already limited resources and spent on the entire infrastructure for user interaction. Therefore, carrying the entire useful functional core, microcontrollers and power keys, takes 5-10% of the physical amount. The rest is a secondary screen and buttons.

This is quite common and almost ubiquitous. Currently working on all these remote controls for TVs, air conditioners, refrigerators, and machines. So many multi-layered menu mazes have been written. And, these built-in mechanical buttons, encoders and screens can all be broken.

In some cases, leaving the rest of the maintenance equipment unusable. At the same time, all of these buttons and screens have a limited capacity of use compared with any of our mobile devices. Comfortable, large contrast, touch screen and "brain".

Some people have dust on the shelves, the old device is quite useful.

In this regard, it is a good thing, or moving to a PC, in a microcontroller project to get rid of the screen, buttons, and move all control and monitoring functions to a mobile device. In my opinion, this will be a more convenient and effective solution for the end user.

Some work has been done in this area. For example, a platform-based model not only shows the weight of a cell phone through Bluetooth, but also tracks its history of change. In any case, the built-in weight indicator still exists.

In my opinion, soon, new patterns emerge for all products. Consumers who buy appliances need to download and install applications from the manufacturer's website to use their features. So why are the benefits so obvious now, but not yet begun to transfer some user interaction from the microcontroller to the mobile device? Because it is difficult to achieve with software.

Because distributed systems are always more complex.

The complexity is not in the principle of communication / transmission, but in the complexity of writing the protocol itself by means of transmission, which has been formalized by UART, I2C, CAN. Some issues: tracking channel failures, requesting retransmissions, scheduling packets, etc. are well-resourced machines that are implemented by the TCP / IP protocol. But there is also a very important part that is to write a communication protocol that is specifically requested for each project. One of the solutions is the automation of the programming process.

For this purpose, as usual, you need to create a language (DSL), formally describe the protocol, and then create a program based on the desired programming language, based on the description of the source code for various target platforms. generate. There are many examples of off-the-shelf solutions.

Protocol Buffers

Cap'n Proto

FlatBuffers

ZCM

MAVLink

Thrift

The extent to which an exchange agreement may be complex may be assessed from the descriptor of the exchange agreement with the helicopter. In this case, XML is viewed as a choice of language protocol description. For microcontrollers, solutions for large machines based on TCP / IP are not suitable due to limited resources. You must use CRC, bit/byte padding, byte order, and take into account the subtleties of this or that are not obvious. Trying to solve the problem by hand writing can transform the programmer's creative life into hell, similar to the confusion supported by Java scripts supported on different browsers. And, on a totally different platform, there are different languages. Even small changes to the debugged protocol can result in lengthy debugging.

Many of the tools listed above have dropped to the microcontroller level in their code generation. Attempts to use the code generation tools described above are hard to apply to older 32-bit families of microcontrollers. The most popular, inexpensive and widely used 8-bit microcontrollers are still on the waitlist. I myself often encounter projects that delegate control to mobile devices. This can sometimes be done, but further support and extension of functionality have become very difficult.

After gaining extensive experience using existing code generation tools and understanding its strengths and weaknesses, I decided to create my own theme park and named it CodeBlackBox.

The code generator itself decided to use SCALA language. The well-known JAVA language as a protocol description of the foundation. Why choose this language? Very simple, JAVA has a lot of handy SDK. Originally enough language structure to describe the type of data transmitted in the packet, there are many additional features, including the very important network topology.

BlackBox generated using the following programming language source code: the JAVA, C #, C
Plan to support SWIFT .

Currently, the code generator BlackBox is built like SaaS. It is necessary to get the generated and tested code:

  • Create a protocol specification. In fact, this is a regular source of java.
  • Here's an example of how to find a demo project on the STM811 via the Bluetooth UART on the STM8S103F3P6 board via the Android flashing LED . When writing a specification, it is necessary to connect to a set of comments in a java project , characterize the data  and follow a small set of rules describing whether the packet, channel, host, communication interface, network topology validation specification was compiled successfully and source The code is sent as an attachment to OneBlackBoxPlease@outlook.com .
  • The server periodically receives the specifications from this box and checks their correctness. Then, generate the source code required by the specification in the required programming language. After that, several tests were created and the source code was run through them. If all the tests are successful, the generated code, the last passed test, and an example using the Ordered API are packaged into an archive and sent to the recipient. In the event of an error, the sender will be notified of possible delays and BlackBox Support Services is handling the difficulties encountered.

Here you can find an example of code generation, example of this code flashing on demo PCB assembled on STM8 in demo control project with android LED mentioned above . With BlackBox, you can not only establish communication between microcontrollers and mobile devices, but also establish communication between ordinary computers. There is no time and effort to waste this is important. In fact, the generated BlackBox code can become the skeleton of a distributed application. The programmer simply adds the handler to the packet's receive event and creates the packet's logic, filling in the data and sending it to the receiver.

See how many projects can benefit by following this new paradigm. Here is an oscilloscope DS212 from Guangzhou. If you move screens and controls to the side of your phone or tablet, you can:

Dramatically Reduced Product Costs All the features of the touch screen greatly improve ergonomics. The oscilloscope itself becomes more compact and can be placed directly at the measurement location, displaying the results in a user-friendly location within 10 meters via Bluetooth. By receiving the measurement data wirelessly, we can use the oscilloscope battery more efficiently, which will be even more economical and therefore we obtain reliable galvanic isolation.

In addition, while creating code for JAVA, I also thought about how to alleviate the problems and disadvantages of the built-in Java enumeration concept . In general, as a solution, Android programmers recommend using IntDef annotations .

Creatively rethinking this issue, I created my own solution -  SlimEnum . In the Java code generation process, it is actively using BlackBox. To facilitate the use of SlimEnum, I wrote a plug-in for IDEA / Android studio that can be installed from the plug-in section of the Intellij repository.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值