bloggerads

2021年6月26日 星期六

C/C++ in Arm Cross Compiler

in Arm, C++ compiler recognizes keyword: extern "C", and the Macro __cplusplus

In C header files, add __cplusplus to make sure the header files can be recognized by C++, as following

#ifdef  __cplusplus // This statement is true in C++ but false in C
extern "C"
{
#endif

//Original Header File Contents

#ifdef __cplusplus
}
#endif

In C++, 

If you'd like to include a C header file without changing the C header, you can do like:

extern "C"{
     #include "CHeader.h"
}

If you'd like to export a function to C, you can do like:

extern "C" int OutputApi(int);



<NOTE>
A header file can only be compiled one time.
So it is needed to add a pure C type header file additionally to designate what C++ exported functions.
This C type header file is actually included in other C source files. (not in C++)
Following are the workable method to achieve the C/C++ cross compiler in ARM.

a.cpp
void aa(void){}

a.h
#ifdef  __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
EXTERN_C  void aa(void);

intermediate.h
include <a.h>

b.c
include <intermediate.h>
void call_c()
{
    aa();
}

2021年2月24日 星期三

Plant UML Example


PlantText UML Editor: https://www.planttext.com/

Flow Chart
@startuml
(*) --> "A example of a step"
    if "Is This is a good example?" then
        --> [Yes] "Copy it"
        -->(*)
    else
        --> [No] "Drop it!"
        -->(*)
    endif
@enduml


@startuml
participant User
 
User -> A1
activate A

-> B2
activate B

-> C3
activate C

C --> B: end3
destroy C

B --> A: end2
deactivate B

-> User: end1
deactivate A
 
@enduml



@startuml
A : A's property
B : B's property
C : C's property
[*] --> A : start to A
[*] --> B : start to B
A --> B : A to B
B --> C : B to C
C --> B : C to B
C --> C : C to C
@enduml

2024/05/21
Set arrow color & set contents color
skinparam arrowColor #blue
AAA-->BBB:  <color:blue> Description
AAA-[#red]->BBB:  Description

2017年10月3日 星期二

Python : struct

這篇說明 Python 要如何像C/C++一樣,將struct資料以binary的形式寫入檔案。
參考以下範例:

#! python2
""" Author: Martin Lee """
import struct
with open('out.bin','wb') as f:
    f.write(struct.pack('B8sHHL', 22, 'Hi World', 1, 2, 0x3322))

fin = open("out.bin", "rb")
i = struct.unpack('B8sHHL', fin.read())
fin.close()

2017年9月17日 星期日

Python : 使用 py2exe 打包 py檔成執行檔

Windows下將py檔打包成執行檔, 以python 2.7為範例

基本上是參考 http://www.py2exe.org/index.cgi/Tutorial

試過import 第三方模組、內建的GUI 模組(Tkinter)、自定義的模組, py2exe 都能打包。以下是流程:

1.安裝 py2exe

2.在要打包的py檔目錄下,新增一個'setup.py'檔,其內容為
  • from distutils.core import setup
  • import py2exe
  • setup(console=['要打包的檔名.py'])
3.python setup.py py2exe

4.會在同目錄下產生兩個資料夾,其一個新增的資料夾'dist'內會產生一個同檔名的exe檔

Linux下將py檔打包成執行檔, 以python 2.7為範例

1. 安裝 pyinstaller (pip install pyinstaller)
2. pyinstaller --onefile filename.py
3. 在同目錄下的dist資料夾內產生可執行檔 filename

2017年9月14日 星期四

Python : JSON

鑒於JSON愈來愈普及, 很多數據都要求使用JSON的格式,因此特別在這篇做個紀錄, 了解JSON以及如何用Python處理JSON。  

了解 JSON 的 format可以從這個
網站開始: http://jsoneditoronline.org/



#  JSON的規則:

1.  key:value
2.  value 型態可以是 數字, 字串, 布林, 陣列[], 物件{}, NULL, 但key一定是要字串
3.  同一個物件內的key不可重複, 如以下的 Age 就重複了
{
    "Martin": {
        "Age":33,
        "Age":5,
     }
}

2017年9月10日 星期日

Python : regular expression

re module的一些紀錄, 持續update

### Common use of the regular expression

\w   [a-zA-Z0-9_]
\d    [0-9]
\s    space
\\     '\'
.       ''
+     1 or more than 1
.\     everything

### Code

>>> import re
>>> string = 'Age=20'
>>> re.search('\d+', string).group()
20

>>> import re
>>> string = 'Beautiful, is; better*than\nugly'
>>> # 分隔符號:,  ;  *  \n
>>> list= re.split(',|; |\*|\n', string)
>>> list
['Beautiful', 'is', 'better', 'than', 'ugly']

2017年9月5日 星期二

Python : Combobox 範例

距離上次Python文,不知不覺又過了兩三個星期了。 時間過得真快,這段時間除了工作外,還去了花蓮玩兩天! 雖然工作上每天都在改code, 但使用到Python的機會很少,本著學海無涯,惟勤是岸的精神,隔一段時間就來po 一下,以免生疏了。今天介紹Combobox,搭配Button作範例,話不多說,馬上端上code:

#! python2
# coding: utf-8

import Tkinter as tk
import ttk   

def clickOkButton():
    print 'Select ' + str(numberChosen.current()) # 丟出選到的index number

win = tk.Tk()
win.title("Python Combobox example")