灯火百家 发表于 2018-4-3 12:01:56

Arduino的FreeRtos相关问题,,求助

在FreeRtos中创建一个新任务TaskJsonRecive时,
只要执行到JsonObject& root = jsonBuffer.parseObject(json);   
就会使整个系统卡死,无反应,
求大神讲解
下面试该任务代码:
void TaskJsonRecive( void *pvParameters __attribute__((unused)) )// This is a Task.
{

for (;;)
{
    // read the input on analog pin 0:
    //int sensorValue = analogRead(A0);
    // See if we can obtain or "Take" the Serial Semaphore.
    // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
    if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
    {
      // We were able to obtain or "Take" the semaphore and can now access the shared resource.
      // We want to have the Serial Port for us alone, as it takes some time to print,
      // so we don't want it getting stolen during the middle of a conversion.
      // print out the value you read:
      //Serial.println(sensorValue);
      if (Serial.available() > 0) {
      delay(200);
      numdata = Serial.readBytes(json, 99);
      StaticJsonBuffer<400> jsonBuffer;
      
      JsonObject& root = jsonBuffer.parseObject(json);///逐步排查是这句代码有问题,,但不知道如何处理
      
      if (!root.success()) {
      Serial.println("parseObject() failed");
      Serial.println("END");
      return;
      }
      const char* sensor = root["sensor"];
      const char* go = root["go"];
      Serial.println(sensor);
      Serial.println(go);
      }
   
   while (Serial.read() >= 0){
      for (int i = 0; i < 99; i++) {
          json = '\0';
      }
   }//清空串口缓存

      xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
    }

    vTaskDelay(67);// one tick delay (15ms) in between reads for stability
}
}
页: [1]
查看完整版本: Arduino的FreeRtos相关问题,,求助