#ifndef _LIB_NXWMS_H
#define _LIB_NXWMS_H

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <time.h>

//magick number for commands
#define IDSetting       0x30
#define StartMeasure    0x31
#define StopMeasure     0x32
#define StatusRead      0x33
#define FileInfoRead    0x34
#define FileDataRead    0x35
#define MeaureFreq      0x36
#define MeasureTime     0x37
#define MagGainSetting  0x38
#define WirelessChannel 0x39
#define WirelessOnOff   0x3a
#define MemoryClear     0x3b
#define Initialize      0x3c

#define DefaultDevice "/dev/ttyUSB0"

#define MEMORYMODE  0x00
#define MONITORMODE 0x01

#define Baudrate 1000000

//ID for Nine-axis Motion Sensor
/* 0x01: 通常版 0x03: 低G版 */
//#define ProductID 0x01
#define ProductID 0x03
#define AckComplete 0x21

extern unsigned char commandbuf[];
extern unsigned char ackbuf[];
extern unsigned char databuf[];

#ifdef __cplusplus
extern "C" 
{
#endif
  int open_nxwms(char* device);
  void close_nxwms(int fd);
  void write_command(int fd, unsigned char magick, unsigned char prdct_id, unsigned char* args);
  unsigned char check_ack_packet(int fd, unsigned char magick, int wirelessflag);
  int get_sensordata(int fd, unsigned char prdct_id, int mode, double* accs, double* gyros, double* mags, int wirelessflag);
  void set_id(int fd, unsigned char prdct_id,  unsigned char id, int wirelessflag);
  void start_measure(int fd, unsigned char prdct_id, unsigned char id, unsigned char mode, int wirelessflag);
  void start_measure_withtime(int fd, unsigned char prdct_id, unsigned char id, unsigned char mode, int year, int month, int day, int hour, int min);
  int stop_measure(int fd, unsigned char prdct_id, unsigned char id, int wirelessflag);
  int stop_measure_with_check(int fd, unsigned char prdct_id, unsigned char id, int wirelessflag);
  void get_status(int fd, unsigned char prdct_id, unsigned char id, unsigned char* status_buf, int wirelessflag);
  void get_fileinfo(int fd, unsigned char prdct_id, unsigned char id, unsigned char* fileinfo_buf, int wirelessflag);
  void get_filedata(int fd, unsigned char prdct_id, unsigned char id, int fileno, long int start_recordno, long int record_num, unsigned char* filedata_buf, int wirelessflag);
  int set_measurefrequency(int fd, unsigned char prdct_id, unsigned char id, int freq, int wirelessflag);
  int set_measuretime(int fd, unsigned char prdct_id, unsigned char id, int hour, int min, int sec, int wirelessflag);
  void set_maggain(int fd, unsigned char prdct_id, unsigned char id, unsigned char gain, int wirelessflag);
  void set_wirelesschannel(int fd, unsigned char prdct_id, unsigned char id, unsigned char channel, int wirelessflag);
  void set_wirelessonoff(int fd, unsigned char prdct_id, unsigned char id, unsigned char onoff, int wirelessflag);
  void memory_allclear(int fd, unsigned char prdct_id, unsigned char id, int wirelessflag);
  void initialize_settings(int fd, unsigned char prdct_id, unsigned char id, int wirelessflag);    
#ifdef __cplusplus
}
#endif

#endif //_LIB_NXWMS_H
