1 -- 协议解析文件描述,根据实际情况修正 2 -- author : andywo 3 -- email : 4 -- date : 2022-01-24 5 -- T0xFD : 气味小播灯 6 7 -- 必须要引入的库 8 local JSON = require "cjson" 9 10 11 12 -- 协议相关常量,请勿修改 13 14 -- 控制请求 15 local BYTE_CONTROL_REQUEST = 0x02 16 -- 查询请求 17 local BYTE_QUERY_REQUEST = 0x03 18 -- 协议头 19 local BYTE_PROTOCOL_HEAD = 0xAA 20 -- 协议头长度 21 local BYTE_PROTOCOL_LENGTH = 0x0A 22 23 -- 公共属性值,预定义的值,请勿修改 24 -- 属性值为未知值时,使用此值。 25 local VALUE_UNKNOWN = "unknown" 26 -- 属性值为无效值时,使用此值。 27 local VALUE_INVALID = "invalid" 28 29 30 31 -- 协议相关变量,此部分根据实际需要修改,但是local变量的个数不能超过60个,若超过,请使用table封装变量。 32 33 -- 数据返回类型,02:控制返回, 03:查询返回, 04:主动上报, 05:主动上报(需要响应), 06:设备异常事件上报。 34 local dataType = 0 35 -- 子命令(若有) 36 local cmdType=0 37 38 -- profile 中的 key定义,若太多,请使用table封装变量 39 local KEY_VERSION = "version" 40 local KEY_POWER = "power" 41 local KEY_SCENE_LIGHT = "scene_light" 42 local KEY_COLOR_TEMPERATURE = "color_temperature" 43 local KEY_BRIGHTNESS = "brightness" 44 local KEY_DELAY_LIGHT_OFF = "delay_light_off" 45 local KEY_LIFE_COLOR_TEMPERATURE = "life_color_temperature" 46 local KEY_LIFE_BRIGHTNESS = "life_brightness" 47 local KEY_READ_COLOR_TEMPERATURE = "read_color_temperature" 48 local KEY_READ_BRIGHTNESS = "read_brightness" 49 local KEY_MILD_COLOR_TEMPERATURE = "mild_color_temperature" 50 local KEY_MILD_BRIGHTNESS = "mild_brightness" 51 local KEY_FILM_COLOR_TEMPERATURE = "film_color_temperature" 52 local KEY_FILM_BRIGHTNESS = "film_brightness" 53 local KEY_LIGHT_COLOR_TEMPERATURE = "light_color_temperature" 54 local KEY_LIGHT_BRIGHTNESS = "light_brightness" 55 local KEY_RESULT = "result" 56 57 -- 存储属性值的变量,若太多,请使用table封装变量 58 local powerValue = 0 59 local sceneLight = 0 60 local colorTemperature = 0 61 local brightness = 0 62 local delayLightOff = 0 63 local lifeColorTemperature = 0 64 local lifeBrightness = 0 65 local readColorTemperature = 0 66 local readBrightness = 0 67 local mildColorTemperature = 0 68 local mildBrightness = 0 69 local filmColorTemperature = 0 70 local filmBrightness = 0 71 local lightColorTemperature = 0 72 local lightBrightness = 0 73 local colorRed=0 74 local colorGreen=0 75 local colorBlue=0 76 local result=0 77 78 79 80 --公共的函数,请勿随意修改。 81 82 -- 从电控协议(byteData)中提取消息体(body),返回的消息体数组索引从0开始。 83 local function extractBodyBytes(byteData) 84 local msgLength = #byteData 85 local msgBytes = {} 86 local bodyBytes = {} 87 for i = 1, msgLength do 88 msgBytes[i - 1] = byteData[i] 89 end 90 --去掉消息头和校验码就剩下消息体 91 local bodyLength = msgLength - BYTE_PROTOCOL_LENGTH - 1 92 --获取消息体 body 部分 93 for i = 0, bodyLength - 1 do 94 bodyBytes[i] = msgBytes[i + BYTE_PROTOCOL_LENGTH] 95 end 96 return bodyBytes 97 end 98 99 -- 计算校验和 100 local function makeSum(tmpbuf, start_pos, end_pos) 101 local resVal = 0 102 for si = start_pos, end_pos do 103 resVal = resVal + tmpbuf[si] 104 end 105 resVal = bit.bnot(resVal)+1 106 resVal = bit.band(resVal, 0x00ff) 107 return resVal 108 end 109 110 -- 1.将bodyBytes组装上电控协议头(10字节)和尾部校验码(1字节)。 111 -- 2.传入的 bodyBytes 为索引从0开始。 112 -- 3.返回的 table 索引也从0开始。 113 local function assembleUart(bodyBytes, type) 114 local bodyLength = #bodyBytes + 1 115 if bodyLength == 0 then 116 return nil 117 end 118 119 local msgLength = (bodyLength + BYTE_PROTOCOL_LENGTH + 1) 120 local msgBytes = {} 121 122 for i = 0, msgLength - 1 do 123 msgBytes[i] = 0 124 end 125 --构造消息部分 126 msgBytes[0] = BYTE_PROTOCOL_HEAD 127 msgBytes[1] = msgLength - 1 128 msgBytes[2] = 0x13 129 msgBytes[9] = type 130 131 for i = 0, bodyLength - 1 do 132 msgBytes[i + BYTE_PROTOCOL_LENGTH] = bodyBytes[i] 133 end 134 135 msgBytes[msgLength - 1] = makeSum(msgBytes, 1, msgLength - 2) 136 return msgBytes 137 end 138 139 -- CRC码表 140 local crc8_854_table = 141 { 142 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, 143 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, 144 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, 145 190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255, 146 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7, 147 219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154, 148 101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36, 149 248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185, 150 140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205, 151 17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80, 152 175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238, 153 50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115, 154 202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139, 155 87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22, 156 233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168, 157 116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53 158 } 159 160 -- CRC校验码 161 local function crc8_854(dataBuf, start_pos, end_pos) 162 local crc = 0 163 164 for si = start_pos, end_pos do 165 crc = crc8_854_table[bit.band(bit.bxor(crc, dataBuf[si]), 0xFF) + 1] 166 end 167 168 return crc 169 end 170 171 -- 将json字符串转换为LUA中的table 172 local function decodeJsonToTable(cmd) 173 local tb 174 175 if JSON == nil then 176 JSON = require "cjson" 177 end 178 179 tb = JSON.decode(cmd) 180 181 return tb 182 end 183 184 -- 将LUA中的table转换为json字符串 185 local function encodeTableToJson(luaTable) 186 local jsonStr 187 188 if JSON == nil then 189 JSON = require "cjson" 190 end 191 192 jsonStr = JSON.encode(luaTable) 193 194 return jsonStr 195 end 196 197 -- 将十六进制string字符串转成LUA中的table 198 local function string2table(hexstr) 199 local tb = {} 200 local i = 1 201 local j = 1 202 203 for i = 1, #hexstr - 1, 2 do 204 local doublebytestr = string.sub(hexstr, i, i + 1) 205 tb[j] = tonumber(doublebytestr, 16) 206 j = j + 1 207 end 208 209 return tb 210 end 211 212 -- 将table转成字符串 213 local function table2string(cmd) 214 local ret = "" 215 local i 216 217 for i = 1, #cmd do 218 ret = ret .. string.char(cmd[i]) 219 end 220 221 return ret 222 end 223 224 -- 将字符串转成十六进制字符串输出 225 local function string2hexstring(str) 226 local ret = "" 227 228 for i = 1, #str do 229 ret = ret .. string.format("%02x", str:byte(i)) 230 end 231 232 return ret 233 end 234 235 -- 检查data的值是否超过边界 236 local function checkBoundary(data, min, max) 237 if (not data) then 238 data = 0 239 end 240 241 data = tonumber(data) 242 243 if ((data >= min) and (data <= max)) then 244 return data 245 else 246 if (data < min) then 247 return min 248 else 249 return max 250 end 251 end 252 end 253 254 -- 将String转int 255 local function string2Int(data) 256 if (not data) then 257 data = tonumber("0") 258 end 259 data = tonumber(data) 260 if (data == nil) then 261 data = 0 262 end 263 return data 264 end 265 266 -- 将int转String 267 local function int2String(data) 268 if (not data) then 269 data = tostring(0) 270 end 271 data = tostring(data) 272 if (data == nil) then 273 data = "0" 274 end 275 return data 276 end 277 278 -- 打印table表 279 local function print_lua_table(lua_table, indent) 280 indent = indent or 0 281 282 for k, v in pairs(lua_table) do 283 if type(k) == "string" then 284 k = string.format("%q", k) 285 end 286 287 local szSuffix = "" 288 289 if type(v) == "table" then 290 szSuffix = "{" 291 end 292 293 local szPrefix = string.rep(" ", indent) 294 formatting = szPrefix .. "[" .. k .. "]" .. " = " .. szSuffix 295 296 if type(v) == "table" then 297 print(formatting) 298 299 print_lua_table(v, indent + 1) 300 301 print(szPrefix .. "},") 302 else 303 local szValue = "" 304 305 if type(v) == "string" then 306 szValue = string.format("%q", v) 307 else 308 szValue = tostring(v) 309 end 310 311 print(formatting .. szValue .. ",") 312 end 313 end 314 end 315 316 317 318 -- 根据电控协议不同,需要改变的函数 319 320 -- 根据传入的json修改全局变量值 321 local function updateGlobalPropertyValueByJson(luaTable) 322 if luaTable[KEY_POWER] == "on" then 323 powerValue = 0x01 324 elseif luaTable[KEY_POWER] == "off" then 325 powerValue = 0x00 326 end 327 328 if luaTable[KEY_SCENE_LIGHT] == "life" then 329 sceneLight=0x02 330 elseif luaTable[KEY_SCENE_LIGHT] == "read" then 331 sceneLight=0x03 332 elseif luaTable[KEY_SCENE_LIGHT] == "mild" then 333 sceneLight=0x04 334 elseif luaTable[KEY_SCENE_LIGHT] == "film" then 335 sceneLight=0x05 336 elseif luaTable[KEY_SCENE_LIGHT] == "light" then 337 sceneLight=0x06 338 end 339 340 if luaTable[KEY_COLOR_TEMPERATURE] ~= nil then 341 colorTemperature=string2Int(luaTable[KEY_COLOR_TEMPERATURE]) 342 end 343 344 if luaTable[KEY_BRIGHTNESS] ~= nil then 345 brightness=string2Int(luaTable[KEY_BRIGHTNESS]) 346 end 347 348 if luaTable[KEY_DELAY_LIGHT_OFF] ~= nil then 349 delayLightOff=string2Int(luaTable[KEY_DELAY_LIGHT_OFF]) 350 end 351 352 --设置色温/亮度 353 if luaTable[KEY_LIFE_COLOR_TEMPERATURE] ~= nil then 354 lifeColorTemperature=string2Int(luaTable[KEY_LIFE_COLOR_TEMPERATURE]) 355 end 356 if luaTable[KEY_LIFE_BRIGHTNESS] ~= nil then 357 lifeBrightness=string2Int(luaTable[KEY_LIFE_BRIGHTNESS]) 358 end 359 360 if luaTable[KEY_READ_COLOR_TEMPERATURE] ~= nil then 361 readColorTemperature=string2Int(luaTable[KEY_READ_COLOR_TEMPERATURE]) 362 end 363 364 if luaTable[KEY_READ_BRIGHTNESS] ~= nil then 365 readBrightness=string2Int(luaTable[KEY_READ_BRIGHTNESS]) 366 end 367 368 if luaTable[KEY_MILD_COLOR_TEMPERATURE] ~= nil then 369 mildColorTemperature=string2Int(luaTable[KEY_MILD_COLOR_TEMPERATURE]) 370 end 371 if luaTable[KEY_MILD_BRIGHTNESS] ~= nil then 372 mildBrightness=string2Int(luaTable[KEY_MILD_BRIGHTNESS]) 373 end 374 375 if luaTable[KEY_FILM_COLOR_TEMPERATURE] ~= nil then 376 filmColorTemperature=string2Int(luaTable[KEY_FILM_COLOR_TEMPERATURE]) 377 end 378 if luaTable[KEY_FILM_BRIGHTNESS] ~= nil then 379 filmBrightness=string2Int(luaTable[KEY_FILM_BRIGHTNESS]) 380 end 381 382 if luaTable[KEY_LIGHT_COLOR_TEMPERATURE] ~= nil then 383 lightColorTemperature=string2Int(luaTable[KEY_LIGHT_COLOR_TEMPERATURE]) 384 end 385 if luaTable[KEY_LIGHT_BRIGHTNESS] ~= nil then 386 lightBrightness=string2Int(luaTable[KEY_LIGHT_BRIGHTNESS]) 387 end 388 end 389 390 -- 根据传入的byte[]修改全局变量值 391 local function updateGlobalPropertyValueByByte(messageBytes) 392 cmdType=messageBytes[0] 393 if cmdType==0x81 then 394 --powerValue=messageBytes[1] 395 result=messageBytes[1] 396 end 397 if cmdType==0x82 then 398 --sceneLight=messageBytes[1] 399 result=messageBytes[1] 400 end 401 if cmdType==0x83 then 402 --colorTemperature=messageBytes[1] 403 result=messageBytes[1] 404 end 405 if cmdType==0x84 then 406 --brightness=messageBytes[1] 407 result=messageBytes[1] 408 end 409 if cmdType==0x85 then 410 --delayLightOff=messageBytes[1] 411 result=messageBytes[1] 412 end 413 if cmdType==0xa4 then 414 brightness=messageBytes[1] 415 colorTemperature=messageBytes[2] 416 sceneLight=messageBytes[3] 417 delayLightOff=messageBytes[4] 418 419 colorRed=messageBytes[5] 420 colorGreen=messageBytes[6] 421 colorBlue=messageBytes[7] 422 423 powerValue=messageBytes[8] 424 425 lifeBrightness=messageBytes[9] 426 lifeColorTemperature=messageBytes[10] 427 readBrightness=messageBytes[11] 428 readColorTemperature=messageBytes[12] 429 mildBrightness=messageBytes[13] 430 mildColorTemperature=messageBytes[14] 431 filmBrightness=messageBytes[15] 432 filmColorTemperature=messageBytes[16] 433 lightBrightness=messageBytes[17] 434 lightColorTemperature=messageBytes[18] 435 end 436 437 if cmdType==0x86 then 438 --lifeBrightness=messageBytes[1] 439 --lifeColorTemperature=messageBytes[2] 440 result=messageBytes[1] 441 end 442 if cmdType==0x87 then 443 --readBrightness=messageBytes[1] 444 --readColorTemperature=messageBytes[2] 445 result=messageBytes[1] 446 end 447 if cmdType==0x88 then 448 --mildBrightness=messageBytes[1] 449 --mildColorTemperature=messageBytes[2] 450 result=messageBytes[1] 451 end 452 if cmdType==0x89 then 453 --filmBrightness=messageBytes[1] 454 --filmColorTemperature=messageBytes[2] 455 result=messageBytes[1] 456 end 457 if cmdType==0x8a then 458 --lightBrightness=messageBytes[1] 459 --lightColorTemperature=messageBytes[2] 460 result=messageBytes[1] 461 end 462 end 463 464 -- 将属性值转换为最终table 465 local function assembleJsonByGlobalProperty() 466 local streams = {} 467 --版本 468 streams[KEY_VERSION] = "2" 469 470 if cmdType==0xa4 then 471 472 streams[KEY_BRIGHTNESS]=int2String(brightness) 473 streams[KEY_COLOR_TEMPERATURE]=int2String(colorTemperature) 474 475 if sceneLight==0x02 then 476 streams[KEY_SCENE_LIGHT] = "life" 477 elseif sceneLight==0x03 then 478 streams[KEY_SCENE_LIGHT] = "read" 479 elseif sceneLight==0x04 then 480 streams[KEY_SCENE_LIGHT] = "mild" 481 elseif sceneLight==0x05 then 482 streams[KEY_SCENE_LIGHT] = "film" 483 elseif sceneLight==0x06 then 484 streams[KEY_SCENE_LIGHT] = "light" 485 elseif sceneLight==0x01 then 486 streams[KEY_SCENE_LIGHT] = "manual" 487 end 488 489 streams[KEY_DELAY_LIGHT_OFF]=int2String(delayLightOff) 490 491 streams["color_red"]=int2String(colorRed) 492 streams["color_green"]=int2String(colorGreen) 493 streams["color_blue"]=int2String(colorBlue) 494 495 if powerValue==0x01 then 496 streams[KEY_POWER] = "on" 497 elseif powerValue==0x00 then 498 streams[KEY_POWER] = "off" 499 end 500 501 streams[KEY_LIFE_BRIGHTNESS]=int2String(lifeBrightness) 502 streams[KEY_LIFE_COLOR_TEMPERATURE]=int2String(lifeColorTemperature) 503 streams[KEY_READ_BRIGHTNESS]=int2String(readBrightness) 504 streams[KEY_READ_COLOR_TEMPERATURE]=int2String(readColorTemperature) 505 streams[KEY_MILD_BRIGHTNESS]=int2String(mildBrightness) 506 streams[KEY_MILD_COLOR_TEMPERATURE]=int2String(mildColorTemperature) 507 streams[KEY_FILM_BRIGHTNESS]=int2String(filmBrightness) 508 streams[KEY_FILM_COLOR_TEMPERATURE]=int2String(filmColorTemperature) 509 streams[KEY_LIGHT_BRIGHTNESS]=int2String(lightBrightness) 510 streams[KEY_LIGHT_COLOR_TEMPERATURE]=int2String(lightColorTemperature) 511 512 streams[KEY_RESULT]="1" 513 else 514 streams[KEY_RESULT]=int2String(result) 515 end 516 517 return streams 518 end 519 520 -- 接口方法,json转二进制,可传入原状态,此方法不能使用local修饰 521 function jsonToData(jsonCmdStr) 522 if (#jsonCmdStr == 0) then 523 return nil 524 end 525 local msgBytes 526 527 528 local json = decodeJsonToTable(jsonCmdStr) 529 530 local deviceSubType = json["deviceinfo"]["deviceSubType"] 531 532 local query = json["query"] 533 local control = json["control"] 534 local status = json["status"] 535 536 --当前是查询指令,构造固定的二进制即可 537 538 if (control) then 539 --将原始状态 转换为属性(全状态协议时使用) 540 if (status) then 541 --updateGlobalPropertyValueByJson(status) 542 end 543 544 --将用户控制 转换为属性 545 if (control) then 546 updateGlobalPropertyValueByJson(control) 547 end 548 549 local bodyLength = 5 550 local bodyBytes = {} 551 for i = 0, bodyLength - 1 do 552 bodyBytes[i] = 0 553 end 554 --构造消息 body 部分 555 556 if control[KEY_POWER] ~=nil then 557 bodyBytes[0] = 0x01 558 bodyBytes[1] = powerValue 559 elseif control[KEY_SCENE_LIGHT] ~= nil then 560 bodyBytes[0] = 0x02 561 bodyBytes[1] = sceneLight 562 elseif control[KEY_COLOR_TEMPERATURE] ~= nil then 563 bodyBytes[0] = 0x03 564 bodyBytes[1] = colorTemperature 565 elseif control[KEY_BRIGHTNESS] ~= nil then 566 bodyBytes[0] = 0x04 567 bodyBytes[1] = brightness 568 elseif control[KEY_DELAY_LIGHT_OFF] ~= nil then 569 bodyBytes[0] = 0x05 570 bodyBytes[1] = delayLightOff 571 elseif control[KEY_LIFE_COLOR_TEMPERATURE] ~= nil and control[KEY_LIFE_BRIGHTNESS] ~= nil then 572 bodyBytes[0] = 0x06 573 bodyBytes[1] = lifeBrightness 574 bodyBytes[2] = lifeColorTemperature 575 elseif control[KEY_READ_COLOR_TEMPERATURE] ~= nil and control[KEY_READ_BRIGHTNESS] ~= nil then 576 bodyBytes[0] = 0x07 577 bodyBytes[1] = readBrightness 578 bodyBytes[2] = readColorTemperature 579 elseif control[KEY_MILD_COLOR_TEMPERATURE] ~= nil and control[KEY_MILD_BRIGHTNESS] ~= nil then 580 bodyBytes[0] = 0x08 581 bodyBytes[1] = mildBrightness 582 bodyBytes[2] = mildColorTemperature 583 elseif control[KEY_FILM_COLOR_TEMPERATURE] ~= nil and control[KEY_FILM_BRIGHTNESS] ~= nil then 584 bodyBytes[0] = 0x09 585 bodyBytes[1] = filmBrightness 586 bodyBytes[2] = filmColorTemperature 587 elseif control[KEY_LIGHT_COLOR_TEMPERATURE] ~= nil and control[KEY_LIGHT_BRIGHTNESS] ~= nil then 588 bodyBytes[0] = 0x0A 589 bodyBytes[1] = lightBrightness 590 bodyBytes[2] = lightColorTemperature 591 end 592 593 msgBytes = assembleUart(bodyBytes, BYTE_CONTROL_REQUEST) 594 elseif (query) then 595 --构造消息 body 部分 596 local bodyLength = 5 597 local bodyBytes = {} 598 for i = 0, bodyLength - 1 do 599 bodyBytes[i] = 0 600 end 601 bodyBytes[0] = 0x24 602 603 msgBytes = assembleUart(bodyBytes, BYTE_QUERY_REQUEST) 604 end 605 606 --lua table 索引从 1 开始,因此此处要重新转换一次 607 local infoM = {} 608 609 local length = #msgBytes + 1 610 611 for i = 1, length do 612 infoM[i] = msgBytes[i - 1] 613 end 614 615 --table 转换成 string 之后返回 616 local ret = table2string(infoM) 617 ret = string2hexstring(ret) 618 return ret 619 end 620 621 -- 接口方法,二进制转json,此方法不能使用local修饰 622 function dataToJson(jsonStr) 623 if (not jsonStr) then 624 return nil 625 end 626 627 local json = decodeJsonToTable(jsonStr) 628 629 local deviceinfo = json["deviceinfo"] 630 631 --根据设备子类型来处理协议差异 632 local deviceSubType = deviceinfo["deviceSubType"] 633 if (deviceSubType == 1) then 634 end 635 636 local binData = json["msg"]["data"] 637 638 local bodyBytes = {} 639 --包括Uart头 640 local byteData = string2table(binData) 641 642 --获取消息数据类型 643 dataType = byteData[10]; 644 645 bodyBytes = extractBodyBytes(byteData) 646 647 --将二进制状态解析为属性值 648 local ret = updateGlobalPropertyValueByByte(bodyBytes) 649 local retTable = {} 650 --将属性转换为table 651 retTable["status"] = assembleJsonByGlobalProperty() 652 --将table转换为json 653 local ret = encodeTableToJson(retTable) 654 return ret 655 end
与美的平台对接,获取自己的设备数据转换成美的平台数据的LUA脚本;指令列表
测试结果
获取设备通道气味编号
{
"deviceinfo": {
"deviceSubType": 1
},
"control": {
"cmd":"getchlscentid"
}
}
下发指令:[1~10]: aa,15,fd,00,00,00,00,00,00,02,[11~20]: f5,00,00,00,00,0e,01,06,51,fb,[21~22]: 55,41
播放通道2持续20秒
{
"deviceinfo": {
"deviceSubType": 1
},
"control": {
"cmd":"playscent",
"channelid":2,
"duration":20
}
}
下发指令:[1~10]: aa,19,fd,00,00,00,00,00,00,02,[11~20]: f5,00,00,00,00,02,05,02,00,00,[21~26]: 4e,20,c9,68,55,f6
停止播放指令
{
"deviceinfo": {
"deviceSubType": 1
},
"control": {
"cmd":"stopplay",
"stopflag":0
}
}
下发指令:[1~10]: aa,15,fd,00,00,00,00,00,00,02,[11~20]: f5,00,00,00,00,00,01,00,90,1a,[21~22]: 55,f7
返回获取通道指令 AA 1D FD E0 00 00 00 00 00 02 F5 00 00 00 00 0E 09 00 10 02 00 30 04 00 50 06 CD 85 55 B5
返回JSON
{
"status": {
"receive": "F5 00 00 00 00 0E 09 00 10 02 00 30 04 00 50 06 CD 85 55 ",
"result": "00",
"cmd": "0E",
"scentid1": 1,
"scentid2": 2,
"scentid3": 3,
"scentid4": 4,
"scentid5": 5,
"scentid6": 6
}
}
-------------------------------------------------------------------------------------------
返回停止执行指令 AA 15 FD 00 00 00 00 00 00 02 F5 00 00 00 00 00 01 00 90 1A 55 F7
返回JSON
{
"status": {
"receive": "F5 00 00 00 00 00 01 00 90 1A 55 ",
"result": 0,
"cmd": "00"
}
}
返回播放指令 AA 19 FD 00 00 00 00 00 00 02 F5 00 00 00 00 02 01 00 41 34 55 44
返回JSON
{
"status": {
"receive": "F5 00 00 00 00 02 01 00 41 34 55 ",
"result": 0,
"cmd": "02"
}
}
返回查询非正常执行指令 AA 15 FD 00 00 00 00 00 00 02 F5 00 00 00 00 99 01 00 90 1A 55 F7
返回JSON
{
"status": {
"receive": "F5 00 00 00 00 99 01 00 90 1A 55 ",
"result": 1,
"cmd": "99"
}
}
返回非正常指令 AA 15 FD 00 00 00 00 00 00 02 00 00 00 00 00 F7
返回JSON
{
"status": {
"receive": "00 00 00 00 00 ",
"result": "01",
"cmd": "FF"
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix