sci_tcpip.cpp

00001 /*
00002   SCI通信の TCP/IP 実装
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "tRunCtrl.h"
00008 #include "sh7045lib.h"
00009 #include "connectionDevice.h"
00010 #include <vector>
00011 
00012 #include <stdio.h>
00013 
00014 
00015 static std::vector<ConnectionDevice*> cons;
00016 static int size_max = 0;
00017 
00018 
00019 void init_sci(int port, ConnectionDevice* con) {
00020   while (cons.size() < static_cast<unsigned int>(port) +1) {
00021     cons.push_back(NULL);
00022     size_max = static_cast<int>(cons.size());
00023   }
00024   cons[port] = con;
00025 }
00026 
00027 
00028 void init_sci(int port, int level) {
00029 }
00030 
00031 
00032 void stop_sci(int port) {
00033   if (port > size_max -1) {
00034     return;
00035   }
00036   cons[port] = NULL;
00037 }
00038 
00039 
00040 int sci_write(int port, const unsigned char* data, int size) {
00041   if (port > size_max -1) {
00042     return -1;
00043   }
00044 
00045   return cons[port]->send((char*)data, size);
00046 }
00047 
00048 
00049 int sci_read(int port, unsigned char *data, int size) {
00050   if (port > size_max -1) {
00051     return -1;
00052   }
00053 
00054   return cons[port]->recv((char*)data, size);
00055 }
00056 
00057 
00058 int sci_copy(int port, unsigned char *data, int size) {
00059   if (port > size_max -1) {
00060     return -1;
00061   }
00062 
00063   return -1;
00064 }
00065 
00066 
00067 int get_sciReadable(int port) {
00068   if (port > size_max -1) {
00069     return 0;
00070   }
00071   // リングバッファで読み込み可能なサイズを返す
00072   return cons[port]->size();
00073 }
00074 
00075 
00076 void flush_sciRecv(int port) {
00077   if (port > size_max -1) {
00078     return;
00079   }
00080 
00081   // リングバッファの内容を破棄
00082   cons[port]->flush();
00083 }
00084 

Generated on Mon Apr 13 22:52:03 2009 by  doxygen 1.5.7.1