1.打开main.c
init();
run();
void systemInit(void)
{
int ret;
clock_gettime(CLOCK_MONOTONIC, &start_time);
printf("[system]Init...\n");
SystemCoreClock = 500 * 1e6; // virtual 500MHz
if (pthread_mutex_init(&updateLock, NULL) != 0) {
printf("Create updateLock error!\n");
exit(1);
}
if (pthread_mutex_init(&mainLoopLock, NULL) != 0) {
printf("Create mainLoopLock error!\n");
exit(1);
}
ret = pthread_create(&tcpWorker, NULL, tcpThread, NULL);
if (ret != 0) {
printf("Create tcpWorker error!\n");
exit(1);
}
ret = udpInit(&pwmLink, simulator_ip, PORT_PWM, false);
printf("[SITL] init PwmOut UDP link to gazebo %s:%d...%d\n", simulator_ip, PORT_PWM, ret);
ret = udpInit(&pwmRawLink, simulator_ip, PORT_PWM_RAW, false);
printf("[SITL] init PwmOut UDP link to RF9 %s:%d...%d\n", simulator_ip, PORT_PWM_RAW, ret);
ret = udpInit(&stateLink, NULL, PORT_STATE, true);
printf("[SITL] start UDP server @%d...%d\n", PORT_STATE, ret);
ret = udpInit(&rcLink, NULL, PORT_RC, true);
printf("[SITL] start UDP server for RC input @%d...%d\n", PORT_RC, ret);
ret = pthread_create(&udpWorker, NULL, udpThread, NULL);
if (ret != 0) {
printf("Create udpWorker error!\n");
exit(1);
}
ret = pthread_create(&udpWorkerRC, NULL, udpRCThread, NULL);
if (ret != 0) {
printf("Create udpRCThread error!\n");
exit(1);
}
}
void tasksInitData(void)
{
for (int i = 0; i < TASK_COUNT; i++) {
tasks[i].attribute = &task_attributes[i];
}
}

