index.ts 11 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
import { FormSchema } from '/@/components/Form';

enum securityEnum {
  IS_X_CERTIFICATE = 'X509',
  IS_PAW_PUBLIC_KEY = 'RPK',
  IS_AUTO_GENERATE = 2,
  IS_AUTO_GENERATE_UNIQUE = 2,
  IS_DRX = 'PSM',
  IS_EDRX = 'E_DRX',
}

const isPawPublicKey = (type: string) => {
  return type === securityEnum.IS_PAW_PUBLIC_KEY;
};

const isCertificate = (type: string) => {
  return type === securityEnum.IS_X_CERTIFICATE;
};

const isAutoGenerate = (type: string) => {
  return type === securityEnum.IS_AUTO_GENERATE;
};

const isAutoGenerateUnique = (type: string) => {
  return type === securityEnum.IS_AUTO_GENERATE_UNIQUE;
};

const isDrx = (type: string) => {
  return type === securityEnum.IS_DRX;
};

const isEdrx = (type: string) => {
  return type === securityEnum.IS_EDRX;
};

export const modelSchemas: FormSchema[] = [
  {
    field: '0',
    component: 'Input',
    label: '对象列表',
    componentProps: {
      placeholder: '请输入Object list',
    },
    colProps: { span: 11 },
  },
];

export const settingsSchemas: FormSchema[] = [
  {
    field: 'fwUpdateStrategy',
    component: 'Select',
    label: '固件更新策略',
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: 'Push firmware update as binary file using Object 5 and Resource 0 (Package)',
          value: 1,
        },
        {
          label:
            'Auto-generate unique CoAP URL to download the package and push firmware update as Object 5 and',
          value: 2,
        },
        {
          label: 'Push firmware update as binary file using Object 19 and Resource 0 (Data)',
          value: 3,
        },
      ],
    },
    colProps: { span: 18 },
  },
  {
    field: 'fwUpdateResource',
    component: 'Input',
    label: '固件更新CoAP资源',
    required: true,
    defaultValue: 'coap://localhost:5685',
    componentProps: {
      placeholder: '请输入',
    },
    ifShow: ({ values }) => isAutoGenerate(Reflect.get(values, 'fwUpdateStrategy')),
    colProps: { span: 11 },
  },
  {
    field: 'swUpdateStrategy',
    component: 'Select',
    label: '软件更新策略',
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: 'Push binary file using Object 9 and Resource 2 (Package)',
          value: 1,
        },
        {
          label:
            'Auto-generate unique CoAP URL to download the package and push software update using Object 9 and',
          value: 2,
        },
      ],
    },
    colProps: { span: 18 },
  },
  {
    field: 'swUpdateResource',
    component: 'Input',
    label: '软件更新CoAP资源',
    required: true,
    defaultValue: 'coap://localhost:5685',
    componentProps: {
      placeholder: '请输入',
    },
    ifShow: ({ values }) => isAutoGenerateUnique(Reflect.get(values, 'swUpdateStrategy')),
    colProps: { span: 11 },
  },
  {
    field: 'powerMode',
    component: 'Select',
    label: '节能模式',
    defaultValue: 'DRX',
    componentProps: {
      options: [
        {
          label: 'Discontinuous Reception (DRX)',
          value: 'DRX',
        },
        {
          label: 'Power Saving Mode (PSM)',
          value: 'PSM',
        },
        {
          label: 'Extended Discontinuous Reception (eDRX)',
          value: 'E_DRX',
        },
      ],
    },
    colProps: { span: 18 },
  },
  {
    field: 'edrxCycle',
    component: 'InputNumber',
    label: 'PSM活动计时器',
    required: true,
    defaultValue: 10,
    colProps: { span: 11 },
    ifShow: ({ values }) => isDrx(values.powerMode),
  },
  {
    field: 'unit2',
    component: 'Select',
    label: '时间单位',
    defaultValue: 'second',
    componentProps: {
      options: [
        { label: 'Milliseconds', value: 'Milliseconds' },
        { label: '秒', value: 'second' },
        { label: '分钟', value: 'minute' },
        { label: '小时', value: 'hour' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isDrx(values.powerMode),
  },

  {
    field: 'edrxCycle',
    component: 'InputNumber',
    label: 'eDRX循环',
    required: true,
    defaultValue: 81,
    componentProps: {
      placeholder: '请输入PSM Activity Timer',
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isEdrx(values.powerMode),
  },
  {
    field: 'unit2',
    component: 'Select',
    label: '时间单位',
    defaultValue: 'second',
    componentProps: {
      options: [
        { label: 'Milliseconds', value: 'Milliseconds' },
        { label: '秒', value: 'second' },
        { label: '分钟', value: 'minute' },
        { label: '小时', value: 'hour' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isEdrx(values.powerMode),
  },
  {
    field: 'pagingTransmissionWindow',
    component: 'InputNumber',
    label: '寻呼传输窗口',
    required: true,
    defaultValue: 10,
    componentProps: {
      placeholder: '请输入Paging Transmission Window',
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isEdrx(values.powerMode),
  },
  {
    field: 'unit',
    component: 'Select',
    label: '时间单位',
    defaultValue: 'second',
    componentProps: {
      options: [
        { label: 'Milliseconds', value: 'Milliseconds' },
        { label: '秒', value: 'second' },
        { label: '分钟', value: 'minute' },
        { label: '小时', value: 'hour' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isEdrx(values.powerMode),
  },
  {
    field: 'compositeOperationsSupport',
    label: '启用',
    colProps: { span: 22 },
    component: 'Checkbox',
    defaultValue: false,
    renderComponentContent: '支持复合读/写/观察操作',
  },
];

export const deviceSchemas: FormSchema[] = [
  {
    field: '1',
    label: 'LWM2M',
    colProps: { span: 22 },
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        maxRows: 50,
      },
    },
    defaultValue: `
    {
      "observeAttr": {
        "observe": [],
        "attribute": [],
        "telemetry": [],
        "keyName": {},
        "attributeLwm2m": {}
      },
      "bootstrap": [
        {
          "shortServerId": 123,
          "bootstrapServerIs": false,
          "host": "0.0.0.0",
          "port": 5685,
          "clientHoldOffTime": 1,
          "serverPublicKey": "",
          "serverCertificate": "",
          "bootstrapServerAccountTimeout": 0,
          "lifetime": 300,
          "defaultMinPeriod": 1,
          "notifIfDisabled": true,
          "binding": "U",
          "securityMode": "NO_SEC"
        }
      ],
      "clientLwM2mSettings": {
        "clientOnlyObserveAfterConnect": 1,
        "fwUpdateStrategy": 1,
        "swUpdateStrategy": 1,
        "powerMode": "DRX",
        "compositeOperationsSupport": false
      },
      "bootstrapServerUpdateEnable": false,
      "type": "LWM2M"
    }
    `,
  },
];

export const serverSchemas: FormSchema[] = [
  {
    field: 'securityMode',
    component: 'Select',
    label: '安全配置',
    defaultValue: 'NO_SEC',
    helpMessage: [
      'X.509 Certificate模式和Raw Public Key模式和Pre-Shared Key模式下,port端口必须是5686',
    ],
    componentProps: {
      options: [
        {
          label: 'No Security',
          value: 'NO_SEC',
        },
        {
          label: 'Pre-Shared Key',
          value: 'PSK',
        },
        {
          label: 'Raw Public Key',
          value: 'RPK',
        },
        {
          label: 'X.509 Certificate',
          value: 'X509',
        },
      ],
    },
    colProps: { span: 8 },
  },
  {
    field: 'shortServerId',
    component: 'InputNumber',
    label: '短服务器ID',
    helpMessage: ['短服务器ID是唯一的'],
    required: true,
    defaultValue: 123,
    colProps: { span: 8 },
  },
  {
    field: 'host',
    component: 'Input',
    label: '主机',
    helpMessage: ['主机是唯一的'],
    required: true,
    defaultValue: '0.0.0.0',
    colProps: { span: 8 },
  },
  {
    field: 'port',
    component: 'Input',
    label: '端口',
    helpMessage: ['端口必须是5685'],
    required: true,
    defaultValue: 5685,
    colProps: { span: 8 },
  },
  {
    field: 'clientHoldOffTime',
    component: 'InputNumber',
    label: '延迟时间',
    required: true,
    defaultValue: 1,
    colProps: { span: 8 },
  },
  {
    field: 'bootstrapServerAccountTimeout',
    component: 'InputNumber',
    label: '超时后的帐户',
    required: true,
    defaultValue: 0,
    colProps: { span: 8 },
  },
  {
    field: 'lifetime',
    component: 'InputNumber',
    label: '注册生存期',
    required: true,
    defaultValue: 300,
    colProps: { span: 8 },
  },
  {
    field: 'defaultMinPeriod',
    component: 'InputNumber',
    label: '两次通知之间的最小周期',
    required: true,
    defaultValue: 1,
    colProps: { span: 8 },
  },
  {
    field: 'binding',
    component: 'Select',
    label: 'Binding',
    defaultValue: 'UQ',
    componentProps: {
      options: [
        {
          label: 'U: Client is reachable via the UDP binding at any time.',
          value: 'U',
        },
        {
          label: 'M: Client is reachable via the MQTT binding at any time.',
          value: 'M',
        },
        {
          label: 'H: Client is reachable via the HTTP binding at any time.',
          value: 'H',
        },
        {
          label: 'T: Client is reachable via the TCP binding at any time.',
          value: 'T',
        },
        {
          label: 'S: Client is reachable via the SMS binding at any time.',
          value: 'S',
        },
        {
          label:
            'N: Client MUST send the response to such a request over the Non-IP binding (is supported since LWM',
          value: 'N',
        },
        {
          label: 'UQ: UDP connection in queue mode (is not supported since LWM2M 1.1)',
          value: 'UQ',
        },
        {
          label:
            'UQS: both UDP and SMS connections active; UDP in queue mode, SMS in standard mode (is not supported since LWM2M 1.1)',
          value: 'UQS',
        },
        {
          label: 'TQ: TCP connection in queue mode (is not supported since LWM2M 1.1)',
          value: 'TQ:',
        },
        {
          label:
            'TQS: both TCP and SMS connections active; TCP in queue mode, SMS in standard mode (is not supported since LWM2M 1.1)	',
          value: 'TQS',
        },
        {
          label: 'SQ: SMS connection in queue mode (is not supported since LWM2M 1.1)',
          value: 'SQ',
        },
      ],
    },
    colProps: { span: 11 },
  },
  {
    field: 'notifIfDisabled',
    label: '是否启用',
    colProps: { span: 22 },
    component: 'Checkbox',
    defaultValue: true,
    renderComponentContent: '禁用或脱机时的通知存储',
  },
  {
    field: 'serverPublicKey',
    component: 'InputTextArea',
    label: '服务器公钥',
    required: true,
    colProps: { span: 22 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入服务器公钥',
    },
    ifShow: ({ values }) =>
      isCertificate(Reflect.get(values, 'securityMode')) ||
      isPawPublicKey(Reflect.get(values, 'securityMode')),
  },
];