00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include"interfaces.h"
00030 #include"..\includes\defines.h"
00031 #include"..\includes\canapi.h"
00032 #include"..\includes\irig.h"
00033 #include<string.h>
00034 #include<stdlib.h>
00035 #include<stdio.h>
00036
00037 extern struct _if_channel channel[CAN_MAXCHANNELS];
00038 extern int if_channel_count;
00039 extern int if_board_count;
00040 extern struct _reftsLink*refts;
00041
00042 #ifdef CANBOARDXL
00043 #include"vector_canboard\vector_canboard.h"
00044 #endif
00045 #ifdef CARDONE
00046 #endif
00047 #ifdef CARDTWO
00048 #endif
00049
00050 struct _s_interface interfaces[]=
00051 {
00052 #ifdef CANBOARDXL
00053 { 0,
00054 vector_canboardprobe,
00055 vector_canboardstartup,
00056 vector_canboardopenchannel,
00057 vector_canboardclosechannel,
00058 vector_canboardshutdown,
00059 vector_canboardread,
00060 vector_canboardwrite,
00061 vector_canboardupdatestatus,
00062 vector_canboardchangestatus
00063 },
00064 #endif
00065 #ifdef CARDONE
00066 {
00067 },
00068 #endif
00069 #ifdef CARDTWO
00070 {
00071 },
00072 #endif
00073 { 0,0,0,0,0,
00074 0,0,0,0,0
00075 }
00076
00077 };
00078
00079
00080
00081
00082
00083
00084
00085
00086 enum
00087 { __IFACE,
00088 __CHAN
00089 };
00090
00091 int boardstartup(int handle,int which)
00092 { int ret;
00093
00094 switch(which)
00095 { case __CHAN:
00096 if(interfaces[channel[handle].board->boardtype].activecount==0)
00097 { ret=interfaces[channel[handle].board->boardtype].startupfunction(handle);
00098 if(ret==IF_FAILURE)
00099 return 0;
00100 interfaces[channel[handle].board->boardtype].activecount=1;
00101 }
00102 break;
00103 case __IFACE:
00104 if(interfaces[handle].activecount==0)
00105 { ret=interfaces[handle].startupfunction();
00106 if(ret==IF_FAILURE)
00107 return 0;
00108 interfaces[handle].activecount=1;
00109 }
00110 break;
00111 default:
00112 ret=0;
00113 break;
00114 }
00115 return ret;
00116 }
00117
00118 int boardprobe()
00119 { int ix;
00120 long err;
00121
00122 for(ix=0;interfaces[ix].probefunction;ix++)
00123 { interfaces[ix].activecount=0;
00124 boardstartup(ix,__IFACE);
00125 err=interfaces[ix].probefunction();
00126 if(err==IF_FAILURE)
00127 { printf("board failed\n");
00128 return 0;
00129 }
00130 }
00131 return 1;
00132 }
00133
00134 int fakecrc(unsigned char*tocrc,int*fakedcrc)
00135 { if(!tocrc)
00136 return 0;
00137 if(!fakedcrc)
00138 return 0;
00139
00140 return 1;
00141 };
00142
00143 int boardopenchannel(int which)
00144 { int ret;
00145 boardstartup(which,__CHAN);
00146
00147 if(channel[which].isopen==0)
00148 { ret=interfaces[channel[which].board->boardtype].openchannelfunction(which);
00149 if(ret==IF_SUCCESS)
00150 { channel[which].isopen=1;
00151 interfaces[channel[which].board->boardtype].activecount++;
00152 }
00153 interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00154 return ret;
00155 }
00156 return 1;
00157 }
00158
00159 int boardread(int which,can_frame*out)
00160 { int ret;
00161 boardopenchannel(which);
00162 ret=interfaces[channel[which].board->boardtype].readfunction(which,out);
00163
00164 if(ret==IF_SUCCESS)
00165 return S_SUCCESS;
00166 else
00167 return ret;
00168 }
00169
00170 int boardwrite(int which,can_frame*in)
00171 { int ret;
00172 boardopenchannel(which);
00173 ret=interfaces[channel[which].board->boardtype].writefunction(which,in);
00174
00175 if(ret==IF_SUCCESS)
00176 return S_SUCCESS;
00177 else
00178 return ret;
00179 }
00180
00181 int boardupdatestatus(int which)
00182 { int ret;
00183 ret=interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00184 return ret;
00185 }
00186
00187 int boardchangestatus(int handle,int which,int status)
00188 { int ret;
00189 ret=interfaces[channel[handle].board->boardtype].changestatusfunction(handle,which,status);
00190 interfaces[channel[handle].board->boardtype].updatestatusfunction(handle);
00191 if(ret==IF_SUCCESS)
00192 return S_SUCCESS;
00193 else
00194 return ret;
00195 }
00196
00197
00198 int boardshutdown(int which)
00199 { unsigned int ix;
00200 for(ix=0;ix<channel[which].board->channelcount;ix++)
00201 { interfaces[channel[which].board->boardtype].closechannelfunction(
00202 channel[which].board->channel[ix]->index);
00203 }
00204
00205 interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00206 if(interfaces[channel[which].board->boardtype].activecount==1)
00207 { interfaces[channel[which].board->boardtype].shutdownfunction();
00208
00209 interfaces[channel[which].board->boardtype].activecount=0;
00210 }
00211 return S_SUCCESS;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243