Add device class name
This commit is contained in:
Родитель
5c9e708489
Коммит
02f30b003e
|
@ -36,6 +36,14 @@ if (w0 == 0x464c457f) {
|
|||
log("assuming BIN file")
|
||||
}
|
||||
|
||||
function fnv1a(data) {
|
||||
let h = 0x811c9dc5
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
h = Math.imul(h ^ data.charCodeAt(i), 0x1000193)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
w0 = buf.readUInt32LE(pos)
|
||||
if ((w0 & 0xff00_0000) == 0x2000_0000) {
|
||||
log("app mode")
|
||||
|
@ -46,12 +54,23 @@ if ((w0 & 0xff00_0000) == 0x2000_0000) {
|
|||
|
||||
// figure out device class
|
||||
const profile_name = basename.replace(/.*\/app-/, "")
|
||||
const src = fs.readFileSync(profiles_path + "/" + profile_name + ".c", "utf8")
|
||||
const m = /DEVICE_CLASS\((0x3[0-9a-f]+)\)/.exec(src)
|
||||
const profile_fn = profiles_path + "/" + profile_name + ".c"
|
||||
const src = fs.readFileSync(profile_fn, "utf8")
|
||||
const m = /DEVICE_CLASS\((0x3[0-9a-f]+),\s*"([^"]+)"\)/.exec(src)
|
||||
if (!m)
|
||||
throw "DEVICE_CLASS(0x3...) missing"
|
||||
const dev_class = parseInt(m[1])
|
||||
log("device class: " + dev_class.toString(16))
|
||||
throw "DEVICE_CLASS(0x3..., \"...\") missing"
|
||||
let dev_class = parseInt(m[1])
|
||||
const dev_class_name = m[2]
|
||||
const computed_class = ((fnv1a(dev_class_name) << 4) >>> 4) | 0x30000000
|
||||
if (computed_class != dev_class) {
|
||||
const trg = "0x" + computed_class.toString(16)
|
||||
const src2 = src.replace(m[1], trg)
|
||||
if (src == src2) throw "whoops"
|
||||
fs.writeFileSync(profile_fn, src2)
|
||||
console.log(`Patching ${profile_fn}: dev_class ${m[1]} -> ${trg}`)
|
||||
dev_class = computed_class
|
||||
}
|
||||
log(`device class: 0x${dev_class.toString(16)} "${dev_class_name}"`)
|
||||
|
||||
const reset = buf.readUInt32LE(pos + 4)
|
||||
const app_reset = buf.readInt32LE(pos + 13 * 4)
|
||||
|
|
|
@ -36,6 +36,15 @@ void ctrl_handle_packet(srv_t *_state, jd_packet_t *pkt) {
|
|||
case JD_CMD_CTRL_RESET:
|
||||
target_reset();
|
||||
break;
|
||||
case (JD_CMD_GET_REG | JD_REG_CTRL_DEVICE_DESCRIPTION):
|
||||
txq_push(JD_SERVICE_NUMBER_CTRL, pkt->service_command, app_dev_class_name,
|
||||
strlen(app_dev_class_name));
|
||||
break;
|
||||
case (JD_CMD_GET_REG | JD_REG_CTRL_DEVICE_CLASS): {
|
||||
uint32_t v = jd_hash_fnv1a(app_dev_class_name, strlen(app_dev_class_name));
|
||||
v = (v << 4 >> 4) | (0x3 << 28);
|
||||
txq_push(JD_SERVICE_NUMBER_CTRL, pkt->service_command, &v, sizeof(v));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
#include "blhw.h"
|
||||
|
||||
#ifdef BL
|
||||
#define DEVICE_CLASS(val) \
|
||||
#define DEVICE_CLASS(dev_class, dev_class_name) \
|
||||
struct bl_info_block __attribute__((section(".devinfo"), used)) bl_info = { \
|
||||
.devinfo = \
|
||||
{ \
|
||||
.magic = DEV_INFO_MAGIC, \
|
||||
.device_id = 0xffffffffffffffffULL, \
|
||||
.device_class = val, \
|
||||
.device_class = dev_class, \
|
||||
}, \
|
||||
.random_seed0 = 0xffffffff, \
|
||||
.random_seed1 = 0xffffffff, \
|
||||
|
@ -25,7 +25,7 @@
|
|||
.reserved1 = 0xffffffff, \
|
||||
};
|
||||
#else
|
||||
#define DEVICE_CLASS(val) /* nothing */
|
||||
#define DEVICE_CLASS(dev_class, dev_class_name) const char app_dev_class_name[] = dev_class_name;
|
||||
#endif
|
||||
|
||||
void init_services(void);
|
||||
|
@ -36,3 +36,5 @@ void crank_init(uint8_t pin0, uint8_t pin1);
|
|||
void light_init(void);
|
||||
void pwm_light_init(uint8_t pin);
|
||||
void servo_init(uint8_t pin);
|
||||
|
||||
extern const char app_dev_class_name[];
|
|
@ -1,6 +1,6 @@
|
|||
#include "jdprofile.h"
|
||||
|
||||
DEVICE_CLASS(0x3f7ffd77);
|
||||
DEVICE_CLASS(0x334b4fb6, "JDM3 acc");
|
||||
|
||||
void init_services() {
|
||||
acc_init();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "jdprofile.h"
|
||||
|
||||
DEVICE_CLASS(0x3d1868a7);
|
||||
DEVICE_CLASS(0x3beb4448, "JDM3 crank");
|
||||
|
||||
void init_services() {
|
||||
crank_init(PIN_P0, PIN_P1);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "jdprofile.h"
|
||||
|
||||
DEVICE_CLASS(0x3fb97809);
|
||||
DEVICE_CLASS(0x33498f7e, "JDM3 mono");
|
||||
|
||||
void init_services() {
|
||||
pwm_light_init(PIN_GLO1);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "jdprofile.h"
|
||||
|
||||
DEVICE_CLASS(0x3bb6c109);
|
||||
DEVICE_CLASS(0x3479bec3, "JDM3 light");
|
||||
|
||||
void init_services() {
|
||||
light_init();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#define PIN_SERVO PA_6
|
||||
|
||||
DEVICE_CLASS(0x35bdb27f);
|
||||
DEVICE_CLASS(0x3a1a3a06, "JDM3 servo");
|
||||
|
||||
void init_services() {
|
||||
servo_init(PIN_SERVO);
|
||||
|
|
Загрузка…
Ссылка в новой задаче