00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00024
00025
00026
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
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
00196 nFANTOM100::tStatus status;
00197 nFANTOM100::iNXTIterator* nxtIteratorPtr;
00198 nFANTOM100::iNXT* nxtPtr;
00199
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