* proper transition. */
struct KindInfo {
+ const char *pname;
Change *(*allocate)(int alloc_motions); /* U->A (always succeeds) */
ErrorCode (*reserve)(Change*, Segment*, int ms); /* A->R; error: A->E */
ErrorCode (*confirm)(Change*, Segment*, int n_motions,
move->i->pname, posnpname(move, chg->actual));
}
-static void motion_done(Segment *move) {
+static void motion_done(Segment *move, MovPosComb actual) {
move->moving= 0;
move->motion= 0;
- move->movposcomb= r->h.actual;
+ move->movposcomb= actual;
oprintf(UPO, "movpos %s position %s stable\n",
move->i->pname, posnpname(move, move->movposcomb));
}
-#define PRPOSN_CHG(chg) \
- (chg)->move->i->pname, \
- (chg)->actual<0 ? "?" : (chg)->move->i->poscombs[(chg)->actual].pname
-
/*========== points ==========*/
/*
int allow_failure;
ErrorCode ec;
- oprintf(DUPO("point") "confirm %s n=%d maxdelay=%d"
+ oprintf(DUPO("movpos/point") "confirm %s n=%d maxdelay=%d"
" (res: n=%d deadline=[t+]%d)\n",
move->i->pname, n_motions, maxdelay_ms,
r->n_motions, r->deadline);
newdeadline= pt_maxdelay_reldeadline(maxdelay_ms);
}
allow_failure= newdeadline < r->deadline;
- oprintf(DUPO("point") " newdeadline=t+%d allow_failure=%d\n",
+ oprintf(DUPO("movpos/point") " newdeadline=t+%d allow_failure=%d\n",
newdeadline, allow_failure);
newdeadline += pt_cslot;
PointReq *existing=
move->moving ? (PointReq*)move->motion : 0; /* U or C */
if (existing) {
- oprintf(DUPO("point")
+ oprintf(DUPO("movpos/point")
" existing %s n=%d deadline=t+%d\n",
existing->h.move->i->pname,
existing->n_motions,
- existing->deadline - pt_slot);
+ existing->deadline - pt_cslot);
pt_dequeue(existing); /* U or CA */
}
/* state CA */
ec= pt_enqueue(&pt_confirmed, r);
- oprintf(DUPO("point") " pt_enqueue=%s\n", ecstr(ec));
+ oprintf(DUPO("movpos/point") " pt_enqueue=%s\n", ec2str(ec));
assert(allow_failure || !ec);
if (existing) { /* CA */
* or ec!=0 state C but bad C
*/
- if (ec) return;
+ if (ec) return ec;
move->moving= 1;
move->motion= chg;
static void pt_check_action(void) {
PicInsn piob;
-fixme add more oprintf DUPO from about here onwards
-
if (!pt_confirmed.n) {
if (sta_state == Sta_Finalising) resolve_motioncheck();
return;
assert(m->posn < m->i->posns);
enco_pic_point(&piob, m->i->boob[m->posn]);
serial_transmit(&piob);
- oprintf(UPO, "movpos %s point %s%d\n", r->move->i->pname,
+ oprintf(UPO, "movpos %s point %s%d\n", r->h.move->i->pname,
m->i->pname, m->posn);
pt_cdu_charged= 0;
assert(move->moving && move->motion == (Change*)r);
pt_queue_remove_index(&pt_confirmed,0);
pt_mark_as_allocated(r); /* now state A aka Done */
- motion_done(move);
+ motion_done(move,r->h.actual);
free(r);
pt_check_action();
}
PointReq *r= pt_confirmed.l[i];
Segment *move= r->h.move;
assert(move->motion == (Change*)r);
- motion_done(move);
+ motion_done(move,r->h.actual);
free(r);
}
pt_confirmed.n= 0;
/*========== method-independent machinery ==========*/
static const KindInfo methodinfos[]= {
- { nomove_allocate, nomove_reserve, nomove_confirm, nomove_destroy },
- { point_allocate, point_reserve, point_confirm, point_destroy },
- { 0 }
+ { "nomove", nomove_allocate, nomove_reserve, nomove_confirm, nomove_destroy },
+ { "point", point_allocate, point_reserve, point_confirm, point_destroy },
+ { 0 }
};
static Change *mp_allocate(const KindInfo *ki, Segment *move,
static int change_needed(const MovFeatInfo *feati, MovPosComb target,
MovPosComb startpoint) {
- return
- startpoint<0 ||
+ int r;
+ r= startpoint<0 ||
(target - startpoint) / feati->weight % feati->posns;
+ oprintf(DUPO("movpos/change-needed") "%s:%s(%d*%d) %d<-%d => %d",
+ methodinfos[feati->kind].pname, feati->pname,
+ feati->posns, feati->weight,
+ target, startpoint, r);
+ return r;
}
static int evaluate_target(Segment *move, MovPosComb target,
const MovFeatInfo *feati;
MovFeatKind kind;
- if (startpoint<0) startpoint= movpos_poscomb_actual(move);
+ oprintf(DUPO("movpos/eval") "%s/%s <-%s\n",
+ move->i->pname, posnpname(move,target), posnpname(move,startpoint));
+
+ if (startpoint<0) {
+ startpoint= movpos_poscomb_actual(move);
+ oprintf(DUPO("movpos/eval") " actual <-%s\n",
+ posnpname(move,startpoint));
+ }
for (feat=0, feati=movei->movfeats, tchanges=0, kind= mfk_none;
feat<movei->n_movfeats;
}
if (kind_r) *kind_r= kind;
+ oprintf(DUPO("movpos/eval") "changes=%d kind=%s\n",
+ tchanges, methodinfos[kind].pname);
return tchanges;
}
if (fwd && !(fwd ==tback || fwd ==tfwd)) continue;
if (movei->n_movfeats>1) {
- //fprintf(stderr," several feats\n");
/* we have to search for the one which is least effort, then */
tchanges= evaluate_target(move,tcomb,startpoint,0);
if (tchanges >= bestchanges) /* prefer low-numbered movposcombs */
actual= move->motion->actual;
}
- {
+ oprintf(DUPO("movpos/change") "%s/%s maxdelay_ms=%d actual=%s\n",
+ move->i->pname, posnpname(move,target),
+ maxdelay_ms, prposn(move, actual));
+ if (chg) oprintf(DUPO("movpos/change") " chg=%s:%s/%s\n",
+ chg->ki->pname, chg->move->i->pname,
+ posnpname(chg->move, chg->move->intent));
+
+ { /* provide horizon for visibility of motions[] */
int n_motions=0;
Motion motions[movei->n_movfeats];
-fixme make these debug
-fprintf(stderr," motions... best=%lu actual=%ld\n",target,actual);
for (feat=0, feati=movei->movfeats;
feat<movei->n_movfeats;
feat++, feati++) {
-fprintf(stderr," checking %s w=%lu posns=%d\n",
- feati->pname,feati->weight,(int)feati->posns);
if (!change_needed(feati,actual,target))
continue;
MovPosComb posn= target / feati->weight % feati->posns;
-fprintf(stderr," motion %s %lu kind=%d\n",feati->pname,posn,kind);
if (kind) {
if (feati->kind != kind) { ec= EC_MovFeatKindsCombination; goto x; }
} else {
}
chg->actual= actual;
-fprintf(stderr," confirming %d motions...\n",n_motions);
+ oprintf(DUPO("movpos/change") "confirm %s:%d...\n", ki->pname, n_motions);
ec= ki->confirm(chg, move, n_motions, motions, maxdelay_ms);
-fprintf(stderr," confirming gave %s\n",errorcodelist[ec]);
+ oprintf(DUPO("movpos/change") "confirm => %s\n",errorcodelist[ec]);
if (ec) goto x;
}
return 0;
ErrorCode ec;
int nchanges;
+ oprintf(DUPO("movpos/reserve") "%s/%s maxdelay_ms=%d startpoint=%s\n",
+ move->i->pname, posnpname(move,target),
+ maxdelay_ms, prposn(move, startpoint));
+
nchanges= evaluate_target(move,target,startpoint,&kind);
if (nchanges==-1) return EC_MovFeatKindsCombination;
const KindInfo *ki= &methodinfos[kind];
- Change *chg= mp_allocate(ki, move, move->i->n_movfeats, target);
+ oprintf(DUPO("movpos/reserve") "allocate %s:%d...\n", ki->pname, nchanges);
+ Change *chg= mp_allocate(ki, move, nchanges, target);
ec= ki->reserve(chg, move, maxdelay_ms);
+ oprintf(DUPO("movpos/reserve") "reserve => %s\n",errorcodelist[ec]);
if (ec) goto x;
*res_r= chg;
void movpos_unreserve(MovPosChange *res) {
if (!res) return;
+ oprintf(DUPO("movpos/unreserve") "%s:%s/%s\n",
+ res->ki->pname, res->move->i->pname,
+ posnpname(chg->move, chg->move->intent));
res->ki->destroy(res);
}