An ultra-lightweight Python interpreter that runs with only 4KB of RAM, zero dependencies. It is ready to use out of the box without any configuration required and easy to extend with C. Similar project: MicroPython, JerryScript.
python部分代码
def pack_cmd():
if key_id == 'MattressMotorCtrl':
if m == "0" and n == "corotation":
return bytes([0x99,0x01,0x00,0x00,0x00,0x00,0x9a,0xbb])
if m == "0" and n == "reversal":
return bytes([0x99,0x02,0x00,0x00,0x00,0x00,0x9b,0xbb])
if m == "1" and n == "corotation":
return bytes([0x99,0x03,0x00,0x00,0x00,0x00,0x9c,0xbb])
if m == "1" and n == "reversal":
return bytes([0x99,0x04,0x00,0x00,0x00,0x00,0x9d,0xbb])
if m == "2" and n == "corotation":
return bytes([0x99,0x05,0x00,0x00,0x00,0x00,0x9e,0xbb])
if m == "2" and n == "reversal":
return bytes([0x99,0x06,0x00,0x00,0x00,0x00,0x9f,0xbb])
.......
c调用python里的函数,python函数里的return值压力测试下会出错
c部分代码 obj_run(pikaMain, "mfr_cmd = pack_cmd()"); uint8_t *buf = obj_getBytes(pikaMain, "mfr_cmd");
python部分代码 def pack_cmd(): if key_id == 'MattressMotorCtrl': if m == "0" and n == "corotation": return bytes([0x99,0x01,0x00,0x00,0x00,0x00,0x9a,0xbb]) if m == "0" and n == "reversal": return bytes([0x99,0x02,0x00,0x00,0x00,0x00,0x9b,0xbb]) if m == "1" and n == "corotation": return bytes([0x99,0x03,0x00,0x00,0x00,0x00,0x9c,0xbb]) if m == "1" and n == "reversal": return bytes([0x99,0x04,0x00,0x00,0x00,0x00,0x9d,0xbb]) if m == "2" and n == "corotation": return bytes([0x99,0x05,0x00,0x00,0x00,0x00,0x9e,0xbb]) if m == "2" and n == "reversal": return bytes([0x99,0x06,0x00,0x00,0x00,0x00,0x9f,0xbb]) .......
python的if分支越多,或return个数越多,越容易出现
requestment.txt内容 pikascript-core==v1.12.5 PikaStdLib==v1.12.5 PikaStdDevice==v2.4.0 pika_cjson==v1.2.5 ESP32==v0.4.2 pika_libc==v1.0.2 time==v0.1.9