From: ian Date: Wed, 23 Apr 2008 20:57:09 +0000 (+0000) Subject: wip debugging X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=e950038f25c0c6c6a6b50c1e7bf4d97e5f5cf596;p=trains.git wip debugging --- diff --git a/hostside/README.commands b/hostside/README.commands index adf687e..1aea699 100644 --- a/hostside/README.commands +++ b/hostside/README.commands @@ -46,6 +46,10 @@ POSSIBLY-ASYNCHRONOUS REPORTING OF MESSAGES TO/FROM (MASTER) PIC U< signalling-problem .... U< signalling-problem detection : + U< movpos point + U< movpos position moving + U< movpos position stable + U< debug : U< info : diff --git a/hostside/movpos.c b/hostside/movpos.c index 4a89d44..512610a 100644 --- a/hostside/movpos.c +++ b/hostside/movpos.c @@ -63,6 +63,28 @@ struct KindInfo { */ }; +static const char *posnpname(Segment *move, MovPosComb poscomb) { + return poscomb<0 ? "?" : move->i->poscombs[poscomb].pname; +} + +static void ouposn_moving(Change *chg) { + Segment *move= chg->move; + oprintf(UPO, "movpos %s position %s moving\n", + move->i->pname, posnpname(move, chg->actual)); +} + +static void motion_done(Segment *move) { + move->moving= 0; + move->motion= 0; + move->movposcomb= r->h.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 ==========*/ /* @@ -304,7 +326,10 @@ static ErrorCode point_confirm(Change *chg, Segment *move, int allow_failure; ErrorCode ec; -fprintf(stderr," point confirm\n"); + oprintf(DUPO("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); /* If the segment is moving, these motions are already based on the * actual physical position which is stored in the existing request. @@ -321,6 +346,8 @@ fprintf(stderr," point confirm\n"); newdeadline= pt_maxdelay_reldeadline(maxdelay_ms); } allow_failure= newdeadline < r->deadline; + oprintf(DUPO("point") " newdeadline=t+%d allow_failure=%d\n", + newdeadline, allow_failure); newdeadline += pt_cslot; /* state A or R */ @@ -328,7 +355,14 @@ fprintf(stderr," point confirm\n"); /* states of existing: */ PointReq *existing= move->moving ? (PointReq*)move->motion : 0; /* U or C */ - if (existing) pt_dequeue(existing); /* U or CA */ + if (existing) { + oprintf(DUPO("point") + " existing %s n=%d deadline=t+%d\n", + existing->h.move->i->pname, + existing->n_motions, + existing->deadline - pt_slot); + pt_dequeue(existing); /* U or CA */ + } /* state A or RA */ memcpy(r->motions, motions, sizeof(r->motions[0])*n_motions); @@ -345,6 +379,7 @@ fprintf(stderr," point confirm\n"); /* state CA */ ec= pt_enqueue(&pt_confirmed, r); + oprintf(DUPO("point") " pt_enqueue=%s\n", ecstr(ec)); assert(allow_failure || !ec); if (existing) { /* CA */ @@ -362,14 +397,14 @@ fprintf(stderr," point confirm\n"); * or ec!=0 state C but bad C */ - if (!ec) { - move->moving= 1; - move->motion= chg; - move->movposcomb= -1; - pt_check_action(); - } + if (ec) return; - return ec; + move->moving= 1; + move->motion= chg; + move->movposcomb= -1; + ouposn_moving(chg); + pt_check_action(); + return 0; } static void point_destroy(Change *chg) { /* X->XA and then free it */ @@ -383,6 +418,8 @@ static void point_destroy(Change *chg) { /* X->XA and then free it */ 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; @@ -396,6 +433,8 @@ static void pt_check_action(void) { 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, + m->i->pname, m->posn); pt_cdu_charged= 0; MovPosComb above_weight= m->i->weight * m->i->posns; @@ -404,6 +443,7 @@ static void pt_check_action(void) { r->actual= above*above_weight + m->posn*m->i->weight + below; if (r->h.actual >= 0 || !r->n_motions) r->h.actual= r->actual; + ouposn_moving(&r->h); } if (!r->n_motions) { @@ -415,9 +455,7 @@ static void pt_check_action(void) { assert(move->moving && move->motion == (Change*)r); pt_queue_remove_index(&pt_confirmed,0); pt_mark_as_allocated(r); /* now state A aka Done */ - move->movposcomb= r->h.actual; - move->moving= 0; - move->motion= 0; + motion_done(move); free(r); pt_check_action(); } @@ -434,9 +472,7 @@ void points_all_abandon(void) { PointReq *r= pt_confirmed.l[i]; Segment *move= r->h.move; assert(move->motion == (Change*)r); - move->moving= 0; - move->motion= 0; - move->movposcomb= r->h.actual; + motion_done(move); free(r); } pt_confirmed.n= 0; @@ -456,7 +492,7 @@ void on_pic_charged(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { /*========== dummy `nomove' kind ==========*/ static Change *nomove_allocate(int alloc_motions) { -fprintf(stderr," nomove allocate %d\n",alloc_motions); + oprintf(DUPO("movfeatkind-momove") "allocate %d\n",alloc_motions); return mmalloc(sizeof(Change)); } static void nomove_destroy(Change *chg) { @@ -464,12 +500,12 @@ static void nomove_destroy(Change *chg) { } static ErrorCode nomove_reserve(Change *chg, Segment *move, int ms) { -fprintf(stderr," nomove reserve\n"); + oprintf(DUPO("movfeatkind-nomove") "reserve\n"); return 0; } static ErrorCode nomove_confirm(Change *chg, Segment *move, int n_motions, const Motion *motions, int ms) { -fprintf(stderr," nomove confirm\n"); + oprintf(DUPO("movfeatkind-nomove") "confirm\n"); nomove_destroy(chg); return 0; } @@ -582,6 +618,7 @@ ErrorCode movpos_change(Segment *move, MovPosComb target, 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; featn_movfeats;