#ifndef __KERNEL_H__ #define __KERNEL_H__ #include #include "util/minimal_io.h" #include #include class Kernel { private: Kernel(); Kernel(const Kernel &orig); ~Kernel(); Kernel &operator=(const Kernel &orig); bool initialized; public: enum special_devices { SYS_MAPPED = 0, UBLOX, GS_LINK, FLASHROM, ADC, FAT_FILE, USB_UART, OBCLED, NUL }; enum ioctl_keys { IOCTL_SYNC, IOCTL_SEEK, IOCTL_RENAME, IOCTL_AUTOSYNC, IOCTL_BUFFER, }; struct SystemIO; class IO : public MinimalIO { private: SystemIO *delegatee; public: unsigned int receive(char *buf, const unsigned int &buf_size); unsigned int transmit(const char *buf, const unsigned int &buf_size); bool ioctl(const Kernel::ioctl_keys &key, const void *param = 0); IO(); IO(SystemIO *io); IO(const IO &orig); IO &operator=(const IO &rhs); ~IO(); }; void initialize(); static Kernel &get_instance(); IO open(const special_devices &id, const void *params = NULL); void simulate_1pps(); struct gps_time_t { Uint32 wn; Uint32 itow_ms; }; void notify_gps_time(const gps_time_t &gps_time); void notify_gps_time(const Uint32 &wn, const Uint32 &itow_ms); gps_time_t gps_time() const; Uint32 wn() const; Uint32 itow_ms() const; enum mbx_devices { MBX_ADC = 0, MBX_SERVO_WRITE, MBX_SERVO_READ, MBX_ADS, MBX_MAG, MBX_TU_INFO, MBX_MU_INFO, MBX_MAG_INFO, MBX_NAV_INFO, MBX_GC_INFO, MBX_NUL }; private: MBX_Handle mbx_handles[MBX_NUL]; public: struct msg_adc_t { Uint32 time_ms; Uint32 ch[8]; }; struct msg_servo_write_t { Uint32 time_ms; Uint16 ch[8]; }; struct msg_servo_read_t { Uint32 time_ms; Uint16 ch_in[8]; Uint16 ch_out[8]; }; struct msg_ads_t { Uint32 time_ms; Uint8 raw_buf[8]; }; struct msg_mag_t { Uint32 time_ms; Uint8 raw_buf[6]; template void convert(NumberType (&values)[N]){ union { Int16 v; Uint8 c[2]; } tmp; for(int i(0), j(0); j < std::min(N, sizeof(raw_buf) / sizeof(tmp)); i += 2, j++){ tmp.c[0] = raw_buf[i + 1]; tmp.c[1] = raw_buf[i]; values[j] = tmp.v; } } }; MBX_Handle mbx(const mbx_devices &id) const; }; #endif /* __KERNEL_H__ */