diff --git a/firmware/command_ctrl.ino b/firmware/command_ctrl.ino index 12a348e..fdea09d 100644 --- a/firmware/command_ctrl.ino +++ b/firmware/command_ctrl.ino @@ -255,14 +255,9 @@ void cc_startMeasurement() // MSG_TYPE_MEAS_FREQ_INFO sendSOM(); Serial.write(MSG_TYPE_MEAS_FREQ_INFO); - Serial.write((uint8_t)((freq & 0xff000000) >> 24)); - Serial.write((uint8_t)((freq & 0x00ff0000) >> 16)); - Serial.write((uint8_t)((freq & 0x0000ff00) >> 8)); - Serial.write((uint8_t) (freq & 0x000000ff)); - Serial.write((uint8_t)((a0_sum & 0xff00) >> 8)); - Serial.write((uint8_t) (a0_sum & 0x00ff)); - Serial.write((uint8_t)((a1_sum & 0xff00) >> 8)); - Serial.write((uint8_t) (a1_sum & 0x00ff)); + send32BitValue(freq); + send16BitValue(a0_sum); + send16BitValue(a1_sum); sendEOM(); si5351.output_enable(SI5351_CLK0, 0); // disable clock output 0 @@ -285,20 +280,10 @@ void cc_getConfig() { sendSOM(); Serial.write(MSG_TYPE_CONFIG); - Serial.write((uint8_t)((start_freq & 0xff000000) >> 24)); - Serial.write((uint8_t)((start_freq & 0x00ff0000) >> 16)); - Serial.write((uint8_t)((start_freq & 0x0000ff00) >> 8)); - Serial.write((uint8_t) (start_freq & 0x000000ff)); - Serial.write((uint8_t)((end_freq & 0xff000000) >> 24)); - Serial.write((uint8_t)((end_freq & 0x00ff0000) >> 16)); - Serial.write((uint8_t)((end_freq & 0x0000ff00) >> 8)); - Serial.write((uint8_t) (end_freq & 0x000000ff)); - Serial.write((uint8_t)((step_freq & 0xff000000) >> 24)); - Serial.write((uint8_t)((step_freq & 0x00ff0000) >> 16)); - Serial.write((uint8_t)((step_freq & 0x0000ff00) >> 8)); - Serial.write((uint8_t) (step_freq & 0x000000ff)); - Serial.write((uint8_t)((intervall & 0xff00) >> 8)); - Serial.write((uint8_t) (intervall & 0x00ff)); + send32BitValue(start_freq); + send32BitValue(end_freq); + send32BitValue(step_freq); + send16BitValue(intervall); Serial.write((uint8_t) drive_str); sendEOM(); } @@ -372,10 +357,7 @@ void cc_saveDefaults(void) void cc_setClkCorrection(void) { - uint32_t tmp_corr = (uint32_t)cc_read_data[0] << 24; - tmp_corr += (uint32_t)cc_read_data[1] << 16; - tmp_corr += (uint32_t)cc_read_data[2] << 8; - tmp_corr += (uint32_t)cc_read_data[3]; + uint32_t tmp_corr = read32BitDataFromBuffer(0); si5351.set_correction(tmp_corr); @@ -389,10 +371,7 @@ void cc_getClkCorrection(void) uint32_t tmp_corr = si5351.get_correction(); sendSOM(); - Serial.write((uint8_t)((tmp_corr & 0xff000000) >> 24)); - Serial.write((uint8_t)((tmp_corr & 0x00ff0000) >> 16)); - Serial.write((uint8_t)((tmp_corr & 0x0000ff00) >> 8)); - Serial.write((uint8_t) (tmp_corr & 0x000000ff)); + send32BitValue(tmp_corr); sendEOM(); } @@ -411,11 +390,9 @@ void cc_init() void cc_abort() { // send abort message, then init - char* tmp = " "; - sprintf(tmp, "%c%c%c%c%c", MSG_SOM1, MSG_SOM2, - MSG_TYPE_ANSWER_NOK, - MSG_EOM1, MSG_EOM2); - Serial.write(tmp); + sendSOM(); + Serial.write(MSG_TYPE_ANSWER_NOK); + sendEOM(); cc_init(); } @@ -535,3 +512,19 @@ void sendEOM() /*****************************************************************************/ +void send32BitValue(uint32_t value) +{ + Serial.write((uint8_t)((value & 0xff000000) >> 24)); + Serial.write((uint8_t)((value & 0x00ff0000) >> 16)); + Serial.write((uint8_t)((value & 0x0000ff00) >> 8)); + Serial.write((uint8_t) (value & 0x000000ff)); +} + +void send16BitValue(uint16_t value) +{ + Serial.write((uint8_t)((value & 0xff00) >> 8)); + Serial.write((uint8_t) (value & 0x00ff)); +} + +/*****************************************************************************/ +