Keil C options-->user-->after build
使用 fromelf 轉換格式…
fromelf --elf --output=$L@L.elf #L
2019年7月8日 星期一
2019年4月10日 星期三
Flutter/Dart神奇的語法
習慣傳統程式語言,這種的初看像謎之符號,細看覺得神奇!!
Future <bool> ShowYesNoDialog(
BuildContext context,
doYes,
doNo
) async
{
return showDialog(
context: context,
builder: (context) => AlertDialog(
actions: <Widget>[
RaisedButton(
onPressed: ((){doYes();}),
),
RaisedButton(
onPressed: ((){doNo();}),
),
],
),
) ??
false;
}
await ShowYesNoDialog(
context, 'SayYesNo', 'Yes or No?',
((){print('yes');}),
((){print('no')}),
);
2019年3月29日 星期五
python 處理 word 表格
# coding=utf-8
import docx
import glob
import os
import csv
#設置檔案路徑
path = '範例檔'
#設置輸出檔名
output = 'output.csv'
#開啟輸出的 CSV 檔案
with open(output, 'w', newline='') as csvfile:
#建立 CSV 檔寫入器
writer = csv.writer(csvfile)
#header
writer.writerow(['檔名','學校','班級','學生','國語','數學','社會','自然','藝術'])
for filename in glob.glob(os.path.join(path, '*.docx')): #遍歷所有檔案
#doc = docx.Document("範例檔\su_sn_11122.docx")
doc = docx.Document(filename)
for table in doc.tables: #遍歷所有表格
print("--------")
_school = ''
_class = ''
_student = ''
_score1 = ''
_score2 = ''
_score3 = ''
_score4 = ''
_score5 = ''
done = False
i = 0
for row in table.rows: #遍歷表格的所有 row
#row_str = "\t".join([cell.text for cell in row.cells]) # 一行數據
#print(row_str)
j = 0
for cell in row.cells: #遍歷 row 中所有 cell
#print( cell.text + "\t" )
#print( str(i)+":"+str(j)+":"+table.cell( i, j ).text + "\t" )
if cell.text == '學校':
_school = table.cell( i, j+1 ).text #抓右邊的 cell
if cell.text == '班級':
_class = table.cell( i, j+1 ).text #抓右邊的 cell
if cell.text == '學生':
_student = table.cell( i, j+1 ).text #抓右邊的 cell
if cell.text == '國語':
_score1 = table.cell( i+1, j ).text #抓下面的 cell
if cell.text == '數學':
_score2 = table.cell( i+1, j ).text #抓下面的 cell
if cell.text == '社會':
_score3 = table.cell( i+1, j ).text #下面的 cell
if cell.text == '自然':
_score4 = table.cell( i+1, j ).text #抓下面的 cell
if cell.text == '藝術':
_score5 = table.cell( i+1, j ).text #抓下面的 cell
done = True #這是最後一筆資料
j = j + 1 #指向下一 cell
if done:
break #完成
i = i + 1 #指向下一 row
if done:
break #完成
print( _school )
print( _class )
print( _student )
print( _score1 )
print( _score2 )
print( _score3 )
print( _score4 )
print( _score5 )
with open('output.csv', 'a', newline='') as csvfile:
#建立 CSV 檔寫入器
writer = csv.writer(csvfile)
#內容
writer.writerow([filename,_school,_class,_student,_score1,_score2,_score3,_score4,_score5])
break #限制1檔1表
import docx
import glob
import os
import csv
#設置檔案路徑
path = '範例檔'
#設置輸出檔名
output = 'output.csv'
#開啟輸出的 CSV 檔案
with open(output, 'w', newline='') as csvfile:
#建立 CSV 檔寫入器
writer = csv.writer(csvfile)
#header
writer.writerow(['檔名','學校','班級','學生','國語','數學','社會','自然','藝術'])
for filename in glob.glob(os.path.join(path, '*.docx')): #遍歷所有檔案
#doc = docx.Document("範例檔\su_sn_11122.docx")
doc = docx.Document(filename)
for table in doc.tables: #遍歷所有表格
print("--------")
_school = ''
_class = ''
_student = ''
_score1 = ''
_score2 = ''
_score3 = ''
_score4 = ''
_score5 = ''
done = False
i = 0
for row in table.rows: #遍歷表格的所有 row
#row_str = "\t".join([cell.text for cell in row.cells]) # 一行數據
#print(row_str)
j = 0
for cell in row.cells: #遍歷 row 中所有 cell
#print( cell.text + "\t" )
#print( str(i)+":"+str(j)+":"+table.cell( i, j ).text + "\t" )
if cell.text == '學校':
_school = table.cell( i, j+1 ).text #抓右邊的 cell
if cell.text == '班級':
_class = table.cell( i, j+1 ).text #抓右邊的 cell
if cell.text == '學生':
_student = table.cell( i, j+1 ).text #抓右邊的 cell
if cell.text == '國語':
_score1 = table.cell( i+1, j ).text #抓下面的 cell
if cell.text == '數學':
_score2 = table.cell( i+1, j ).text #抓下面的 cell
if cell.text == '社會':
_score3 = table.cell( i+1, j ).text #下面的 cell
if cell.text == '自然':
_score4 = table.cell( i+1, j ).text #抓下面的 cell
if cell.text == '藝術':
_score5 = table.cell( i+1, j ).text #抓下面的 cell
done = True #這是最後一筆資料
j = j + 1 #指向下一 cell
if done:
break #完成
i = i + 1 #指向下一 row
if done:
break #完成
print( _school )
print( _class )
print( _student )
print( _score1 )
print( _score2 )
print( _score3 )
print( _score4 )
print( _score5 )
with open('output.csv', 'a', newline='') as csvfile:
#建立 CSV 檔寫入器
writer = csv.writer(csvfile)
#內容
writer.writerow([filename,_school,_class,_student,_score1,_score2,_score3,_score4,_score5])
break #限制1檔1表
2019年3月15日 星期五
Modbus 傳輸資料型態轉換
Modbus 協議傳輸的資料一般只有基本的 U16 型態,但在實際應用上可能因裝置不同而有不同的應用,例如長整數、浮點數,但又因為硬體 CPU/MCU/OS 實際狀況而有位元順序的問題,底下是 python 轉換函式…
def Convert( theType, values ):
if( theType == 'FLOAT(ABCD)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[0],tobytes[1],tobytes[2],tobytes[3])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'FLOAT(CDAB)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[2],tobytes[3],tobytes[0],tobytes[1])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'FLOAT(BADC)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[1],tobytes[0],tobytes[3],tobytes[2])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'FLOAT(DCBA)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[3],tobytes[2],tobytes[1],tobytes[0])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'UINT32(ABCD)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[0],tobytes[1],tobytes[2],tobytes[3])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'UINT32(CDAB)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[2],tobytes[3],tobytes[0],tobytes[1])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'UINT32(BADC)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[1],tobytes[0],tobytes[3],tobytes[2])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'UINT32(DCBA)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[3],tobytes[2],tobytes[1],tobytes[0])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'INT32(ABCD)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[0],tobytes[1],tobytes[2],tobytes[3])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'INT32(CDAB)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[2],tobytes[3],tobytes[0],tobytes[1])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'INT32(BADC)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[1],tobytes[0],tobytes[3],tobytes[2])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'INT32(DCBA)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[3],tobytes[2],tobytes[1],tobytes[0])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'UINT16(AB)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[0],tobytes[1])
set_value = struct.unpack('>H', packit)[0]
elif( theType == 'UINT16(BA)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[1],tobytes[0])
set_value = struct.unpack('>H', packit)[0]
elif( theType == 'INT16(AB)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[0],tobytes[1])
set_value = struct.unpack('>h', packit)[0]
elif( theType == 'INT16(BA)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[1],tobytes[0])
set_value = struct.unpack('>h', packit)[0]
else:
set_value = values[0]
return set_value
#Modbus 讀值可能是 2byte 也可能是 4byte
values = [-4370,-8756]
Convert( 'FLOAT(ABCD)' ,values )
Convert( 'FLOAT(DCBA)' ,values )
Convert( 'FLOAT(BADC)' ,values )
Convert( 'FLOAT(CDAB)' ,values )
Convert( 'UINT32(ABCD)' ,values )
Convert( 'UINT32(DCBA)' ,values )
Convert( 'UINT32(BADC)' ,values )
Convert( 'UINT32(CDAB)' ,values )
Convert( 'INT32(ABCD)' ,values )
Convert( 'INT32(DCBA)' ,values )
Convert( 'INT32(BADC)' ,values )
Convert( 'INT32(CDAB)' ,values )
Convert( 'UINT16(AB)' ,values )
Convert( 'INT16(AB)' ,values )
Convert( 'INT16(BA)' ,values )
Convert( 'UINT16(BA)' ,values )
def Convert( theType, values ):
if( theType == 'FLOAT(ABCD)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[0],tobytes[1],tobytes[2],tobytes[3])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'FLOAT(CDAB)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[2],tobytes[3],tobytes[0],tobytes[1])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'FLOAT(BADC)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[1],tobytes[0],tobytes[3],tobytes[2])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'FLOAT(DCBA)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[3],tobytes[2],tobytes[1],tobytes[0])
set_value = struct.unpack('>f', packit)[0]
elif( theType == 'UINT32(ABCD)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[0],tobytes[1],tobytes[2],tobytes[3])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'UINT32(CDAB)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[2],tobytes[3],tobytes[0],tobytes[1])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'UINT32(BADC)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[1],tobytes[0],tobytes[3],tobytes[2])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'UINT32(DCBA)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[3],tobytes[2],tobytes[1],tobytes[0])
set_value = struct.unpack('>L', packit)[0]
elif( theType == 'INT32(ABCD)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[0],tobytes[1],tobytes[2],tobytes[3])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'INT32(CDAB)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[2],tobytes[3],tobytes[0],tobytes[1])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'INT32(BADC)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[1],tobytes[0],tobytes[3],tobytes[2])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'INT32(DCBA)' ):
packit = struct.pack('>hh',values[0],values[1])
tobytes = struct.unpack('>4c', packit)
packit = struct.pack('>4c',tobytes[3],tobytes[2],tobytes[1],tobytes[0])
set_value = struct.unpack('>l', packit)[0]
elif( theType == 'UINT16(AB)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[0],tobytes[1])
set_value = struct.unpack('>H', packit)[0]
elif( theType == 'UINT16(BA)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[1],tobytes[0])
set_value = struct.unpack('>H', packit)[0]
elif( theType == 'INT16(AB)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[0],tobytes[1])
set_value = struct.unpack('>h', packit)[0]
elif( theType == 'INT16(BA)' ):
packit = struct.pack('>h',values[0])
tobytes = struct.unpack('>2c', packit)
packit = struct.pack('>cc',tobytes[1],tobytes[0])
set_value = struct.unpack('>h', packit)[0]
else:
set_value = values[0]
return set_value
#Modbus 讀值可能是 2byte 也可能是 4byte
values = [-4370,-8756]
Convert( 'FLOAT(ABCD)' ,values )
Convert( 'FLOAT(DCBA)' ,values )
Convert( 'FLOAT(BADC)' ,values )
Convert( 'FLOAT(CDAB)' ,values )
Convert( 'UINT32(ABCD)' ,values )
Convert( 'UINT32(DCBA)' ,values )
Convert( 'UINT32(BADC)' ,values )
Convert( 'UINT32(CDAB)' ,values )
Convert( 'INT32(ABCD)' ,values )
Convert( 'INT32(DCBA)' ,values )
Convert( 'INT32(BADC)' ,values )
Convert( 'INT32(CDAB)' ,values )
Convert( 'UINT16(AB)' ,values )
Convert( 'INT16(AB)' ,values )
Convert( 'INT16(BA)' ,values )
Convert( 'UINT16(BA)' ,values )
2019年1月23日 星期三
Holtek 使用 HSI 的方式
Holtek 使用 HSI 的方式…
以 HT32f2220 為例
從 project_template 建立專案的話,修改底下 define …
在 system_ht32f5xxxx_02.c 中…
#define HSI_ENABLE (1) /*!< 0: DISABLE, 1: ENABLE */
#define HSE_ENABLE (0) /*!< 0: DISABLE, 1: ENABLE */
#define LSI_ENABLE (1) /*!< 0: DISABLE, 1: ENABLE */
#define LSE_ENABLE (0) /*!< 0: DISABLE, 1: ENABLE */
#define PLL_ENABLE (1) /*!< 0: DISABLE, 1: ENABLE */
#define PLL_CLK_SRC (1) /*!< 0: HSE, 1: HSI */
以 HT32f2220 為例
從 project_template 建立專案的話,修改底下 define …
在 system_ht32f5xxxx_02.c 中…
#define HSI_ENABLE (1) /*!< 0: DISABLE, 1: ENABLE */
#define HSE_ENABLE (0) /*!< 0: DISABLE, 1: ENABLE */
#define LSI_ENABLE (1) /*!< 0: DISABLE, 1: ENABLE */
#define LSE_ENABLE (0) /*!< 0: DISABLE, 1: ENABLE */
#define PLL_ENABLE (1) /*!< 0: DISABLE, 1: ENABLE */
#define PLL_CLK_SRC (1) /*!< 0: HSE, 1: HSI */
再直接使用 example 中的 SysClockConfig_HSI() 函式進入 HIS 模式即可。
這樣 XTALIN、XTALOUT 就能拿來當 gpio 腳了。
2018年11月21日 星期三
Debian Security Bug Tracker
檢查弱點分析的方式
到…
Debian Security Bug Tracker
https://security-tracker.debian.org/tracker/
查詢弱點…
譬如 CVE-2017-3169
Debian / Raspberry Pi 檢查版本
dpkg -l apache2
比較版本號是否有修正此 bug
到…
Debian Security Bug Tracker
https://security-tracker.debian.org/tracker/
查詢弱點…
譬如 CVE-2017-3169
Debian / Raspberry Pi 檢查版本
dpkg -l apache2
比較版本號是否有修正此 bug
2018年7月20日 星期五
備份 Raspberry Pi 時SD卡容量不相符的解決方式
備份回復 rpi image 的時候有時會遇到 sd card 雖號稱一樣 g 數,但實際大小卻不一樣,導致回復時出問題,此時可以用底下 scripts 解決,先把檔案變小就好解決… (linux 環境下)
Shrink your Raspberry Pi SD Card Image size
https://github.com/Drewsif/PiShrink
Very Nice !!
硬體從 rpi2 改到 rpi3
舊 SDCard 無法順利在 rpi3 開機的問題
apt-get install rpi-update
rpi-update
Shrink your Raspberry Pi SD Card Image size
https://github.com/Drewsif/PiShrink
Very Nice !!
硬體從 rpi2 改到 rpi3
舊 SDCard 無法順利在 rpi3 開機的問題
apt-get install rpi-update
rpi-update
訂閱:
文章 (Atom)
VirtualBox 空間減肥
@windows vm sdelete64 -z c: @macos VBoxManage modifymedium disk "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi" --compact *.vdi...
-
ARis... ARis 是日本一間公司出品的產品,應用了 ARToolKit 技術。 展示影片在這… http://www.youtube.com/watch?v=yCCx7zANsGE YouTube上可以找到更多類似的影片。 這邊是我用 FLARToolK...
-
install… sudo apt-get install bluez sudo hciconfig hci0 up scan… sudo hcitool lescan or scan if no response... sudo bluetoothctl ...
-
由於ASSEMBLA即將開始收費,因此要把所有的SVN進行大搬家,連帶的一些教學文件也跟著搬家了,看來還是GOOGLE的窩最舒適(重點是免費) FPPA實驗平台教學教材-使用C語言 FPPA實驗平台簡介 實驗(一) 8位元LED輸出單元 與 模組設計總論 實驗(二) 按鍵開關輸入...
