/*public virtual */TGSError TGSRotatorGS232B::rotateElevationTo(int param) { std::string response; int azimuth; char temp[32]; TGSError error(TGSERROR_OK); if ((error = super::rotateElevationTo(param)) == TGSERROR_NO_SUPPORT) { flushRead(); if ((error = write("C")) == TGSERROR_OK) { if ((error = read(&response)) == TGSERROR_OK) { if (sscanf(response.c_str(), "AZ=%03d", &azimuth) >= 1) { if (snprintf(temp, sizeof(temp), "W%03d %03d", azimuth, param) >= 0) { error = write(temp); } else { error = TGSERROR_FAILED; } } else { error = TGSERROR_INVALID_FORMAT; } } } } return error; }
/*public virtual */TGSError TGSRotatorGS232B::open(std::string const& port, int baud, bool verbose) { std::string response; TGSError error(TGSERROR_OK); if (1200 <= baud && baud <= 9600) { if ((error = super::open(port, baud, false, verbose)) == TGSERROR_OK) { if ((error = write("")) == TGSERROR_OK) { usleep(1000000); flushRead(); if ((error = write("")) == TGSERROR_OK) { if ((error = read(&response)) == TGSERROR_OK) { if (response == "?>") { if (verbose) { std::cout << "TGSRotatorGS232B::open [port : " << port << ", baud : " << baud << "]" << std::endl; } } else { error = TGSERROR_INVALID_STATE; } } } } if (error != TGSERROR_OK) { self::close(); } } } else { error = TGSERROR_INVALID_PARAM; } return error; }
/*public virtual */TGSError TGSRotatorGS232B::getAngleElevation(int* result) { std::string response; TGSError error(TGSERROR_OK); if ((error = super::getAngleElevation(result)) == TGSERROR_NO_SUPPORT) { flushRead(); if ((error = write("B")) == TGSERROR_OK) { if ((error = read(&response)) == TGSERROR_OK) { if (sscanf(response.c_str(), "EL=%03d", result) < 1) { error = TGSERROR_INVALID_FORMAT; } } } } return error; }
/*public virtual */TGSError TGSRotatorGS232B::getAngle(int* azimuth, int* elevation) { std::string response; TGSError error(TGSERROR_OK); if ((error = super::getAngle(azimuth, elevation)) == TGSERROR_NO_SUPPORT) { flushRead(); if ((error = write("C2")) == TGSERROR_OK) { if ((error = read(&response)) == TGSERROR_OK) { if (sscanf(response.c_str(), "AZ=%03d EL=%03d", azimuth, elevation) < 2) { error = TGSERROR_INVALID_FORMAT; } } } } return error; }
bool PHN_Sim::writeATCommand(const char* command) { // Before executing anything, flush the serial with an update update(); // Execute the command, retry as needed uint8_t retryIdx, readIdx; for (retryIdx = 0; retryIdx < SIM_ATCOMMAND_TRYCNT; retryIdx++) { // Flush the incoming data flushRead(Serial1); // Write the command, wait for a response Serial1.println(command); if (!waitRead()) { continue; } // Try reading back the echo from the SIM, and validate readIdx = 0; while (command[readIdx] && waitRead()) { if (Serial1.read() != command[readIdx++]) { readIdx = 0; } } if (command[readIdx]) { continue; } // Read the two newline characters (\r\n) as well if (!waitRead() || Serial1.read() != '\r') continue; if (!waitRead() || Serial1.read() != '\n') continue; // Success! return true; } return false; }