You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

566 lines
12 KiB

8 months ago
  1. using System;
  2. using System.Text.Json.Serialization;
  3. namespace Mirle.Component.API.ProgrammableLogicController.Models
  4. {
  5. /// <summary>
  6. /// 異常等級
  7. /// </summary>
  8. public enum AlarmLevel
  9. {
  10. /// <summary>
  11. /// 警告
  12. /// </summary>
  13. Warning,
  14. /// <summary>
  15. /// 異常
  16. /// </summary>
  17. Alarm
  18. }
  19. /// <summary>
  20. /// 回應代碼
  21. /// </summary>
  22. public enum ReplyCode
  23. {
  24. /// <summary>
  25. /// 成功
  26. /// </summary>
  27. OK,
  28. /// <summary>
  29. /// 失敗
  30. /// </summary>
  31. NG
  32. }
  33. #region === [Mode] ===
  34. /// <summary>
  35. /// 任務模式
  36. /// </summary>
  37. public enum TaskActionMode
  38. {
  39. /// <summary>
  40. /// 入庫
  41. /// </summary>
  42. StoreIn,
  43. /// <summary>
  44. /// 出庫
  45. /// </summary>
  46. StoreOut,
  47. }
  48. /// <summary>
  49. /// 取消模式
  50. /// </summary>
  51. public enum TaskCancelMode
  52. {
  53. /// <summary>
  54. /// 取消
  55. /// </summary>
  56. Cancel,
  57. /// <summary>
  58. /// 強制取消
  59. /// </summary>
  60. ForceCancel,
  61. /// <summary>
  62. /// 強制完成
  63. /// </summary>
  64. ForceComplete
  65. }
  66. /// <summary>
  67. /// 維修門動作
  68. /// </summary>
  69. public enum RepairDoorActionMode
  70. {
  71. /// <summary>
  72. /// 開門
  73. /// </summary>
  74. Open,
  75. /// <summary>
  76. /// 關門
  77. /// </summary>
  78. Close,
  79. /// <summary>
  80. /// 取消
  81. /// </summary>
  82. Cancel
  83. }
  84. /// <summary>
  85. /// 鐵捲門動作
  86. /// </summary>
  87. public enum RollingDoorActionMode
  88. {
  89. /// <summary>
  90. /// 開啟
  91. /// </summary>
  92. Open,
  93. /// <summary>
  94. /// 關閉
  95. /// </summary>
  96. Close
  97. }
  98. /// <summary>
  99. /// 操作模式
  100. /// </summary>
  101. public enum OperationMode
  102. {
  103. /// <summary>
  104. /// 連線可控制
  105. /// </summary>
  106. OnlineRemote,
  107. /// <summary>
  108. /// 連線不可控制
  109. /// </summary>
  110. OnlineLocal,
  111. /// <summary>
  112. /// 離線
  113. /// </summary>
  114. Offline
  115. }
  116. #endregion
  117. #region === [Status] ===
  118. /// <summary>
  119. /// 任務完成狀態
  120. /// </summary>
  121. public enum TaskCompleteStatus
  122. {
  123. /// <summary>
  124. /// 完成
  125. /// </summary>
  126. Complete,
  127. /// <summary>
  128. /// 強制完成
  129. /// </summary>
  130. ForceComplete,
  131. /// <summary>
  132. /// 失敗
  133. /// </summary>
  134. Failed,
  135. /// <summary>
  136. /// 取消
  137. /// </summary>
  138. Cancel,
  139. /// <summary>
  140. /// 強制取消
  141. /// </summary>
  142. ForceCancel
  143. }
  144. /// <summary>
  145. /// 棧板供應狀態
  146. /// </summary>
  147. public enum PalletSupplyStatus
  148. {
  149. /// <summary>
  150. /// 滿載
  151. /// </summary>
  152. Full,
  153. /// <summary>
  154. /// 空載
  155. /// </summary>
  156. Empty
  157. }
  158. /// <summary>
  159. /// 移動台車狀態
  160. /// </summary>
  161. public enum MoveCarStatus
  162. {
  163. /// <summary>
  164. /// 回到原點
  165. /// </summary>
  166. Ready,
  167. /// <summary>
  168. /// 尚未回到原點
  169. /// </summary>
  170. NotReady
  171. }
  172. /// <summary>
  173. /// 電梯狀態
  174. /// </summary>
  175. public enum LifterStatus
  176. {
  177. /// <summary>
  178. /// 抵達
  179. /// </summary>
  180. Arrived,
  181. /// <summary>
  182. /// 異常
  183. /// </summary>
  184. Alarm
  185. }
  186. /// <summary>
  187. /// 電梯貨物狀態
  188. /// </summary>
  189. public enum LifterItemStatus
  190. {
  191. /// <summary>
  192. /// 有貨物
  193. /// </summary>
  194. HadItem,
  195. /// <summary>
  196. /// 無貨物
  197. /// </summary>
  198. NotHaveItem
  199. }
  200. /// <summary>
  201. /// 鐵捲門狀態
  202. /// </summary>
  203. public enum RollingDoorStatus
  204. {
  205. /// <summary>
  206. /// 開啟
  207. /// </summary>
  208. Open,
  209. /// <summary>
  210. /// 關閉
  211. /// </summary>
  212. Close
  213. }
  214. /// <summary>
  215. /// 維修門狀態
  216. /// </summary>
  217. //[JsonConverter(typeof(JsonStringEnumConverter))]
  218. public enum RepairDoorStatus
  219. {
  220. /// <summary>
  221. /// 開啟
  222. /// </summary>
  223. Open,
  224. /// <summary>
  225. /// 強制開啟
  226. /// </summary>
  227. ForceOpen,
  228. /// <summary>
  229. /// 關閉
  230. /// </summary>
  231. Close
  232. }
  233. #endregion
  234. #region === [Event] ===
  235. /// <summary>
  236. /// 取放貨事件
  237. /// </summary>
  238. public enum LoadUnloadEvent
  239. {
  240. /// <summary>
  241. /// 取貨
  242. /// </summary>
  243. Load,
  244. /// <summary>
  245. /// 放貨
  246. /// </summary>
  247. Unload
  248. }
  249. /// <summary>
  250. /// 緊急事件
  251. /// </summary>
  252. public enum EmergencyEvent
  253. {
  254. /// <summary>
  255. /// 地震
  256. /// </summary>
  257. Earthquake,
  258. /// <summary>
  259. /// 消防
  260. /// </summary>
  261. Fire
  262. }
  263. /// <summary>
  264. /// 庫區派送命令事件
  265. /// </summary>
  266. public enum DispatchEvent
  267. {
  268. /// <summary>
  269. /// 上鎖
  270. /// </summary>
  271. Lock,
  272. /// <summary>
  273. /// 解鎖
  274. /// </summary>
  275. Unlock
  276. }
  277. #endregion
  278. #region === [Result Code] ===
  279. /// <summary>
  280. /// 建立命令結果
  281. /// </summary>
  282. public enum CreateCommandResultCode
  283. {
  284. /// <summary>
  285. /// 成功
  286. /// </summary>
  287. Success,
  288. /// <summary>
  289. /// 拒絕
  290. /// </summary>
  291. Reject,
  292. /// <summary>
  293. /// 起始位置不存在
  294. /// </summary>
  295. SourceNotExist,
  296. /// <summary>
  297. /// 目的位置不存在
  298. /// </summary>
  299. DestinationNotExist
  300. }
  301. /// <summary>
  302. /// 取消命令結果
  303. /// </summary>
  304. public enum CancelCommandResultCode
  305. {
  306. /// <summary>
  307. /// 成功
  308. /// </summary>
  309. Success,
  310. /// <summary>
  311. /// 拒絕
  312. /// </summary>
  313. Reject
  314. }
  315. /// <summary>
  316. /// 建立取放貨結果
  317. /// </summary>
  318. public enum CreateLoadUnloadResultCode
  319. {
  320. /// <summary>
  321. /// 成功
  322. /// </summary>
  323. Success,
  324. /// <summary>
  325. /// 失敗
  326. /// </summary>
  327. Reject
  328. }
  329. /// <summary>
  330. /// 允許取放貨結果
  331. /// </summary>
  332. public enum PermitLoadUnloadResultCode
  333. {
  334. /// <summary>
  335. /// 允許
  336. /// </summary>
  337. Permit,
  338. /// <summary>
  339. /// 不允許
  340. /// </summary>
  341. NotPermit
  342. }
  343. /// <summary>
  344. /// 檢查載具編號及物料編號結果
  345. /// </summary>
  346. public enum CarrierIDInsepectResultCode
  347. {
  348. /// <summary>
  349. /// 成功
  350. /// </summary>
  351. Success,
  352. /// <summary>
  353. /// 載具編號錯誤
  354. /// </summary>
  355. CarrierIDError,
  356. /// <summary>
  357. /// 物料編號錯誤
  358. /// </summary>
  359. MaterialIDError
  360. }
  361. /// <summary>
  362. /// 移動台車詢問結果
  363. /// </summary>
  364. public enum MoveCarResultCode
  365. {
  366. /// <summary>
  367. /// 成功
  368. /// </summary>
  369. Success,
  370. /// <summary>
  371. /// 拒絕
  372. /// </summary>
  373. Reject
  374. }
  375. /// <summary>
  376. /// 呼叫電梯結果
  377. /// </summary>
  378. public enum CallLifterResultCode
  379. {
  380. /// <summary>
  381. /// 成功
  382. /// </summary>
  383. Success,
  384. /// <summary>
  385. /// 拒絕
  386. /// </summary>
  387. Reject
  388. }
  389. /// <summary>
  390. /// 使用維修門結果
  391. /// </summary>
  392. public enum UseRepairDoorResultCode
  393. {
  394. /// <summary>
  395. /// 成功
  396. /// </summary>
  397. Success,
  398. /// <summary>
  399. /// 維修門不存在
  400. /// </summary>
  401. RepairDoorNotExist
  402. }
  403. /// <summary>
  404. /// 使用鐵捲門結果
  405. /// </summary>
  406. public enum UseRollingDoorResultCode
  407. {
  408. /// <summary>
  409. /// 成功
  410. /// </summary>
  411. Success,
  412. /// <summary>
  413. /// 拒絕
  414. /// </summary>
  415. Reject
  416. }
  417. /// <summary>
  418. /// 物料檢測結果
  419. /// </summary>
  420. public enum MaterialInspectResultCode
  421. {
  422. /// <summary>
  423. /// 成功
  424. /// </summary>
  425. Success,
  426. /// <summary>
  427. /// 過輕
  428. /// </summary>
  429. TooLight,
  430. /// <summary>
  431. /// 過重
  432. /// </summary>
  433. TooHeavy,
  434. /// <summary>
  435. /// 沒有重量
  436. /// </summary>
  437. NoWeight
  438. }
  439. /// <summary>
  440. /// 緊急事件結果
  441. /// </summary>
  442. public enum EmergencyEventResultCode
  443. {
  444. /// <summary>
  445. /// 成功
  446. /// </summary>
  447. Success,
  448. /// <summary>
  449. /// 失敗
  450. /// </summary>
  451. Failed
  452. }
  453. /// <summary>
  454. /// 建立電梯命令結果
  455. /// </summary>
  456. public enum CreateLifterCommandResultCode
  457. {
  458. /// <summary>
  459. /// 成功
  460. /// </summary>
  461. Success,
  462. /// <summary>
  463. /// 拒絕
  464. /// </summary>
  465. Reject
  466. }
  467. /// <summary>
  468. /// 取消電梯命令結果
  469. /// </summary>
  470. public enum CancelLifterCommandResultCode
  471. {
  472. /// <summary>
  473. /// 成功
  474. /// </summary>
  475. Success,
  476. /// <summary>
  477. /// 拒絕
  478. /// </summary>
  479. Reject
  480. }
  481. #endregion
  482. /// <summary>
  483. /// 訊息擴充方法類別
  484. /// </summary>
  485. public static class MessageExtension
  486. {
  487. /// <summary>
  488. /// 轉換成任務模式
  489. /// </summary>
  490. /// <param name="taskMode">任務模式 (資料庫)</param>
  491. /// <returns>任務模式</returns>
  492. /// <exception cref="ArgumentException">未定義數值</exception>
  493. public static TaskActionMode ToTaskMode(this int taskMode)
  494. {
  495. return (taskMode) switch
  496. {
  497. 1 => TaskActionMode.StoreIn,
  498. 2 => TaskActionMode.StoreOut,
  499. _ => throw new ArgumentException($"Unknown task mode {taskMode}")
  500. };
  501. }
  502. /// <summary>
  503. /// 轉換成任務狀態 (資料庫)
  504. /// </summary>
  505. /// <param name="taskCompleteStatus">任務完成狀態</param>
  506. /// <returns>任務狀態 (資料庫)</returns>
  507. /// <exception cref="ArgumentException">未定義列舉項目</exception>
  508. public static int ToTaskStatus(this TaskCompleteStatus taskCompleteStatus)
  509. {
  510. return (taskCompleteStatus) switch
  511. {
  512. TaskCompleteStatus.Complete => 4,
  513. TaskCompleteStatus.ForceComplete => 5,
  514. TaskCompleteStatus.Failed => 6,
  515. TaskCompleteStatus.Cancel => 7,
  516. TaskCompleteStatus.ForceCancel => 8,
  517. _ => throw new ArgumentException($"Unknown task complete status {taskCompleteStatus}")
  518. };
  519. }
  520. /// <summary>
  521. /// 轉換成任務狀態
  522. /// </summary>
  523. /// <param name="cancelMode">取消模式列舉</param>
  524. /// <returns>任務狀態</returns>
  525. /// <exception cref="ArgumentException">未定義列舉項目</exception>
  526. public static int ToTaskStatus(this TaskCancelMode cancelMode)
  527. {
  528. return (cancelMode) switch
  529. {
  530. TaskCancelMode.ForceComplete => 5,
  531. TaskCancelMode.Cancel => 7,
  532. TaskCancelMode.ForceCancel => 8,
  533. _ => throw new ArgumentException($"Unknown cancel mode {cancelMode}")
  534. };
  535. }
  536. /// <summary>
  537. /// 轉換成操作模式
  538. /// </summary>
  539. /// <param name="operationMode">操作模式</param>
  540. /// <returns>操作模式</returns>
  541. public static int ToOperationMode(this OperationMode operationMode)
  542. {
  543. return (operationMode) switch
  544. {
  545. OperationMode.OnlineRemote => 0,
  546. OperationMode.OnlineLocal => 1,
  547. OperationMode.Offline => 2,
  548. _ => 3
  549. };
  550. }
  551. }
  552. }