我一直在我的Raspi上运行一个脚本,同时逐步提高它的性能,它工作正常,直到我今天早上开始编辑它,现在cout<<不会打印到控制台,但有趣的是 - radio.printDetails打印,使用printf。我想也许SD卡开始死了?这会导致问题吗?
标题
#include <bcm2835.h>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <RF24/RF24.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>
#include <time.h>
#define arrSize 50
//
// Hardware configuration
// Configure the appropriate pins for your connections
/****************** Raspberry Pi ***********************/
RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0);//, BCM2835_SPI_SPEED_4MHZ);
//RF24 radio(22,0); // CE GPIO, CSN SPI-BUS
int interruptPin = 23; // GPIO pin for interrupts
int i=0;
/**************************************************************/
// Radio pipe addresses for the 2 nodes to communicate.
//const uint8_t pipes[][6] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
const uint8_t pipes[][6] = {"1Node","2Node"};
volatile int accelArryNo = 0;
volatile int currentArryNo = 0;
uint8_t ack = 30;
int liveAccelArray[arrSize*3];
float liveCurrentArray[arrSize];
const int max_receivePayload_size = 32;
volatile int recvd = 0;
uint8_t receivePayload[max_receivePayload_size]; // +1 to allow room for a terminating NULL char
uint8_t receivePayloadBuff[max_receivePayload_size];
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
//mysql pointers
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
主要():
int main(){
char *server = "localhost";
char *user = "monitor";
char *password = "monitor"; /* set me first */
char *database = "data";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
/* output table name */
// printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
//printf("%s \n", row[0]);
mysql_free_result(res);
// Setup and configure rf radio
radio.begin();
radio.setAutoAck(1);
radio.enableDynamicPayloads();
radio.enableAckPayload();
radio.setRetries(0,15);
radio.setDataRate(RF24_1MBPS);
radio.printDetails();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.writeAckPayload(1, &ack, sizeof(ack));
if(radio.available()){
std::cout << "available";
uint8_t len;
len = radio.getDynamicPayloadSize();
radio.read(&receivePayload, len);
}
std::cout << "listening";
attachInterrupt(interruptPin, INT_EDGE_FALLING, intHandler); //Attach interrupt to bcm pin 23
radio.startListening();
// forever loop
while(1){
if (recvd == 2){
//addLiveData();
recvd = 0;
} else if (recvd == 1) {
insertData();
recvd = 0;
}
}
}
由于