/* pの先頭から出力して行き,その階層のjump/proceedが出てくるまでを変換する jump先は中間命令ではアドレスになっているが, そのポインタ値が何個めのjump先として現れたか(index)を,その関数のシグネチャに使う 物理的に次の読み込み場所を返す (変換するスタート地点, 変換する必要のある部分の記録, ルールのシグネチャ:trans_**_**_**, 成功時コード, 失敗時コード, インデント) */ const BYTE *translate_instructions(const BYTE *p, Vector *jump_points, const char *header, const char *successcode, const char *failcode, int indent) { while(1){ /* 自動生成で変換可能な中間命令をトランスレートする */ /* 終了フラグ: 正のとき変換成功+次を変換, 0のとき変換成功+jump/proceed等なので終了, 負のとき変換失敗 */ const BYTE *next; int finishflag; next = translate_instruction_generated(p, jump_points, header, successcode, failcode, indent, &finishflag); if (finishflag > 0){ p = next; continue; } else if(finishflag == 0) { return next; } else { /* 自動生成で対処できない中間命令をトランスレートする */ next = translate_instruction(p, jump_points, header, successcode, failcode, indent, &finishflag); if (finishflag > 0) { p = next; continue; } else if(finishflag == 0) { return next; } else { LmnInstrOp op; READ_VAL(LmnInstrOp, p, op); fprintf(stderr, "translator: unknown instruction: %d\n", op); exit(1); } } } }
static int py_anal(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { PyObject *tmpreg = NULL; int size = 0; int seize = -1; int i = 0; if (!op) return -1; if (py_anal_cb) { memset(op, 0, sizeof (RAnalOp)); // anal(addr, buf) - returns size + dictionary (structure) for RAnalOp Py_buffer pybuf = { .buf = (void *) buf, // Warning: const is lost when casting .len = len, .readonly = 1, .ndim = 1, .itemsize = 1, }; PyObject *memview = PyMemoryView_FromBuffer (&pybuf); PyObject *arglist = Py_BuildValue ("(NK)", memview, addr); PyObject *result = PyEval_CallObject (py_anal_cb, arglist); if (result && PyList_Check (result)) { PyObject *len = PyList_GetItem (result, 0); PyObject *dict = PyList_GetItem (result, 1); if (dict && PyDict_Check (dict)) { seize = PyNumber_AsSsize_t (len, NULL); op->type = getI (dict, "type"); op->cycles = getI (dict, "cycles"); op->size = seize; op->addr = getI (dict, "addr"); op->jump = getI (dict, "jump"); op->fail = getI (dict, "fail"); op->stackop = getI (dict, "stackop"); op->stackptr = getI (dict, "stackptr"); op->ptr = getI (dict, "ptr"); op->eob = getB (dict, "eob"); // Loading 'src' and 'dst' values // SRC is is a list of 3 elements PyObject *tmpsrc = getO (dict, "src"); if (tmpsrc && PyList_Check (tmpsrc)) { for (i = 0; i < 3; i++) { PyObject *tmplst = PyList_GetItem (tmpsrc, i); // Read value and underlying regs READ_VAL(tmplst, op->src[i], tmpreg) } } PyObject *tmpdst = getO (dict, "dst"); // Read value and underlying regs READ_VAL(tmpdst, op->dst, tmpreg) // Loading 'var' value if presented r_strbuf_set (&op->esil, getS (dict, "esil")); // TODO: Add opex support here Py_DECREF (dict); } Py_DECREF (result); } else {
int main(void) { int c; int ret; uint8_t id; uint8_t type; uint8_t * data; int16_t cntr = 0; DDRA |= _BV(PA6) | _BV(PA7); DDRC = 0xFF; //PORTC= 0X00; int ii=0; uint8_t val = 1; init(); uart0_printf("estop initialized\r\n"); DynamixelPacket xbeePacket; DynamixelPacketInit(&xbeePacket); uint8_t robotId; uint8_t robotState; const int bufSize = 256; uint8_t buf[bufSize]; uint8_t * pbuf; uint8_t estopPacketLen; const int nRobots = 9; uint8_t mode[nRobots+1] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; estopPacketLen = DynamixelPacketWrapData(MMC_ESTOP_DEVICE_ID, MMC_ESTOP_STATE,mode,nRobots+1,buf,bufSize); uint8_t modVal; while(1) { cntr++; if (cntr == 1000) cntr = 0; modVal = cntr % 200; if (modVal == 0) { //generate new packet based on the latest desired estop state estopPacketLen = DynamixelPacketWrapData(MMC_ESTOP_DEVICE_ID, MMC_ESTOP_STATE,commandedState,nRobots+1,buf,bufSize); pbuf = buf; for (ii=0; ii<estopPacketLen; ii++) uart1_putchar(*pbuf++); //uart0_printf("sent estop packet\r\n"); } //show the actual status for brief moment if (modVal < 50) { ShowActualStateAll(); } else { ShowCommandedStateAll(); } //read from xbee while( (c = uart1_getchar()) != EOF ) { //uart0_printf("%X ",c);; ret = DynamixelPacketProcessChar(c,&xbeePacket); if (ret > 0) { id = DynamixelPacketGetId(&xbeePacket); type = DynamixelPacketGetType(&xbeePacket); data = DynamixelPacketGetData(&xbeePacket); if (id == MMC_ESTOP_DEVICE_ID && type == MMC_ESTOP_STATE) { robotId = data[0]; robotState = data[1]; if ( (robotId > 0) && (robotId < 11) && (robotState >= 0) && (robotState < 3) ) { actualState[robotId] = robotState; uart0_printf("Robot%d: estop = %d\r\n",robotId,robotState); } else uart0_printf("xbee received bad data : Robot%d: estop = %d\r\n",robotId,robotState); } } } READ_ESTOP_STATE(1); READ_ESTOP_STATE(2); READ_ESTOP_STATE(3); READ_ESTOP_STATE(4); READ_ESTOP_STATE(5); READ_ESTOP_STATE(6); READ_ESTOP_STATE(7); READ_ESTOP_STATE(8); READ_ESTOP_STATE(9); READ_ESTOP_STATE(10); //check the master pause button if ( (READ_VAL(RP_IN0_PORT,RP_IN0_PIN)) && debounceCntr[0] == DEBOUNCE_DELAY ) { if ( commandedState[0] == 1 ) { for (ii=0; ii<11; ii++) commandedState[ii] = 0; } else if (commandedState[0]==0) { for (ii=0; ii<11; ii++) commandedState[ii] = 1; } debounceCntr[0] = 0; } if (debounceCntr[0] < DEBOUNCE_DELAY) debounceCntr[0]++; SHOW_COMMANDED_STATE(0); /* if ( READ_VAL(RP_IN1_PORT,RP_IN1_PIN) ) SET_PIN(LED_OUT1_PORT,LED_OUT1_PIN); else CLEAR_PIN(LED_OUT1_PORT,LED_OUT1_PIN); */ /* if (val == 0) DDRC=0x00; //val = 1; else val = val << 1; PORTC = val; */ //PORTC = PINL; _delay_ms(5); } return 0; }
const BYTE *translate_instruction(const BYTE *instr, Vector *jump_points, const char *header, const char *successcode, const char *failcode, int indent, int *finishflag) { LmnInstrOp op; /* const BYTE *op_address = instr; */ READ_VAL(LmnInstrOp, instr, op); switch (op) { case INSTR_JUMP:{ /* 残念ながら引数読み込み途中のinstrからオフセットジャンプするため */ /* 先に全部読み込んでしまうと場所を忘れてしまう */ LmnInstrVar num, i, n; LmnJumpOffset offset; LmnRuleInstr next; int next_index; READ_VAL(LmnJumpOffset, instr, offset); next = (BYTE*)instr + offset; /*ワーニング抑制 */ next_index = vec_inserted_index(jump_points, (LmnWord)next); print_indent(indent); fprintf(OUT, "{\n"); print_indent(indent); fprintf(OUT, " static const int newid[] = {"); i = 0; /* atom */ READ_VAL(LmnInstrVar, instr, num); for (; num--; i++) { READ_VAL(LmnInstrVar, instr, n); if(i != 0) fprintf(OUT, ","); fprintf(OUT, "%d", n); } /* mem */ READ_VAL(LmnInstrVar, instr, num); for (; num--; i++) { READ_VAL(LmnInstrVar, instr, n); if(i != 0) fprintf(OUT, ","); fprintf(OUT, "%d", n); } /* vars */ READ_VAL(LmnInstrVar, instr, num); for (; num--; i++) { READ_VAL(LmnInstrVar, instr, n); if(i != 0) fprintf(OUT, ","); fprintf(OUT, "%d", n); } fprintf(OUT, "};\n"); print_indent(indent); fprintf(OUT, " extern BOOL %s_%d();\n", header, next_index); print_indent(indent); fprintf(OUT, " if (tr_instr_jump(%s_%d, rc, thisisrootmembutnotused, rule, %d, newid))\n" , header, next_index, i); print_indent(indent); fprintf(OUT, " %s;\n", successcode); print_indent(indent); fprintf(OUT, " else\n"); print_indent(indent); fprintf(OUT, " %s;\n", failcode); print_indent(indent); fprintf(OUT, "}\n"); *finishflag = 0; return instr; } default: *finishflag = -1; /* 常に失敗,終了 */ return instr; } }