// PrintCANFrame // print out the frame when it comes in // this was added in the function part void PrintCANFrame(DataFrame * frame) { char temp[500]; char temp2[500]; if(frame->Idlen!=11) return; WriteInfo("PrintCANFrame only prints standard can frames!"); sprintf(temp, "Id = %02X 02X, time = %ld, IdFlag = %d, Datalen = %d", ID(frame)[0], ID(frame)[1], frame->time, frame->datalen); WriteInfo(temp); sprintf(temp2,"Data = ", DATA(frame)[0], DATA(frame)[1], DATA(frame)[2], DATA(frame)[3], DATA(frame)[4], DATA(frame)[5], DATA(frame)[6], DATA(frame)[7]); WriteInfo(temp2); sprintf(temp, "Mode = %d, Priority = %d, Stat = %d, Context = %d", frame->mode, frame->priority, frame->stat, frame->context); WriteInfo(temp); } void OnError(uchar channel, uchar error_type) { WriteInfo("On Error!"); } //when a frame comes in print it out void OnFrame(DataFrame *frame, uchar channel) { PrintCANFrame(frame); } void OnKey(char character) { DataFrame * tempFrm; char temp[50]; int result = 0; tempFrm = CreateDataFrame(11,5,0); switch(character) { //when 'A' is pressed by the user send out a message on channels 1,2 then 3. case 'A': ID(tempFrm)[0] = 0x23; ID(tempFrm)[1] = 0x45; tempFrm->Idlen = 11; /* std can is 11 bits */ tempFrm->datalen = 5; DATA(tempFrm)[0] = 0xAA; DATA(tempFrm)[1] = 0xBB; DATA(tempFrm)[2] = 0xCC; DATA(tempFrm)[3] = 0xDD; DATA(tempFrm)[4] = 0xEE; /* channel 1 is the High Speed CAN Channel */ result = TransmitDataFrame(tempFrm,1); if(result==-1) { WriteInfo("Transmit Failed!"); } else { WriteInfo("CAN Frame Transmitted!"); } result = TransmitDataFrame(tempFrm,2); if(result==-1) { WriteInfo("Transmit Failed!"); } else { WriteInfo("CAN Frame Transmitted!"); } result = TransmitDataFrame(tempFrm,3); if(result==-1) { WriteInfo("Transmit Failed!"); } else { WriteInfo("CAN Frame Transmitted!"); } break; //if 'B' is pressed start a timer case 'B': WriteInfo("Tried To Start Timer"); if(StartTimer(2,1000,OnTimer)==0) WriteInfo("Timer should be started!"); else WriteInfo("Timer was not started!"); break; //if 'F' is pressed stop the timer case 'F': WriteInfo("Tried to Stop Timer"); if(StopTimer(2)==0) WriteInfo("Timer should be stopped!"); else WriteInfo("Timer was not stopped!"); break; //if 'E' is pressed transmit a CAN Error on channel 1,2,3 (NOTE:MAKE SURE IT IS ON A CAN CHANNEL!!!!) case 'E': result = TransmitError(1,GCAN); if(result==-1) { WriteInfo("Transmit CAN ErrorFrame DW1 Failed!"); } else { WriteInfo("CAN Error Frame DW1 Transmitted!"); } result = TransmitError(2,GCAN); if(result==-1) { WriteInfo("Transmit CAN ErrorFrame DW2 Failed!"); } else { WriteInfo("CAN Error Frame DW2 Transmitted!"); } result =TransmitError(3,GCAN); if(result==-1) { WriteInfo("Transmit CAN ErrorFrame SW Failed!"); } else { WriteInfo("CAN Error Frame SW Transmitted!"); } break; //if 'Y' was pressed send a trigger case 'Y': if(SendTrigger()==0) WriteInfo("Start of Program Block Trigger"); else WriteInfo("Stop Program Block Trigger"); break; //if none of the above keys were pressed just print the key out to the screen default: sprintf(temp,"Key pressed was %c",character); WriteInfo(temp); break; } FreeDataFrame(tempFrm); } //print out the start time void OnStart(long time) { char temp[50]; sprintf(temp,"OnStart time was %d",time); WriteInfo(temp); } //print out the stop time void OnStop(long time) { char temp[50]; sprintf(temp,"OnStop time was %d",time); WriteInfo(temp); } //when the timer goes off print out which timer it was void OnTimer(uint p_timerid) { char temp[50]; sprintf(temp,"OnTimer Id was %d",p_timerid); WriteInfo(temp); } //when a trigger comes in output the time void OnTrigger(long time) { char temp[50]; sprintf(temp,"Trigger time was %d",time); WriteInfo(temp); }