星期五, 5月 15, 2020
星期五, 5月 08, 2020
Protocol Buffers
protobuf:
- https://yami.io/protobuf/
- https://github.com/protocolbuffers/upb
- https://jpa.kapsi.fi/nanopb/
- https://github.com/protobuf-c/protobuf-c
- *** pack , unpack, repeat, cross compilers ***
gRPC:
golang:
星期四, 5月 07, 2020
websocket library
websocket library:
- https://github.com/Theldus/wsServer/blob/master/README.md
- send_receive.html
- ./send_receive
Test by wscat:
- wscat -c ws://10.1.59.109:8080
Just check connection:
- curl --include \ --no-buffer \ --header "Connection: Upgrade" \ --header "Upgrade: websocket" \ --header "Host: example.com:80" \ --header "Origin: http://example.com:80" \ --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \ --header "Sec-WebSocket-Version: 13" \ http://example.com:80/
How to detect Linux memory leak?
https://blog.xuite.net/antony0604/blog/254546994
最近所參與開發的linux系統發生了,死機的情形. http 還可連入, 但整個動作非常的慢.
在console mode下, 打 top 命令也非常慢才出現, 而看不到任何一支程式吃掉CPU,
但system CPU 佔全部的 80% 以上. 之後再仔細看到memory free剩非常的少(跟剛開機的時侯相比)
故而懷疑是 memory leak 導致的, 於是寫了一支程式去吃記憶體, 複製發生異常時,情形是否一致.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
void main(){
printf("this program will eat memory 1M every 10 seconds\n");
int i = 0;
while (1){
i++;
sleep(10);
if (i<= 50) {
char* leak_mem;
leak_mem = malloc (1024*1024);
int iValue = i % 256;
memset(leak_mem,iValue,1024*1024);
int j=0;
for ( j=0; j< 1024*1024; j++)
{
leak_mem[j] = (iValue+j) % 256;
}
printf("%d. eat 1M memory now ... %d %d ~ %d %d \n", i,leak_mem[0],leak_mem[1],leak_mem[1024*1024-2],leak_mem[1024*1024-1]);
}
printf("this program will eat memory 1M every 10 seconds\n");
int i = 0;
while (1){
i++;
sleep(10);
if (i<= 50) {
char* leak_mem;
leak_mem = malloc (1024*1024);
int iValue = i % 256;
memset(leak_mem,iValue,1024*1024);
int j=0;
for ( j=0; j< 1024*1024; j++)
{
leak_mem[j] = (iValue+j) % 256;
}
printf("%d. eat 1M memory now ... %d %d ~ %d %d \n", i,leak_mem[0],leak_mem[1],leak_mem[1024*1024-2],leak_mem[1024*1024-1]);
}
}
printf("this program exit now \n");
}
printf("this program exit now \n");
}
由於Linux如果將吃掉記憶的程式砍掉的話, 其記憶體還是會被釋放回來, 故而當吃掉一定程度的記憶體之後, 即開始休息(不要離開程式, 否則會釋放回去). 另外allocate的記憶體須要memset,才會真的使用到.
可以用來看系統CPU分配的情形, 可以經由top 中的Load average, 其欄位分別記錄著過去時間有多少程式須共用一個CPU, 分別是1/5/15 分鐘. 也可經由下列指令得知 cat /proc/loadavg
另外top也可以有不同的排序方式 N/M/P/T (show CPU usage, sort by pid/mem/cpu/time) . 而top 也能看到記憶使用的仔細情形 ( S: show memory), 可以觀察到VSZ RSS 的使用情形.
想要得知某一程式有多少執行緒正在執行, 命令如下:
ps -T | grep process-name
如果要得知wis-stream 有多少個執行緒在執行, 則範例如下(除了主程式外還有四個子執行緒):
#
# ps -T | grep wis-stream
1376 root 56:19 /bin/wis-streamer
1377 root 0:01 /bin/wis-streamer
1378 root 0:00 /bin/wis-streamer
1379 root 0:00 /bin/wis-streamer
1380 root 0:00 /bin/wis-streamer
15792 root 0:00 grep wis-stream
#
#
# ps -T | grep wis-stream
1376 root 56:19 /bin/wis-streamer
1377 root 0:01 /bin/wis-streamer
1378 root 0:00 /bin/wis-streamer
1379 root 0:00 /bin/wis-streamer
1380 root 0:00 /bin/wis-streamer
15792 root 0:00 grep wis-stream
#
而要查看某一執行緒(pid) , 有執行那些 system call 的指令會特別佔用記憶體, 則用下列命令去查詢:
strace -c -p PidOfThread
strace此會attech 到此pid ,直到你中斷它的執行(Ctrl-C), 如要看上述wis-streamer的情形如下:
# strace -c -p 1376
Process 1376 attached - interrupt to quit
^CProcess 1376 detached
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
97.10 0.220000 280 785 select
2.90 0.006581 3 2501 gettimeofday
------ ----------- ----------- --------- --------- ----------------
100.00 0.226581 3286 total
#
Process 1376 attached - interrupt to quit
^CProcess 1376 detached
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
97.10 0.220000 280 785 select
2.90 0.006581 3 2501 gettimeofday
------ ----------- ----------- --------- --------- ----------------
100.00 0.226581 3286 total
#
可以得知大部分的CPU 都在執行select 這個system call 上面.
那些命令屬於 system call , 可以查詢下列網址 Linux System Call Table
要看記憶體使用的情形, 可以用下列命令:
free -m
cat /proc/meminfo
top (執行之後再按大寫 S)
pidstat -r 10 -p ALL
其中以 pidstat 較好用, 它可以看到所有程式佔用記憶體的情形
# pidstat -r 10 -p ALL
Linux 2.6.38.8 (VN-H228) 11/18/14 _armv6l_ (1 CPU)
Linux 2.6.38.8 (VN-H228) 11/18/14 _armv6l_ (1 CPU)
11:37:17 PID minflt/s majflt/s VSZ RSS %MEM Command
11:37:28 1 0.00 0.00 3272 700 0.66 linuxrc
11:37:28 823 0.00 0.00 2532 968 0.91 check_daemon
11:37:28 826 0.00 0.00 3784 1164 1.09 syslogd
11:37:28 828 0.00 0.00 3276 660 0.62 logger
11:37:28 830 0.00 0.00 12224 1476 1.39 topbus
11:37:28 837 0.10 0.00 60608 2988 2.81 topservice
11:37:28 842 0.00 0.00 3272 328 0.31 telnetd
11:37:28 843 0.00 0.00 3276 728 0.68 sh
11:37:28 874 0.00 0.00 0 0 0.00 loop0
11:37:28 875 0.00 0.00 0 0 0.00 ext4-dio-unwrit
11:37:28 943 0.00 0.00 0 0 0.00 dsplogd
11:37:28 944 0.00 0.00 0 0 0.00 vsyncd
11:37:28 958 0.00 0.00 0 0 0.00 hdmid
11:37:28 967 0.00 0.00 279680 1324 1.24 capture_server
11:37:28 979 0.00 0.00 164904 1056 0.99 encode_server
11:37:28 982 0.00 0.00 69304 1704 1.60 tv_3a_service
11:37:28 989 0.00 0.00 30872 3992 3.75 jackd
11:37:28 1028 0.00 0.00 18716 800 0.75 check_auth
11:37:28 1033 0.00 0.00 2300 672 0.63 detection
11:37:28 1036 0.00 0.00 2676 1128 1.06 fget
11:37:28 1039 0.00 0.00 2292 556 0.52 fset
11:37:28 1041 0.00 0.00 18596 848 0.80 ieee8021x
11:37:28 1104 0.00 0.00 2436 780 0.73 yaweb
11:37:28 1120 0.00 0.00 60444 788 0.74 ftp_service
11:37:28 1122 0.00 0.00 60460 712 0.67 email_service
11:37:28 1124 0.00 0.00 18388 540 0.51 sd_service
11:37:28 1126 0.00 0.00 43256 968 0.91 event_service
11:37:28 1155 0.00 0.00 30128 1136 1.07 subscriberman
11:37:28 1157 0.10 0.00 26668 760 0.71 tv_wsdiscovery
11:37:28 1159 0.00 0.00 1868 412 0.39 dbgsvr
11:37:28 1161 0.00 0.00 18392 620 0.58 FocusAssist
11:37:28 1163 0.00 0.00 18396 620 0.58 alarmserver
11:37:28 1169 0.00 0.00 18428 564 0.53 scan_port
11:37:28 1171 0.00 0.00 48360 2324 2.18 audio_server
11:37:28 1173 0.00 0.00 23780 2180 2.05 jvc_audio_clien
11:37:28 1175 0.00 0.00 40176 2212 2.08 audio_read
11:37:28 1204 0.00 0.00 21800 492 0.46 subscriberman
11:37:28 1213 0.00 0.00 18500 664 0.62 jvc_search
11:37:28 1234 0.00 0.00 18500 664 0.62 jvc_search
11:37:28 1246 0.29 0.00 12072 4008 3.77 upnpd
11:37:28 1272 0.00 0.00 43020 796 0.75 rtsp_client
11:37:28 1281 0.00 0.00 10204 624 0.59 ipfinder
11:37:28 1316 0.00 0.00 24604 4176 3.92 snmpd
11:37:28 1376 0.00 0.00 93700 1828 1.72 wis-streamer
11:37:28 1619 0.00 0.00 5736 2032 1.91 lighttpd
11:37:28 1660 0.00 0.00 79444 1972 1.85 rtsp_over_http
11:37:28 1774 0.00 0.00 82516 1808 1.70 rtsp_over_http
11:37:28 6321 0.00 0.00 0 0 0.00 kworker/0:0
11:37:28 7513 0.00 0.00 0 0 0.00 kworker/0:4
11:37:28 15898 0.00 0.00 0 0 0.00 flush-ubifs_0_0
11:37:28 15899 0.00 0.00 0 0 0.00 flush-7:0
11:37:28 1 0.00 0.00 3272 700 0.66 linuxrc
11:37:28 823 0.00 0.00 2532 968 0.91 check_daemon
11:37:28 826 0.00 0.00 3784 1164 1.09 syslogd
11:37:28 828 0.00 0.00 3276 660 0.62 logger
11:37:28 830 0.00 0.00 12224 1476 1.39 topbus
11:37:28 837 0.10 0.00 60608 2988 2.81 topservice
11:37:28 842 0.00 0.00 3272 328 0.31 telnetd
11:37:28 843 0.00 0.00 3276 728 0.68 sh
11:37:28 874 0.00 0.00 0 0 0.00 loop0
11:37:28 875 0.00 0.00 0 0 0.00 ext4-dio-unwrit
11:37:28 943 0.00 0.00 0 0 0.00 dsplogd
11:37:28 944 0.00 0.00 0 0 0.00 vsyncd
11:37:28 958 0.00 0.00 0 0 0.00 hdmid
11:37:28 967 0.00 0.00 279680 1324 1.24 capture_server
11:37:28 979 0.00 0.00 164904 1056 0.99 encode_server
11:37:28 982 0.00 0.00 69304 1704 1.60 tv_3a_service
11:37:28 989 0.00 0.00 30872 3992 3.75 jackd
11:37:28 1028 0.00 0.00 18716 800 0.75 check_auth
11:37:28 1033 0.00 0.00 2300 672 0.63 detection
11:37:28 1036 0.00 0.00 2676 1128 1.06 fget
11:37:28 1039 0.00 0.00 2292 556 0.52 fset
11:37:28 1041 0.00 0.00 18596 848 0.80 ieee8021x
11:37:28 1104 0.00 0.00 2436 780 0.73 yaweb
11:37:28 1120 0.00 0.00 60444 788 0.74 ftp_service
11:37:28 1122 0.00 0.00 60460 712 0.67 email_service
11:37:28 1124 0.00 0.00 18388 540 0.51 sd_service
11:37:28 1126 0.00 0.00 43256 968 0.91 event_service
11:37:28 1155 0.00 0.00 30128 1136 1.07 subscriberman
11:37:28 1157 0.10 0.00 26668 760 0.71 tv_wsdiscovery
11:37:28 1159 0.00 0.00 1868 412 0.39 dbgsvr
11:37:28 1161 0.00 0.00 18392 620 0.58 FocusAssist
11:37:28 1163 0.00 0.00 18396 620 0.58 alarmserver
11:37:28 1169 0.00 0.00 18428 564 0.53 scan_port
11:37:28 1171 0.00 0.00 48360 2324 2.18 audio_server
11:37:28 1173 0.00 0.00 23780 2180 2.05 jvc_audio_clien
11:37:28 1175 0.00 0.00 40176 2212 2.08 audio_read
11:37:28 1204 0.00 0.00 21800 492 0.46 subscriberman
11:37:28 1213 0.00 0.00 18500 664 0.62 jvc_search
11:37:28 1234 0.00 0.00 18500 664 0.62 jvc_search
11:37:28 1246 0.29 0.00 12072 4008 3.77 upnpd
11:37:28 1272 0.00 0.00 43020 796 0.75 rtsp_client
11:37:28 1281 0.00 0.00 10204 624 0.59 ipfinder
11:37:28 1316 0.00 0.00 24604 4176 3.92 snmpd
11:37:28 1376 0.00 0.00 93700 1828 1.72 wis-streamer
11:37:28 1619 0.00 0.00 5736 2032 1.91 lighttpd
11:37:28 1660 0.00 0.00 79444 1972 1.85 rtsp_over_http
11:37:28 1774 0.00 0.00 82516 1808 1.70 rtsp_over_http
11:37:28 6321 0.00 0.00 0 0 0.00 kworker/0:0
11:37:28 7513 0.00 0.00 0 0 0.00 kworker/0:4
11:37:28 15898 0.00 0.00 0 0 0.00 flush-ubifs_0_0
11:37:28 15899 0.00 0.00 0 0 0.00 flush-7:0
如果有那支程式的RSS欄位一直在增長, 則表示此程序有可能是造成memory leak的元凶.此處不能光看VSZ欄位, 因為VSZ 有可能只是allocate memory, 但並沒有真的使用它.
而RSS欄位的增長有時是因為使用到ShareMemory的關後, 所以要配合看free memory是否有減少, 才能正確判斷是否一直吃記憶體.
PS 2019/6/18: 如果採用ram拿來當linux aufs , 則檔案一直寫入增大的話, 會導致memory cache一直增大; 最後可用的記憶體會被吃光而當機. 所以不能有任何程式一直讓檔案變大.
另外, 試了 valgrind , 可以用來偵測 memory leak的問題. 但由於ld-uClibc-0.9.33.2.so 是stripped, 所以cross-compile之後無法有效偵測memory.
d-uClibc-0.9.33.2.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, stripped
2 - 不要使用完全剝離的Linux發行版/lib/ld.so。(比如上面的getoff-arm-linux 就連結了 /lib/ld-uClibc.so.0, 那就要求我們的開發板根目錄下的/lib/ld-uClibc.so.0 必須是 not stripped)
2 - 不要使用完全剝離的Linux發行版/lib/ld.so。(比如上面的getoff-arm-linux 就連結了 /lib/ld-uClibc.so.0, 那就要求我們的開發板根目錄下的/lib/ld-uClibc.so.0 必須是 not stripped)
refernce of valgrind as follow:
星期二, 5月 05, 2020
DBUS
sd-bus
- http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html
- https://bryceknowhow.blogspot.com/2017/09/linux-ubuntuinter-process-communication.html
libdbus
gdbus:
- gdbus demo程序简介 gdbus-codegen
- GIO Reference Manual
Performance:
星期五, 4月 17, 2020
gstreamer H264 rtmp
gstreamer读取USB摄像头H264帧并用rtmp推流
relay server
experimental:
relay server
experimental:
- relay:
- ./rtsp-simple-server&
- source:
- ./ffmpeg -re -stream_loop -1 -i "../608798609.972728.mp4" -codec copy -f rtsp rtsp://10.1.59.111:8554/mystream&
- broker:
- ./ffmpeg -rtsp_transport tcp -i rtsp://10.1.59.111:8554/mystream -codec copy -f rtsp rtsp://@10.1.59.111:8554/test
Reference:
星期四, 4月 09, 2020
[Linux] 計算程式運行的最低需求(Code size & Shared libraries) @ Ubuntu 12.04
[Linux] 計算程式運行的最低需求(Code size & Shared libraries) @ Ubuntu 12.04
新版部落格:blog.changyy.org
git clone https://github.com/changyy/resource-calculator.git
$ ./resource-calculator/resource-calculator.sh
Usage> ./resource-calculator.sh -v -r path_bin_readelf -s path_bin_strip -o output_dir -l path_for_library_finding [ BIN_FILE | BIN_DIR | LIB_FILE | LIB_DIR ] ...
$ ./resource-calculator/resource-calculator.sh
Usage> ./resource-calculator.sh -v -r path_bin_readelf -s path_bin_strip -o output_dir -l path_for_library_finding [ BIN_FILE | BIN_DIR | LIB_FILE | LIB_DIR ] ...
其中 -r 是吃 readelf 工具位置,可以用 -r `which armv6-linux-gnueabi-readelf`;-s 是指定 strip 位置,也就是產出時順便 strip 一下;-o 則是輸出到指定輸出目錄;-l 是指定讀取 shared library 位置,如 cross compiler 的 library 位置、platform sysroot/lib 位置和第三方 shared library 位置等;最後的參數則是要驗證的 tool 或 library ,若接目錄則是進去撈 bin 或 so 出來。
實例 (已在 PATH 環境變數中加入 cross compiler 的搜尋位置):
$ ./resource-calculator/resource-calculator.sh -o /tmp/output -r `which armv6-linux-gnueabi-readelf` -s `which armv6-linux-gnueabi-strip` -l /path/armv6-linux-gnueabi/compiler/lib -l /path/armv6-linux-gnueabi/platform/sysroot/lib -l /path/armv6-linux-gnueabi/3rd-party/lib /path/imagemagick-convert
[INFO] READELF: /path/armv6-linux-gnueabi-readelf
[INFO] STRIP: /path/armv6-linux-gnueabi-strip
[INFO] OTHER LIB: /path/armv6-linux-gnueabi/compiler/lib /path/armv6-linux-gnueabi/platform/sysroot/lib /path/armv6-linux-gnueabi/3rd-party/lib
[INFO] TARGET: /path/imagemagick-convert
[INFO] OUTPUT: /tmp/output/lib /tmp/output/bin /tmp/output/slib
-------------
..............*...............*
All:
libdl.so.2 libm.so.6 librt.so.1 libpthread.so.0 libMagickWand-6.Q8.so.1 libgcc_s.so.1 libjpeg.so.62 libpng10.so.0 libtiff.so.5 libz.so.1 libMagickCore-6.Q8.so.1 libc.so.6 ld-linux.so.3 libxml2.so.2 libgomp.so.1
$ du -h /tmp/output/
6.7M /tmp/output/lib
1.9M /tmp/output/slib
12K /tmp/output/bin
8.5M /tmp/output/
$ ls -R /tmp/output/
/tmp/output/:
bin lib slib
/tmp/output/bin:
convert
/tmp/output/lib:
libdl.so.2 libMagickCore-6.Q8.so.1 libtiff.so.5
libgomp.so.1 libMagickWand-6.Q8.so.1 libxml2.so.2
libjpeg.so.62 libpng10.so.0 libz.so.1
/tmp/output/slib:
ld-linux.so.3 libc.so.6 libgcc_s.so.1 libm.so.6 libpthread.so.0 librt.so.1
[INFO] READELF: /path/armv6-linux-gnueabi-readelf
[INFO] STRIP: /path/armv6-linux-gnueabi-strip
[INFO] OTHER LIB: /path/armv6-linux-gnueabi/compiler/lib /path/armv6-linux-gnueabi/platform/sysroot/lib /path/armv6-linux-gnueabi/3rd-party/lib
[INFO] TARGET: /path/imagemagick-convert
[INFO] OUTPUT: /tmp/output/lib /tmp/output/bin /tmp/output/slib
-------------
..............*...............*
All:
libdl.so.2 libm.so.6 librt.so.1 libpthread.so.0 libMagickWand-6.Q8.so.1 libgcc_s.so.1 libjpeg.so.62 libpng10.so.0 libtiff.so.5 libz.so.1 libMagickCore-6.Q8.so.1 libc.so.6 ld-linux.so.3 libxml2.so.2 libgomp.so.1
$ du -h /tmp/output/
6.7M /tmp/output/lib
1.9M /tmp/output/slib
12K /tmp/output/bin
8.5M /tmp/output/
$ ls -R /tmp/output/
/tmp/output/:
bin lib slib
/tmp/output/bin:
convert
/tmp/output/lib:
libdl.so.2 libMagickCore-6.Q8.so.1 libtiff.so.5
libgomp.so.1 libMagickWand-6.Q8.so.1 libxml2.so.2
libjpeg.so.62 libpng10.so.0 libz.so.1
/tmp/output/slib:
ld-linux.so.3 libc.so.6 libgcc_s.so.1 libm.so.6 libpthread.so.0 librt.so.1
故程式運行時所需的 size 是 8.5MB ,但其中有 sysroot libraries 為 1.9MB ,所以移植到板子上的程式碼大小 = 8.5MB - 1.9MB。
星期三, 2月 19, 2020
Real Time Streaming Protocol 2.0 (RTSP)
Reference:
- draft-ietf-mmusic-rfc2326bis-33
- RTSP MUST follow the same guidelines with regards to TLS [RFC5246] usage as specified for HTTP, see [RFC2818].
- https://stackoverflow.com/questions/40123596/rtsp-over-ssl-rtsps
- ffmpeg -re -i -acodec copy -vcodec copy -f rtsp rtsps://username:password@:443/live/myStream
星期五, 2月 07, 2020
cursor
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
const char ESC = '\x1b';
int r, c, np, i;
time_t x;
struct tm * now;
DIR * proc;
struct dirent * de;
r = argc > 1 ? atoi(argv[1]) : 1;
c = argc > 2 ? atoi(argv[2]) : 72;
while (1) {
time(& x);
now = localtime(& x);
printf("%c7%c[7m", ESC, ESC);
printf("%c[%d;%dH%02d:%02d:%02d%c[K", ESC, r, c,
now->tm_hour, now->tm_min, now->tm_sec, ESC);
printf("%c[%d;%dH%s%c[K", ESC, r+1, c, "jack test" , ESC);
printf("%c[m%c8", ESC, ESC);
fflush(stdout);
usleep(50000);
}
return 0;
}
puts("\x1b[2Jerase screen (清除螢幕)");
puts("\x1b[0;0Hmove cursor (移動游標)");
puts("\x1b[1mbold (粗體)[m");
puts("\x1b[4munderline (底線)[m");
puts("\x1b[5mblink (閃爍)[m");
puts("\x1b[7mreverse (反白)[m");
puts("\x1b[36mcyan foreground (青字)[m");
puts("\x1b[41mred background (紅底)[m");
// 第一位數字: 3=前景, 4=背景 */
// 第二位數字: 1=red 2=green 3=yellow 4=blue 5=magenta 6=cyan 7=white
// puts("\x1b[1m[4m[5m[7m[36[41meverything (上述全部)[m");
https://www.cyut.edu.tw/~ckhung/b/mi/textmode.php
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html
https://www.cyut.edu.tw/~ckhung/b/mi/c/sysinfo.c
https://www.cyut.edu.tw/~ckhung/b/mi/vt100_reference_card.txt
Article 248 of comp.terminals:
Newsgroups: comp.terminals
Path: cs.utk.edu!gatech!udel!bogus.sura.net!opusc!usceast!chan
From: chan@ece.scarolina.edu (Simon Chan)
Subject: VT100 Reference Card !! ( if you are looking for....)
Message-ID: <chan.728236678@hertz>
Keywords: vt100 terminal escape codes
Sender: usenet@usceast.cs.scarolina.edu (USENET News System)
Organization: USC Department of Computer Science
Date: 28 Jan 93 15:57:58 GMT
Lines: 162
Taken from VT100 Programming Reference Card (DIGITAL)
ANSI Compatible Mode
Cursor Movement Commands
Cursor up ESC [ Pn A
Cursor down ESC [ Pn B
Cursor forward (right) ESC [ Pn C
Cursor backward (left) ESC [ Pn D
Direct cursor addressing ESC [ Pl; Pc H or
ESC [ Pl; Pc f
Index ESC D
Next Line ESC E
Reverse index ESC M
Save cursor and attributes ESC 7
Restore cursor and attributes ESC 8
* Pn = decimal parameter in string of ASCII digits.(default 1)
* Pl = line number (default 0); Pc = column number (default 0)
Line Size (Double-Height and Double-Width) Commands
Change this line to double-height top half ESC # 3
Change this line to double-height bottom half ESC # 4
Change this line to single-width single-height ESC # 5
Change this line to double-width single-height ESC # 6
Character Attributes
ESC [ Ps;Ps;Ps;...,Ps m
Ps = 0 or None All Attributes Off
1 Bold on
4 Underscore on
5 Blink on
7 Reverse video on
Any other parameter values are ignored.
Erasing
From cursor to end of line ESC [ K or ESC [ 0 K
From beginning of line to cursor ESC [ 1 K
Entire line containing cursor ESC [ 2 K
From cursor to end of screen ESC [ J or ESC [ 0 J
From beginning of screen to cursor ESC [ 1 J
Entire screen ESC [ 2 J
Programmable LEDs
ESC [ Ps;Ps;...Ps q
Ps = 0 or None All LEDs Off
1 L1 on
2 L2 on
3 L3 on
4 L4 on
Any other parameter values are ignored.
Character Set (G0 and G1 Designators)
Charactor Set G0 Designator G1 Designator
United Kingdom (UK) ESC ( A ESC ) A
United States (USASCII) ESC ( B ESC ) B
Special graphics characters ESC ( 0 ESC ) 0
and line drawing set
Alternate character ROM ESC ( 1 ESC ) 1
Alternate character ROM ESC ( 2 ESC ) 2
special graphics characters
Scrolling Region
ESC [ Pt ; Pb r
Pt is the number of the top line of the scrolling region;
Pb is the number of the bottom line of the scrolling region
and must be greater than Pt.
(The default for Pt is line 1, the default for Pb is the end
of the screen)
TAB stops
Set tab at current column ESC H
Clear tab at curent column ESC [ g or ESC [ 0 g
Clear all tabs ESC [ 3 g
Modes
To Set To Reset
Mode Name Mode Sequence Mode Sequence
Line feed/new line New line ESC [20h Line feed ESC [20l
Cursor key mode Application ESC [?1h Cursor ESC [?l
ANSI/VT52 mode ANSI N/A VT52 ESC [?2l
Column mode 132 Col ESC [?3h 80 Col ESC [?3l
Scrolling mode Smooth ESC [?4h Jump ESC [?4l
Screen mode Reverse ESC [?5h Normal ESC [?5l
Origin mode Relative ESC [?6h Absolute ESC [?6l
Wraparound On ESC [?7h Off ESC [?7l
Auto repeat On ESC [?8h Off ESC [?8l
Interlace On ESC [?9h Off ESC [?9l
Graphic proc. option On ESC 1 Off ESC 2
Keypad mode Application ESC = Numeric ESC >
Reports
Cursor Position Report
Invoked by ESC [ 6 n
Response is ESC [ Pl; Pc R
* Pl = line number; Pc = column number
Status Report
Invoked by ESC [ 5 n
Response is ESC [ 0 n (terminal ok)
ESC [ 3 n (terminal not ok)
What Are You
Invoked by ESC [ c or ESC [ O c
Response is ESC [ ?1 ; Ps C
Ps = 0 Base VT100, no options
1 Processor option (STP)
2 Advanced Video option (AVO)
3 AVO and STP
4 Graphocs processor option (GO)
5 GO and STP
6 GO and AVO
7 GO, STP, and AVO
Alternately invoked by ESC Z (not recommended.) Response is the same.
Reset
ESC c
Confidence Tests
Fill Screen with "Es" ESC # 8
Invoke Test(s) ESC [ 2 ; Ps y
Ps = 1 Power-up self test
(ROM checksum, RAM, NVR,
keyboard and AVO if installed)
2(loop back connector required) Data Loop Back
4(loop back connector required) ETA Modern Control Test
8 Repeat selected test(s)
indefinitely
(until failure or power off)
VT52 Compatible Mode
Cursor Up ESC A
Cursor Down ESC B
Cursor Right ESC C
Cursor Left ESC D
Select Special Graphics character set ESC F
Select ASCII character set ESC G
Cursor to home ESC H
Reverse line feed ESC I
Erase to end of screen ESC J
Erase to end of line ESC K
Direct cursor address ESC Ylc (see note 1)
Identify ESC Z (see note 2)
Enter alternate keypad mode ESC =
Exit alternate keypad mode ESC >
Enter ANSI mode ESC <
NOTE 1: Line and column numbers for direct cursor address are single
character codes whose values are the desired number plus
37 (in Octal). Line and column numbers start at 1.
NOTE 2: Response to ESC Z is ESC / Z.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Simon Chan chan@ece.scarolina.edu
Department of Electrical & Computer Engineering
Swearingen Engineering Centre
University of South Carolina
Coulmbia, South Carolina 29208
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Article 269 of comp.terminals:
Path: cs.utk.edu!gatech!news.ans.net!cmcl2!adm!smoke!gwyn
From: gwyn@smoke.brl.mil (Doug Gwyn)
Newsgroups: comp.terminals
Subject: Re: VT100 Reference Card !!
Keywords: vt100 terminal escape codes
Message-ID: <19629@smoke.brl.mil>
Date: 1 Feb 93 15:01:49 GMT
References: <chan.728236678@hertz>
Organization: U.S. Army Ballistic Research Lab, APG MD.
Lines: 25
In article <chan.728236678@hertz> chan@ece.scarolina.edu (Simon Chan) writes:
>Taken from VT100 Programming Reference Card (DIGITAL)
Note that EK-VT100-RC-001 contains several errors and omissions.
The errors appear to all be fixed in the posted version.
Here are some additions:
Parameters to Direct cursor addressing can be omitted if 1.
"Index" is broken if NEWLINE is enabled (set-up).
"Reverse index" scrolls up retaining the same column.
CHARACTER SET DESIGNATORS: G0 = Shift-In, G1 = Shift-Out
> ANSI/VT52 mode ANSI N/A VT52 ESC [?2l
ANSI/VT52 mode ANSI ESC < VT52 ESC [?2l
Modes can be combined using ";", for example "ESC [ ? 3 ; 4 ; 7 h"
CONFIDENCE TESTS: Parameter bits are summed into one parameter.
Hardcopy ESC # 7
Graphic processor ON ESC 1
Graphic processor OFF ESC 2
The reference card showed incorrect graphics for octal code 140; its
correct graphic is ` (accent grave).
訂閱:
文章 (Atom)