/* Packs command structure to SerialCommand object */ void SBGC_cmd_trigger_pack(SBGC_cmd_trigger_t &p, SerialCommand &cmd) { cmd.init(SBGC_CMD_TRIGGER_PIN); #ifdef SBGC_CMD_STRUCT_ALIGNED memcpy(cmd.data, &p, sizeof(p)); cmd.len = sizeof(p); #else cmd.writeByte(p.pin); cmd.writeByte(p.state); #endif }
/* Packs command structure to SerialCommand object */ void SBGC_cmd_servo_out_pack(SBGC_cmd_servo_out_t &p, SerialCommand &cmd) { cmd.init(SBGC_CMD_SERVO_OUT); #ifdef SBGC_CMD_STRUCT_ALIGNED memcpy(cmd.data, &p, sizeof(p)); cmd.len = sizeof(p); #else for(uint8_t i=0; i<8; i++) { cmd.writeWord(p.servo[i]); } #endif }
/* Packs command structure to SerialCommand object */ void SBGC_cmd_api_virt_ch_control_pack(SBGC_cmd_api_virt_ch_control_t &p, SerialCommand &cmd) { cmd.init(SBGC_CMD_API_VIRT_CH_CONTROL); #ifdef SBGC_CMD_STRUCT_ALIGNED memcpy(cmd.data, &p, sizeof(p)); cmd.len = sizeof(p); #else for(uint8_t i=0; i<SBGC_API_VIRT_NUM_CHANNELS; i++) { cmd.writeByte(p.data[i]); } #endif }
/* Packs command structure to SerialCommand object */ void SBGC_cmd_control_ext_pack(SBGC_cmd_control_ext_t &p, SerialCommand &cmd) { cmd.init(SBGC_CMD_CONTROL); #ifdef SBGC_CMD_STRUCT_ALIGNED memcpy(cmd.data, &p, sizeof(p)); cmd.len = sizeof(p); #else cmd.writeBuf(p.mode, 3); for(uint8_t i=0; i<3; i++) { cmd.writeWord(p.data[i].speed); cmd.writeWord(p.data[i].angle); } #endif }
/* Packs command structure to SerialCommand object */ void SBGC_cmd_set_adj_vars_pack(SBGC_cmd_set_adj_vars_var_t vars[], uint8_t vars_num, SerialCommand &cmd) { cmd.init(SBGC_CMD_SET_ADJ_VARS_VAL); cmd.writeByte(vars_num); // number of variables #ifdef SBGC_CMD_STRUCT_ALIGNED cmd.writeBuf(vars, sizeof(SBGC_cmd_set_adj_vars_var_t)*vars_num); #else for(uint8_t i=0; i<vars_num; i++) { cmd.writeByte(vars[i].id); cmd.writeLong(vars[i].val); } #endif }
/* Packs command structure to SerialCommand object */ void SBGC_cmd_control_pack(SBGC_cmd_control_t &p, SerialCommand &cmd) { cmd.init(SBGC_CMD_CONTROL); #ifdef SBGC_CMD_STRUCT_ALIGNED memcpy(cmd.data, &p, sizeof(p)); cmd.len = sizeof(p); #else cmd.writeByte(p.mode); cmd.writeWord(p.speedROLL); cmd.writeWord(p.angleROLL); cmd.writeWord(p.speedPITCH); cmd.writeWord(p.anglePITCH); cmd.writeWord(p.speedYAW); cmd.writeWord(p.angleYAW); #endif }