static void Sun2Intel_SMCD( struct smcd_gome *smcd ) { register int ni; smcd->indx_spec = byte_swap_16( smcd->indx_spec ); smcd->indx_leak = byte_swap_16( smcd->indx_leak ); ni = 0; do { smcd->indx_bands[ni] = byte_swap_16( smcd->indx_bands[ni] ); } while ( ++ni < NUM_SPEC_BANDS ); smcd->utc_date = byte_swap_u32( smcd->utc_date ); smcd->utc_time = byte_swap_u32( smcd->utc_time ); IEEE_Swap__FLT( &smcd->north_sun_zen ); IEEE_Swap__FLT( &smcd->north_sun_azim ); IEEE_Swap__FLT( &smcd->north_sm_zen ); IEEE_Swap__FLT( &smcd->north_sm_azim ); IEEE_Swap__FLT( &smcd->sun_or_moon ); IEEE_Swap__FLT( &smcd->dark_current ); IEEE_Swap__FLT( &smcd->noise_factor ); smcd->ihr.subsetcounter = byte_swap_u16( smcd->ihr.subsetcounter ); smcd->ihr.prism_temp = byte_swap_u16( smcd->ihr.prism_temp ); smcd->ihr.averagemode = byte_swap_u16( smcd->ihr.averagemode ); smcd->ihr.intg.two_byte = byte_swap_u16( smcd->ihr.intg.two_byte ); ni = 0; do { smcd->ihr.pmd[0][ni] = byte_swap_u16( smcd->ihr.pmd[0][ni] ); smcd->ihr.pmd[1][ni] = byte_swap_u16( smcd->ihr.pmd[1][ni] ); smcd->ihr.pmd[2][ni] = byte_swap_u16( smcd->ihr.pmd[2][ni] ); } while ( ++ni < PMD_IN_GRID ); ni = 0; do { smcd->ihr.peltier[ni] = byte_swap_u16( smcd->ihr.peltier[ni] ); } while ( ++ni < SCIENCE_CHANNELS ); }
void update_int16(uint16_t value) { #if __BYTE_ORDER == __LITTLE_ENDIAN m_crc.process_bytes(&value, sizeof(uint16_t)); #else uint16_t v = byte_swap_16(value); m_crc.process_bytes(&v, sizeof(uint16_t)); #endif }
/* Common packets handlers. * Return 1 when packet has been handled, or 0 if the type is not a common one and some * board or application specific code should take care of it. */ static int dtplug_protocol_common_handles(struct dtplug_protocol_handle* handle, struct packet* question) { uint32_t tmp_val_swap = 0; /* These we can always handle */ switch (question->info.type) { case PKT_TYPE_PING: question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */ dtplug_protocol_send_reply(handle, question, NO_ERROR, 0, NULL); /* A ping needs no aditional data */ dtplug_protocol_release_old_packet(handle); break; case PKT_TYPE_RESET: /* Software reset of the board. No way out. */ NVIC_SystemReset(); break; case PKT_TYPE_SET_TIME: { struct time_spec new_time, time_diff; uint32_t* seconds = (uint32_t*)question->data; uint16_t* msec = (uint16_t*)&(question->data[4]); uint8_t time_buff[6]; if (question->info.seq_num & QUICK_DATA_PACKET) { dtplug_protocol_send_reply(handle, question, ERROR_IN_PKT_STRUCTURE, 0, NULL); break; } if (question->info.data.size != 6) { dtplug_protocol_send_reply(handle, question, ERROR_IN_DATA_VALUES, 0, NULL); break; } new_time.seconds = byte_swap_32(*seconds); new_time.msec = (uint16_t)byte_swap_16(*msec); if (!(question->info.seq_num & PACKET_NEEDS_REPLY)) { set_time(&new_time); } else { set_time_and_get_difference(&new_time, &time_diff); time_to_buff_swapped(time_buff, &time_diff); dtplug_protocol_send_reply(handle, question, NO_ERROR, 6, time_buff); } } dtplug_protocol_release_old_packet(handle); break; case PKT_TYPE_SET_USER_INFO: { uint8_t tmp_data[sizeof(struct user_info)] __attribute__ ((__aligned__(4))) = {}; uint8_t offset = question->data[0]; uint8_t size = question->data[1]; if (question->info.seq_num & QUICK_DATA_PACKET) { dtplug_protocol_send_reply(handle, question, ERROR_IN_PKT_STRUCTURE, 0, NULL); break; } /* Check that amount of data provided is OK and does not go beyond user_info structure end */ if ((question->info.data.size != (size + 2)) || ((offset + size) > sizeof(struct user_info))) { dtplug_protocol_send_reply(handle, question, ERROR_IN_DATA_VALUES, 0, NULL); break; } /* Copy all board data before flash erase */ memcpy(tmp_data, get_user_info(), sizeof(struct user_info)); /* Update information in the copy */ memcpy(&(tmp_data[offset]), &(question->data[2]), size); /* Update the user flash information pages */ if (dtplug_protocol_user_flash_update(handle, question, tmp_data, sizeof(struct user_info)) != 0) { /* Reply got sent, if return value is not 0 */ break; } } /* Software reset of the board. No way out. */ NVIC_SystemReset(); break; case PKT_TYPE_GET_NUM_PACKETS: question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */ tmp_val_swap = byte_swap_32(handle->packet_count); dtplug_protocol_send_reply(handle, question, NO_ERROR, 4, (uint8_t*)(&tmp_val_swap)); dtplug_protocol_release_old_packet(handle); break; case PKT_TYPE_GET_ERRORS: question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */ dtplug_protocol_send_reply(handle, question, NO_ERROR, 0, NULL); /* Error handling code will take care of filling the message */ dtplug_protocol_release_old_packet(handle); break; case PKT_TYPE_GET_NUM_ERRORS: question->info.seq_num |= PACKET_NEEDS_REPLY; /* Make sure the reply will be sent */ tmp_val_swap = byte_swap_32(handle->errors_count); dtplug_protocol_send_reply(handle, question, NO_ERROR, 4, (uint8_t*)(&tmp_val_swap)); dtplug_protocol_release_old_packet(handle); break; default: /* We do not handle this type, it must be a board specific one */ return 0; } /* Packet handled */ status_led(green_off); return 1; }