Advance C/C++ lang topics

// Here we can see that more than one variables
// are being used without reporting any error.
// That is because they are declared in the
// different namespaces and scopes.
#include <iostream>
using namespace std;

// Variable created inside namespace
namespace first
{
int val = 500;
}

// Global variable
int val = 100;

int main()
{
// Local variable
int val = 200;

// These variables can be accessed from
// outside the namespace using the scope
// operator ::
cout << first::val << ‘\n’;

return 0;
}

C++[] –> namespace is like a named-scope, so you can use it kind of like everywhere

CNU library

https://www.gnu.org/software/libc/manual/html_node/Getopt.html

More about C/C++ library

https://www.tutorialspoint.com/c_standard_library/index.htm

https://www.tutorialspoint.com/cpp_standard_library/index.htm

Advertisements

WSL (Windows Subsystem Linux)

on Windows 10: install via store

on Powershell: enter the command

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

 

To run linux command on cmd::::

wsl ls -la

wsl xxxxxxx

 

To run windows command on WSL:::::

cmd.exe /C dir

or

PING.exe , ipconfig.exe

(( this depended on if the command has file extension or a bat file.

 

Basic thing, telegram on NodeMCU

Example used: HTTPSRequest

/*
HTTP over TLS (HTTPS) example sketch

This example demonstrates how to use
WiFiClientSecure class to access HTTPS API.
We fetch and display the status of
esp8266/Arduino project continuous integration
build.

Limitations:
only RSA certificates
no support of Perfect Forward Secrecy (PFS)
TLSv1.2 is supported since version 2.4.0-rc1

Created by Ivan Grokhotkov, 2015.
This example is in public domain.
*/

telegram:
get Info of bot: https://api.telegram.org/bot<YOUR-BOT-TOKEN>/getme

SendMessage: http://api.telegram.org/bot<YOUR-BOT-TOKEN>/sendMessage?chat_id=<YOUR-CHATID>&text=HelloFromESP8266

ReceiveMessage: https://api.telegram.org/bot<YOUR-BOT-TOKEN>/getUpdates

 

On the NodeMCU: Since it is HTTPS –> I cannot find a way to used it with AT COMMAND

Programming to NodeMCU:
HTTPSRequest:

–>fingerprint[] –> inside the Chrome –> certificate –> detail –> thumb print

 

GPRS A9 Module AT Command list

https://wiki.ai-thinker.com/gprs

//

AT+CGDCONT=1,”IP”,”cmhk”<\r><\n>
AT+CGATT=1<\r><\n>
AT+CGACT=1,1<\r><\n>

//

AT+CDNSGIP=”erp.hkite.com”<\r><\n>

Test the DNS, and check with terminal

host -a erp.hkite.com

//Base station location

+CREG: 2,1,”00A0″,”0D37″<\r><\n>
<\r><\n>
OK<\r><\n>

http://www.gpsspg.com/bs.htm

MCC:454 -> HK//http://www.gpsspg.com/bs/mcc.htm

MNC: 12 -> CMHK//http://www.gpsspg.com/bs/mnc.htm

LAC: 160 -> 0xA0

CI:3383 -> 0xD37

Google Cloud AutoML test

Overview:

Google 機器學習三大服務:AutoML, Cloud ML Engine, ML API 介紹與比較

screenshot:

https://docs.google.com/presentation/d/1KCSoR_aG-yn_vPBYFlLTzQdBAlBcdQgRYp5zdgH5IFA/edit?usp=sharing

Cloud AutoML Vision Object Detection

https://cloud.google.com/vision/automl/object-detection/docs/?_ga=2.244268482.-671499862.1555384491

With my training data: https://cloud.google.com/vision/automl/object-detection/docs/prepare

Getting Started on Sipeed MAIX M1

https://item.taobao.com/item.htm?id=578484113485
Link of the product.

Sipeed MAIX M1 is a SoC of the kendryte K210: https://kendryte.com/
Sipeed is AI enabler https://www.sipeed.com/#/

When if ship, it has Maxipy flashed inside the SoC. Connect to the PC via USB cable, connect with UART, putty (success)

MaixPy 是将 Micropython 移植到 K210( 一款64位双核带硬件FPU和卷积加速器的 RISC-V CPU, ) 的一个项目.
https://micropython.org/
https://maixpy.sipeed.com/zh/
https://github.com/sipeed/MaixPy —-> source code

About the chip:
https://github.com/kendryte/
https://kendryte.com/downloads/

About the M1 SoC: https://maixpy.sipeed.com/assets/M1_pin.png

—-> doc from the sipeed
http://dl.sipeed.com/

FreeRTOS on Arduino

https://github.com/feilipu/Arduino_FreeRTOS_Library

#include
#include // add the FreeRTOS functions for Semaphores (or Flags).

//===create task===
void TaskBlink( void *pvParameters );
void TaskAnalogRead( void *pvParameters );
void TaskDigitalRead( void *pvParameters );

void setup(){

//===create task event
xTaskCreate(
TaskBlink
, (const portCHAR *)”Blink” // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 2 // Priority, with 3 (configMAX_PRIORITIES – 1) being the highest, and 0 being the lowest.
, NULL );

}

void loop(){}

//====everything is in task
void TaskAnalogRead(void *pvParameters) // This is a task.
{
(void) pvParameters;

/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

for (;;)
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
}
}

===========
#include // add the FreeRTOS functions for Semaphores (or Flags).

// Declare a mutex Semaphore Handle which we will use to manage the Serial Port.
// It will be used to ensure only only one Task is accessing this resource at any time.
SemaphoreHandle_t xSerialSemaphore;

void setup(){
// Semaphores are useful to stop a Task proceeding, where it should be paused to wait,
// because it is sharing a resource, such as the Serial port.
// Semaphores should only be used whilst the scheduler is running, but we can set it up here.
if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created.
{
xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port
if ( ( xSerialSemaphore ) != NULL )
xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by “Giving” the Semaphore.
}
}

so… to check

// See if we can obtain or “Take” the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 );
–> will return pdTRUE/pdFALSE
xSemaphoreGive( xSerialSemaphore ); // Now free or “Give” the Serial Port for others.

if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or “Take” the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don’t want it getting stolen during the middle of a conversion.
// print out the value you read:
Serial.println(sensorValue);

xSemaphoreGive( xSerialSemaphore ); // Now free or “Give” the Serial Port for others.
}

//==end of the example of the arduino freeRTOS

Flow of doing that:
– Task function declaration
– create task in the setup
– write the task function

Generally in FreeRTOS

int main(void){
prvSetupHardwar(); //perform hardware setup
//create task here
//======end=====
vTaskStartScheduler(); /start the created tasked
while(1);
return 0;
}

the naming of the FreeRTOS
c: char, s: short(int16_t), l: long(int32_t), x: BaseType_t
uc: unsigned char(uint8_t), pc: pointer2char

pdTRUE, pdFALSE: 1,0
pdPASS, pdFAIL: 1,0

For Task Management
void

ATmel studio, ASF compare, HAL vs HPL

There are few people talk about the structure of the atmel studio code set.

I look through the library and the document and give the following result.

http://www.microchip.com/avr-support/advanced-software-framework-(asf)
https://www.microchip.com/mplab/avr-support/advanced-software-framework
http://ww1.microchip.com/downloads/en/DeviceDoc/50002633A.pdf

Advanced Software Framework(ASF) is the framwork used by Mircochip for Atmel product

ASF4 must be used in conjunction with Atmel START, which replaces the ASF Wizard of ASF3.

After configuring in the Atmel START, you can see a list of library inside the folder.

列出磁碟區 Windows 的資料夾 PATH
磁碟區序號為 EE0C-64C1
C:.
├─.atmel-start-backup
├─.atmelstart
├─Config
├─Debug
│ ├─Config
│ ├─Device_Startup
│ ├─examples
│ ├─hal
│ │ ├─include
│ │ ├─src
│ │ └─utils
│ │ ├─include
│ │ └─src
│ ├─hpl
│ │ ├─adc
│ │ ├─core
│ │ ├─dmac
│ │ ├─gclk
│ │ ├─mclk
│ │ ├─osc32kctrl
│ │ ├─oscctrl
│ │ ├─pm
│ │ ├─port
│ │ ├─rtc
│ │ ├─sercom
│ │ ├─systick
│ │ ├─tc
│ │ └─wdt
│ └─hri
├─Device_Startup
├─examples
├─hal
│ ├─include
│ ├─src
│ └─utils
│ ├─include
│ └─src
├─hpl
│ ├─adc
│ ├─core
│ ├─dmac
│ ├─gclk
│ ├─mclk
│ ├─osc32kctrl
│ ├─oscctrl
│ ├─pm
│ ├─port
│ ├─rtc
│ ├─sercom
│ ├─systick
│ ├─tc
│ └─wdt
└─hri

atmel_start_pins.h –> let you find the name of the pin and use it in the program –> \param[in] pin The pin number for device, (const uint8_t pin)

(if middleware is used, it will be the toppest model)
Three main word appear:
• Hardware Abstraction Layer – HAL
Naming convention: HAL functions start with usecase_, for example: adc_dma_driver

• Hardware Proxy Layer – HPL
Naming convention: HPL functions start with _usecase_, for example: _usart_async_init()

• Hardware Register Interface – HRI
accessing the register.

PS, in the utils, it has list, marco, ringbuffer for you to use

Install uPython on NodeMCU

https://docs.micropython.org/en/latest/esp8266/tutorial/intro.html

highly Reference to this website
https://github.com/micropython/micropython
 

 

//===========

About the ESPtool

pip install esptool

inWindows, run as python module

python -m esptool xxxxxxxx

//======================

uPython for ESP8266

 

>>> import machine
>>> pin = machine.Pin(16, machine.Pin.OUT)
>>> pin.on()
>>> pin.off()

the help has the procedure to connect to the internet

import os
os.listdir() –> show the current file

dir()

The special variable _ –> store the last result

it has uos module for the os module

ctrl D is for restart
ctrl E is paste Mode, essentially turns off the auto-indent feature
ctrl A is in Raw REPL mode
Raw Mode
Raw mode is not something that a person would normally use. It is intended for programmatic use. It essentially behaves like paste mode with echo turned off.

Raw mode is entered using Ctrl-A. You then send your python code, followed by a Ctrl-D. The Ctrl-D will be acknowledged by ‘OK’ and then the python code will be compiled and executed. Any output (or errors) will be sent back. Entering Ctrl-B will leave raw mode and return the the regular (aka friendly) REPL

uos.listdir()
uos.mkdir(‘myDir’)
uos.chdir(‘..’)
uos.rmdir(‘myDir’)

//==============adafruit
ampy run –no-output xxx.py
ampy run -n xxx.py

–> to run the code on PC