// process EVENT TRIGGER interrupt = software interrupt void __attribute__((__interrupt__,__no_auto_psv__)) _C2Interrupt(void) { indicate_loading_inter ; interrupt_save_set_corcon ; int eventIndex; EVENT* pEvent; _EVENT_TRIGGERIF = 0 ; // clear the interrupt if(event_init_done) { for(eventIndex = 0; eventIndex < MAX_EVENTS; eventIndex++) { pEvent = &events[eventIndex]; if(pEvent->eventPending == true) { pEvent->eventPending = false; if(pEvent->event_callback != NULL) { pEvent->event_callback(); } } } } interrupt_restore_corcon ; return ; }
void __attribute__((__interrupt__, __no_auto_psv__)) _EVENTM_INTERUPT(void) { _EVENTM_TRIGGERIF = 0; // clear the interrupt indicate_loading_inter; set_ipl_on_output_pin; interrupt_save_set_corcon; int16_t eventIndex; EVENT* pEvent; if (event_init_done) { for (eventIndex = 0; eventIndex < MAX_EVENTS; eventIndex++) { pEvent = &events[eventIndex]; if ((pEvent->eventPending == true) && (pEvent->priority == EVENT_PRIORITY_MEDIUM)) { pEvent->eventPending = false; if (pEvent->event_callback != NULL) { pEvent->event_callback(); } } } } interrupt_restore_corcon; unset_ipl_on_output_pin; }
void processEvents(LIST* evl, int tm) { cout << "\n \n" << "Processing events at time " << tm << "\n\n" << endl; while (evl->getFirstEvent() != NULL) { EVENT* e = evl->getFirstEvent(); int r = e->getprocessTime(); if (evl->getFirstEvent()->getprocessTime() <= tm) { cout << " Processing event:\n\n"; evl->getFirstEvent()->display(); evl->removeFirstEvent(); } else { break; } } return; };
void BOCTX::CheckForCross(SEGM2 * sp, SEGM2 * sn) { assert(sp->n == sn); if (sn != sp and sn != &*m_S.end() and sp != &*m_S.end()) { INT32 xDiv, yDiv; int xSgn, ySgn; if (CalcIsect(*sp, *sn, &xDiv, &xSgn, &yDiv, &ySgn)) { EVENT e; e.SetType(EVENT::X); e.x = xDiv, e.SetSignX(xSgn); e.y = yDiv, e.SetSignY(ySgn); e.c.s0 = sp; e.c.s1 = sn; e.id = m_nId++; m_E.push(e); } } } // BOCTX::CheckForCross
void processEvents(LIST* evl, int tm) { cout << "\n \n" << "Processing events at time " << tm << "\n\n" << endl; while (evl->getFirstEvent() != NULL) { EVENT* e = evl->getFirstEvent(); int r = e->getprocessTime(); if (evl->getFirstEvent()->getprocessTime() <= tm) { cout << " Processing event:\n\n"; evl->getFirstEvent()->display(); if (evl->getFirstEvent()->isThisMyDevice("Left Turn Signal")) { processLeftTurnSignal(e); } else if (evl->getFirstEvent()->isThisMyDevice("Right Turn Signal")) { processRightTurnSignal(e); } else if (evl->getFirstEvent()->isThisMyDevice("Brake")) { processBrake(e); } else if (evl->getFirstEvent()->isThisMyDevice("Accelerator")) { processAccelerator(e); } else if (evl->getFirstEvent()->isThisMyDevice("Left Turn Lamp")) { processLeftTurnLamp(e); } else if (evl->getFirstEvent()->isThisMyDevice("Right Turn Lamp")) { processRightTurnLamp(e); } evl->removeFirstEvent(); } else { break; } } return; };
void BOCTX::HandleEvent(EVENT & event) { switch (event.GetType()) { case EVENT::E: { SEGM2 * sn = event.e.s->n; SEGM2 * sp = event.e.s->p; // untie segment m_S.erase(SEGM_LIST::iterator(event.e.s)); CheckForCross(sp, sn); } break; case EVENT::S: InsMainList(event.s.s); CheckForCross(event.s.s, event.s.s->n); CheckForCross(event.s.s->p, event.s.s); break; case EVENT::X: { if (event.c.s0->n != event.c.s1) return; // ignore crossing event in case of non-adjacent segments SEGM_LIST::iterator s0(event.c.s0), s1(event.c.s1); // swap segments assert(s0->n == &*s1 and s1->p == &*s0); // untie s0 m_S.erase(s1); m_S.insert(s0, *s1); CheckForCross(s1->p, &*s1); CheckForCross(&*s0, s0->n); } break; } } // BOCTX::HandleEvent
INT32 BOCTX::EVENT::Compare(const EVENT &a, const EVENT &b) { assert(INT20_MIN <= a.x and a.x <= INT20_MAX); assert(INT20_MIN <= a.y and a.y <= INT20_MAX); assert(INT20_MIN <= b.x and b.x <= INT20_MAX); assert(INT20_MIN <= b.y and b.y <= INT20_MAX); if (a.x != b.x) return a.x - b.x; TYPE aType = a.GetType(); TYPE bType = b.GetType(); int asx, asy, bsx, bsy; if (aType == X) asx = a.GetSignX(), asy = a.GetSignY(); else asx = asy = 0; if (bType == X) bsx = b.GetSignX(), bsy = b.GetSignY(); else bsx = bsy = 0; if (asx != bsx) return asx - bsx; if (a.y != b.y) return a.y - b.y; if (asy != bsy) return asy - bsy; if (aType != bType) return aType - bType; return a.id - b.id; } // EVENT::Compare
//----------------------------------------------------------------------------- int main(int argc, char** argv) { int iZone = atoi(argv[1]); char buf[0xFF] = ""; sprintf(buf, "%d.lua", iZone); outputFile = fopen(buf, "w"); //freopen("test.lua", "w", stdout); if(testEvent.LoadEvent(iZone) == false) { printf("ERROR!\n"); } EventDataArray testArray = testEvent.m_arEvent; std::map<int, EVENT_DATA*>::iterator iter1 = testArray.m_UserTypeMap.begin(); std::map<int, EVENT_DATA*>::iterator iter2 = testArray.m_UserTypeMap.end(); for(int i=0; iter1!=iter2; ++iter1, ++i) { EVENT_DATA* eventData = (*iter1).second; if (eventData->m_bDup) continue; if(i == 0) { fprintf(outputFile, "if nEventID == %d then\n", eventData->m_EventNum); FillEventID(eventData); } else { fprintf(outputFile, "elseif nEventID == %d then\n", eventData->m_EventNum); FillEventID(eventData); } } fprintf(outputFile, "else\n"); fprintf(outputFile, "\tpUser:SendDebugString(\"Unprocessed event id (\"..nEventID..\")\");\n"); fprintf(outputFile, "end\n"); fclose(outputFile); /* printf("\n\n----- NODES -----\n"); iter1 = testArray.m_UserTypeMap.begin(); iter2 = testArray.m_UserTypeMap.end(); for (int i = 0; iter1 != iter2; ++iter1, ++i) { EVENT_DATA* eventData = (*iter1).second; if (eventData->m_bUsedByAnother) continue; int sSid = 0; ExecArray::iterator iter3 = eventData->m_arExec.begin(); for (; iter3 != eventData->m_arExec.end(); ++iter3) { switch ((*iter3)->m_Exec) { case EXEC_SELECT_MSG: sSid = (*iter3)->m_ExecInt[0]; printf("nEventID = %d; sSid = %d\n", eventData->m_EventNum, sSid); break; } } } */ system("pause"); return 0; }