osgText::Text* createLabel(const std::string& l, const char* f, unsigned int size) { static osg::Vec3 pos(10.0f, 10.0f, 0.0f); osgText::Text* label = new osgText::Text(); osgText::Font* font = osgText::readFontFile(f); label->setFont(font); label->setCharacterSize(size); label->setFontResolution(size, size); label->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); label->setPosition(pos); label->setAlignment(osgText::Text::LEFT_BOTTOM); // It seems to be important we do this last to get best results? label->setText(l); textInfo(label); pos.y() += size + 10.0f; return label; }
// Handles a single line of input from the cell shield int8_t CellDriver::parse(std::string inputResponse) { #ifdef CELLPRINTDEBUG printf("This is what it is trying to parse:\n\r"); std::cout << inputResponse << std::endl; #endif if (isReceivingTextMessage) { messageData = inputResponse; TextMessage newMessage; newMessage.index = index; newMessage.messageType = messageType; newMessage.number = number; newMessage.name = name; newMessage.time = time; newMessage.messageData = messageData; #ifdef CELLPRINTDEBUG printf("About to push messgeQueue\n\r"); #endif messageQueue.push(newMessage); #ifdef CELLPRINTDEBUG printf("Succeeded to push newMessage to messageQueue\n\r"); #endif isReceivingTextMessage = false; return true; } if (strcmp(inputResponse.substr(0,2).c_str(), "OK") == 0) { this->isWaitingForOk = false; return false; } // Response to a request to list all text messages // This details exactly one text message (there may be multiple of these responses) if (strcmp(inputResponse.substr(0,5).c_str(), "+CMGL") == 0) { // There is a colon immediately following the message the +CMGL, so we skip over it to the comma separated data std::stringstream textInfo(inputResponse.substr(6)); getline(textInfo, index, ','); getline(textInfo, messageType, ','); getline(textInfo, number, ','); getline(textInfo, name, ','); getline(textInfo, time, ','); messageData = ""; #ifdef CELLPRINTDEBUG printf("Loaded text information into the text class\n\r"); #endif isReceivingTextMessage = true; return false; } // Response to a request for cell tower information if (strcmp(inputResponse.substr(0,5).c_str(), "+CNCI") == 0) { if(!isReceivingCellTowers) { isReceivingCellTowers = true; // The first +CNCI response gives us the number of towers we will get info on // First clear out old info towerInfoList.erase(); // Returning 0 towers to receive on error is perfectly acceptable here... // And we skip the first 6 characters (+CNCI:) totalTowersToReceive = strtol(inputResponse.substr(6).c_str(), NULL, 10); #ifdef CELLPRINTDEBUG printf("Towers to receive: %i\n\r", totalTowersToReceive); #endif } else { towerInfoList.append(inputResponse); towerInfoList.append(" "); //put a space between entries #ifdef CELLPRINTDEBUG printf("Towers Read: %i\n\r",strtol(inputResponse.substr(6).c_str(), NULL, 10)); #endif if (strtol(inputResponse.substr(6).c_str(), NULL, 10) >= totalTowersToReceive - 1) { // We have received them all! newTowerInfo = true; isReceivingCellTowers = false; } } return false; } return false; }