2022年2月26日 星期六

C 字串和 const

變數的資料型別 const 修飾後變成「唯讀」,除了初始值外,不能再指定值。

char a[] = "test"; // 可修改的字串,配置 5 bytes 空間 (不考慮對齊的話)。

char *b = a; // 一個指標,可以動態指到不同的可改字串。

const char c[] = "Test"; // 內容為 const char 的陣列 (不能改的字串)

const char *d = a; // 內容為 const char *,是一個指標,而這個指標指到 const char。指標本身可以改,指標指到的內容不能改。可以動態指到不同的不可改字串,也可以指到可改字串 (變成不可改)。

b = (char *)d; //

char * const e; // const 修飾變數本身,而不是 char。一個不能改的指標,但指到的字串可以修改。

const char * const f; // 一個不能改的指標,指到的字串也不能修改。

const int &g=100; // 常數引用,即不能改變引用的值。

二維

const char e[][] = {"str1", "str12", "str123"}; // 3 * 7 的二維 char 陣列,內容不能變,e[0] 是 "str1"

const char *f[] = {"Str1", "Str12", "Str123"}; // 指標陣列,每個可以動態指到不同的字串。初始值使用的空間 5 + 6 + 7。

const char **g; // 一個指標

char * const h[];

參考

https://www.youtube.com/watch?v=R2rhMxtjuv0

2022年2月19日 星期六

SIP dialog

INVITESUBSCRIBE... 可建立 dialg。

使用 tag 作為 dialog 識別在 RFC 3261 是強制的,但在 RFC 2543 是 optional。(有一端是 RFC 3261 的話,至少 From Tag 或 To Tag 中會有一個,RFC 2543v會保留嘛?)

...

12.2 Requests within a Dialog

兩個 UA 建立 dialog 後,任一端需要時可發起新 transaction。請求可 (還是有 Route Set 時必須) 包含 Record-Route 和 Contact。這些請求不能改變 dialog 的 route set (為什麼?)。這些中,屬於 target refresh request 才可以改變 remote target URI (什麼是 target?什麼是 remote target URI?依建立 dialog 的 method 而有不同?),並不能更新 route set。更新 route set 和 RFC2543 系統會有嚴重相容問題 (什麼問題?)。INVITE 建立的 dialog,唯一的 target refresh request 是 re-INVITE。ACK 並不是 target refresh request。

12.2.1 UAC Behavior

12.2.1.1 Generating the Request

...

target refresh request 應該要有 Contact,且除非有改變的需要,應該和 dialog 內之前的請求一致。如果 "secure" flag 是 true,必須是 SIPS URI。如同 Section 12.2.2 所討論,target refresh request 的 Contact 更新 remote target URI,不是 target refresh request 不更新 remote target URI。

請求剩下部份照 Section 8.1.1 描述形成。compute the address of the server,照 Section 8.1.2 送請求,一般送給 topmost Route 或沒有時送給 Request-URI。Subject to certain restrictions,允許送給不在 route set 的其它位址,例如, default outbound proxy。

12.2.1.2 Processing the Responses

如果 client transaction timeout,視同收到 408 Request Timeout。

收到 3xx,行為描述在 Section 8.1.3.4.

target refresh request 收到 2xx,如果有 Contact,必須取代為 dialog 的新的 remote target URI。

481 Call/Transaction Does Not Exist 或 408 Request Timeout,應該結束 dialog。INVITE 的 dialog 結束,包含送 BYE。

12.2.2 UAS Behavior

如果收到請求有 To tag,UAS core 比對 dialog 符合,先如同 Section 8.2 處理。如果不符合,可能是 UAS 有重啟、或收到要給其它 UAS 的請求 (possibly failed) UAS (the UASs can construct the To tags so that a UAS can identify that the tag was for a UAS for which it is providing recovery)、或者純粹跑錯。UAS 可以基於 To tag 決定是否接受來提供 robustness,讓 dialog 即使重啟仍可以維持。提供此功能需考慮維持 CSeq 序號增加、重建 route set、和接受 out-of-range RTP timestamps and sequence numbers。如果要 reject,回 481 Call/Transaction Does Not Exist。

如果 remote sequence number 是空的,設為 CSeq 序號。如果 remote sequence number 大於 CSeq 序號,the request is out of order and MUST 回 500 Server Internal Error。如果 remote sequence number 小於 CSeq 序號 (包括差 1 以上),request is in order 並更新為 CSeq 序號。如果請求 proxy challenges,並不會送到 UAS。UAC 需要序號增加重送請求 with credentials,所以序號可能會有 gap。

當收到 target refresh request,如果有 Contact,必須用來取代 dialog 的 remote target URI。

12.3 Termination of a Dialog

建立 dialog 失敗,同時也結束 early dialog。結束 dialog 的機制是 method specific,例如 BYE 結束一個 INVITE 建立的 session 以及 associated dialog。

Call-ID 分大小寫,tag 不分大小寫

tag-param = "tag" EQUAL token

tag 值是 token,包含英文字母、數字和其他符號共 72 字元,不分大小寫的話 46 (會有設備去改大小寫嗎?)。

參考

  1. RFC 3261

2022年2月12日 星期六

ballast 安定器

ballast:(船的)壓艙物;(氣球的)鎮重物;(馬路或鐵路路基的)道碴

傳統安定器是電感式

啟動器的目的是提供一個暫時性的通路預熱日光燈管兩頭的燈絲產生足夠的電子雲霧。通常由內含雙金屬片溫度開關的特製氖氣放電管構成,並且並聯一電容器抑制開關時造成的火花與雜訊,需搭配線圈型傳統安定器使用。通電後,啟動器放電管點亮發熱,讓雙金屬片閉合後熄滅,由此交變電流通過安定器、燈絲和雙金屬片開關,加熱燈絲。失去熱量來源後雙金屬片將斷開,迴路中交變電流將因為安定器自感而產生暫態高電壓,此高電壓將載入到與安定器串聯的日光燈管上,使之點亮。

電子式啟動器

電子式安定器免用啟動器

快速啟動

預熱啟動

參考

  1. 維基百科:啟動器

SIP header Via

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