Tuesday, May 28, 2019

Embedded Software Architecture

Scope of this document

This document mainly focuses on the importance of Architectural design used in Embedded Project. It shows the significance of Architectural design. It lights on the side effect of bad or no design in the project. This document mainly divided into 2 Parts –
Part I mainly targeted for beginner. This portion is designed to groom the mindset of new entry into embedded field and seeking guidance to understand what & how basic design of Embedded Project done in companies. It also answers about why such designs are needed.
Part II mainly targeted for Intermediate. Since at this level user almost acquaint with most of the basics. But seek guidance in channelizing those skill set for better embedded project design. Pending

Software Designing – Concept & Importance

As in our real world without a design blueprint or a plan we cannot construct infrastructure, R&D projects remain directionless, Governmental organization cannot run economical bodies.

Similarly, Software domain is the one which has multi-applications. It deals with People in their day-to-day life. In today’s world any kind of intelligent machines are just a piece of junk without software.  Hence, software needs to be designed elegantly to make best use of the piece of iron.

Any existing software which challenges designer for following –

  1. Restriction for feature expansion
  2. Maintenance Overhead
Not considered as good quality software.

How it affect industry?? It affect mainly because of followings –

  1. Time to Market will be large
  2. Competitor Overrun
  3. Product stability not guaranteed
  4. Cost of the product

That is the main reason why Software designing concept introduced. It helps designers and hence the stake holder to give futuristic optimizations. It means one can easily be able to identify what are the basic capabilities of the software & the hardware associated with. And hence the timely Scope of product improvement/enhancement can be decided. It provides a pictorial view of whole system. And seeing a pictorial representation is more creative then imaginary analysis.


Every Product when designed, manufacturer main intent is to maintain it for long run. Hence the basic philosophy behind end-to-end design is –

  1. Scalability
  2. Maintenance
  3. Easy-to-Understand

Scalability – Meaning to facilitate extension/contraction. When it comes to Software designing it holds true. One of the attribute of Software design is scalability. Market environment changes very rapidly. Based on market requirement the product needs to add new features time-to-time. And also old/obsolete features need to be eradicated or deactivated. This further entitled portabilitymodularityReusability.

Maintenance – Bug tracing & Bug Fixing
Users are the actual end-tester of the product. So, bug could occur from any corner of the design. Hence, Software design must facilitate bug traceability and then the bug fixing.

Easy-to-Understand – Based on the workload team-size may vary. Based on the commonality among products, different teams in an organization do use same software design. All new members must find the design easy to understand, easy to work on.


Basic Foundation Architectural layer for Embedded Software –


Fig. 1) Basic Architecture Layer
        

Above arrangement is the core hierarchy arrangement of Firmware design. Hardware Layer remains as the bottom act as a source of needful parameter. System Software act as an intermediate layer helps to translate the parameter to a format which allows application to use it. Application Layer is the one which interact with user, allows a command interface to user for communicating with the machine/device. It facilitates basic feature implementation of the product. And also controls underlying layer by configuring and providing appropriate user input.
This is commonly known as Layered Architecture Design. Such designs form the core structure of software in many areas. Automotive Sector, Electrical & Electronic Sector, Lighting Sector etc.



Monday, March 13, 2017

Window Interface for Embedded System - Using Visual Studio GUI

Problem statement
----------------------------------------------------
Have you ever come across a situation where an automated intimation of ongoing process required. Lets not make it vary  chaotic. Lets consider some practical scenario - 
Scenario 1 - You're working on a project and you need to measure the ongoing/past activity anytime & anywhere.

Scenario 2 - End consumer of your product want to get intimation and detail report regarding the ongoing/past operation carried at his/her site anytime & anywhere.

Adding to these two cases, requirement also demand that the system should provide provision for quick analysis of operation in few glance.  




Possible Solution
----------------------------------------------
If I am not wrong, the first thought appear to your mind is to make the system compatible for long distance connectivity and communication using Ethernet as one of the source. 

yes, thats completely correct!!

But, what about the dynamic & static analysis of ongoing/past operation. Off course it may bring some faint idea of log collection or report collection. And made this accessible through Internet. That also somewhat correct!! 

But, now if I say the report or log should be self explainable without intervening much into it.So, what's the next thought.Here also number of option arise -

  1. Draw a graphical plot especially in line chart format which narrate the entire story.
  2. Mark the reading in logged data with special symbol or color to identify any abnormal occurrence.
Aha, both are right approach but option 1) for graphical plot is more intuitive and save a lots of time of analysis. Consider, a case of identifying odd value out from a bunch of 1000 reading of a process. By option 2) of marking & coloring the odd counts, will make it simple but still user intervene to check the nearby value. But, yes using a graphical plot of any type - like line or bar graph makes it speak a lot of things together.    



What this blog going to say ??
--------------------------------------------------------------------------------
Hence, the intention of this blog is to tell about the method of accessing & analyzing any embedded system using suitable target device.The target device can be anything - Mac OS, Linux, Window, Android based device.



 Proposed Solutions
-----------------------------------------------------
Solution is to provide a GUI on all above mentioned devices which should be capable of establishing distance connection and then talk to the embedded device to get the ongoing process data. Finally log the data and also represent the data in graphical format.



How it is practical for small system like Embedded ??
------------------------------------------------------------------------------------------------------------
There is nothing like high end and low end. Once the unit is connected to Ethernet then what high-end unit can deliver, the same can be delivered using an embedded device.It may/may not require any additional h/w support depend on the requirement.

You can refer my previous blog on "Web-interface for Embedded Device" [1], it give very detail idea on Ethernet connectivity.




 How to begin??
-------------------------------
So, the idea is to develop a user interactive GUI which reside in customer machine like PC, Mobile or Tablet. And using this GUI, client/customer can communicate with the target device which is an embedded system.



 What is QT?? What is VB??
-------------------------------------------------------
There are many GUI development tool available. Some of the well known & commonly used tools are QT and Visual Studio. QT is basically used for developing multi-platform applications and GUI that can run on various software and hardware with limited changes. Its a cross-platform application software.Its have very high end usage it supports a huge versatility which includes - Linux, mac/ios, Windows, Embedded - QNX, VXworks and many more. Its full fledge license cost is more then 3500$.

On other hand Visual Studio is also coming up with multi-platform support. Along with its native Window platform, it also facilitate installation on Android, Linux & Mac. It's an IDE which also support GUI development commonly known as "Window form application" or MFC. It support a huge variety of GUI also. And its license cost starts from 30K INR to some lakhs in INR depending on the version. Visual Studio currently doesn't support any GUI development for Embedded Platform [2]. But still its having demand in many application & GUI development.  



And how much time needed for development??
---------------------------------------------------------------------------------
In today's date all these applications are so automated and trailing ample amount of resources on Internet using which one can become a quick learner of GUI development. Also user can start with trial version of these GUI in order to check the comfortability. So, bothering about development time is no more a stringent requirement. But, yes in essence developer need to be familiar with the object oriented concept. Because almost all well known GUI uses C++ as underlying concept. 

I hope till now the rationale of this blog is very much clear to reader. So, before narrating ahead let me make the topic completely clear. In this blog I will be showing you how I am using Visual Studio "Visual basic C++" for GUI development and using this how I am reading an analog data from embedded device and plotting a graph for user analysis.Its a miniature demo of home automation & its live graphical capture.




End Application - IoT & Microsoft Azure
------------------------------------------------------------------------------------------------------------
Yes, its a part of cloud computing used in day-to-day life. It can be considered as an end solution for IoT, where number of sensors feeding the data to client end. And dynamic plotting of values done at client side for analysis. Similarly Microsoft Azure provide remote solution to client/customer. The same methodology can be plugged in to the Azure for remote uses.


Methodology - What exactly I done here ??
-----------------------------------------------------------------------------------------------------------------
Embedded based system is the server end. And visual basic based application running on client end on a windows platform. Both the server & client remain connected to a local LAN. Off course the same is very very apparent in WLAN, it require some paid uses [3]. So, the client application will ping to server system to send the latest data. On receiving the request the Embedded server end will run its .exe program for extracting the current analog value. [Here, basically an analogy of sensor is made by varying the potentiometer, but in practical there might be any real life sensors like temperature, light, pressure etc.] 


So, the current analog data will be collected by a file stream and registered on the file. Once registered, the server side web-service i.e. a node.js based javascript will read and send the content of file to the client side service which is again a javascript for receiving the data from server. Client side web-service will read the data and append it to the repository file from where the Visual basic based application will fetch the data and plot the analysis graph.


On Window Platform end -
Here it contains the Visual c++ based Window form application (WFA) which provide the GUI part. Along with this there is a javascript running on the background which frequently make connection with the server end at an periodic interval of approximately 1.8sec. Fetch the data from server and log the data in appending form to the client file. The GUI which is an Visual basic based application checks continuously if the file is ideal or not. If the GUI find its ideal, then it read the latest value from the file and extrapolate the value on a line graph in X-Y format.

On Embedded Side -
Ideally speaking, it can be any embedded based device which is having capability of running Ethernet stack and capable of doing HTTP based interaction. So, here I had used a Beagle bone Black, a Linux based Embedded System. On this, a javascript which form the server runs and listen for any incoming connection. Once a connection is identified, then the immediate next task is to run the .exe application which is responsible for measuring the analog parameter and log the value on to the file system. Further the server script will read this file and pass the same data to the web-client, who has requested for the service. 




You can refer the architectural block diagram shown below for better understanding -





Point of Interest
---------------------------------------
So, I guess with this much description one point strike the mind of most of the user & enthusiast is "how to build a GUI using Visual Basics.

The solution is pretty simple. I recommend viewing the tutorial available on You Tube, visual studio has a rich source of graphical widgets, so its not possible to expect You Tube to cover each & every widget usage in detail. But, yes it covers all basic concept right from installation of visual studio to uses of common widgets for application development. Also the msdn site [4] (i.e. Microsoft Native site) has all detail content right from methods & class related to all widgets provided by visual studio. Also it shows a bunch of code snippet in VB, .net & c++ which helps user to understand application development using Visual Studio. Also once the developer done with the GUI and tested all its functionality, then he can publish the .exe of this application and easily transfer to the customer via any media or online source.

From the technical point - Its a c++ based framework. So, at some point down the line the GUI developer has to link itself to the coding part and need to interact with C++ domain. Still C as a active logic can be used, but beauty will comes from the use of object oriented concept. e.g. In the GUI, if the requirement is to fetch a data from a file on a button press. Then with C++ advance concept like file class or stream class things can be directly used which minimize the developer handling effort. But, same time with generic c concept the developer has to handle in the code. Also as we know C++ has many advantage & some disadvantages. Disadvantage tells about the memory footprint, but it really doesn't matter for GUI end. Since, many time the intended app is developed on a target system which has quite a good memory as compared to the embedded counterpart. So, its really very much practical to develop a complete interactive and user friendly GUI on system like Windows, MACoS, Android & Linux.




Video Description Explanation
-------------------------------------------------------------------------
As mentioned earlier. Here, I had used a Beagle bone which form the web server. Apart from this the extra h/w used are - 2 2.5mm LED's, One 1k Potentiometer, connecting wire and a breadboard.

The Red LED is used for PWM dimming. Based on the potentiometer setting the dimming done. So, it will give clear indication to user that the analog section is varying the value. Also depending on the intensity the viewer can also realize the changes done on potentiometer variation.

The Blue LED is a pulsing LED. Although it appear to pulsate at an interval of 1.8 sec and so. But this period is not fixed. It depends on client side. When connection is established it become ON and when client disconnect it OFF. Since at the client system the process is carried synchronously, hence the Blue LED blink gives a feel of periodic event. i.e. pulsing. 

The Potentiometer it use to control an analog voltage of 3.3V and feed output to AIN6 i.e. 6th channel of ADC in Beagle bone. Its a 1K pot which can vary the output from 3mV to 3V. Depending on these value the ADC counts will be calculated. Here, the ADC used is a 12-bit resolution based ADC. Furthur the code is programmed for taking this count and manage a 50% duty cycle PWM and accordingly manage the brightness intensity of Red LED.

Apart from this a console based controlling can be done for beagle bone which will be part of server side. Usually it needed for initiating the server side process only. But additionally the current analog value also thrown on the console window, it may be used for debugging purpose. But having no role in overall application.

Finally coming to the Windows App. On Visual Basics. Its basically has 2 operational button - StartScan & StopScan. Rest all are the non-operational part which is not intended for the use of demo perspective. Apart from this there are - 1 TextBox & 1 Chart. Textbox is for representing data in digital format. And chart will represent data in analog form i.e. line chart. Textbox will only show the starting 25 readings not more then that, as logic for that has not developed for demo version. Also the chart will read a max of 100 readings and then it will roll over from 1st reading. After completion of 100 data, the log will automatically initiate. Large graphical representation is not the intention of this demo. But yes, it can be increased to tens of thousands.


Once, the user hit the startscan button the process of reading start, which also additionally pop-up two window console in order to give better idea about ongoing process [5]. These consoles are solely for developer & debug purpose, hence it can be eliminated from actual application when handover to the customer. On hitting StopScan the running process stops. And the textbox & Chart area get cleaned. Also StopScan will automatically facilitate the logging of current data. 

Log as shown in demo is having a specific format which clearly tell the data & time stamp in its name. Easy for user to identify when the log has been taken. The actual application also has facility to upload this log and view the same in graphical form. Also alert the user for any abnormality by sending mail. For user information - Visual studio also supports SMTP using which window application also capable of sending mail to configured user.



 


Possible Extension
---------------------------------------------
Its basically a concept. Its up to user to decide its possible usage. Since it involves 3 major activities - Connectivity, Current/Previous data fetching & extrapolating, And logging as well. So, it can be part of numerous application. The one for which this application is built is basically for dynamic update & image identification. Rest details led to proprietary act.



References 
---------------------------

  1. Web Interface - Step by Step Process
  2. Visual Studio ToolChain
  3. https://yaler.net/
  4. MSDN Documentation & Tutorial
  5. Console Application 

Monday, November 21, 2016

Generic Web-Interface steps for Embedded Devices







In today's world any equipment is considered as fully automatized, if and only if it can be accessed from anywhere??

What anywhere means??
anywhere means ???[anywhere]
Thats funny ha ha ha..... Anywhere refer to any corner of world.

How it happen??
Its all about the interface we are providing from embedded device to real world. And that interface must support long distance accessibility. So, possibilities are -
1) UART - Not a long distance
2) Bluetooth - Not a long distance
3) GPRS/GSM - Yes, it does
4) Internet - Yes, it does.

So, the preferable is 3) & 4). But 4 is dominating over 3, as of terrain & network accessibility issue. So, here the discussion is all about "Accessibility of Embedded Hardware over internet".

What is needed for implementing this -
* The designer need to familiar with HTML, Javascript/php/python/cgi & many more, If Javascript
then get acquaint with node.js/jquery/Angular JS/AJax. These are some library & framework, All
this needed for web server development.
* The designer need to fully familiar with Embedded environment - OS used in MCU like Linux,
Windows, Android or Embedded RTOS which should support HTTP protocol &
TCP/IP protocol in the library.
* The method of accessing the h/w of embedded controller using C/C++ or any other relevant
language.
* Router with port forwarding functionality or use Yaler.net (accessibility of device from web it take
care of firewall restriction of router).


So, lets start our discussion only for web server design for Embedded System using HTML & Javascript. However, Javascript is starting choice for beginner, as you grow experienced in embedded its quite difficult to stick to Javascript as embedded system need to be dependable & predictable. But there is no way to guarantee correct timing and response times with code that runs on an interpreter. And also memory management is big constraint with embedded system. So, for more complex or professional development you may need to switch on to some other option.



Javascript can use the power of the web browser to create an experience that the device itself could never produce. To be able serve anything, at least two conditions must be met:
1) System will need to have some sort of network connection
2) System must able to accept and respond to HTTP requests over the network connection, The HTTP request can, of course, be proximate by some other system.




Starting on an Embedded System -
Lets consider we have a “xyz” microcontroller based board. And an LED is connected to port 2.19 of the controller. We have a generic program written in c/c++ to control led on/off condition named as led_blinky.c/led_blinky.cpp. Lets consider below scenario -
  1. We'hv a linux based OS on our controller where everything is considered as file. So, in this case our program led_blinky is converted into an executable lets using command $(CC) "led_blink.c/.cpp" -o "led_blinky_executable" [Where CC is the cross compiler may be gcc or g++]. Lets keep this executable in a specific file loction say "/home/program/". For running this use command prompt and cd to this location then turn on LED by executing "./led_blinky_executable 1" & for turning off execute "./led_blinky_executable 0".
  2. We have a plane embedded system with RTOS. Here static web page can be created using HTML and served to client on request. And a dynamic web page need to be created using CGI (Comon gateway interface) script using C or C++. Refer Tutorialspoint. The entire process here has to include - checking request from client, doing operation as per the request and all this has to embedded together and keep on running unlike linux, which run on demand.

Types of Web Pages used -
  1. "A static page" is the page developed using HTML. This serve the role of crating all kind of graphical interface. It might be in the form of button, checkbox, radiobutton, text area, scroll bar, graph, window etc.
  2. "A Dynamic page" is the page actually it is known as a script. This is known as script since it is designed to run on special run-time environment and it automate multiple steps, like taking input from web page widget (These inputs known as forms in HTML) and perform particular action related to hardware. So, this dynamic page is the most important in dealing with embedded hardware. For scenario1 builting dynamic page is bit easier task, we simply have to include some javascript library like node.js/jquery/Angular JS/AJax. But for scenario2 we need to develop a CGI script in c/c++/python (python is not best choice for embedded RTOS) as it needed for handling GET & POST methods.



So, our furthur discussion is on Javascript and its library implementation for embedded hardware interface. Lets consider an use-case of controlling LED connected to one of the IO pin. Below are the step wise explanation -
  1. Create a static web page. It is fairly simpler job using HTML & Javascript. Refer some artical mentioned below and you will through.
    <html>
    <head>
    <title>My LED Blinker Site</title>
    <script language="javascript" src="..." type="text/javascript">
    ----
    </script>
    </head>
    <body>
    <!--------Radio Button Control----------->
    <!------Created by <input> tag----------->
    <form>
    <input type="radio" name="led_control" value="led_On"> led_On
    <input type="radio" name="led_control" value="led_Off"> led_Off
    </form>
    </body>
    </html>

  1. Create a scripting page.
    *Prerequisite - Make sure that npm, nodejs, socket.io, some web server like apache should
    be installed in your system.
    1. To control the LED with Javascript, we will need to use a librarry built for Node.js called "socket.io". This can be checked using "npm info socket.io version". Refer Tutorialspoint socket.io tutorial for detail using of socket.io. This simply creates socket for listening communication from web-browser.
    2. Then one need to include express framework which is used for handling get & post methods needed for communication between Server and host.
    3. Then create Server.js script which can emit & handle events from web browser to web server and vice-versa.



















Code & Script -











Working -





















References -

  1. Tutorialspoint best site for all integrated information of all programming language.