2024年7月5日 星期五

SIP header Via

所有 SIP 訊息都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。

格式 sent-protocol sent-by[;branch=branch][;參數...]

  • sent-protocol 格式是「SIP/2.0/transport」,transport 可以是 UDPTCPTLSSCTP 等。
  • sent-by 格式是 host[:port],host 可以是主機的網域名稱或 IP 位址,可以加上 port。host 建議 FQDN。無 port 時,預設值在 UDP/TCP/SCTP 是 5060、TLS 是 5061。在 用來送回應。收到請求的 Via 中有 sent-by 且 branch 符合自己送的,
  • 參數 branch:
    • 意思是分支。在 RFC3261 以「z9hG4bK」開頭,是必要的。值對某個 UAC 而言是時空上唯一,用來快速識別 Transaction,但在 CANCEL 和 INVITE 失敗的 ACK 是沿用原始請求的 branch。
    • 在 RFC2543,forking proxy 插入 branch 用來區分不同分支,同一個 call 在不同 proxy 可能用相同的 branch 值,沒有唯一的特性,不適合作為 Transaction ID。某種程度上不會產生「z9hG4bK」開頭的值。
    • Proxy 也用來偵測 loop。
  • 參數 received: Server Transport 收到請求檢查頂頭 Via 的 sent-by,如果是網域主機名稱,或不同於封包的來源 IP 位址時,紀錄封包的來源位址,助於之後 server transport 送回應。
  • 參數 maddr:Client Transport 紀錄
  • 參數 ttl:Client Transport 紀錄
Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds

比較:Contact

2024年6月14日 星期五

Linux System Load Average

Linux 的系統平均負載可在 uptimetop、cat /proc/loadavg、w(ho) 等看到,有三組數字,分別表示最近 1 分鐘、5 分鐘、和 15 分鐘的平均負載。

平均負載在 Linux kernel 紀錄在 avenrun[],每 5 秒更新一次,公式為

new = old * exp_n + active * (1 - exp_n)

採用定點表示,計算式變成

new = old * EXP_N + active * (FIXED_1 - EXP_N);
if (active >= old)
    new += FIXED_1 - 1;
new /= FIXED_1;

小數部份有 11 bits,相乘擴充為 22 bits,所以精確度為 10 bits 整數,加上 11 bits 小數。FIXED_1 為 1.0,是 (1<<11)。EXP_N 在 1 分鐘、5 分鐘、和 15 分鐘分別是

#define EXP_1   1884    /* 1/exp(5sec/1min) as fixed-point */
#define EXP_5   2014    /* 1/exp(5sec/5min) */
#define EXP_15  2037    /* 1/exp(5sec/15min) */

1/exp5/60 * FIXED_1 = 1884

包含 TASK_UNINTERRUPTIBLE?

參考

  1. Dr. Neil Gunther 的 UNIX Load Average Part 1: How It Works, Part 2: Not Your Average Average

https://hackmd.io/@RinHizakura/S1K4fQtaF

2024年6月2日 星期日

NVIS

NVIS (Near vertical incidence skywave)

同樣是 HF 頻率,DX 以低角度發射到電離層,反射到長距離外;而 NVIS 以接近垂直的角度射向電離層,再反射回周遭地帶,依天線效能、發射功率、電離層狀況,覆蓋範圍可達 400km。NVIS 為視距外 (泛指VHF,UHF),又未需長距離 DX 通訊內的近區通訊選擇。NVIS 的傳播特性接近直上直落,幾乎沒有阻礙關係,訊號衰減較傳統電波傳播少和比較穩定,適合小功率和電池操作的場合。NVIS 使用的是 F2 電離層,為此電波既要穿過 D layer,又不能讓之直飛太空,日夜以至不同季節,電離層狀況,太陽粒子周期等因素所用頻率皆不盡相同。一般只能使用1.8 – 7MHz。

https://www.vr2xkp.org/2023/07/30/天空之鏡-nvis-技術淺談/

Citizens band radio

Citizens band radio (市民頻段無線電、民用波段無線電台、CB無線電),在台灣CB頻率從26.965至27.405MHz之間,頻道間隔 10 kHz,共分40個波段頻道,第9頻道27.065MHz是緊急頻道,CB機的發射功率最高只能到5W。波長 11 米。使用手持機可通訊的視線距離約300至500公尺左右,使用基地天線收發大約通訊距離約1至5公里之間。27MHz 屬於 HF 頻帶,可經由電離層反射到遠方,電波一次的跳躍距離約500至800公里之間。

參考:https://www.radio.club.tw/forum.php?mod=viewthread&tid=9642

2024年4月13日 星期六

dn_expand()

擴展網域名稱 (dn, doamin name)。DNS 詢問或回覆訊息中的網域名稱,並沒有「.」,每個「.」隔開的 label 改為前面加 1-byte 欄位放 label 的長度。另外,先前出現的最長字尾,可以用訊息 offset 表示,來減少封包長度。dn_expand() 將其還原為原本完整的樣子。

int dn_expand( // 回傳處理的壓縮 dn 長度,錯誤回 -1
    const unsigned char *msg, // 訊息開始
    const unsigned char *eomorig, // 訊息結束
    const unsigned char *comp_dn, // 壓縮的 dn
    char *exp_dn, // buffer 放擴展後的 dn
    int length); // buffer 大小

壓縮的 dn 每個 label 第 1 byte 的 MSB 2-bit 是

  • 00 表示沒有壓縮,剩下 6-bit 是後續資料的長度,依照常長度將後續資料複製到 buffer,特殊字元前加 '\'、不可印的字元轉成 \ddd。
  • 11 表示有壓縮,剩下 6-bit 和下個 byte 合起來是訊息的 offset,檢查是否在範圍內,跳到 offset 繼續處理。
  • 其它為錯誤。

參考

  1. RFC 1035 4.1.4

2024年4月12日 星期五

LoRa Devices

Semtech SX1262 LoRa transceiver 比 SX1276 新,效能較好。基於 nRF52 比基於 ESP32 省電,但較貴。

  • SX1261, SX1262 and SX1268 sub-GHz radio transceivers,。
  • compliance with radio regulations ETSI EN 300 220, FCC CFR 47 Part 15, China regulatory requirements and the Japanese ARIB T-108. 頻率涵蓋150MHz ~ 960MHz 支援全世界主要 sub-GHz ISM bands。
  • FSK, GFSK, MSK, GMSK, LoRa and Long Range FHSS modulations。LoRa 最快 62.5kbps LoRa,FSK 最快 300kbps。
  • 170dB maximum link budget (SX1262 / 68)
  • +22dBm (SX1262/SX1268) 或 +15dBm (SX1261) high efficiency PA [傳送能力]
  • Low RX current of 4.6mA (???4.2 mA of active receive current consumption)
  • High sensitivity: down to -148dBm
  • 88dB blocking immunity at 1MHz offset
  • Co-channel rejection of 19dB in LoRa mode
  • Automatic Channel Activity Detection (CAD) with ultra-fast AFC

LoRa Modulation Parameter:• Modulation BandWidth (BW_L)• Spreading Factor (SF)• Coding Rate (CR)• Low Data Rate Optimization (LDRO)

Spreading Factor (SF):spread spectrum LoRa® modulation 是用多個 chip 代表一個 bit 資料。symbol rate (Rs)。SF = (nominal Rs)/(chip rate) = the number of symbols sent per bit of information.

Rs = BW/2SF

SF 5 = 25 = 32 chips/symbol

svrhost

 svrhost

2024年4月6日 星期六

Meshtastic

Meshtastic® 一個開放原始碼的組織,提供程式用 LoRa 無線裝置來建立傳輸文字訊息的低功率長距離 mesh 網路,存取界面可以是藍牙/Wi-Fi/Ethernet/Serial,不依賴其它通訊平台。

原理:rebroadcast

  • 未達 hop limit
  • 過濾重複的訊息 (保留最新 30 則嗎?)
  • 逾時沒回應重送,最多 3 次。

終點未連上用戶會存大約 30 則最新的訊息。

封包格式:Preamble (16) + LoRa Physical Header (2) + Packet Header (16) + Packet Data (max. 237)

  • Preamble:同步訊號頻率好開始傳資料。
  • LoRa Physical Header:Packet Length (1) + Sync Word (1)。Sync Word 0x2B 表示是 Meshtastic。
  • Packet Header:Destination NodeID (4) + Sender NodeID (4) + Packet ID (4) + Flags (1) + Channel Hash (1) + Padding (2)
    • 不加密,便於路由。
    • NodeID 是藍牙 MAC 位址後 4-byte,Destination NodeID 都 1 表示廣播。
    • Packet ID:和加密有關
    • Flags:3-bit Hop Limit,1-bit WantACK,1-bit ViaMQTT。WantACK 決定 reliable 傳送,等候終點回應。廣播行為不同,有收到 rebroadcast 就視為 ACK。
    • Channel Hash
  • Packet Data:最長 237,不含 protobuf overhead。超過 truncated。237 是因為 + 16 + 2 = 255?

CSMA/CD:傳送前進行 Channel Acitivity Detection (CAD),等候取自 contention window (CW) 的 random slot time。Channel 使用率越高 CW 越大,接收 SNR 越小,CW 越小。

限制 group member, 100 裝置以上。

  • 頻率
  • 機器位置靠近手機基地台,且有 B8 頻段,可以嘗試 RX Boosted Gain 選項關閉。

2024年4月4日 星期四

免執照頻段Unlicensed Band

免執照的頻段,也就是 ISM (Industrial Scientific Medical、工科醫) 頻段,各國挪出一些頻段主要開放給工業,科學和醫學使用,無需許可證或費用,只需要遵守一定的發射功率(一般低於1W),並且不要對其它頻段造成干擾即可,有 2.4GHz 和 Sub-GHz(5GHz?)。其中 2.4GHz 屬於短距離無線傳輸,大量應用於 Wi-Fi、Bluetooth、ZigBee、 微波爐、醫療器材、嬰兒監視器等,容易相互干擾,節點少不適合多點佈建。Sub-GHz 頻段傳輸距離遠、干擾較少、功耗低,適合工業製造領域。

Sub-GHz 部份

  • 全球通用:433 MHz頻段。
  • 868 MHz (歐洲)、315 MHz (北美、亞洲和日本)。
  • 美國 902–928 MHz (澳洲?)
  • 歐洲 868MHz
  • 台灣 902~928 MHz

台灣《中華民國無線電頻率分配表》112 年 3 月修正

  • 430 - 432 供業餘無線電使用432 - 440 供業餘無線電在次要使用條件下使用
  • 885 - 915, 930 - 960 供行動通信使用,920 - 925 供低功率物聯網設備(低功率射頻電機)在次要條件下使用,920 - 928 供無線射頻辨識系統(RFID)使用,922 - 926 供國道高速公路收費系統使用,926 - 928 供 0.5W 以下低功率海上活動示標器在海上以次要條件使用

參考

  1. https://delorescetleh.medium.com/lora-lorawan-第三節-10cbb86b55ae

2024年2月10日 星期六

SIP MWI

RFC3842 SIP event package for MWI

Alice 訂閱 message-summary 狀態 1 天,馬上同步目前狀態。refresh 或停止訂閱也會同步目前狀態。Via 省略 for clarity。

  • Event 帶 event package 名稱「message-summary」。
  • Accept 帶 NOTIFY 批體使用的 MIME 格式是 application/simple-message-summary
SUBSCRIBE sip:alice@vmail.example.com SIP/2.0
To: <sip:alice@example.com>
From: <sip:alice@example.com>;tag=78923
Date: Mon, 10 Jul 2000 03:55:06 GMT
Call-Id: 1349882@alice-phone.example.com
CSeq: 4 SUBSCRIBE
Contact: <sip:alice@alice-phone.example.com>
Event: message-summary
Expires: 86400
Accept: application/simple-message-summary
Content-Length: 0

回應

SIP/2.0 200 OK
To: <sip:alice@example.com>;tag=4442
From: <sip:alice@example.com>;tag=78923
Date: Mon, 10 Jul 2000 03:55:07 GMT
Call-Id: 1349882@alice-phone.example.com
CSeq: 4 SUBSCRIBE
Expires: 86400
Content-Length: 0

馬上同步目前狀態:2 new and 8 old [2 urgent] 語音留言

  • Event 帶 message-summary。
  • Subscription-State 是 active。
  • Content-Type: application/simple-message-summary 表示批體的格式。
NOTIFY sip:alice@alice-phone.example.com SIP/2.0
To: <sip:alice@example.com>;tag=78923
From: <sip:alice@example.com>;tag=4442
Date: Mon, 10 Jul 2000 03:55:07 GMT
Call-Id: 1349882@alice-phone.example.com
CSeq: 20 NOTIFY
Contact: <sip:alice@vmail.example.com>
Event: message-summary
Subscription-State: active
Content-Type: application/simple-message-summary
Content-Length: 99

Messages-Waiting: yes
Message-Account: sip:alice@vmail.example.com
Voice-Message: 2/8 (0/2)

批體的格式

message-summary = msg-status-line CRLF
                   [msg-account CRLF]
                   [*(msg-summary-line CRLF)]
                   [ *opt-msg-headers ]

msg-status-line  = "Messages-Waiting" HCOLON msg-status
msg-status = "yes" / "no"
msg-account = "Message-Account" HCOLON Account-URI
Account-URI = SIP-URI / SIPS-URI / absoluteURI

msg-summary-line = message-context-class HCOLON newmsgs SLASH oldmsgs
                [ LPAREN new-urgentmsgs SLASH old-urgentmsgs RPAREN ]

opt-msg-headers = CRLF 1*(extension-header CRLF) ;新訊息 heeaders

message-context-class 見 Section 6.2 of RFC 3458 [7].
newmsgs = msgcount
oldmsgs = msgcount
new-urgentmsgs = msgcount
old-urgentmsgs  = msgcount
msgcount = 1*DIGIT   ; MUST NOT exceed 2^32-1

新訊息通知。新訊息一些 headers appended。

NOTIFY sip:alice@alice-phone.example.com SIP/2.0
To: <sip:alice@example.com>;tag=78923
From: <sip:alice@example.com>;tag=4442
Date: Mon, 10 Jul 2000 04:28:53 GMT
Contact: <sip:alice@vmail.example.com>
Call-ID: 1349882@alice-phone.example.com
CSeq: 31 NOTIFY
Event: message-summary
Subscription-State: active
Content-Type: application/simple-message-summary
Content-Length: 503

Messages-Waiting: yes
Message-Account: sip:alice@vmail.example.com
Voice-Message: 4/8 (1/2)

To: <alice@atlanta.example.com>
From: <bob@biloxi.example.com>
Subject: carpool tomorrow?
Date: Sun, 09 Jul 2000 21:23:01 -0700
Priority: normal
Message-ID: 13784434989@vmail.example.com

To: <alice@example.com>
From: <cathy-the-bob@example.com>
Subject: HELP! at home ill, present for me please
Date: Sun, 09 Jul 2000 21:25:12 -0700
Priority: urgent
Message-ID: 13684434990@vmail.example.com

使用 Callee Capabilities 和 Caller Preferences 的範例。使用 callee capabilities,notifier 進行註冊,Contact 含有參數 methods 和 events。為了表明身份,可以加 actor="msg-taker"。

REGISTER sip:sip3-sj.example.com SIP/2.0
To: <sip:alice@example.com>
From: <sip:alice@example.com>;tag=4442
...
Contact: <sip:alice@vm13-sj.example.com>
 ;actor="msg-taker";methods="SUBSCRIBE"
 ;automata;events="message-summary"

SUBSCRIBE 可看到上述的 Contact 參數。

SUBSCRIBE sip:alice@example.com SIP/2.0
...
Accept: application/simple-message-summary
Event: message-summary
Accept-Contact: *;automata;actor="msg-taker"

2024年2月7日 星期三

Q.931 CALL PROCEEDING

Q.931 訊息是被叫送給主叫表示已經開始建立請求的呼叫,不再接受其它呼叫建立資訊。

什麼是 call establishment information (呼叫建立資訊)?

可有下列選擇性 IE

  • Channel identification:如果是回應 SETUP 的第一個訊息,在 network-to-user 是必要的,在 user-to-network 不接受 SETUP 的 B-channel 時是必要的。
  • Progress indicator:interworking 提供 in-band information/patterns。在 user-to-network if Annex K is implemented or in accordance with the procedures of 5.11.3 and 5.12.3.
  • Display (限 n → u):最長 34 或 82 octets。
  • Bearer capability:included when the procedures of 5.11 for bearer capability selection apply. When present, progress indication No. 5, interworking has occurred and has resulted in a telecommunication service change, shall also be present.
  • High layer compatibility:included when the procedures of 5.12 for high layer compatibility selection apply. When present, progress indication No. 5, interworking has occurred and has resulted in a telecommunication service change, shall also be present.

SIP interworking

  • 收到 CALL PROCEEDING (撥入都用 En bloc,全部撥號都在 SETUP,沒有撥號結束的問題。)
    • 忽略?
    • 送 183?會被誤認為陣鈴?如果 183 /wo SDP 呢?
  • 送 CALL PROCEEDIN
    • ALERTING 前,也就是收到 180 或 183 /w SDP?
    • 收到 183 /wo SDP?
    • 送 SIP INVITE 前?
    • 認為撥號結束?

參考

  1. Q.931 3.1.2

2024年2月2日 星期五

UTC GMT

GMT (Greenwich Mean Time,格林威治標準時間):原理是平均太陽日。英國倫敦的格林威治皇家天文台觀察一整年「過中天」的時間,得到平均一天的長度,再細分成時、分、秒等。這個時間概念 1884 年確立,並往歐陸其他國家擴散。1924 開始,每小時就會向全世界播報時間。

後來有更穩定的觀測太陽日的方法,而不一定要在格林威治天文台,稱為世界時 (Universal Time,UT),有三種版本,UT0 是原始的觀測結果計算值,UT1 則是修正了地球在長時間尺度下會產生的自轉軸漂移的影響,UT2 則是為了研究需求更多修正了季節性的影響。基本上 UT1 和 GMT 是一致的。

由於地球的自轉正在緩慢減速,導致平均太陽日會逐漸變長,GMT 的 1 秒會愈來愈久,會變動對度量衡而言並不適合。1967 國際度量衡大會把秒的定義改成銫原子固定震盪次數的時間 (原子鐘),依此計算時間與日期的系統稱作國際原子時 (International Atomic Time, TAI),和地球自轉脫節了。。

國際原子時有個問題是長久下來會超前 GMT 愈來愈多。以國際原子時為基準,選擇適當的時間加入閏秒,來和 GMT 時間對齊,叫做協調世界時 (Universal Time Coordinated,UTC)。由於 UTC 相關國際度量衡標準,目前所有的國際通訊系統,像是衛星、航空、GPS 等,都採用 UTC 時間。

參考

  1. https://pansci.asia/archives/84978

2024年1月26日 星期五

disable anydesk autostart

systemctl disable anydesk.service

「systemctl list-unit-files」可列出系統服務。另外 LXQT 有另一套 autostart 在 /etc/xdg/autostart。

參考

2024年1月5日 星期五

copy_from_user() 和 copy_to_user()

unsigned long copy_from_user (void *to, const void *from, unsigned long count);
unsigned long copy_to_user (void *to, const void *from, unsigned long count);

在 read()、write()、或 ioctl() 等,可能需要在 user-space 和 kernel-space 間搬移資料,本質是 memcpy(),回傳未完成的 byte 數。此外也 access_ok() 檢查 user-space 指標是否 valid。另外有 __get_user() 和 __put_user()。

User-space 資料

  • user-space 指標在 kernel 未必是對的,和運行的 architecture 和 kernel 的設定有關。(有不對的例子嗎?)
  • user-space 資料可能 page-out 而不在記憶體中,直接存取會造成 page fault OOPS。
  • user program 提供的 pointer 可能是 buggy or malicious,而開了一個後門造成安全問題。例如指到 kernel-space 並寫入資料,變成 kernel 資料無故被改變。

如果不需要 access_ok() 檢查,例如已經檢查過,__copy_to_user()、__copy_from_user()、__get_user() 和 __put_user() 版本。

driver accesses user space must be reentrant, must be able to execute concurrently with other driver functions, and, in particular, must be in a position where it can legally sleep.

參考

  1. LDD chap 3
  • LDD chap 6

2023年12月16日 星期六

Fixed-point arithmetic 定點運算

fixed-point 是一種小數表示方式,儲存固定位數小數。某個固定單位的部份,皆可視為小數。

閱讀時,有小數點分隔整數和小數。但在內部處理程式,並沒有實際的分隔,而由程式隱含定義位置。

低成本嵌入式處理器,沒有浮點運算單元,有些計算需要定點運算適當的 scaling 來達到可接受的動態範圍。定點運算可以比浮點運算更快、更高精確度,但寫程式需要更精確預測數值範圍,調整 scaling facotr,避免 overflow。

表示法

  • Qm.n:通常是有號數,不含 sign-bit,整數部份 m-bit,小數部份 n-bit。在 ARM,m 包含 sign-bit。
  • UQm.n:無號數,整數部份 m-bit,小數部份 n-bit。
  • Qn:小數部份 n-bit。

加法和減法:相同 scaling factor,結果 scaling factor 不變。overflow。

乘法:scaling factor 相乘。在二進位,通常使用 scaling factor that is a power of two,乘完後 scaling factor 可透過 shifting right 調整回來。Rounding 可在 shift 前加上 scaling factor 的一半。證明:round(x/y) = floor(x/y + 0.5) = floor((x + y/2)/y) = shift-of-n(x + 2^(n-1))。

// saturate to range of int16_t
int16_t sat16(int32_t x)
{
	if (x > 0x7FFF) return 0x7FFF;
	else if (x < -0x8000) return -0x8000;
	else return (int16_t)x;
}

int16_t q_mul(int16_t a, int16_t b)
{
    int16_t result;
    int32_t temp;

    temp = (int32_t)a * (int32_t)b; // result type is operand's type
    // Rounding; mid values are rounded up
    temp += 1 << (Q - 1);
    // Correct by dividing by base and saturate result
    result = sat16(temp >> Q);

    return result;
}

除法 https://lirobo.blogspot.com/2021/08/rounding-integer-division.html

int16_t q_div(int16_t a, int16_t b)
{
    int32_t temp = (int32_t)a << Q;
    // Rounding: mid values are rounded up.
    if (((temp >> 31) & 1) == ((b >> 15) & 1)) {
        temp += b>>1; // round up
    } else {
        temp -= b>>1; // round down for negative value
    }
    return (int16_t)(temp / b);
}

參考

  • https://en.wikipedia.org/wiki/Fixed-point_arithmetic
  • libfixmath

2023年12月15日 星期五

Rounding

Rounding 是用較短的、簡單的、或 more explicit 的近似值表示數值,例如 $23.4476 用 $23.45, 表示、,the fraction 312/937 用 1/3 表示,或 √2 用 1.414 表示。

捨棄低位元時,增加尾數 0 或減少小數位數,決定是否進位。

round down:捨去,是指 round toward zero,但在 2’s complement 數值會是 round toward negative infinity,負值是有所不同。

round up:進位。

round toward zero:無條件捨去法。正數捨去低位元是變小,負數捨去低位元是捨去一些負值而變大,所以都是趨向 0。ROUNDDOWN() truncate()

round away from zero:無條件進位法。捨去低位元時一律進位,正數是變大,負數是變小,所以都是遠離 0。ROUNDUP()

round toward negative infinity:程式的無條件捨去法。一般程式數值用 2’s complement,正數捨去低位元是變小,負數捨去低位元也是變小。floor()

round half down

round half up

round half toward zero (五捨六入)

round half away from zero (四捨五入)

round half toward even (四捨六入五成雙)

round half toward odd

round half alternatively

round half randomly

stochastic round

參考

  1. https://en.wikipedia.org/wiki/Rounding

truncation:無條件捨去法
round (round-to-nearest)

  • 傳統是四捨五入,只看一位是五就進位,其實五居中 (biased rounding)
  • convergent rounding:不只看一位
  • unbiased rounding:如果剛好居中,只會變成是偶數。

Rounding off to nearest power of 2

找出大於等於某個值的最小 power of two
count leading zeros (clz) http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
http://en.wikipedia.org/wiki/Find_first_set

http://stackoverflow.com/questions/466204/rounding-off-to-nearest-power-of-2

http://graphics.stanford.edu/~seander/bithacks.html

http://stackoverflow.com/questions/364985/algorithm-for-finding-the-smallest-power-of-two-thats-greater-or-equal-to-a-giv

2023年12月2日 星期六

barrier 多台電腦共用鍵盤和滑鼠

Barrier 予你用一組鍵盤滑鼠透過網路控制幾若電腦,意思是排除電腦之間的壁壘。Barrier 欲 Synergy 1.9 分出來,今仔 Symless 已經佮 Synergy 商業化,袂合。

每台電腦隴需要安裝佮執行 barrier。有鍵盤和滑的那台是 server,揤「Configure server」為每一台 client 拉一個新螢幕到格子,「Screen name」設作電腦的名。佇 client 設定 Server IP (或 Bonjour Auto config) 了 Start。

功能

  • 切換電腦:徙滑鼠過螢幕邊仔,抑是用按鍵
  • Clipboard sharing
  • 跨不同作業系統

問題

  • VirtualBox 跨邊界游標不見,需要轉動滾輪。
  • 重新連線
  • 滑鼠抖動
  • Logging
  • Auto Config

參考

  1. https://github.com/debauchee/barrier
  • https://www.ptt.cc/bbs/Linux/M.1629992667.A.B31.html
  • Wayland 通訊協定

Fractional Numbers

實數分著整數 (integer) 和小數 (subinteger, fractional) 兩部份,中央是小數點 (decimal point,在二進位是 binal point),小數是實數中比 ±1 小的部份。有時陣,有小數部份的實數嘛叫做小數,有可能是表示著分數的有限小數或循環小數、或是無理數的不循環又無限的小數。

DSP 指令假定 binal point convention 的位置如下表:

Register SizeFormatNotationSign BitExtension BitFractional Bit
40-bitSigned 9.311831
Unsigned 8.320832
32-bitSigned 1.311031
Unsigned 0.320032
16-bitSigned 1.151015
Unsigned 0.160016

1.31 乘以 1.31 是 2.62,過程中需要右移 31 位、或左移一位後取前半段,以維持 1.31。但在一般 32-bit 處理器,只有整數乘法,且結果沒有 64 bits 或大於 32 bits 的空間,只能存後面 32 bits,變成相乘前兩者都要先右移 16-bit,變成 17.15 乘 17.15,結果是 34.30,實際只存後面的 2.30,再左移 1 位變成 1.31,精確度會差一點。

整數除法如何保留小數?被除數左移 16-bit、除數又移 16-bit?

int Q = a/b; // quotaent
int r = a - b * Q; // remainder
int f = 0;
int p = 0; // 十進位小數位數
while (r) {
    r *= 10;
    f *= 10;
    f += r/b;
    p++;
}
int Q = a/b; // quotaent
int r = a - b * Q; // remainder
int f = 0; // fraction
int p; // 二進位小數剩餘位數
for (p = 32; p > 0; p--) {
    f <<= 1;
    r <<= 1;
    q = r/b;
    f |= q;
    r -= b * q;
}

Saturation:結果大於最大值存成最大值,小於最小值存成最小值。

Overflow:結果超出暫存器範圍,捨棄 MSBs

Truncation 或 Rounding:移除 lower-order bits 減少 precision。

  • 無條件捨去
  • 四捨五入:中間值進位是 biased rounding
  • 四捨六入 convergent rounding:中間值轉成最接近的偶數值是 unbiased rounding。二進位 0.01 少一位是 0.0,0.11 是 1.0

參考

  1. Blackfin Processor Programming Reference

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...