void PHN_Sim::update() { init(); if (Serial1.available()) { const int INPUT_BUFF_LEN = 100; char inputBuffer[INPUT_BUFF_LEN+1]; int inputIndex = 0; while (inputIndex < INPUT_BUFF_LEN && waitRead()) { inputBuffer[inputIndex++] = Serial1.read(); } inputBuffer[inputIndex] = 0; // Debugging: log all incoming data Serial.print("Update input: "); Serial.println(inputBuffer); // Find any commands in the received message char* inputText; for (int i = 0; i < inputIndex; i++) { inputText = inputBuffer+i; if (strstr(inputText, "NO CARRIER") == inputText) { // No carrier call status update callStatus = SIM_CALL_STATUS_NONE; i += 9; } else if (strstr(inputText, "BUSY") == inputText) { // Busy call status update callStatus = SIM_CALL_STATUS_BUSY; i += 3; } else if (strstr(inputText, "+CLIP: ") == inputText) { // Caller information received. // +CLIP: "+1234567890",145,"",,"",0 char* args[1]; if (getSimTextArgs(inputText+7, args, 1)) { // Voice call strcpy(incomingNumber, args[0]); callStatus = SIM_CALL_STATUS_CALLED; } } else if (strstr(inputText, "+CMTI: ") == inputText) { // +CMTI: "SM",11 // Text message received // Read arguments char* args[2]; if (getSimTextArgs(inputText+7, args, 2)) { // Receiving a new text message if (!strcmp(args[0], "SM")) { latestInbox = atoi(args[1]) - 1; } } } else if (strstr(inputText, "GPS Ready") == inputText) { gpsReady = true; } else if (strstr(inputText, "Call Ready") == inputText) { callReady = true; } } } }
// Read the status with the void tdc::ReadStatus(){ unsigned int DATA=0; waitRead(); TestError(readData(StatusRegister,&DATA),"TDC: read Status"); if (DATA%2 > 0){ if(vLevel(NORMAL))cout << "Event Ready"<<endl;} else {if(vLevel(NORMAL))cout<< "No data ready"<<endl;} if (DATA%8 >3) if(vLevel(NORMAL))cout<< " Output Buffer is Full"<< endl; else {if(vLevel(NORMAL))cout<< " Output Buffer is not full"<<endl;} if (DATA%16 >7 ){if(vLevel(NORMAL))cout<< " Operating Mode : Trigger "<<endl;} else{ if(vLevel(NORMAL))cout<< "Operating Mode : Continuous"<<endl;} }
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; }
void tdc::readOpcode(unsigned int &DATA) { waitRead(); TestError(readData(Opcode,&DATA),"TDC: reading OPCODE"); }