Otpvondoiats opened a new pull request, #13538:
URL: https://github.com/apache/nuttx/pull/13538

   ## Summary
   - Bug fix. When the remote core publishes a message, the subscribed cores 
will receive the message. When the subscribed core publishes a new message, it 
will take away the message published by the remote core, so all stublist 
information needs to be updated.
   
   ## Impact
   - Sensor cross-core communication.
   
   ## Testing
   ```
   /****************************************************************************
    * apps/examples/hello/hello_main.c
    *
    * Licensed to the Apache Software Foundation (ASF) under one or more
    * contributor license agreements.  See the NOTICE file distributed with
    * this work for additional information regarding copyright ownership.  The
    * ASF licenses this file to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance with the
    * License.  You may obtain a copy of the License at
    *
    *   http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    * License for the specific language governing permissions and limitations
    * under the License.
    *
    
****************************************************************************/
   
   /****************************************************************************
    * Included Files
    
****************************************************************************/
   
   #include <nuttx/config.h>
   #include <stdio.h>
   #include <errno.h>
   #include <math.h>
   #include <poll.h>
   #include <string.h>
   #include <stdarg.h>
   #include <stdlib.h>
   #include <unistd.h>
   #include <inttypes.h>
   
   #include <uORB/uORB.h>
   #include <sensor/gps.h>
   #include <uv.h>
   
   /****************************************************************************
    * Public Functions
    
****************************************************************************/
   
   /****************************************************************************
    * hello_main
    
****************************************************************************/
   
    void cp_advertiser(void);
    void cp_subscriber(void);
    void sensor_adv_sub_er(void);
   
   enum FakeCmd {
     FAKE_CONTROL_CMD,
     FAKE_DISTRIBUTE_CMD,
   };
   
   enum FakeAttribute {
     HELLO_QUEUE_SIZE = 5,
     HELLO_SLEEP_DURA = 20,
   };
   
   int main(int argc, FAR char *argv[])
   {
     printf("Hello, World!!\n");
     if (argc == 1) {
       cp_advertiser();
     } else if (argc == 2) {
       cp_subscriber();
     }else {
       sensor_adv_sub_er();
     }
     return 0;
   }
   
    void cp_advertiser(void) {
     int instance = 0;
     int adv_fd = orb_advertise_multi_queue(ORB_ID(sensor_gps), NULL, 
&instance, HELLO_QUEUE_SIZE);
     syslog(3, "DEBUG_IN_HELLO, cp adv:%d\n", adv_fd);
   
     while(true) {
       sleep(HELLO_SLEEP_DURA);
       struct sensor_gps gps = {};
       gps.timestamp = (uint64_t)time(NULL);
       gps.time_utc = FAKE_CONTROL_CMD;
       int ret = orb_publish(ORB_ID(sensor_gps), adv_fd, &gps);
       syslog(3, "DEBUG_IN_HELLO, cp send ctl:%d,%" PRIu64 ",%" PRIu64 "\n",
              ret, gps.time_utc, gps.timestamp);
     }
   }
   
   static void cp_read_cb(uv_poll_t* handle, int status, int events) {
     struct sensor_gps gps = {};
     int* fd = (int*)(handle->data);
     read(*fd, &gps, sizeof(gps));
     syslog(3, "DEBUG_IN_HELLO, cp recv data:%" PRIu64 ",%" PRIu64 "\n",
            gps.time_utc, gps.timestamp);
   }
   
   void cp_subscriber(void) {
     int sub_fd = orb_subscribe(ORB_ID(sensor_gps));
     syslog(3, "DEBUG_IN_HELLO, cp sub:%d\n", sub_fd);
   
     uv_poll_t handle = {};
     handle.data = &sub_fd;
     uv_poll_init(uv_default_loop(), &handle, sub_fd);
     uv_poll_start(&handle, UV_READABLE, cp_read_cb);
     uv_run(uv_default_loop(), UV_RUN_DEFAULT);
   
   }
   
   struct TopicFD {
     int sub_fd;
     int adv_fd;
   };
   
   static void sensor_read_cb(uv_poll_t* handle, int status, int events) {
     struct sensor_gps gps = {};
     struct TopicFD* fds = (struct TopicFD*)handle->data;
     read(fds->sub_fd, &gps, sizeof(gps));
   
     syslog(3, "DEBUG_IN_HELLO, sen recv data:%" PRIu64 ",%" PRIu64 "\n",
            gps.time_utc, gps.timestamp);
     // need distribute
     if (gps.time_utc == FAKE_CONTROL_CMD) {
       gps.time_utc = FAKE_DISTRIBUTE_CMD;
       int ret = orb_publish(ORB_ID(sensor_gps), fds->adv_fd, &gps);
       syslog(3, "DEBUG_IN_HELLO, sen distribute ctl:%d,%" PRIu64 ",%" PRIu64 
"\n",
              ret, gps.time_utc, gps.timestamp);
     }
   }
   
   void sensor_adv_sub_er(void) {
     int instance = 0;
     int adv_fd = orb_advertise_multi_queue(ORB_ID(sensor_gps), NULL, 
&instance, HELLO_QUEUE_SIZE);
     syslog(3, "DEBUG_IN_HELLO, sen adv:%d\n", adv_fd);
     int sub_fd = orb_subscribe(ORB_ID(sensor_gps));
     syslog(3, "DEBUG_IN_HELLO, sen sub:%d\n", sub_fd);
   
     uv_poll_t handle = {};
     struct TopicFD fds = {};
     fds.sub_fd = sub_fd;
     fds.adv_fd = adv_fd;
     handle.data = &fds;
     uv_poll_init(uv_default_loop(), &handle, sub_fd);
     uv_poll_start(&handle, UV_READABLE, sensor_read_cb);
     uv_run(uv_default_loop(), UV_RUN_DEFAULT);
   }
   ```
   
   1. rpserver and rpproxy open uorb config
   2. build
   ```
   ./build.sh nuttx/boards/sim/sim/sim/configs/rpserver -j16
   ./build.sh nuttx/boards/sim/sim/sim/configs/rpproxy -j16
   ```
   order:
   rpserver:  hello &  and hello 1 &
   rpproxy:  hello 1 1 &
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to