int AnDepArrayArrayCmp(const void* _One, const void* _Two) { int _LenOne = ArrayLen(((const struct AnimalDep*)_One)->Tbl); int _LenTwo = ArrayLen(((const struct AnimalDep*)_Two)->Tbl); int _Result = 0; if(_LenOne != _LenTwo) return _LenOne - _LenTwo; for(int i = 0; i < _LenOne; ++i) { if((_Result = GoodBaseCmp(((const struct AnimalDep*)_One)->Tbl[i], ((const struct AnimalDep*)_Two)->Tbl[i])) != 0) return _Result; } return 0; }
void AnimalDepAddAn(const struct AnimalDep* _Dep, const struct Array* _Tbl) { int _Len = 0; int _DepLen = 0; for(int i = 0; i < _Tbl->Size; ++i) { _Len = ArrayLen(((struct AnimalDep*)_Tbl->Table[i])->Animals->Table); if(_Len <= 1) continue; _DepLen = ArrayLen(_Dep->Tbl); for(int j = 0; j < _DepLen; ++j) { if(BinarySearch(_Dep->Tbl[j], _Tbl->Table, _Tbl->Size, AnDepArrayCmp) == NULL) return; } ((struct AnimalDep*)_Tbl->Table[i])->Nutrition += _Dep->Nutrition; } }
int SemaphoresQuery(int semid,unsigned short **arrptr) { union semun se; struct semid_ds ds; int r; unsigned short *arr=0; se.buf = &ds; r = semctl(semid,0,IPC_STAT,se); if (r < 0) { return LockErrorSemctlBase-errno; } //printf("semaphores=%d\n",ds.sem_nsems); arr = malloc(4+sizeof(unsigned short)*ds.sem_nsems); arr += 2; // skip 4 bytes which hold length ArrayLen(arr) = ds.sem_nsems; se.array = arr; r = semctl(semid, 0, GETALL,se); if (r < 0) { return LockErrorSemctlBase; } *arrptr = arr; return ds.sem_nsems; }
int AnDepArrayCmp(const void* _One, const void* _Two) { int _Result = GoodBaseCmp(_One, ((const struct AnimalDep*)_Two)->Tbl[0]); int _Len = ArrayLen(((const struct AnimalDep*)_Two)->Tbl); if(_Len == 1 && _Result == 0) return 0; else if(_Len != 1) return -1; return _Result; }
int FoodArrayAnDepArray(const void* _One, const void* _Two) { int _LenOne = ArrayLen(_One); int _LenTwo = ArrayLen(((const struct AnimalDep*)_Two)->Tbl); int _Return = 0; int i; if(_LenOne != _LenTwo) { _Return = GoodBaseCmp(((const void**)_One)[0], ((const struct AnimalDep*)_Two)->Tbl[0]); if(_Return == 0) return _LenOne - _LenTwo; return _Return; } for(i = 0; i < _LenOne; ++i) { if((_Return = GoodBaseCmp(((const void**)_One)[i], ((const struct AnimalDep*)_Two)->Tbl[i])) != 0) return _Return; } return 0; }
int main(void) { char *s1 = "abcde"; char s2[] = "abc"; int a[] = {1, 2, 3, 0}; int *b = a; printf("%d\n", StrLen(s1)); printf("%d\n", StrLen(s2)); printf("%d\n", ArrayLen(a)); printf("%d\n", ArrayLen(b)); add1(&tmp); printf("%d\n", tmp); return 0; }
void MavDbgSender::start(void) { char key[PARAM_REGISTRY_ID_SIZE + 1]; for (uint8_t i=0; i<MAV_DBG_VAL_MAX; i++) { memset(key, 0, sizeof(key)); construct_key(i, key); param_registry.valueSearch(key, &dbg_val_registry[i].decimator); } for (size_t i=0; i<ArrayLen(vector_names); i++) { memset(key, 0, sizeof(key)); construct_key(vector_names[i], key); param_registry.valueSearch(key, &dbg_vect_registry[i].decimator); strncpy(dbg_vect_registry[i].msg.name, vector_names[i], sizeof(mavlink_debug_vect_t::name)); } ready = true; }
/** * @brief Pack and send debug vector via mavlink. * @details External time parameter needs when you need to send * multiple messages with the same timestamp. */ void MavDbgSender::send(const char *name, float x, float y, float z, uint64_t time_usec) { size_t idx = ~0U; for (size_t i=0; i<ArrayLen(vector_names); i++) { if (0 == strncmp(name, vector_names[i], sizeof(mavlink_debug_vect_t::name))) { idx = i; } } osalDbgCheck(~0U != idx); auto &v = dbg_vect_registry[idx]; v.cycles++; if ((0 != *v.decimator) && (v.cycles >= *v.decimator)) { v.cycles = 0; v.msg.x = x; v.msg.y = y; v.msg.z = z; v.msg.time_usec = time_usec; v.mail.fill(&v.msg, MAV_COMP_ID_SYSTEM_CONTROL, MAVLINK_MSG_ID_DEBUG_VECT); mav_postman.post(v.mail); } }
"acc_bias", "gyr_bias", "acc_scale", "gyr_scale", "mag_data", "maneuver" }; struct dbg_vect_ { const uint32_t *decimator = nullptr; size_t cycles = 0; mavlink_debug_vect_t msg; mavMail mail; }; static dbg_vect_ dbg_vect_registry[ArrayLen(vector_names)]; /* ****************************************************************************** * EXTERNS ****************************************************************************** */ /* ****************************************************************************** * PROTOTYPES ****************************************************************************** */ /* ******************************************************************************