Friday, 23 March 2018

OpenCV Helloworld Trouble


Just want to quickly do an openCV helloworld:

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
Mat srcImage = imread("lena.jpg");
imshow("image",srcImage);

waitKey(0);

return 0;
}

Compile:
g++ `pkg-config opencv --cflags` opencv.cpp -o opencv `pkg-config opencv --libs` 

but I got this error:
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /home/boris/Softwares/openCV/opencv/modules/highgui/src/window.cpp, line 611 terminate called after throwing an instance of 'cv::Exception' what(): /home/boris/Softwares/openCV/opencv/modules/highgui/src/window.cpp:611: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage

Something is wrong with QT?

sudo apt-get install libqt4-dev
cmake -D WITH_QT=ON ..
make
sudo make install

ref:
https://stackoverflow.com/questions/14655969/opencv-error-the-function-is-not-implemented
https://blog.csdn.net/keith_bb/article/details/52864851




Thursday, 22 March 2018

Just Installed openCV


Error:
./opencv: error while loading shared libraries: libopencv_highgui.so.3.3: cannot open shared object file: No such file or directory

$ sudo ldconfig


ref:
https://github.com/pjreddie/darknet/issues/382

Install openCV on Ubuntu 16.04

I was installing openCV following the instruction from the first google search:
          https://www.learnopencv.com/install-opencv3-on-ubuntu/

But I met the following problems so far.

sudo apt-get install git gfortran

error:
The following packages have unmet dependencies:
 gfortran : Depends: gfortran-5 (>= 5.3.1-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

solution:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gfortran-5
Now do it again and it works.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install libjpeg8-dev libjasper-dev libpng12-dev

error:
The following packages have unmet dependencies:
 libjasper-dev : Depends: libjasper1 (= 1.900.1-debian1-2.4ubuntu1) but 1.900.1-debian1-2.4ubuntu1.1 is to be installed
E: Unable to correct problems, you have held broken packages.

solution:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

Now do it again and it works.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) 
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Solution:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

~$ sudo dpkg --configure -a

Do it again and worked:
~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

~$ sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

error:
The following packages have unmet dependencies:
 libgstreamer-plugins-base0.10-dev : Depends: libglib2.0-dev but it is not going to be installed
 libgstreamer0.10-dev : Depends: libglib2.0-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Solution:
Install the dependency libglib2.0-dev:
sudo apt-get install libglib2.0-dev libglib2.0-0=2.48.0-1ubuntu4

Do it again and worked:
~$ sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev
I jumped over qt5-default, too many dependencies...so just:
~$ sudo apt-get install libgtk2.0-dev libtbb-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install python-dev python-pip python3-dev python3-pip

errors:
The following packages have unmet dependencies:
 python3-pip : Depends: python-pip-whl (= 8.1.1-2) but 8.1.1-2ubuntu0.4 is to be installed
               Recommends: python3-setuptools but it is not going to be installed
               Recommends: python3-wheel but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

solution:
Don't know yet...I jumped over python3-pip for now.

/////////////////////////////////////////////////////////////////////////////////////////////////////

OK finally cmake...but I got errors. After trying a lot to install some dependencies like qt5, I still couldn't get rid of the errors. I found the official website has a tutorial about installation:
            
                https://docs.opencv.org/trunk/d2/de6/tutorial_py_setup_in_ubuntu.html

Note that you have to delete ./build directory and create a new folder and do:
$ cmake ../

...and it worked!
..............
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
 ...................


ref:
https://www.learnopencv.com/install-opencv3-on-ubuntu/
https://askubuntu.com/questions/720948/problems-installing-gfortran
https://github.com/opencv/opencv/issues/8622
https://askubuntu.com/questions/15433/unable-to-lock-the-administration-directory-var-lib-dpkg-is-another-process
https://askubuntu.com/questions/884413/unable-to-install-libgtk2-0-dev-on-ubuntu-16-04/886022

https://docs.opencv.org/trunk/d2/de6/tutorial_py_setup_in_ubuntu.html
https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

Tuesday, 20 March 2018

Problem with Spotify Keys


Problem:

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repository.spotify.com stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EFDC8610341D9410
W: Failed to fetch http://repository.spotify.com/dists/stable/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EFDC8610341D9410
W: Some index files failed to download. They have been ignored, or old ones used instead.

####################################################################3


This happen when somehow we'd lost the keys.
To solve i have executed the first step listed here https://www.spotify.com/de/download/linux/

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0DF731E45CE24F27EEEB1450EFDC8610341D9410


ref:
https://superuser.com/questions/932781/failed-to-fetch-spotify-repository-while-updating-ubuntu

Tuesday, 13 March 2018

Tinkering OpenWRT (5) : Build OpenWRT Source Code

Step 1: Inslall softwares
sudo apt-get install subversion g++ zlib1g-dev build-essential git python rsync man-db 
sudo apt-get install libncurses5-dev gawk gettext unzip file libssl-dev wget

Step 2: download source
git clone https://git.lede-project.org/source.git lede 
cd lede 

Step 3:
./scripts/feeds update -a 
./scripts/feeds install -a 

Step 4:
make menuconfig # Maximum the terminal when doing this.
More research needs to be done here to fit different systems. Here we compile for VirtualBox as an example.
      “Target System” ⇒ “x86”
      “Target Images” ⇒ “Build VirtualBox image files(VDI)”
Save and Exit.

Step 5: Compile
make
 make[1] world
 make[2] tools/compile
 make[3] -C tools/flock compile
 make[3] -C tools/sed compile
 make[3] -C tools/patch compile
 make[3] -C tools/xz compile
 make[3] -C tools/tar compile
 make[3] -C tools/m4 compile
 make[3] -C tools/autoconf compile
 make[3] -C tools/pkg-config compile
 make[3] -C tools/automake compile
 make[3] -C tools/missing-macros compile
 make[3] -C tools/libtool compile
 make[3] -C tools/gmp compile
 make[3] -C tools/mpfr compile
 make[3] -C tools/mpc compile
 make[3] -C tools/libelf compile
 make[3] -C tools/expat compile
 make[3] -C tools/flex compile
 make[3] -C tools/bison compile
 make[3] -C tools/mklibs compile
 make[3] -C tools/sstrip compile
 make[3] -C tools/make-ext4fs compile
 make[3] -C tools/e2fsprogs compile
 make[3] -C tools/mtd-utils compile
 make[3] -C tools/libressl compile
 make[3] -C tools/mkimage compile
 make[3] -C tools/firmware-utils compile
 make[3] -C tools/patch-image compile
 make[3] -C tools/findutils compile
 make[3] -C tools/quilt compile
 make[3] -C tools/padjffs2 compile
 make[3] -C tools/mm-macros compile
 make[3] -C tools/cmake compile
 make[3] -C tools/scons compile
 make[3] -C tools/bc compile
 make[3] -C tools/gengetopt compile
 make[3] -C tools/patchelf compile
 make[3] -C tools/mtools compile
 make[3] -C tools/dosfstools compile
 make[3] -C tools/qemu compile
 make[3] -C tools/lzma compile
 make[3] -C tools/squashfs4 compile
 make[2] toolchain/compile
 make[3] -C toolchain/gdb compile
 make[3] -C toolchain/binutils compile
 make[3] -C toolchain/gcc/initial compile
 make[3] -C toolchain/kernel-headers compile
 make[3] -C toolchain/musl compile
 make[3] -C toolchain/gcc/final compile
 make[3] -C toolchain/fortify-headers compile
 make[3] -C toolchain/yasm compile
 make[2] target/compile
 make[3] -C target/linux compile
 make[2] diffconfig
 make[2] package/cleanup
 make[2] package/compile
 make[3] -C package/libs/libubox host-compile
 make[3] -C package/system/opkg host-compile
 make[3] -C package/libs/toolchain compile
 make[3] -C package/libs/libnl-tiny compile
 make[3] -C package/libs/libjson-c compile
 make[3] -C package/utils/lua compile
 make[3] -C package/libs/libubox compile
 make[3] -C package/system/ubus compile
 make[3] -C package/system/uci compile
 make[3] -C package/network/config/netifd compile
 make[3] -C package/firmware/linux-firmware compile
 make[3] -C package/firmware/prism54-firmware compile
 make[3] -C package/kernel/linux compile
 make[3] -C package/system/ubox compile
 make[3] -C package/libs/ncurses host-compile
 make[3] -C package/libs/zlib compile
 make[3] -C package/libs/ncurses compile
 make[3] -C package/utils/util-linux compile
 make[3] -C package/system/fstools compile
 make[3] -C package/system/fwtool host-compile
 make[3] -C package/system/fwtool compile
 make[3] -C package/system/procd compile
 make[3] -C package/system/usign host-compile
 make[3] -C package/utils/jsonfilter compile
 make[3] -C package/system/lede-keyring compile
 make[3] -C package/system/usign compile
 make[3] -C package/base-files compile
 make[3] -C package/boot/grub2 host-compile
 make[3] -C package/boot/grub2 compile
 make[3] -C package/kernel/button-hotplug compile
 make[3] -C package/libs/mbedtls compile
 make[3] -C package/libs/ustream-ssl compile
 make[3] -C package/libs/uclient compile
 make[3] -C package/network/utils/iptables compile
 make[3] -C package/network/config/firewall compile
 make[3] -C package/network/ipv6/odhcp6c compile
 make[3] -C package/network/services/dnsmasq compile
 make[3] -C package/network/services/dropbear compile
 make[3] -C package/network/services/odhcpd compile
 make[3] -C package/libs/libpcap compile
 make[3] -C package/network/utils/linux-atm compile
 make[3] -C package/network/utils/resolveip compile
 make[3] -C package/network/services/ppp compile
 make[3] -C package/system/mtd compile
 make[3] -C package/system/opkg compile
 make[3] -C package/utils/busybox compile
 make[3] -C package/utils/e2fsprogs compile
 make[3] -C package/utils/f2fs-tools compile
 make[2] package/install
 make[2] target/install
 make[3] -C target/linux install
 make[2] package/index
 make[2] checksum

It took my T420 almost 2 hours to finish the first make...You can ultimately find the results in the bin file.

############################################3

Keep updated with the official website:
    https://openwrt.org/docs/guide-developer/quickstart-build-images


ref:
https://www.youtube.com/watch?v=kjzQg_sB8rY
https://openwrt.org/docs/guide-developer/quickstart-build-images!!!!!!
http://blog.csdn.net/gubenpeiyuan/article/details/8024247

Wednesday, 7 March 2018

Tinkering OpenWRT (6) : Connect Raspberry Pi to Computer with TTL-USB Converter FTDI

It must be frustrating to use a Pi as a new computer and give it all the peripherals like mouse and keyboards and most annoying one, an extra monitor. We can simply use the serial port to connect the Pi with Computer. Here is how.

Step 1:
Plug in the FTDI module and do:
       ls /dev/ttyUSB*
usually FTDI is mounted at ttyUSB0.

Step 2:
Conncet FTDI with your PI, I am using B+ model.




Step 3:
      screen /dev/ttyUSB0 115200

And voila!

BusyBox v1.23.2 (2016-01-31 10:28:42 CET) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 CHAOS CALMER (15.05.1, r48532)
 -----------------------------------------------------
  * 1 1/2 oz Gin            Shake with a glassful
  * 1/4 oz Triple Sec       of broken ice and pour
  * 3/4 oz Lime Juice       unstrained into a goblet.
  * 1 1/2 oz Orange Juice
  * 1 tsp. Grenadine Syrup
 -----------------------------------------------------
root@OpenWrt:/# [   19.795613] random: nonblocking pool is initialized

root@OpenWrt:/# 

Step 4: Blinky
root@OpenWrt:/# ls -1 /sys/class/leds/
led0

root@OpenWrt:/# echo 1 > /sys/class/leds/led0/brightness     // ? just blink?
root@OpenWrt:/# echo 1 > /sys/class/leds/led0/brightness     // ? just blink?
root@OpenWrt:/# echo 1 > /sys/class/leds/led0/brightness     // ? just blink?
root@OpenWrt:/# echo 0 > /sys/class/leds/led0/brightness     // off
root@OpenWrt:/# echo 1 > /sys/class/leds/led0/brightness     // NOW KELP ON ??!!!


ref:
http://caoyudong.com/2015/10/03/%E9%80%9A%E8%BF%87USB%E8%BD%AC%E4%B8%B2%E5%8F%A3%E6%A8%A1%E5%9D%97%E8%BF%9E%E6%8E%A5%E6%A0%91%E8%8E%93%E6%B4%BE/
http://ediy.com.my/index.php/tutorials/item/131-openwrt-control-led-manually
http://hacklabos.org/2014/04/playing-with-gpio-and-sensors-on-openwrt/

Sunday, 4 March 2018

Tinkering OpenWRT (4) : make config

When I tried to configure my make config menu for openwrt, I got:

Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
/home/boris/workspace/openWRT/WRTKernel/source/include/toplevel.mk:136: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 1

Don't worry, this simply means you have to maximize your terminal window.

Wednesday, 28 February 2018

Tinkering OpenWRT (3) : Setting up OpenWRT on a Raspberry Pi

Step 1: Use an SD Card Reader to load up a MicroSD card.

Step 2: I'm using Raspberry Pi B+, that's an RPi 1.
So from:
     https://wiki.openwrt.org/toh/raspberry_pi_foundation/raspberry_pi
download:
     Raspberry Pi 1: http://downloads.openwrt.org/chaos_calmer/15.05.1/brcm2708/bcm2708/

Step 3:
Use etcher to make an bootable SD card.

Step 4: insert the bootable SD card to RPi.


ref:
https://www.raspberrypi.org/documentation/installation/installing-images/      !!!!!
https://etcher.io/                                                                                                   !!!!!

http://www.ct-networks.io/community/tutorials/openwrt-installing-firmware-on-raspberry-pi.html   !!
https://devzone.nordicsemi.com/b/blog/posts/trying-openwrt-chaos-calmer-1505-rc1-on-raspberry-
https://computers.tutsplus.com/articles/installing-openwrt-on-a-raspberry-pi-as-a-new-home-firewall--mac-55984
https://www.qualityology.com/tech/how-to-install-openwrt-on-raspberry-pi/
https://tecadmin.net/format-usb-in-linux/

Friday, 16 February 2018

Tinkering OpenWRT (2) : Installing Softwares (eg. Python)

For example, I want to install Python.

Do this first!!!!
opkg update

Now we can install Python related packages:

opkg install libffi
opkg install python-mini
opkg install python
opkg install python-openssl



ref:
http://www.rendoumi.com/openwrtan-zhuang-python-pip/
http://blog.csdn.net/frankechen/article/details/78660437
http://www.cnblogs.com/xianfangloveyangmei/p/4091882.html

Tinkering OpenWRT (1) : Getting Started

I don't have an actual board in my hand yet but I just couldn't wait to start play around with OpenWRT! So no bullshit here is how I got started in VirtualBox.

Step 1: Get it
Option 1 :
http://downloads.openwrt.org/backfire/10.03.1/x86_generic/openwrt-x86-generic-combined-ext2.vdi
As can be seen, the file is already a .vdi so it can be used directly.

Option 2 :
http://downloads.openwrt.org/backfire/10.03.1/x86_generic/openwrt-x86-generic-combined-ext2.img.gz
If you want to go with this option, you need to convert the image file to vdi file:

VBoxManager convertfromraw --format VDI openwrt-18.06.0-x86-generic-combined-ext4.img.gz openwrt-1806-x86.vdi

##################################################################

Troubleshooting:

Problem (1)
Command 'VBoxManager' not found, did you mean:

  command 'VBoxManage' from deb virtualbox


Try: sudo apt install <deb name>

Solution:
$ which VBoxManage
/usr/bin/VBoxManage

and then
/usr/bin/VBoxManage convertfromraw --format VDI openwrt-18.06.0-x86-generic-combined-ext4.img.gz openwrt-1806-x86.vdi


Problem (2)
$ /usr/bin/VBoxManage convertfromraw --format VDI openwrt-18.06.0-x86-generic-combined-ext4.img.gz openwrt-1806-x86.vdi
Converting from raw image file="openwrt-18.06.0-x86-generic-combined-ext4.img.gz" to file="openwrt-1806-x86.vdi"...
Creating dynamic image with size 7896443 bytes (8MB)...
VBoxManage: error: VD: The given disk size 7896443 is not aligned on a sector boundary (512 bytes)
VBoxManage: error: Error code VERR_VD_INVALID_SIZE at /home/vbox/vbox-5.2.16/src/VBox/Storage/VD.cpp(6219) in function int VDCreateBase(PVDISK, const char*, const char*, uint64_t, unsigned int, const char*, PCVDGEOMETRY, PCVDGEOMETRY, PCRTUUID, unsigned int, PVDINTERFACE, PVDINTERFACE)

VBoxManage: error: Cannot create the disk image "openwrt-1806-x86.vdi": VERR_VD_INVALID_SIZE


Solution:
$ dd if=openwrt-18.06.0-x86-generic-combined-ext4.img.gz of=openwrt.img bs=128000 conv=sync
61+1 records in
62+0 records out

7936000 bytes (7.9 MB, 7.6 MiB) copied, 0.138767 s, 57.2 MB/s


$ /usr/bin/VBoxManage convertfromraw --format VDI openwrt.img openwrt-1806-x86.vdi
Converting from raw image file="openwrt.img" to file="openwrt-1806-x86.vdi"...

Creating dynamic image with size 7936000 bytes (8MB)...

##################################################################

Step 2: Vbox configuration
Settings are as shown in following pictures. Some of the areas are grey because my openwrt is running.

settings 0:

Settings 1: You must choose IDE controller. It won't boot if you go with SATA.

Settings 2: We need at least two NIC.


Settings 3:

Step 3: Run!
 Press ENTER here!


Voila!!


ref:
http://www.cnblogs.com/hdk1993/p/4769141.html
http://blog.tshine.me/virtualbox%E5%AE%89%E8%A3%85openwrt.html
https://vsxen.github.io/2017/05/15/openwrt-install-virtualbox/
http://blog.csdn.net/js93105/article/details/44704283
https://openwrt.org/docs/guide-user/virtualization/virtualbox-vm





Thursday, 8 February 2018

Git delete tag locally and remotely


To delete a local tag:
git tag -d tag-name

To delete a remote tag:
git tag -d tag-name                                    // first: delete it locally
git push origin :refs/tags/tag-name         // then push the empty tag to origin

ref:
http://www.manikrathee.com/how-to-delete-a-tag-in-git.html

Friday, 2 February 2018

Building esp-open-sdk


Following the instructions in
                 https://github.com/pfalcon/esp-open-sdk

until make. You might meet errors because of missing tools.

These are the things I did:

sudo apt-get install autoconf
sudo apt-get install gperf
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install texinfo
sudo apt-get install help2man
sudo apt-get install gawk
sudo apt-get install libncurses5-dev

Hope it helps you.

ref:
https://github.com/pfalcon/esp-open-sdk
https://github.com/crosstool-ng/crosstool-ng/issues/329
https://www.crifan.com/files/doc/docbook/crosstool_ng/release/htmls/crosstool_ng_common_errors.html#missing_gperf
https://www.howtoinstall.co/en/ubuntu/trusty/help2man
https://askubuntu.com/questions/710379/do-i-need-to-install-awk-or-is-it-inbuilt-in-ubuntu
https://www.crifan.com/ubuntu_crosstool_ng_configure_error_could_not_find_curses_header_required_for_the_kconfig_frontends/





Friday, 19 January 2018

How to Downgrade Particle System Firmware


Particle sometimes rushes to release their newest system firmware but your applications could stop working or some unexpected things happen for some reason.
So here is how to downgrade the system firmware.

Step 1: check the current system fw on the device
- connect your device to your computer with a USB cable
- press the SETUP button for 3 seconds to enter setup mode.
- using a serial monitor such as PuTTY (Windows) or screen (linux/OSX), to connect to the device
press 'v' - this prints the "system version, e.g. 0.6.3".

I'm using Linux so my command is:
                                screen /dev/ttyACM0

Step 2: download the target system fw
Say I want go back to 0.6.3, I can down load the system-part1 and part2 .bin file from this link.
https://github.com/particle-iot/firmware/releases/tag/v0.6.3

Step 3: flashing
particle flash YOUR_DEVICE_NAME system-part1-0.6.3-p1.bin particle flash YOUR_DEVICE_NAME system-part2-0.6.3-p1.bin particle flash YOUR_DEVICE_NAME tinker (NOT optional)

NOTE THAT THE LAST STEP, FLASHING TINKER, IS NOT OPTIONAL.

I think the device might have to handshake with the particle cloud at some point. If you don't do this, you can check the system fw with step 1, and you might see it's still showing you the old version number.


ref:
https://community.particle.io/t/determining-the-version-of-system-firmware-on-a-photon-p1/13324
https://github.com/particle-iot/firmware/releases/tag/v0.6.3
https://community.particle.io/t/particle-firmware-updates-thread/14378/25

Sunday, 7 January 2018

platformio ImportError: cannot import name LockFile


sudo apt-get purge python-lockfile
sudo pip install -U platformio


ref:
https://github.com/platformio/platformio-atom-ide/issues/48  *****
https://github.com/platformio/platformio-core/issues/360
https://github.com/platformio/platformio-core/issues/252

Discard unstaged changes in Git

There could be times that you just temporarily tried something, or showing other people something and you have some garbage code.

When using Git, it is common to make changes that you want to remove entirely before the staging phase. For example, after working on a few files, you realize that you want to revert the changes made to one specific file. To discard the changes before staging and committing, use the $git checkout command.

To unstage one file :
$ git checkout <path-to-file>
Remember to replace <path-to-file> with the actual file name.

To unstage all files:
$ git checkout -- .
ref:
https://forum.freecodecamp.org/t/discard-unstaged-changes-in-git/13214

Thursday, 28 December 2017

Print a Range of a char Array without a for Loop

Code:
#include <stdio.h> 
 int main() 
   char a[1024] = "abcdefghijklmnopqrstuvwxyz";  
   printf("Characters 0 through 2 of a[]: %.3s\n", a); 
   printf("Characters 10 through 15 of a[]: %.6s\n", &a[10]); return 0; 
}

Prints this:
Characters 0 through 2 of a[]: abc 
Characters 10 through 15 of a[]: klmnop

The "%.Ns" notation in the printf string is "%s" with a precision specifier. It's buried in the geek-speak in the printf(3) man page


ref:
https://www.linuxquestions.org/questions/programming-9/is-there-a-way-to-print-a-range-of-a-char-array-without-a-for-loop-842798/

Tuesday, 26 December 2017

Arduino Command Line Usage


arduino is simply a program from your installation directory. Without any parameters, it would just start the Arduino IDE.

open ~/.bashrc and add the following line at the bottom:
              PATH=$PATH:/home/aaa/xxx/yyy/arduinoIDE/arduino-1.8.2
Now we can use cmd "arduino" everywhere.

Use cases:
For arduino nano:
arduino --board arduino:avr:nano:cpu=atmega328 --port /dev/ttyUSB0 --upload beep.ino

Serial Monitor:
picocom /dev/ttyUSB0 -b 9600

ref:
https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path
https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc

Tuesday, 19 December 2017

I think the following problems are the same:

Problem 1:
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?


Problem  2:
sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
5 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up linux-image-extra-4.4.0-104-generic (4.4.0-104.127) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-104-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-104-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-104-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-extra-4.4.0-104-generic; however:
  Package linux-image-extra-4.4.0-104-generic is not configured yet.

dpkg: error processing package linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 4.4.0.104.109); however:
  Package linux-image-generic is not configured yet.

dpkg: error processing package linux-generic (--configure):
 dependency problems - leaving unconfigured
Setting up linux-image-4.4.0-98-generic (4.4.0-98.121) ...
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          No apport report written because the error message indicates its a followup error from a previous failure.
                                                                             Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-4.4.0-98-generic
vmlinuz(/boot/vmlinuz-4.4.0-98-generic
) points to /boot/vmlinuz-4.4.0-98-generic
 (/boot/vmlinuz-4.4.0-98-generic) -- doing nothing at /var/lib/dpkg/info/linux-image-4.4.0-98-generic.postinst line 491.
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-98-generic /boot/vmlinuz-4.4.0-98-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-98-generic /boot/vmlinuz-4.4.0-98-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-98-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-98-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-4.4.0-98-generic.postinst line 1052.
dpkg: error processing package linux-image-4.4.0-98-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
No apport report written because MaxReports is reached already
                                                              dpkg: dependency problems prevent configuration of linux-image-extra-4.4.0-98-generic:
 linux-image-extra-4.4.0-98-generic depends on linux-image-4.4.0-98-generic; however:
  Package linux-image-4.4.0-98-generic is not configured yet.

dpkg: error processing package linux-image-extra-4.4.0-98-generic (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-image-extra-4.4.0-104-generic
 linux-image-generic
 linux-generic
 linux-image-4.4.0-98-generic
 linux-image-extra-4.4.0-98-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

Problem  3:
The volume "boot" has only  bytes disk space remaining

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Solution:

Step 1:
List all the current existing kernels.

ls /boot/ | grep vmlinuz
vmlinuz-4.4.0-104-generic
vmlinuz-4.4.0-97-generic
vmlinuz-4.4.0-98-generic

Step 2:
Find the current kernel in use.

uname -r
4.4.0-97-generic

Step 3:
Remove one of them not in use:

sudo apt-get purge linux-image-4.4.0-104-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-104 linux-headers-4.4.0-104-generic linux-headers-generic thermald
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.



ref:
https://askubuntu.com/questions/218783/the-volume-boot-has-only-0-bytes-disk-space-remaining


Thursday, 7 December 2017

Toubleshooting: ampy "could not enter raw repl" error


When using ampy tool, nothing works!

ampy --port /dev/ttyUSB0 get boot.py

>>> 
Traceback (most recent call last):
  File "/usr/local/bin/ampy", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ampy/cli.py", line 96, in get
    contents = board_files.get(remote_file)
  File "/usr/local/lib/python2.7/dist-packages/ampy/files.py", line 68, in get
    self._pyboard.enter_raw_repl()
  File "/usr/local/lib/python2.7/dist-packages/ampy/pyboard.py", line 184, in enter_raw_repl
    raise PyboardError('could not enter raw repl')
ampy.pyboard.PyboardError: could not enter raw repl

On the NodeMCU side it prints:
...
>>>
>raw REPL; CTRL-B to exit >

The reason is because the serial port is busy. So after I closed the REPL python terminal and called ampy again, every thing works perfectly. 


ref:
http://forums.openmv.io/viewtopic.php?t=298

Casting Bitwise struct to Integer

I have bitwise structure with a bunch of flags.

struct {
  uint8_t a: 4; 
  uint8_t b: 4; 
} _tVarA

_tVarA Var_A = {0,0};

But when I want to view them as a whole integer, I need to cast it like this:
                               *(uint8_t*)&Var_A

ref:
http://www.avrfreaks.net/forum/casting-bitfield-struct-integer
https://stackoverflow.com/questions/11903820/casting-struct-into-int