1
0

registers.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. const MODBUS_AREAS = {
  2. coil: {
  3. key: 'coil',
  4. label: '线圈',
  5. readFunction: '01',
  6. writeFunction: '05 / 0F',
  7. access: '读写'
  8. },
  9. input: {
  10. key: 'input',
  11. label: '输入寄存器',
  12. readFunction: '04',
  13. writeFunction: '--',
  14. access: '只读'
  15. },
  16. holding: {
  17. key: 'holding',
  18. label: '保持寄存器',
  19. readFunction: '03',
  20. writeFunction: '06 / 10',
  21. access: '读写'
  22. }
  23. }
  24. const BYTE_POSITIONS = {
  25. high: {
  26. label: '高8位',
  27. shift: 8
  28. },
  29. low: {
  30. label: '低8位',
  31. shift: 0
  32. }
  33. }
  34. function hex(address) {
  35. return `0x${address}`
  36. }
  37. function getRegisterCount(item) {
  38. return item.registerCount || (item.type === 'float' ? 2 : 1)
  39. }
  40. function getAddressDisplay(address, registerCount) {
  41. if (registerCount <= 1) return hex(address)
  42. const start = parseInt(address, 16)
  43. const end = start + registerCount - 1
  44. return `${hex(address)}-${hex(end.toString(16).toUpperCase())}`
  45. }
  46. function withArea(items, areaKey, category) {
  47. return items.map((item) => ({
  48. ...item,
  49. ...(() => {
  50. const byteMeta = item.bytePosition ? BYTE_POSITIONS[item.bytePosition] : null
  51. const byteLabel = item.byteLabel || (byteMeta ? byteMeta.label : '')
  52. const registerCount = getRegisterCount(item)
  53. const addressDisplay = byteLabel
  54. ? `${getAddressDisplay(item.address, registerCount)} ${byteLabel}`
  55. : getAddressDisplay(item.address, registerCount)
  56. return {
  57. byteLabel,
  58. byteShift: byteMeta ? byteMeta.shift : null,
  59. category,
  60. addressText: hex(item.address),
  61. addressDisplay,
  62. registerCount,
  63. area: MODBUS_AREAS[areaKey]
  64. }
  65. })()
  66. }))
  67. }
  68. const OBS_ADDRESSES = {
  69. EK1: '30',
  70. EK2: '31',
  71. EK3: '32',
  72. EK4: '33',
  73. FOC_KFG: '34',
  74. SPEED_KLPF: '35',
  75. OBS_FBASE: '36',
  76. OBS_EA_KS: '37',
  77. OBS_KP_START: '38',
  78. OBS_KI_START: '39',
  79. OBS_KP_RUN1: '3A',
  80. OBS_KI_RUN1: '3B',
  81. OBS_KP_RUN2: '3C',
  82. OBS_KI_RUN2: '3D',
  83. OBS_KP_RUN3: '3E',
  84. OBS_KI_RUN3: '3F',
  85. OBS_KP_RUN4: '40',
  86. OBS_KI_RUN4: '41',
  87. DQ_KP_START: '42',
  88. DQ_KI_START: '43',
  89. DQ_KP_RUN: '44',
  90. DQ_KI_RUN: '45',
  91. TAILWIND_SPEED_KLPF: '46',
  92. TAILWIND_OBS_EA_KS: '47',
  93. TAILWIND_OBS_KP: '48',
  94. TAILWIND_OBS_KI: '49',
  95. ALIGN_ANGLE: '4A'
  96. }
  97. const CONFIG_ADDRESSES = {
  98. LD: '60',
  99. LQ: '62',
  100. RS: '64',
  101. POLE_PAIRS: '66',
  102. SPEED_BASE: '67',
  103. SPEED_CTRL: '68',
  104. CURVE_MAX_SPEED: '69',
  105. CURVE_MIN_SPEED: '6A',
  106. SOUT_MAX: '6B',
  107. START_RAMP_INC: '6C',
  108. START_RAMP_DEC: '6E',
  109. RUN_RAMP_INC: '70',
  110. RUN_RAMP_DEC: '72',
  111. START_VOLT: '74',
  112. STOP_VOLT: '75',
  113. CURVE_MAX_VOLT: '76',
  114. CURVE_MIN_VOLT: '77',
  115. SPEED_CURVE_K: '78',
  116. OIL_SPEED: '7A',
  117. OIL_TIME: '7B'
  118. }
  119. const controlButtonRegisters = withArea([
  120. { key: 'protocol', address: '00', type: 'uint8_t', name: 'Modbus控制', writeValue: 1, nextName: 'VSP控制', nextWriteValue: 0 },
  121. { key: 'direction', address: '02', type: 'uint8_t', name: '正转', writeValue: 0, nextName: '反转', nextWriteValue: 1 },
  122. { key: 'power', address: '01', type: 'uint8_t', name: '开机', writeValue: 1, nextName: '关机', nextWriteValue: 0 },
  123. { key: 'save', address: '03', type: 'uint8_t', name: '固化', writeValue: 1, momentary: true },
  124. { key: 'reset', address: '04', type: 'uint8_t', name: '复位', writeValue: 1, momentary: true }
  125. ], 'coil', '控制类寄存器')
  126. const speedCommandRegister = withArea([
  127. { address: CONFIG_ADDRESSES.SPEED_CTRL, type: 'uint16_t', name: '转速命令', unit: 'RPM', inputValue: '', writeValue: '--' }
  128. ], 'holding', '参数配置')[0]
  129. const tailwindSwitchRegisters = withArea([
  130. { address: '05', type: 'uint8_t', name: '顺逆风启用', value: false, writeValue: 0 },
  131. { address: '06', type: 'uint8_t', name: '预定位启用', value: false, writeValue: 0 }
  132. ], 'coil', '顺逆风控制')
  133. const protectionSwitchRegisters = withArea([
  134. { address: '07', type: 'uint8_t', name: '保护使能', value: false, writeValue: 0 },
  135. { address: '08', type: 'uint8_t', name: '恢复使能', value: false, writeValue: 0 },
  136. { address: '09', type: 'uint8_t', name: '电压保护使能', value: false, writeValue: 0 },
  137. { address: '0A', type: 'uint8_t', name: '电流保护使能', value: false, writeValue: 0 },
  138. { address: '0B', type: 'uint8_t', name: '堵转保护使能', value: false, writeValue: 0 },
  139. { address: '0C', type: 'uint8_t', name: '功率保护使能', value: false, writeValue: 0 },
  140. { address: '0D', type: 'uint8_t', name: '温度保护使能', value: false, writeValue: 0 },
  141. { address: '0E', type: 'uint8_t', name: '缺相保护使能', value: false, writeValue: 0 },
  142. { address: '0F', type: 'uint8_t', name: 'PWM 丢失保护', value: false, writeValue: 0 },
  143. { address: '10', type: 'uint8_t', name: '串口丢失保护', value: false, writeValue: 0 }
  144. ], 'coil', '保护控制')
  145. const estimatorRegisters = withArea([
  146. { address: OBS_ADDRESSES.EK1, type: 'uint16_t', name: 'OBS_E1K', conversion: '2047 * 3.0 / 125.0 * LQ / TPWM_VALUE * 电流基准 / 电压基准' },
  147. { address: OBS_ADDRESSES.EK2, type: 'uint16_t', name: 'OBS_E2K', conversion: '2047 * 0.8 * RS * 电流基准 / 电压基准' },
  148. { address: OBS_ADDRESSES.EK3, type: 'uint16_t', name: 'OBS_E3K', conversion: '255 * 2.5' },
  149. { address: OBS_ADDRESSES.EK4, type: 'uint16_t', name: 'OBS_E4K', conversion: '((LD - LQ) * TPWM_VALUE * MAX_OMEGA_RAD_SEC) / (LD + RS * TPWM_VALUE)' },
  150. { address: OBS_ADDRESSES.FOC_KFG, type: 'uint16_t', name: 'FOC_KFG', conversion: 'TIM4频率 / BASE_FREQ / FG_K * 极对数' },
  151. { address: OBS_ADDRESSES.SPEED_KLPF, type: 'uint16_t', name: 'SPEED_KLPF', conversion: '32767 * 2PI * SPD_BW * TPWM_VALUE' },
  152. { address: OBS_ADDRESSES.OBS_FBASE, type: 'uint16_t', name: 'OBS_FBASE', conversion: '32767 * TPWM_VALUE' },
  153. { address: OBS_ADDRESSES.OBS_EA_KS, type: 'uint16_t', name: 'OBS_EA_KS', conversion: '32767 * 2 * SMOMIN * 2PI * BASE_FREQ * TPWM_VALUE / 速度基准' },
  154. { address: OBS_ADDRESSES.OBS_KP_START, type: 'uint16_t', name: 'OBS_KP_START', conversion: '4095 * 2PI * ATT_COEF * ATO_BW / BASE_FREQ' },
  155. { address: OBS_ADDRESSES.OBS_KI_START, type: 'uint16_t', name: 'OBS_KI_START', conversion: '32767 * 2PI * ATO_BW * ATO_BW * TPWM_VALUE / BASE_FREQ' },
  156. { address: OBS_ADDRESSES.OBS_KP_RUN1, type: 'uint16_t', name: 'OBS_KP_RUN1' },
  157. { address: OBS_ADDRESSES.OBS_KI_RUN1, type: 'uint16_t', name: 'OBS_KI_RUN1' },
  158. { address: OBS_ADDRESSES.OBS_KP_RUN2, type: 'uint16_t', name: 'OBS_KP_RUN2' },
  159. { address: OBS_ADDRESSES.OBS_KI_RUN2, type: 'uint16_t', name: 'OBS_KI_RUN2' },
  160. { address: OBS_ADDRESSES.OBS_KP_RUN3, type: 'uint16_t', name: 'OBS_KP_RUN3' },
  161. { address: OBS_ADDRESSES.OBS_KI_RUN3, type: 'uint16_t', name: 'OBS_KI_RUN3' },
  162. { address: OBS_ADDRESSES.OBS_KP_RUN4, type: 'uint16_t', name: 'OBS_KP_RUN4' },
  163. { address: OBS_ADDRESSES.OBS_KI_RUN4, type: 'uint16_t', name: 'OBS_KI_RUN4' },
  164. { address: OBS_ADDRESSES.DQ_KP_START, type: 'uint16_t', name: 'DQ_KP_START' },
  165. { address: OBS_ADDRESSES.DQ_KI_START, type: 'uint16_t', name: 'DQ_KI_START' },
  166. { address: OBS_ADDRESSES.DQ_KP_RUN, type: 'uint16_t', name: 'DQ_KP_RUN' },
  167. { address: OBS_ADDRESSES.DQ_KI_RUN, type: 'uint16_t', name: 'DQ_KI_RUN' },
  168. { address: OBS_ADDRESSES.TAILWIND_SPEED_KLPF, type: 'uint16_t', name: 'SPEED_KLPF_TAILWIND' },
  169. { address: OBS_ADDRESSES.TAILWIND_OBS_EA_KS, type: 'uint16_t', name: 'OBS_EA_KS_TAILWIND' },
  170. { address: OBS_ADDRESSES.TAILWIND_OBS_KP, type: 'uint16_t', name: 'OBS_KP_TAILWIND' },
  171. { address: OBS_ADDRESSES.TAILWIND_OBS_KI, type: 'uint16_t', name: 'OBS_KI_TAILWIND' },
  172. { address: OBS_ADDRESSES.ALIGN_ANGLE, type: 'uint16_t', name: '预定位角度' }
  173. ], 'holding', '估算器配置参数')
  174. const atoBandwidthInputRegisters = [
  175. { suffix: 'START', name: 'ATO_BW_START', kpAddress: OBS_ADDRESSES.OBS_KP_START, kiAddress: OBS_ADDRESSES.OBS_KI_START, kpName: 'OBS_KP_START', kiName: 'OBS_KI_START' },
  176. { suffix: 'RUN1', name: 'ATO_BW_RUN1', kpAddress: OBS_ADDRESSES.OBS_KP_RUN1, kiAddress: OBS_ADDRESSES.OBS_KI_RUN1, kpName: 'OBS_KP_RUN1', kiName: 'OBS_KI_RUN1' },
  177. { suffix: 'RUN2', name: 'ATO_BW_RUN2', kpAddress: OBS_ADDRESSES.OBS_KP_RUN2, kiAddress: OBS_ADDRESSES.OBS_KI_RUN2, kpName: 'OBS_KP_RUN2', kiName: 'OBS_KI_RUN2' },
  178. { suffix: 'RUN3', name: 'ATO_BW_RUN3', kpAddress: OBS_ADDRESSES.OBS_KP_RUN3, kiAddress: OBS_ADDRESSES.OBS_KI_RUN3, kpName: 'OBS_KP_RUN3', kiName: 'OBS_KI_RUN3' },
  179. { suffix: 'RUN4', name: 'ATO_BW_RUN4', kpAddress: OBS_ADDRESSES.OBS_KP_RUN4, kiAddress: OBS_ADDRESSES.OBS_KI_RUN4, kpName: 'OBS_KP_RUN4', kiName: 'OBS_KI_RUN4' },
  180. { suffix: 'TAILWIND', name: 'ATO_BW_TAILWIND', kpAddress: OBS_ADDRESSES.TAILWIND_OBS_KP, kiAddress: OBS_ADDRESSES.TAILWIND_OBS_KI, kpName: 'OBS_KP_TAILWIND', kiName: 'OBS_KI_TAILWIND' }
  181. ].map((item) => ({
  182. ...item,
  183. type: 'float',
  184. inputValue: '',
  185. writeValue: '--',
  186. kpWriteValue: '--',
  187. kiWriteValue: '--',
  188. category: '估算器配置参数',
  189. addressDisplay: `${hex(item.kpAddress)}/${hex(item.kiAddress)}`,
  190. area: MODBUS_AREAS.holding
  191. }))
  192. const dqGainInputRegisters = withArea([
  193. { address: OBS_ADDRESSES.DQ_KP_START, type: 'uint16_t', name: 'DQ_KP_START', protocolName: 'DQ_KP_START', gainType: 'kp' },
  194. { address: OBS_ADDRESSES.DQ_KI_START, type: 'uint16_t', name: 'DQ_KI_START', protocolName: 'DQ_KI_START', gainType: 'ki' },
  195. { address: OBS_ADDRESSES.DQ_KP_RUN, type: 'uint16_t', name: 'DQ_KP_RUN', protocolName: 'DQ_KP_RUN', gainType: 'kp' },
  196. { address: OBS_ADDRESSES.DQ_KI_RUN, type: 'uint16_t', name: 'DQ_KI_RUN', protocolName: 'DQ_KI_RUN', gainType: 'ki' }
  197. ], 'holding', '估算器配置参数').map((item) => ({
  198. ...item,
  199. inputValue: '',
  200. writeValue: '--'
  201. }))
  202. const parameterRegisters = withArea([
  203. { address: CONFIG_ADDRESSES.LD, type: 'float', name: 'LD', unit: 'H', step: '0.000001' },
  204. { address: CONFIG_ADDRESSES.LQ, type: 'float', name: 'LQ', unit: 'H', step: '0.000001' },
  205. { address: CONFIG_ADDRESSES.RS, type: 'float', name: 'RS', unit: 'Ω', step: '0.0001' },
  206. { address: CONFIG_ADDRESSES.POLE_PAIRS, type: 'uint16_t', name: '极对数' },
  207. { address: CONFIG_ADDRESSES.SPEED_BASE, type: 'uint16_t', name: '速度基准', unit: 'RPM' },
  208. { address: CONFIG_ADDRESSES.CURVE_MAX_SPEED, type: 'uint16_t', name: '速度最大值', unit: 'RPM' },
  209. { address: CONFIG_ADDRESSES.CURVE_MIN_SPEED, type: 'uint16_t', name: '速度最小值', unit: 'RPM' },
  210. { address: CONFIG_ADDRESSES.SOUT_MAX, type: 'uint16_t', name: 'SOUT_MAX', unit: 'A' },
  211. { address: CONFIG_ADDRESSES.START_RAMP_INC, type: 'float', name: '启动加速加速度', unit: 'RPM/S' },
  212. { address: CONFIG_ADDRESSES.START_RAMP_DEC, type: 'float', name: '启动减速加速度', unit: 'RPM/S' },
  213. { address: CONFIG_ADDRESSES.RUN_RAMP_INC, type: 'float', name: '运行加速加速度', unit: 'RPM/S' },
  214. { address: CONFIG_ADDRESSES.RUN_RAMP_DEC, type: 'float', name: '运行减速加速度', unit: 'RPM/S' },
  215. { address: CONFIG_ADDRESSES.START_VOLT, type: 'uint16_t', name: '开机电压', unit: 'V' },
  216. { address: CONFIG_ADDRESSES.STOP_VOLT, type: 'uint16_t', name: '关机电压', unit: 'V' },
  217. { address: CONFIG_ADDRESSES.CURVE_MAX_VOLT, type: 'uint16_t', name: '调速最高电压', unit: 'V' },
  218. { address: CONFIG_ADDRESSES.CURVE_MIN_VOLT, type: 'uint16_t', name: '调速最低电压', unit: 'V' },
  219. { address: CONFIG_ADDRESSES.SPEED_CURVE_K, type: 'float', name: '调速曲线斜率' },
  220. { address: CONFIG_ADDRESSES.OIL_SPEED, type: 'uint16_t', name: '上油转速', unit: 'RPM' },
  221. { address: CONFIG_ADDRESSES.OIL_TIME, type: 'uint16_t', name: '上油时间', unit: 's' }
  222. ], 'holding', '参数配置')
  223. const parameterInputNames = [
  224. 'LD',
  225. 'LQ',
  226. 'RS',
  227. '极对数',
  228. '速度基准'
  229. ]
  230. const configParameterInputNames = [
  231. '开机电压',
  232. '关机电压',
  233. '速度最小值',
  234. '速度最大值',
  235. 'SOUT_MAX',
  236. '调速最低电压',
  237. '调速最高电压'
  238. ]
  239. const speedLoopExtraInputNames = [
  240. '启动加速加速度',
  241. '启动减速加速度',
  242. '运行加速加速度',
  243. '运行减速加速度'
  244. ]
  245. const oilParameterInputNames = [
  246. '上油转速',
  247. '上油时间'
  248. ]
  249. const prepositionParameterInputNames = [
  250. '预定位角度'
  251. ]
  252. const parameterByName = parameterRegisters.reduce((result, item) => {
  253. result[item.name] = item
  254. return result
  255. }, {})
  256. const motorParameterInputRegisters = parameterInputNames
  257. .map((name) => parameterByName[name])
  258. .filter(Boolean)
  259. .map((item) => ({
  260. ...item,
  261. inputValue: item.inputValue || '',
  262. writeValue: item.writeValue || '--'
  263. }))
  264. const parameterInputRegisters = configParameterInputNames
  265. .map((name) => parameterByName[name])
  266. .filter(Boolean)
  267. .map((item) => ({
  268. ...item,
  269. inputValue: item.inputValue || '',
  270. writeValue: item.writeValue || '--'
  271. }))
  272. const speedSlopeRegister = {
  273. ...parameterByName['调速曲线斜率'],
  274. inputValue: '',
  275. writeValue: '--'
  276. }
  277. const speedLoopExtraRegisters = speedLoopExtraInputNames
  278. .map((name) => parameterByName[name])
  279. .filter(Boolean)
  280. .map((item) => ({
  281. ...item,
  282. inputValue: '',
  283. writeValue: '--'
  284. }))
  285. const oilParameterInputRegisters = oilParameterInputNames
  286. .map((name) => parameterByName[name])
  287. .filter(Boolean)
  288. .map((item) => ({
  289. ...item,
  290. inputValue: '',
  291. writeValue: '--'
  292. }))
  293. const prepositionParameterInputRegisters = prepositionParameterInputNames
  294. .map((name) => estimatorRegisters.find((item) => item.name === name))
  295. .filter(Boolean)
  296. .map((item) => ({
  297. ...item,
  298. inputValue: '',
  299. writeValue: '--'
  300. }))
  301. function isAtoGainRegister(item) {
  302. return item.name.startsWith('OBS_KP_') || item.name.startsWith('OBS_KI_')
  303. }
  304. function isDqGainRegister(item) {
  305. return item.name.startsWith('DQ_KP_') || item.name.startsWith('DQ_KI_')
  306. }
  307. const calculatedParameterRegisters = [
  308. ...estimatorRegisters.filter((item) => !isAtoGainRegister(item) && !isDqGainRegister(item) && !prepositionParameterInputNames.includes(item.name)),
  309. ...parameterRegisters.filter((item) => !parameterInputNames.includes(item.name)
  310. && !configParameterInputNames.includes(item.name)
  311. && !speedLoopExtraInputNames.includes(item.name)
  312. && !oilParameterInputNames.includes(item.name)
  313. && !prepositionParameterInputNames.includes(item.name)
  314. && item.name !== '调速曲线斜率')
  315. ].map((item) => ({
  316. ...item,
  317. inputValue: '',
  318. writeValue: '--'
  319. }))
  320. const protectionRegisters = withArea([
  321. { address: '7C', type: 'uint16_t', name: '硬件过流值', unit: 'A' },
  322. { address: '7D', type: 'uint16_t', name: '软件过流值', unit: 'A', conversion: '32767 * 限制值 / 电流基准' },
  323. { address: '7E', type: 'uint16_t', name: '过压保护值', unit: 'V', conversion: '32767 * 限制值 / 电压采样最大值' },
  324. { address: '7F', type: 'uint16_t', name: '欠压保护值', unit: 'V' },
  325. { address: '80', type: 'uint16_t', name: '过压恢复值', unit: 'V' },
  326. { address: '81', type: 'uint16_t', name: '欠压恢复值', unit: 'V' },
  327. { address: '82', type: 'uint16_t', name: '速度限制最大值', unit: 'RPM', conversion: '32767 * 限制值 / 速度基准' },
  328. { address: '83', type: 'uint16_t', name: '速度限制最小值', unit: 'RPM' },
  329. { address: '84', type: 'uint16_t', name: '反电动势低阈值' },
  330. { address: '85', type: 'uint16_t', name: '反电动势高阈值' },
  331. { address: '86', type: 'uint16_t', name: '速度中间值', unit: 'RPM' },
  332. { address: '87', type: 'uint16_t', name: '功率保护值', unit: 'W', conversion: '32767 * 保护值 / 电流采样最大值 / 电压采样最大值' },
  333. { address: '88', type: 'uint16_t', name: '功率保护检测时间', unit: 'ms' },
  334. { address: '89', type: 'uint16_t', name: '温度保护值', unit: '℃' },
  335. { address: '8A', type: 'uint16_t', name: '温度恢复值', unit: '℃' },
  336. { address: '8B', type: 'uint16_t', name: '温度保护检测时间', unit: 'ms' },
  337. { address: '8C', type: 'uint16_t', name: '故障恢复检测时间', unit: 'ms' },
  338. { address: '8D', type: 'uint16_t', name: '串口丢失检测时间', unit: 'ms' }
  339. ], 'holding', '保护配置')
  340. const readonlyParamRegisters = withArea([
  341. { address: 'A8', type: 'ascii', name: '芯片型号', displayValue: '--', registerCount: 4, hideMeta: true },
  342. { address: 'AC', type: 'ascii', name: '型号', displayValue: '--', registerCount: 8, hideMeta: true },
  343. { address: 'A0', type: 'uint8_t', name: '载波频率', unit: 'KHz', displayValue: '--', bytePosition: 'high' },
  344. { address: 'A0', type: 'uint8_t', name: '基准电压', unit: 'V', displayValue: '--', bytePosition: 'low' },
  345. { address: 'A1', type: 'uint16_t', name: '运放倍数', displayValue: '--' },
  346. { address: 'A2', type: 'uint16_t', name: '采样电阻', unit: 'mΩ', displayValue: '--' },
  347. { address: 'A3', type: 'uint16_t', name: '全区 Flash 校验码', displayValue: '--' },
  348. { address: 'A4', type: 'float', name: '母线电压分压比', displayValue: '--' },
  349. { address: 'A6', type: 'float', name: '模拟输入电压分压比', displayValue: '--' }
  350. ], 'input', '只读参数寄存器')
  351. const userStatusRegisters = Array.from({ length: 10 }, (_, index) => ({
  352. address: (0xD3 + index).toString(16).toUpperCase(),
  353. type: 'uint16_t',
  354. name: `用户状态字 ${index + 1}`
  355. }))
  356. const statusRegisters = withArea([
  357. { address: 'C0', type: 'uint8_t', name: '状态机', bytePosition: 'high' },
  358. { address: 'C0', type: 'uint8_t', name: '故障码', bytePosition: 'low' },
  359. { address: 'C1', type: 'int16_t', name: 'UQ' },
  360. { address: 'C2', type: 'int16_t', name: 'UD' },
  361. { address: 'C3', type: 'int16_t', name: 'IQ' },
  362. { address: 'C4', type: 'int16_t', name: 'ID' },
  363. { address: 'C5', type: 'int16_t', name: 'A 相电流' },
  364. { address: 'C6', type: 'int16_t', name: 'B 相电流' },
  365. { address: 'C7', type: 'int16_t', name: 'C 相电流' },
  366. { address: 'C8', type: 'uint16_t', name: '相电流最大值' },
  367. { address: 'C9', type: 'uint16_t', name: '相电流最小值' },
  368. { address: 'CA', type: 'int16_t', name: '估算速度', unit: 'RPM' },
  369. { address: 'CB', type: 'uint16_t', name: '估算反电动势' },
  370. { address: 'CC', type: 'uint16_t', name: '母线电压', unit: '0.1V', displayUnit: 'V' },
  371. { address: 'CD', type: 'uint16_t', name: '母线电流', unit: '0.01A', displayUnit: 'A' },
  372. { address: 'CE', type: 'uint16_t', name: '估算功率', unit: 'W' },
  373. { address: 'CF', type: 'uint16_t', name: 'NTC 电压', unit: 'V', displayUnit: 'V' },
  374. { address: 'D0', type: 'uint16_t', name: '模拟输入电压', unit: 'V', displayUnit: 'V' },
  375. { address: 'D1', type: 'uint16_t', name: '频率', unit: 'Hz', displayUnit: 'Hz' },
  376. { address: 'D2', type: 'uint16_t', name: '占空比', unit: '%', displayUnit: '%' },
  377. ...userStatusRegisters
  378. ], 'input', '状态类寄存器')
  379. function getByteRegisterValue(item, wordValue) {
  380. if (!item || item.type !== 'uint8_t' || !item.bytePosition) return wordValue
  381. return (Number(wordValue) >> item.byteShift) & 0xFF
  382. }
  383. module.exports = {
  384. controlButtonRegisters,
  385. speedCommandRegister,
  386. atoBandwidthInputRegisters,
  387. dqGainInputRegisters,
  388. oilParameterInputRegisters,
  389. prepositionParameterInputRegisters,
  390. motorParameterInputRegisters,
  391. parameterInputRegisters,
  392. calculatedParameterRegisters,
  393. protectionSwitchRegisters,
  394. protectionRegisters,
  395. readonlyParamRegisters,
  396. speedLoopExtraRegisters,
  397. speedSlopeRegister,
  398. statusRegisters,
  399. tailwindSwitchRegisters,
  400. getByteRegisterValue
  401. }