Monday, July 13, 2020

Python List and Dictionary

Python List Tuples and Dictionary

Lists are what they seem - a list of values. Each one of them is numbered, starting from zero - the first one is numbered zero, the second 1, the third 2, etc. You can remove values from the list, and add new values to the end. Example: Your many cats' names.

Tuples are just like lists, but you can't change their values. The values that you give it first up, are the values that you are stuck with for the rest of the program. Again, each value is numbered starting from zero, for easy reference. Example: the names of the months of the year.

Dictionaries are similar to what their name suggests - a dictionary. In a dictionary, you have an 'index' of words, and for each of them a definition. In python, the word is called a 'key', and the definition a 'value'. The values in a dictionary aren't numbered - they are similar to what their name suggests - a dictionary. In a dictionary, you have an 'index' of words, and for each of them a definition. In python, the word is called a 'key', and the definition a 'value'. The values in a dictionary aren't numbered - they aren't in any specific order, either - the key does the same thing. You can add, remove, and modify the values in dictionaries. Example: telephone book.

Monday, June 29, 2020

Linux File System

A file system is a process that manages how and where data on a storage disk is stored, accessed and managed.

In a UNIX/Linux type OS, "Everything is a file", which means that everything in the computer system from processes, files, directories, sockets, pipes, ... is represented by a file descriptor abstracted over the virtual file-system layer in the kernel. The virtual file system is an interface provided by the kernel. Hence the more accurate phrase is "Everything is a file descriptor", or to make it even more accurate, Linus Torvalds himself corrected it again as :"Everything is a stream of bytes".

Linux main directories list:

/(root file system)
The root file system is the top level directory of the file system. It must contain all of the files required to boot the Linux system before other file systems are mounted. It must include all of the required executables and libraries required to boot the remaining file systems. After the system is booted, all other file system are mounted on standard, well-defined mount points as sub-directories of the root file system.

/bin
Contains User executable files.

/boot
Contains the static boot loader and kernel executable and configuration files required to boot a Linux computer.

/dev
This abstract directory contains the device files for every hardware device attached to the system. These are not device drivers, rather they are files that represent each device on the computer and facilitate access to those devices.

/proc
Another abstracted directory which is created when the system boots. Contains information about the processed on your system.

/etc
Contains the local system configuration files for the host computer.

/home
Home directory storage for user files. Each user has a sub-directory in /home.

/lib
Contains shared library files that are required to boot the system.

/media
A place to mount external removable media devices such as USB thumb drives that may be connected to the host.

/mnt
A temporary mount point for regular file systems (as in not removable media) that can be used while the administrator is repairing or working on a file system.

/opt
Optional files such as vendor supplied application programs should be located here.

/root
This is not the root (/) file system. It is the home directory for the root user.

/sbin
System binary files. These are executables used for system administration.

/tmp
Temporary directory. Used by the operating system and many programs to store temporary files., Users may also store files here temporarily. Not that files stored here may be deleted at any time without prior notice.

/usr
These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.

/var
Variable data files are stored here. This can include things like log files, MySQL, and other database files, web server data files, email inboxes, and much more.


Sunday, June 28, 2020

C++ concepts

Vector




Vectors are sequence containers representing arrays that can change in size. Vectors in C++ are preferable when managing ever-changing data elements.

Example: 
vector PersonalId (1000);

Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.

Internally, vectors use a dynamically allocated array to store their elements. This array may need to be reallocated in order to grow in size when new elements are inserted, which implies allocating a new array and moving all elements to it. This is a relatively expensive task in terms of processing time, and thus, vectors do not reallocate each time an element is added to the container.

Instead, vector containers may allocate some extra storage to accommodate for possible growth, and thus the container may have an actual capacity greater than the storage strictly needed to contain its elements (i.e., its size). Libraries can implement different strategies for growth to balance between memory usage and reallocations, but in any case, reallocations should only happen at logarithmically growing intervals of size so that the insertion of individual elements at the end of the vector can be provided with amortized constant time complexity (see push_back).

Therefore, compared to arrays, vectors consume more memory in exchange for the ability to manage storage and grow dynamically in an efficient way.

Compared to the other dynamic sequence containers (dequeslists and forward_lists), vectors are very efficient accessing its elements (just like arrays) and relatively efficient adding or removing elements from its end. For operations that involve inserting or removing elements at positions other than the end, they perform worse than the others, and have less consistent iterators and references than lists and forward_lists.


Virtual

A virtual function is a member function in the base class that you expect to redefine in derived classes.

The goal of object-oriented programming is to divide a complex problem into small sets. This helps understand and work with problem in an efficient way. Sometimes, it's desirable to use inheritance just for the case of better visualization of the problem. In C++, you can create an abstract class that cannot be instantiated (you cannot create object of that class). However, you can derive a class from it and instantiate object of the derived class. Abstract classes are the base class which cannot be instantiated.

A virtual function whose declaration ends with =0 is called a pure virtual function.
Any C++ class with at least one pure virtual function is considered to be an abstract class.

Function Template

Function templates are functions that serve as a pattern for creating other similar functions. The basic idea behind function templates is to create a function without having to specify the exact type(s) of some or all of the variables. Instead, we define the function using placeholder types, called template type parameters. Once we have created a function using these placeholder types, we have effectively created a “function stencil”.

When you call a template function, the compiler “stencils” out a copy of the template, replacing the placeholder types with the actual variable types from the parameters in your function call! Using this methodology, the compiler can create multiple “flavors” of a function from one template! 

Example:

template
T add(T num1, T num2)
{
   return (num1 + num2);
}

int main() {

    int result1;
    double result2;
    // calling with int parameters
    result1 = add(2, 3);
    cout << result1 << endl;

    // calling with double parameters
    result2 = add(2.2, 3.3);
    cout << result2 << endl;

    return 0;
}    





Sunday, June 21, 2020

Why Real Time Embedded Linux ?


Why Real Time Embedded Linux ?

You might hear of embedded Linux for real time very often. It sounds the entire embedded world depends on this. The question really contains 3 important concepts, we can break this question into 3 sub-questions based on these 3 concepts.

Why Linux ?

This is a generic question, easy for public to understand. Linux is Open source, less legal issues, popular, easier to get support, APIs and expertise. etc.

Why Embedded (vs Desktop Linux) ?

A bit more technical.

1. Embedded Linux system usually requires great reliability. Desktop Linux may have >100M code installed, with a lot of un-necessary features. Embedded Linux typically have 1M foot print, with only required feature installed.

2. Resource constraint. Embedded Linux has no HDD, and its non-volatile storage is life constraint. This coupled with the reliability and power safe requirement, a large portion of embedded linux system is actually read only.

Why Real Time ?

A common mis-understanding about Real Time is that Real Time means Fast, actually Real Time means deterministic. In other words, to complete a task within a specified time, otherwise will lead to an error condition. For example, a dish washer need to stop water filling in Read Time fashion, but screen display update may not be real time.

We classify a task either deterministic or in-deterministic, so the concept of soft Real Time should be obsolete.

Linux is not intrinsically deterministic, there are processed can run to completion. Hence, we need some other modification to make Embedded Linux real-time, mainly two ways, use a RealTime kernal and make regular Linux as a process. or use Preempt_RT, break down Linux locked processes, and put main ISR routine to a task, only left signaling inside ISR, like FreeRTOS. In practical, we can control the worst case latency to be less than 100 micro-seconds, good enough for Real-Time applications.

ARM in a nutshell.

What is ARM ?

ARM is an Advanced RISC Machine,. 

It is a RISC not CISC processor.  It is basically a LOAD-STORE architecture, where data processing operations are only between registers and does not involve any memory operations. 

It is a 32 bit processor and also has variants of 16 bit and 8 bit architecture, so a word is 32 bits, not 16 bits.

It got auto-increment and auto decremented addressing modes to optimize program loops, which is not very common with RISC processors.

It has a very good speed vs power consumption ratio which makes it suitable for embedded system.

It has 3 stages pipe-line: Fetch, Decode and Execute. 

7 sounds a lucky number for ARM: 

It has 7 operating modes:  Supervisor mode;  User Mode, System Mode, Fast Interrupt Mode, Interrupt Mode, Undefined mode and abort Mode. 

It has 7 interrupts/exceptions, Reset, Undefined, Pre-fetch abort, data abort, software interrupt, FIQ and IRQ, make ARM enter 5 modes, User Mode and System Mode do not need interrupt to enter,

It has 7 addressing modes: immediate mode, index mode, indirect mode, absolute (Direct) mode register mode, displacement mode and Auto-increment/Auto'decrement mode. 
 







Tuesday, December 1, 2009

The most important factor to make a software project success

We often talk about resource, budget, timing, quality when talking about project management. I treat project scope management as the most important factor among all the project management factors, more important than factors like schedule, cost, budget, …Since I saw too many times what project team delivered is not what customer wants.

 

Project scope management is essentially acting as the bridge between the project team and outside world, especially customer. The project manager has the responsibility to make sure the project team is doing something expected by business team, or customer. No budget, resource wasted on activities not align with customer request. There are maybe some project sponsored by internal authorities, but still there should be scope statement from the internal authority.

 

The project manager has the responsibility to communicate/control the sub-module scope among the project team.  There are 3 good practices for doing this:

  1. Document the scope in structured, better itemized statement list;
  2. Organize all stake holders to present the scope in understandable chart;
  3. Publish the scope statements and charts to a place easily accessible and editable by relevant stakeholders.

In summary, project manager should ensure project team members are working towards the correct scope at any project stage. I think anyone has experience on software development team with more than 3 software Engineers knows the difficulty to actually achieve this goal.

Sunday, November 15, 2009

Project Charter Example

I always wonder how to specify project charter clearly and efficiently (no excessive document), until I see the example below.

1. Project Title and Description

What is the project?

Customer Satisfaction Fix-It Project: Over the last few months the quality assurance department has discovered many of our customers' orders for our ABC equipment have taken the customer ten times longer to place through our computer network than our competitors' networks. The purpose of this project is to investigate the reasons for the problem and propose a solution. The solution will be authorized as a subsequent project. Quality Control has detailed records of their findings that can be used to speed up this project.

2. Project Manager Assigned and Authority Level

Who is given authority to lead the project, and can he/she determine, manage and approve changes to budget, schedule, staffing, etc.?


Alexis Sherman shall be the project manager for this project and have authority to select team members and determine the final project budget.

3. Business Need

Why is the project being done?

This project is being completed in order to prevent a further breakdown of customer satisfaction.

4. Project Justification

Business case-On what financial or other basis can we justify doing this project?


We expect that improved customer satisfaction will increase revenue to the company in the first year by at least $200,000 due to a decrease in service calls. As a side benefit, we hope that the project will generate ideas on improving customer
satisfaction while fixing this problem.

5. Resource Pre-assigned

How many or what resources will be provided?

Morgan and Danny are already dedicated to the project because of their expertise in computer networks of this type. Other resources will be determined by the project manager.

6. Stake-Holders

Who will affect, or be affected by the project (influence the project), as known to date?

Stakeholders include Connor representing Quality Control, Ruth in Customer Service and Mary in Marketing. These resources are available to assist the project as needed by the project manager.

7. Stake-holder Requirements as Known

Requirements related to both project and product scope.

Attached to this document are the detailed specifications for the existing system, the requirements that the existing system was designed to meet. It is expected that this project will not change how the system affects the existing requirements. The project must include utilizing the data available from quality control.

5. Product Description/Deliverables

What specific product deliverables are wanted and what will be the end result of the project.

  1. A report that outlines what can be changed, how much each change will cost and expected decrease in the time it takes to place and order resulting from each change. Few words are necessary in the report, but it must be created electronically and be agreed to by the heads of quality control, customer service and marketing in addition to the project team.
  2. A list of the interactions with our customers necessary to complete the changes. A work breakdown structure, due within two weeks, that outlines the plan for accomplishing the project, followed one week later by a list of risks in completing the project.
6. Constraints and Assumptions

A constraint is any limiting factor and an assumption is something taken to be true, but which may not be true.

Complete the project no later than <date>. Spend no more than <certain amount money>. We have assumed that Kerry will be available to assist the project and that testing can be done on the seller’s computer.

Project Sponsor Approval:

<Signature>