C:/Documents and Settings/Owner/My Documents/My Code/NXT++/files/include/comm.h

Go to the documentation of this file.
00001 // File: comm.h
00002 //
00003 // Copyright (c) 2007 by XXX
00004 // -------------------------------------------------------------------------
00005 // DESCRIPTION
00006 // Header file containing OS specific function. 
00007 //
00008 // HISTORY
00009 // Date         By who         Description
00010 // -------------------------------------------------------------------------
00011 // 04/26/2007   maddock     Header comments
00012 // 05/12/2007   phyizal     Added fantom file support
00013 // 05/16/2007   phyizal     Removed fantom function call 
00014 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include <vector>
00018 #include <iostream>
00019 #include "fantom/iNXT.h"
00020 #include "fantom/iNXTIterator.h"
00021 #include "fantom/tStatus.h"
00022 
00023 //Error codes.
00024 //TODO: Make them more comprehensive based on status code from NXT.
00025 //       Also provide a method to translate numeric error code to more
00026 //       user friendly error string.
00027 
00028 enum ErrorCode
00029 {               
00030         UnsupportedType = -1,
00031         IteratorFailed = -2,
00032         InvalidFileIterator = -3,
00033         IteratorAdvanceFailed = -4,
00034         InvalidFileHandler = -5,
00035         FileOpenFailed = -6,            
00036         WriteNotEnabled = -7,
00037         FileNotOpen = -8,               
00038         ReadFailed = -9,
00039         WriteFailed = -10,
00040         FileCloseFailed = -11,          
00041         WriteBufferIllegalSize = -12,
00042 };
00043 
00045 struct NXTFile
00046 {
00048         NXTFile() : file(NULL) , name(NULL)
00049         {
00050                 size = 0;
00051                 asize = 0;
00052                 isOpen = false;
00053                 isWriteable = false;
00054         }
00055 
00057         NXTFile(nFANTOM100::iFile* f): name((char*) malloc(20))
00058         {
00059       file = f;
00060 
00061           if (f == NULL) return;
00062 
00063           f->getName(name);
00064 
00065           nFANTOM100::tStatus status;
00066 
00067           size = f->getSize(status);
00068           asize = f->getAvailableSize(status);
00069 
00070           if (status.isFatal())
00071                   size = -1;
00072 
00073           isOpen = false;
00074           isWriteable =false;
00075         }
00076 
00078         char * name;
00080         int size;
00082         int asize;
00084         int mode;
00085 
00087         bool isOpen;
00089         bool isWriteable;
00090 
00091         //Won't be use in case of linux
00093         nFANTOM100::iFile* file; 
00094         bool isValid(); 
00095         int open(int mode, int size=100);
00096         int remove();
00097         int read(char* buff, int size);
00098         int write(char* buff, int size);
00099         int close();
00100 };
00101 
00103 struct NXTFileIterator
00104 {
00106         NXTFileIterator() : iter(NULL)
00107         {
00108         }
00109 
00111         NXTFileIterator(nFANTOM100::iFileIterator *i)
00112         {
00113                 iter = i;
00114         }
00115 
00117         nFANTOM100::iFileIterator *iter;
00119         bool isValid();
00121         int next();
00123         int close();
00125         int getFile(NXTFile& file);
00127         int getCurrFileSize();
00129         const char* getCurrFileName();
00130         
00131 };
00132 
00134 struct NXTModule
00135 {
00137         NXTModule() : internalModule(NULL)
00138         {
00139         }
00140 
00142         NXTModule(nFANTOM100::iModule *m)
00143         {
00144                 internalModule = m;
00145         }
00146 
00148         nFANTOM100::iModule *internalModule;
00150         int getName(std::string &name);
00152         int getModuleID(int &id);
00154         int getModuleSize(int &size);
00156         int getIOMapSize(int &size);
00158         int readIOMap(ViPByte buffer, int offset, int number_of_bytes);
00160         int writeIOMap(const ViPByte, int offset, int number_of_bytes);
00161 
00162 };
00163 
00165 struct NXTModuleIterator
00166 {
00168         NXTModuleIterator() : internalIter(NULL)
00169         {
00170         }
00171 
00173         NXTModuleIterator(nFANTOM100::iModuleIterator *i)
00174         {
00175                 internalIter = i;
00176         }
00177 
00179         nFANTOM100::iModuleIterator *internalIter;
00181         int next();
00183         int getModule(NXTModule &module);
00185         int getName(std::string &s);
00186 };
00187 
00189 namespace Comm
00190 {
00191         void SearchBT(std::vector<std::string> *names);
00192 
00193         class NXTComm {
00194         public:
00195                 // global variable
00196                 nFANTOM100::tStatus status;
00197                 nFANTOM100::iNXTIterator* nxtIteratorPtr;
00198                 nFANTOM100::iNXT* nxtPtr;
00199                 //For fetching list of files
00200                 nFANTOM100::iFileIterator* fileIteratorPtr;
00201 
00202                 NXTComm() {
00203                         nxtIteratorPtr = NULL;
00204                         nxtPtr = NULL;
00205                         fileIteratorPtr = NULL;
00206                 }
00207 
00209 
00211                 bool Open();
00213 
00215                 bool OpenBT();
00217 
00219                 bool OpenBT(char * name);
00221                 void Close();
00223 
00230                 void SendDirectCommand(ViBoolean response, ViByte * dc_buf, int dc_buf_size, ViByte *re_buf, int re_buf_size);
00231                 double GetProtocolVersion();
00232                 double GetFirmwareVersion();
00233                 std::string GetName();
00234                 bool SetName(char* name);
00236                 double GetAvailableFlash();
00238                 NXTFile GetNXTFile(std::string filename, bool &isFatal);
00240                 NXTFileIterator GetFileIterator(std::string pattern, bool &isFatal);
00242                 void destroyFileIterator(NXTFileIterator &iter);
00244                 void destroyFile(NXTFile &file);
00246                 NXTModuleIterator GetModuleIterator(std::string pattern, int &statusCode);
00248                 void destroyModuleIterator(NXTModuleIterator &iter);
00250                 NXTModule GetModule(std::string moduleName, int moduleID, int moduleSize, int ioMapSize, int &statCode);
00252                 void destroyModule(NXTModule &module);
00253         };
00254 };
00255 
SourceForge.net Logo