All posts by end2end

PiDVR Record over the air TV on a Raspberry Pi 4

PiDVR Record over the air TV on a Raspberry Pi 4

About the project

The following project explains how I used a Raspberry Pi 4 to create a personal digital video recorder to record over-the-air tv.

Required Hardware

This project requires the following hardware:

  • Raspberry Pi 4 (with the required parts)
    • 4GB of ram
    • A 16GB SD card
    • A micro HDMI cable
    • Monitor with HDMI input
    • A 15.3W USB-C Power Supply (3A @ 5v power supply)
    • Raspberry Pi 4 case. Preferably a passive cooling case for noise consideration.
      I used the Argon One case.
  • An HDHomeRun Dual tuner from Silicondust. The oldest model will do. For this build, I used the HDHR3-US which dates back to 2012-2013.
  • An over-the-air tv antenna for ATSC signals. For this build I use the Clearstream 4 antenna by Antennas Direct.
  • 50ft to 100ft Coaxial Cable, 18AWG, 75 Ohm to connect the antenna to the HDHomeRun.
  • External Solid State Drive (SSD) with about 500Gb in size.
  • USB 3.0 to SATA Converter Adapter – Look for one that has UASP support.

Software list

This section defines the list of required software for the project. Follow the instructions in the next section to know when and how to install them.

  1. Download Raspberry Pi OS with desktop and recommended software from https://www.raspberrypi.org/software/operating-systems/
  2. Download the Raspberry Pi Imager to write the Raspberry Pi OS image to an SD card.

Instructions

Write Raspberry Pi OS image file to your SD card

  1. Launch the Raspberry Pi Imager for writing the Raspberry Pi OS image file to your SD card. There are plenty of online tutorial for this operation
  2. Turn on the Raspberry Pi and follow “first launch” instructions on screen.

Update the Raspberry Pi firmware

The oldest Raspberry Pi 4 models that originally shipped uses an out of date firmware. Most of all, they do not support booting from an SSD drive connected through USB. Updating the firmware provides better thermals and USB boot support.

Jeff Geerling has written an excellent guide on how to upgrade the Raspberry Pi 4’s firmware.
Follow his instructions available at:
https://www.jeffgeerling.com/blog/2019/upgrade-raspberry-pi-4s-firmware-bootloader-better-thermals.

In summary, run the following commands in a terminal:

Check that USB 3.0 to SATA adaptor has UASP support

UASP stands for USB Attached SCSI Protocol. In very few words, it is a protocol used in USB storage devices and adapters that performs better that the traditional USB 1.1 protocol.

Jeff Geerling has written an excellent guide on how to verify if your adaptor is UASP compatible.
Follow his instructions available at:
https://www.jeffgeerling.com/blog/2020/uasp-makes-raspberry-pi-4-disk-io-50-faster.

In summary, connect your ssd drive and run the following commands in a terminal:

From Jeff Geerling article:

This command lists all the USB devices in a tree, and for each of the hard drives, you should see a Driver listed. If it’s uas , then your drive supports UASP and you’ll get the best speed. If it’s usb-storage , then it’s using the older BOT protocol and you won’t see the full potential.

Enable USB boot on the Raspberry Pi

A USB 3.0 Flash Drive or an USB 3.0 SSD is almost always preferable to an SD Card when booting the Raspberry Pi OS. The thing about booting Operating Systems is that 4K Read/Write Speed dictate the experience more than the sequential Read/Write Speed (the usual advertised speed). SD card usually have bad performance regarding 4K Read/Write speed.

On the Raspberry Pi4, you can specify whether to boot from USB or network if the SD card isn’t inserted.

The raspi-config utility can enable USB Booting on the Raspberry Pi 4:

  1. Launch the application in a terminal.
  2. Enter Advanced Options section.
  3. Enter Boot Order section.
  4. Select USB Boot option.

See raspi-config.md documentation and bcm2711_bootloader_config.md documentation on https://www.raspberrypi.org/ for more details.

Move Raspberry Pi OS from SD card to SSD drive

Running the Raspberry Pi 4 on an SD card has great read and write speed. Opening an application feels good and we do not have to wait forever to get us going. However, an SD card cannot sustain the passage of time. Our build requires to run the raspberry pi 24/7. Sooner or later the SD card will get corrupted during a write operation and then our precious setup we created won’t be able to boot from the card anymore.

One solution is to moving the root file system of your Raspberry PI to an external USB drive bypasses this problem. This article presents instructions on moving the root file system from the SD card to an external USB drive, such that you can boot your Raspberry PI with the root file system on the USB drive.

The SD Card Copier application, which can be found on the Accessories menu of the Raspberry Pi Desktop, will copy Raspberry Pi OS from your SD card to your SSD drive. To use it, you will need to have the USB drive already connected before launching the application.

Follow the following instruction for moving the Raspberry Pi OS from SD card to SSD drive:

  1. Connect the SSD drive to a USB 3.0 port on the Raspberry Pi.
  2. Launch the SD Card Copier application, which can be found on the Accessories menu of the Raspberry Pi Desktop.
  3. Select your SD card device in the Copy From Device dropbown. It should probably be labeled /dev/mmcblk0.
  4. Select your SSD device in the Copy To Device dropbown. It should probably be labeled /dev/sda.
  5. Click on Start button.
  6. Wait for the process to complete.
  7. Close the application.

Shrink the Operating System partition

Following the copy of the Raspberry Pi OS from the SD card to the SSD, the SD Card Copier application has automatically increased the size of the last partition to the total size of the SSD. This is a problem for the following reasons:

  1. If we have a single huge partition, we are not able to backup the operating system on our disk. This is because a backup destination image cannot be stored on the same partition that it is backuping from. We need at least 2 partitions to backup the operating system to the same disk.
  2. To allow quick backup of the operating system, we need the partition to be reasonably small. On a 16GB card, the operating system partition is 14.58 GB of which about half is in use. This gives us plenty of additional space if we need to install other software.
  3. For our build, we want to store our tv recordings and the operating system on different partitions. TV recordings should be stored in the largest partition of the disk.
  4. In many cases, it is better to store operational data (in our case: recordings, backups, etc) on a separate partition (other than the OS). This configuration allows to restore the OS from a backup or install a fresh new operating system without having to erase the operational data. In other words, we get to keep our recordings in case of an OS corruption or a boot failure.

The following instructions explains how to reduce the size of the OS partition:

  1. Open GParted.
  2. Switch to the SSD device (probably /dev/sda)
  3. Select the last partition. This is the partition of the Operating System.
  4. Resize the partition to the original size of the SD card.
  5. Create a partition for the remaining space of the SSD.
    Format the partition as ext4. This is to make sure we get the best read and write performance.
    For reference, the Rraspberry Pi 4 is capable of the following writing speeds:

     

    • 85 mb/s to an external usb 3.0 SSD with an ext4 partition.
    • 26 mb/s to an external usb 3.0 SSD with an NTFS partition.
  6. Set the name of the partition to pidvr.

Boot from the SSD drive

At this point, our SSD is now properly configured to be used as our boot device.

Follow these instructions to boot from the SSD:

  1. Shutdown the device
  2. Disconnect the power cable.
  3. Remove the SD card from the SD card slot.
  4. Connect the power cable to the Raspberry Pi.

Uninstall nonessential software

Since we installed the Raspberry Pi OS with desktop and recommended software image, there are multiple software that are shipped with the image that we do not intend to use. Most importantly, some of them uses a lot of disk space.

Uninstall the following unneeded software:

  1. Open Recommended Software manager, which can be found in Preferences menu.
  2. Uncheck the following software
    1. In Education, uncheck SmartSim
    2. In Games, uncheck them all
    3. In Programming, Uncheck Mathematica, Scratch, Scratch 3, Sense HAT emulator, Sonic Pi
  3. Click Apply button to uninstall

Install additional software

To allow management of the PiDVR, we will need to install other software.

Argon One fan script

This is specific to our build since we are using the Argon One case. The instructions from http://wagnerstechtalk.com/argonone/ properly explains how to install the scripts to support the Argon One power button and fan speed.

In summary, run the following commands in a terminal:

Other

The following list of programs can be installed manually in the terminal:

The following instructions can install all software mentioned above:

Create storage directories for our recordings

The instructions in this section explains how to create our base storage directories.

As discussed above, we want tv recordings to be stored on the SSD in the pidvr partition which is automatically mounted at /media/pi/pidvr.

In directory /media/pi/pidvr, create the following directories:

  • backup, for storing backup images of the raspberry pi os
  • recordings, for storing our recordings, obviously
  • shared, for creating a Windows shared directory for easily transferring files from/to the raspberry pi. See next section below.

By default, these directories will only be writable (or accessible) for the pi user on the Raspberry Pi. This is a problem for our build since tvheadend run as hts user and hts user won’t have access by default to our recordings directory. To allow anyone to have read and write access to these directories, enter the following command in a terminal:

Note: by default, a partition permissions are inherited from its parent directory where the partition is mounted. In this case, the partition mounted at /media/pi/pidvr inherits the permissions from /media/pi directory.

A reboot of the Raspberry Pi may be required for the new partition is show up as writable for everyone.

Install Samba SMB/CIFS support

By default, Raspberry Pi OS does not include CIFS/Samba support, but this can easily be added. The Raspberry Pi documentation has an article available at https://www.raspberrypi.org/documentation/remote-access/samba.md that explains how to proceed.

In summary, run the following commands in a terminal:

Note: During installation, if you have other samba servers on your network, choose no which is the default option.

To create shared directories that can be accessed by a Windows computer, edit the configuration file /etc/samba/smb.conf with the following command:

and add the following new sections:

Restart the samba daemon service for the changes to take effect:

Run Raspberry Pi Configuration utility

The default configuration of the pi should be properly set for most users. For our usage, we need to change some of the configuration settings.

For example, the default hostname for the raspberry pi is raspberrypi which is a problem if you own multiple raspberry pies because the hostname of a device on a network must be unique for every device in order to be reachable by others. It is also good practice to change the hostname to something that represent the intended usage of the pi.

The Raspberry Pi Configuration application, which can be found on the Preferences menu of the Raspberry Pi Desktop, will allow you to change the required settings. Please change the following settings accordingly:

  1. In System tab, change the hostname to pidvr.
  2. In Interfaces tab, enable SSH and VNC.

Install Tvheadend

This is the main software for the build. You can find more information about tvheadend at https://tvheadend.org/.

There are already great guides that explains how to install and configure tvheadend. For example, thepihut and pimylifeup have great instruction guides.

In summary, run the following commands in a terminal to install tvheadend:

Note: During installation, you will need to provide a username and password for the tvheadend aministrator. You can use pidvr and pidvr.

Tvheadend initial configuration setup

After installation, connect to the tvheadend web interface to configure the application and scan for channels. Head over to the following address:
http://pidvr:9981/

Welcome (1 of 2)

tvheadend - welcome page (1 or 2)

tvheadend – welcome page (1 or 2)

This first screen will require you to select a language the web interface and the electronic program guide (EPG):

Enter the following values:

  • English
  • French

Click Save & Next to get to the next page.

Note: Since we actually changed the language of the web interface, the same page may be displayed when you first click Save & Next. Click it again.

Welcome (2 of 2)

tvheadend - welcome page (2 or 2)

tvheadend – welcome page (2 or 2)

The next page allows you to configure the network access.

We are going to allow all network access by leaving the ‘Allowed network’ field blank.

We are also going to bypass any logins by entering * in each of those fields.

Click Save & Next to get to the next page.

Network settings

tvheadend - network settings

tvheadend – network settings

The next screen configures the tuners.

Leave the IPTV fields from Network 1 blank.

At this point, tbheadend should have already discovered both HDHomeRun ATSC-T Tuner #0 and #1 identified in “Network 2” and “Network 3” sections. Select ATSC-T Network in the Network type fields for each network.

Click Save & Next to get to the next page.

Assign predefined muxes to networks

tvheadend - muxes

tvheadend – muxes

We now have to set the “muxes”. To save you from manually entering muxes, Tvheadend includes predefined mux lists. For best results in Montreal area, select the following muxes: United States: us-ATSC-center-frequencies-8VSB

Click Save & Next to get to the next page.

Scan status

tvheadend - scan status

tvheadend – scan status

The scan will now commence. It will search for “muxes” and “services” that are distributed via those muxes. Note, a service is a TV channel. When the scan hits 100% you’ll be able to see how many muxes and services it’s picked up.

tvheadend - scan status (100% completed)

tvheadend – scan status (100% completed)

Click Save & Next to get to the next page

Service mapping

tvheadend - service mapping

tvheadend – service mapping

Next on the wizard is service mapping. This step maps the services that your scan discovered to channels. If you are interested in adding all channels in your area, do not tick any checkbox. Otherwise, tick the three check boxes.

Click Save & Next to get to the next page.

Finished

tvheadend - setup finished

tvheadend – setup finished

The initial setup is finished. Click Finish to complete the

At this stage we like to reboot the Raspberry Pi. In the terminal use the following command to restart your Raspberry Pi:

Tvheadend additional configuration

The following list are specific configuration settings that I like to set for tvheadend:

Set web interface level to Advanced by default

  1. Go to Configuration, General, Base tab.
  2. Set User interface level to value Advanced.
  3. Click on Save when done.

Test for tvheadend has access to ‘recordings’ directory

tvheadend runs as user hts. To test read and write access from hts user perspective, type the following in a terminal:

The commands specified above should not output any error like the following:

Setup preferred recordings settings

  1. Go to Configuration, Recording, Digital Video Recorder Profiles tab.
  2. Click on the Default profile.
  3. Set Recording system path to value /media/pi/pidvr/recordings.
  4. Set Pre-recording padding to 1 min.
  5. Set Post-recording padding to 3 min.
  6. Uncheck Skip commercials options.
  7. Check Include date in filename, Include time in filename and Use Windows-compatible filenames options.
  8. Click on Save when done.

Enable Timeshift

Timeshift is disabled by default and needs to be enabled to get the maximum out of tvheadend.

  1. Go to Configuration, Recording, Timeshift tab.
  2. Switch to Expert mode. This is to work around a bug explained here and here.
  3. Check enabled.
  4. Set Storage path to value /media/pi/pidvr/recordings.
  5. Set Maximum size (MB) to value 4096.
  6. Check On-demand (no first rewind) and Fit to RAM (cut rewind).
  7. Click on Save when done.

Set Network Character set

Montreal channels have the EPG encoding using UTF-8. The network character encoding must be specified manually.

  1. Go to Configuration, DVB Inputs, Networks tab.
  2. Select the default network created by the first scan (named ATSC-T Network).
  3. Click edit button.
  4. Change the name of the network (i.e. My ATSC Network)
  5. Set Character set to value UTF-8.
  6. Click on Save.

  7. Switch to Muxes tab.
  8. Select all available muxes: click on the first mux and press CTRL+A.
  9. Click edit button.
  10. Check Character set in Advanced Settings.
  11. Set Character set to value UTF-8.
  12. Click on Save.

  13. Switch to Services tab.
  14. Select all available services: click on the first service and press CTRL+A.
  15. Click edit button.
  16. Switch to Export view level.
  17. Check Character set in Advanced Settings.
  18. Set Character set to value UTF-8.
  19. Click on Save.

Map desired services as channels

If you did not mapped all services as channels during first configuration, now is the time to do it.

For Montreal area, here is the list of French channels:

  • Radio-Canada CBFT-DT
  • TVA CFTM-DT
  • Noovo CFJP-DT
  • Télé-Québec CJNT
  1. Go to Configuration, DVB Inputs, Services tab.
  2. Select all available services: click on the first service and press CTRL+A.
  3. Click edit button.
  4. Check Enabled setting in Basic Settings and uncheck the value.
  5. Click on Save.
  6. Check only the your desired channels that you want to map
  7. Click on Save.
  8. Click on Map Selected then Map selected services, a new window will open
  9. Uncheck Create type-based tags.
  10. Click on Map sercices.
  11. Wait for the mapping process to end.

Change channel identifiers to meaningful names

This is for changing the name of the channels from CBFT (or something) to the actual name of the tv network that owns these channels.

  1. Go to Configuration, Channel / EPG, Channels tab.
  2. Double click the name of each channel that you need to rename
  3. Click on Save when done.

For example:

  • Radio-Canada – CBFT-DT
  • TVA – CFTM-DT
  • Noovo – CFJP-DT
  • Télé-Québec – CJNT

UTF-8 characters in Electronic Program Guide (EPG) – bug

The tv guide seems to be still using non-utf8 characters. This is still an open issue and I have not yet figured out a way to solve the issue:

 

Configure Kodi to connect to tvheadend

The following instructions defines how to connect Kodi with tvheadend to view recordings:

Install tvheadend add-on

  1. Open Kodi.
  2. Go to Settings.
  3. Select Add-ons.
  4. Select Install from repository.
  5. Select PVR Clients category.
  6. Select Tvheadend HTSP Client.
  7. Select Install and wait for the add-on to install.
  8. Select Tvheadend HTSP Client (again).
  9. Select Configure.
  10. Set tvheadend hostname to pidvr.
  11. Click on OK when done.

How to setup macOS Catalina 10.15 in VirtualBox for C++ development on Github.

Introduction

This post explains all the instructions required in order to get started with c++ no macOS 10.15 Catalina.

This article assumes that you already have access to a macOS image ISO file and that you already created a macOS virtual machine in VirtualBox.

Update macOS with latest security updates and bug fixes

Following macOS Catalina 10.15 installation, it is best practice to update the Operating System with the latest software & security update.

  1. Open System Preferences.
  2. Click on Software Update, a new window will open.
  3. Install all updates that are available for macOS Catalina 10.15.

At the time of this writing, the latest version of macOS Catalina is version 10.15.7.

Note: You can install optional updates by clicking on More info… and selecting updates that are related to Catalina.

 

Set system preferences for developers

Enable SSH and File sharing

  1. Open System Preferences.
  2. Click on Sharing.
  3. Set a new Computer hostname:
    1. Locate Computer Name field.
    2. Click the Edit button.
    3. Set a meaningful value for the Local Hostname. For example MACDEV01.
    4. Click the OK button.
  4. Check File Sharing.
    1. Click Options… button.
    2. In Windows File Sharing section, check you account name and enter your account password. This will make sure that shared folders requires a username/password for write access.
    3. Click on Done button.
  5. Check Remove Login.
    1. Allow access for All users instead of only for Administrators.
    2. Note your computer ip address in the note To log in to this computer remotely.

Add Terminal icon in Dock

By default, a Terminal icon is not already available in Dock. As most developers, you will probably require to use Terminal more than once. Do the following to add Terminal in Dock:

  1. Open Launchpad.
  2. Expand Other group.
  3. Drag Terminal icon to Dock.

Show address bar in Finder

By default, Finder does not show the address bar (the location of the current directory).

Open a Terminal and enter the following command:

The command will change the default setting and restart all Finder application instances.

Also, enable the following View settings in Finder :

  1. Click on menu View.
  2. Select Show Path Bar.
  3. Select Show Status Bar.

Source: How can I get an address bar in Finder?

Show hidden file and folders in Finder

By default, Finder does not show hidden file and folders. As most developers, you will probably require enable this setting.

Open a Terminal and enter the following command:

The command will change the default setting and restart all Finder application instances.

Source: How to Show Hidden Files on Mac

Xcode

Xcode is Apple’s integrated development environment (IDE) for macOS, used to develop software for macOS.

Install Xcode application

A relatively new version of xcode is required for c++ development on macOS. At the time of this writing, the latest version of xcode is 12 but we do not need to be using the latest version. It is better to use the previous stable version. At the time of this writing, xcode 11.7 is available. This stackoverflow article defines the location of xcode 11.7 installation package.

  1. Download Xcode_11.7.xip.
  2. Open the file in Finder and double-click on it. Wait for the digital signature to validate. This will extract Xcode.app application file to the Downloads directory.
  3. In Finder, move Xcode.app file to Applications folder.
  4. Open LaunchPad and click on Xcode application. This will register Xcode tools with your account.

Note: you will require a valid Apple ID for downloading the installation package.

Verify Xcode installation

To verify that Xcode is properly installed, open a Terminal and enter the command: system_profiler SPDeveloperToolsDataType.

The expected output is the following:

Once Xcode is properly registered on the system, you can delete file Xcode_11.7.xip.

Install VirtualBox’s Guest Additions

On macOS 10.15 Catalina, Guest Additions cannot be installed by default. The installation cannot be completed as normal because the OS now require packages to be digitally signed. I think this applies to macOS 10.14 Mojave as well. To get around this security limitation, you need to disable multiple security features in order to install the package.

To install Guest Additions using VirtualBox version 6.1.16 on Windows 7 to share the clipboard values between the host and the guest. If someone else wants to install this, here is the whole process:

Disable Gatekeeper

  1. Be sure to exit System Preferences on your Mac.
  2. Open a Terminal
  3. Enter the command sudo spctl --master-disable.

Source: How to open apps from unidentified developers on Mac in macOS Catalina

Check Gatekeeper is disabled

  1. Click on System Preferences on your Mac Dock.
  2. Choose Security & Privacy.
  3. Look at Allow apps download from:, it should be set to Anywhere. If it is, you are done.
  4. If not, click the lock icon at the bottom left of the screen.
  5. Choose the Anywhere option under Allow apps downloaded from. Prior to making the change, this option wasn’t available.
  6. Click the unlocked lock again to keep the change.

Disable SIP (System Integrity Protection) and allow Oracle identifier for kext

  1. Restart your computer in Recovery mode. In your VM’s terminal enter the following command :
    sudo nvram recovery-boot-mode=unused && sudo shutdown -r now.
  2. Launch Terminal from the Utilities menu.
  3. Run the command csrutil disable which will disable SIP.
  4. Run the command spctl kext-consent add VB5E2TV963 which will allow Oracle identifier for kext.
  5. Restart your computer and exit Recovery Mode. In your VM’s terminal enter the following command :
    nvram -d recovery-boot-mode && shutdown -r now.

Note: VB5E2TV963 is the code for oracle.

Source: Install problem 10.14.5 vBox 6.0

Check SIP is disabled

You can verify that SIP is disabled with the command:
csrutil status
which should display:
System Integrity Protection status: disabled..

Change ownership and permissions on filesystem

Enable writing to /System/Library/Extensions/.

In your VM’s terminal enter the following commands:

Source: Guest Additions not installing on macOS 10.15 Catalina guests

Install Guest Additions

At this point, the installation of Guest Addition should succeed. Proceed with normal installation instructions:

  1. On VirtualBox emulation window, click on Devices menu.
  2. Select Insert Guest Additions CD image… .
  3. In your VM, click on the new CD image on the desktop.
  4. Click on VBoxDarwinAdditions.pkg.
  5. Follow the instructions on screen.
  6. A reboot is required after the installation.

Check clipboard sharing is working

Check that clipboard is shared between the host and the guest.

  1. On VirtualBox emulation window, click on Devices menu.
  2. Select menu Shared Clipboard -> Bidirectional.
  3. In your VM, open a terminal.
  4. Select text.
  5. Right-click on the selected text and select Copy.
  6. On your host, open a note taking application.
  7. Right-click and select Paste.

Enable Gatekeeper

  1. Be sure to exit System Preferences on your Mac.
  2. Open a Terminal
  3. Enter the command sudo spctl --master-enable.

Enable SIP

  1. Restart your computer in Recovery mode.
  2. Launch Terminal from the Utilities menu.
  3. Run the command csrutil enable .
  4. Restart your computer.

Install Homebrew

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s operating system macOS as well as Linux.

You can install Homebrew with the following commands:

  1. Open a Terminal app.
  2. Enter the command
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
  3. You’ll see messages in the Terminal explaining what you need to do to complete the installation process.

Source: Installing Homebrew on a Mac.

Install CMake command line via Homebrew

CMake is cross-platform free and open-source software for build automation, testing and packaging using a compiler-independent method. CMake is not a build system but rather it’s a build-system generator.

cmake can be installed with the following command:
brew install cmake

Install CMake (GUI version)

The GUI version of CMake can be installed with these instructions:

  1. Open CMake download page.
  2. Search for the Latest Release section and then Binary distributions section.
  3. Download the dmg installer for Mac OS X 10.13 or later. At the time of this writing, the file cmake-3.19.6-macos-universal.dmg is available.
  4. Locate the downloaded file in Finder and double-click the file. A new window will open
  5. Drag the CMake triangle icon over the Applications folder, making it available in the macOS Launchpad.
  6. Add CMake to your Dock by right-clicking on the icon to bring up the context menu and choosing Options, Keep in Dock.

Install GCC via Homebrew

GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ source code. It can also be used to compile Objective C and Objective C++.

gcc can be installed with the following command:
brew install gcc

Source: How does one install GCC on a Mac?

Register Xcode as current Command Line Tools

Following the installation of Xcode, the application may not be registered on the system as the current Command Line Tools.

The cause of the issue is one of the following errors when compiling :

  • fatal error: limits.h: No such file or directory
  • fatal error: ‘wchar.h’ file not found
  • The output of command xcode-select -p outputs /Library/Developer/CommandLineTools.

This is documented as a bug at the following locations:

The solution is to register (again) Xcode as the current current Command Line Tools:

  1. Open Launchpad.
  2. Select Xcode.
  3. In Xcode menu, select Preferences.
  4. Click on Locations tab.
  5. In Command Line Tools field, select Xcode 11.7 (11E801a).

Validate the change with the command xcode-select -p which should output /Applications/Xcode.app/Contents/Developer.

Then create a simlink for a missing directory. The instruction is detailed here.
Enter the following command in a Terminal :
ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk.

Install Visual Studio Code

Visual Studio Code is a freeware source-code editor made by Microsoft for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Users can change the theme, keyboard shortcuts, preferences, and install extensions that add additional functionality.

  1. Download Visual Studio Code for macOS.
  2. Open the browser’s download list and locate the downloaded archive.
  3. Select the magnifying glass icon to open the archive in Finder.
  4. Drag Visual Studio Code.app to the Applications folder, making it available in the macOS Launchpad.
  5. Add VS Code to your Dock by right-clicking on the icon to bring up the context menu and choosing Options, Keep in Dock.

Source: Running Visual Studio Code on macOS

Install required Extensions

  1. Open Visual Studio Code.
  2. On the left toolbar, click the Extensions icon.
  3. Search and install the following extensions:
    • C/C++
    • CMake
    • CMake Tools

Configure SSH keys

If you use GitHub without setting up an SSH key, you’re really missing out. Using ssh keys allow you to connect to other systems without having to provide a username and password.

Find out if you already have ssh keys on your system

ssh keys are stored in $HOME/.ssh directory. The private and public keys are usually named id_rsa and id_rsa.pub.

If this directory does not exists on your system and you cannot find these files, you don’t have ssh keys defined for your system. Continue to the next section for instructions on how to import or create new ssh keys.

If your keys already exist, skip ahead to the Configure Git for Github section below.

Import existing generated keys

Note: This section is for importing keys that you have generated previously. For example, if you are restoring a system backup, you may like to use the same key as previously. If you did not generate keys for your system, you can skip this section.

ssh-agent is a program that starts when you log in and stores your private keys. For it to work properly, it needs to be running and have a copy of your private key.

  1. Make sure that ssh-agent is running with the command :
    eval "$(ssh-agent -s)"
    The output should look like this:
    Agent pid 1030
  2. Create the .ssh directory in user’s home directory with the command :
    mkdir -p ~/.ssh
  3. Copy your existing public and private keys to $HOME/.ssh directory.
  4. Add your private key to ssh-agent with the command :
    ssh-add ~/.ssh/your_filename where your_filename is the name of your private key.

Generate a new set of keys

  1. Create the .ssh directory in user’s home directory with the command :
    mkdir -p ~/.ssh
  2. Create a new pair of keys with the command :
    ssh-keygen -o
  3. Validate the new keys with the command :
    ls -al $HOME/.ssh
  4. Print the content of your public key with the command :
    cat ~/.ssh/id_rsa.pub

The command output should look something like this:

Note: SSH keys are always generated as a pair of public (id_rsa.pub) and private (id_rsa) keys. It’s extremely important that you never reveal your private key, and only use your public key for things like GitHub authentication.

Source: Git on the Server – Generating Your SSH Public Key.

Configure Git for Github

Git is bundled with Xcode and should be already installed on the system. You can verify if git is installed with the command git --version.

Set your user global settings

Before make change to a repository, git should be configured with your username and email address.
Open a Terminal and enter the following commands:

Where myusername and myemailaddress@gmail.com must be replaced with your desired username (preferably one matching your github account) and your email address, respectively.

Source: Git – Generating Your SSH Public Key

Add your public SSH key to your Github account

Online Git servers such as Gitlab, Bitbucket or Github provides authentication services using ssh keys. As a general rules, you must add your public key to your account. The following instructions shows how to do so with Github.

  1. Copy your public SSH key to the clipboard with the command :
    cat ~/.ssh/id_rsa.pub
  2. Highlight the output of the command and copy to the clipboard.
  3. Go to your GitHub SSH keys settings page and click the New SSH key button.
  4. Give your key a recognizable title (such as MACDEV01) and paste in your public (id_rsa.pub) key.

Finally, test your authentication with:

If you’ve followed all of these steps correctly, you should see this message:

Where your_user_name matches your actual Github username.

Test C++ compilation in Terminal

At this point, you should be ready to compile c++ code in Terminal. These instructions show how to compile googletest, Google Testing and Mocking Framework.

Checkout the code from github with :

The commands above will create directory ~/dev/googletest with googletest source code.

Create the build system directory with :

Build and install googletest with :

This commands above will build googletest with 4 cores and install the library in ~/dev/install directory.

Test C++ compilation with Visual Studio Code

These instructions show how to compile zlib, a massively spiffy yet delicately unobtrusive compression library.

  1. Open Visual Studio Code.
  2. On the left toolbar, click the Source Control icon.
  3. Click on the Clone Repository button.
  4. A Command Pallet will open.
  5. Enter the following url: https://github.com/madler/zlib.git and press enter.
  6. Select the location where to checkout the repository. For example, ~/dev.
  7. Wait for the repository to checkout.
  8. A notification window will appear and ask Would you like to open the cloned repository? Click Open button.
  9. On the left toolbar, click the CMake icon.
  10. At the top of the window, click on Configure All Projects icon.
  11. A Command Pallet will open.
  12. Select [Unspecified] (Let CMake guess what compilers and environment to use) option.
  13. Wait for the configuration to complete.
  14. At the top of the window, click on Build All Projects icon.
  15. Wait for the build to complete.
  16. Right-click on the example target and select Run in Terminal menu item.
  17. The Terminal should output the following: /Users/your_user_name/dev/zlib/build/example zlib version 1.2.11 = 0x12b0, compile flags = 0xa9 uncompress(): hello, hello! gzread(): hello, hello! gzgets() after gzseek: hello! inflate(): hello, hello! large_inflate(): OK after inflateSync(): hello, hello! inflate with dictionary: hello, hello!

You can also allow the extension to connect to your personal GitHub account in order to checkout your own repositories:

  1. In the Command Pallet, select option Clone from GitHub.
  2. The extension ‘GitHub’ may request your to sign in to GitHub.
    1. Click Allow button.
    2. A Safari window will open which request Authorization for Visual Studio Code to access GitHub.
    3. Click Continue button.
    4. Enter your GitHub credentials and click on Sign In button.
    5. Read the given permissions and click on Authorize github.
    6. In the Safari window, note Your Authorization Token. It should look like the following: vscode://vscode.github-authentication/did-authenticate?windowid=1&code=ca7506dce69e40699277&state=5c05c8f1-9af0-4630-b257-3fe8adeb9a75.
    7. To use the token, in Visual Studio Code, click Signing in to github.com… in the status bar.
    8. Paste the token and hit enter.
  3. In Visual Studio Code, allow the extension to open your token url.
    1. Check Don’t ask again for this extension.
    2. Click the Open button.
  4. Select the location where to checkout the repository. For example, ~/dev/mygithubrepositories.

Cloning GitHub repo with Visual Studio Code

At the time of this writing, when a user clone one of his own GitHub repository using Visual Studio Code, the URL used for cloning is in format https://github.com/<Username>/<Project>.git instead of using the url in format git@github.com:<Username>/<Project>.git. Using the https url force users to enter their GitHub username and password everytime they want to push changes to GitHub.

You can validate the remote origin url with the following command :
git config --get remote.origin.url.

To get around this, one must change the remote url format from https://github.com/<Username>/<Project>.git to git@github.com:<Username>/<Project>.git. The instructions for this are explained in Push to GitHub without a password using ssh-key.

Enter the following command to change the remote origin url :
git remote set-url origin git@github.com:<Username>/<Project>.git
where <Username> and <Project> are replaced with the correct values.

How to encode command line parameters on Windows – done right

How to encode command line parameters on Windows – done right

Introduction

This post is a follow up on command line arguments. I recently published a C++ library (libArgvCodec) which properly handles all encoding and decoding of command line arguments. It is much safer to use the library than simply wrap each argument with double quotes.

This post is about the list of rules that the library implements for encoding and decoding of arguments.

Keep reading How to encode command line parameters on Windows – done right ?

libArgvCodec – A c++ library which properly encode and decode command line arguments

Introduction

This post is about a decade old problem: how to properly encode command line arguments. Properly encoding string arguments into a long command line should not be a complicated issue. However, I have seen multiple situations where people wrongfully assume that wrapping each argument with double quotes is ‘safe enough’ for most situations. That is simply not true.

Keep reading libArgvCodec – A c++ library which properly encode and decode command line arguments ?

libvariant c++ library

libVariant – A c++ library which encapsulate any value of variant types

Introduction

The following article is about my new c++ library: libVariant. The library allows one to easily store/encapsulate a value of any c++ type into an instance of type Variant. The library is useful for declaring objects, interfaces, APIs or plugins to be type-independent.

Keep reading libVariant – A c++ library which encapsulate any value of variant types ?

Déballage et assemblage du Radian Pro – Un planeur hors pair

Voici un autre modèle d’avion que j’ai assemblé: le planeur Radian Pro de ParkZone.

C’est un excellent appareil. Je le recommande fortement. Lorsque je le pilote, je dois m’apporter une chaise afin de m’asseoir parce qu’une fois que cet oiseau est dans les airs, il ne veut juste plus redescendre au sol. Il faut s’armer de patience.

Le tout présenté en time lapse.

Lire la suite de Déballage et assemblage du Radian Pro – Un planeur hors pair ?

Assemblage du quadrirotor F450 – Mon premier drone

J’ai fait l’acquisition de mon premier quadrirotor. Puisque je préfère de loin les options DIY, j’ai décidé de ne pas acheter un modèle RTF (ready-to-fly) et de plutôt opter pour un modèle livré à la maison en pièce détachée.

Tous comme avec mon Avistar Elite, j’ai capturé le déballage et l’assemblage de l’engin sur photos afin de réaliser un vidéo time lapse.

Pour le plaisir de vos yeux, voici le vidéo démontrant le déballage et l’assemblage de mon premier quadrirotor.

Lire la suite de Assemblage du quadrirotor F450 – Mon premier drone ?

Exemple de d'affichage toutes les polices

Comment afficher un exemple de toutes les polices dans Microsoft Word

Introduction

À chaque fois que je travail en graphisme et que je dois ajouter du texte à une image, je me retrouve toujours avec le même problème: “Comment faire pour identifier rapidement la meilleure police pour mon affiche ?”

Je crois maintenant avoir finalement trouver la solution à ce problème.

Lire la suite de Comment afficher un exemple de toutes les polices dans Microsoft Word ?

DIY lost plane alarm finder and 10 watts LED visual aids for easy orientation

Introduction

The reason I started this project is because I recently had a bad experience flying a quadcopter too far from me until I was not able to distinguish if the quad was facing me or not. It does not require much distance before a quadcopter looks like a tiny black dot in the sky. Basically, I lost orientation of the quad and I had to land way too far from my takeoff location.

I was in need of more tools (or more ways) to help myself when I will inevitably get into this situation again. The following project explains how I build a DIY solution to help a pilot know a quadcopter orientation when its far away from the point of view and easily locate the quadcopter in case of emergency landing.

Keep reading DIY lost plane alarm finder and 10 watts LED visual aids for easy orientation ?