int16_t RogueSD::readln(int8_t handle, uint16_t maxlength, char *dest) { int8_t r; int16_t i; if (_fwLevel == 0) return -1; print(_prefix); print("RL"); // Read a line, maxlength chars, maximum print((char)('0' + handle)); print(' '); print(maxlength, DEC); print('\r'); if (!_getResponse()) { if (lastErrorCode == ERROR_EOF) // EOF return -1; else return -2; } // otherwise, read the data i = 0; r = _readBlocked(); while (r != _promptChar) // we could have a blank line { dest[i++] = r; r = _readBlocked(); } dest[i] = 0; // terminate our string return i; }
int16_t RogueSD::getSetting(char setting) { uint8_t value; print('S'); if (_moduleType != uMMC) print('T'); print(setting); print('\r'); while (!_commAvailable()); if (_commPeek() != 'E') { value = _getNumber(10); _readBlocked(); // consume prompt } else { value = _getResponse(); // get the error } return value; }
int8_t RogueSD::openDir(const char *dirname) { int8_t resp = 0; if (_fwLevel > 0) { // new print(_prefix); print("LS "); print(dirname); print('\r'); resp = _getResponse(); if (resp) _readBlocked(); // consume prompt only if OK return resp; } else { // old lastErrorCode = ERROR_NOT_SUPPORTED; return -1; } }
void RogueSD::closeAll(void) { if (_fwLevel > 0) { // new print(_prefix); print('C'); print('\r'); _readBlocked(); // consume prompt } else { // old for (uint8_t i = 1; i <= 4; i++) // 4 = Max handles { print(_prefix); print('C'); print((char)('0' + i)); print('\r'); _getResponse(); } } }
int OMMoCoMaster::command(uint8_t p_addr, uint8_t p_cmd) { // 0 bytes sent to node after command sendPacketHeader(p_addr, p_cmd, 0); return _getResponse(); }
int8_t RogueSD::entryToFilename(char *dest, uint8_t count, uint16_t entrynum, const char *path, const char *filemask) { char c; int8_t entrytype = TYPE_FILE; if (_fwLevel > 0) { // new print(_prefix); print("LE "); print(entrynum, DEC); print(' '); if (path != NULL) print(path); if (filemask != NULL && strlen(filemask) > 0) { if (strlen(path) == 0 || path[strlen(path) - 1] != '/') { print('/'); } print(filemask); } print('\r'); if (_getResponse()) { // we have the file info next while (!_commAvailable()); if (_commPeek() == 'D') { // we have a directory _commRead(); // consume 'D' entrytype = TYPE_FOLDER; } else { // it's a file, with a file size _getNumber(10); // discard (for now) entrytype = TYPE_FILE; } _readBlocked(); // consume separator ' ' // now get filename while ((c = _readBlocked()) != '\r') { if (count > 0) { count--; *dest++ = c; } } *dest = 0; // terminate string _readBlocked(); // consume prompt return entrytype; } else { // had an error return 0; } } else { // old lastErrorCode = ERROR_NOT_SUPPORTED; return -1; } }
int8_t RogueSD::readDir(char *dest, const char *filemask) { // retrieve the next entry from the directory // returns: // 0 when no more files/folders (EOF) // -1 on failure // 1 if entry is a file // 2 if entry is a folder/directory // currently using the original file listing style, i.e. D/fs filename char c; int8_t entrytype = TYPE_FILE; if (_fwLevel > 0) { print(_prefix); print("LI "); if (filemask) print(filemask); else print('*'); print('\r'); if (_getResponse()) { // we have the file info next while (!_commAvailable()); if (_commPeek() == 'D') { // we have a directory _commRead(); // consume 'D' entrytype = TYPE_FOLDER; } else { // it's a file, with a file size _getNumber(10); // discard (for now) entrytype = TYPE_FILE; } _readBlocked(); // consume separator ' ' // now get filename while ((c = _readBlocked()) != '\r') { *dest++ = c; } *dest = 0; // terminate string _readBlocked(); // consume prompt return entrytype; } else { // had an error if (lastErrorCode == ERROR_EOF) return 0; else return -1; } } else { // old lastErrorCode = ERROR_NOT_SUPPORTED; return -1; } }