--- /dev/null
+#include <types.h>\r
+#ifdef BTH_LX\r
+#include <cpu_def.h>\r
+#include <h8s2638h.h>\r
+#include <system_def.h>\r
+#include <periph/sci_rs232.h>\r
+#endif\r
+\r
+#include <stdlib.h>\r
+#include "hci.h"\r
+#include "hci_error.h"\r
+\r
+\r
+/**\r
+ * Errors generated by a bluetooth device\r
+*/\r
+\r
+static struct {\r
+ uint8_t error_code;\r
+ char *error_doc;\r
+} status_command[] = {\r
+ { 0x00, "Status OK" },\r
+ { 0x01, "Unknown HCI Command" },\r
+ { 0x02, "No Connection" },\r
+ { 0x03, "Hardware Failure" },\r
+ { 0x04, "Page Timeout" },\r
+ { 0x05, "Authentication Failure" },\r
+ { 0x06, "Key Missing" },\r
+ { 0x07, "Memory Full" },\r
+ { 0x08, "Connection Timeout" },\r
+ { 0x09, "Max Number Of Connections" },\r
+ { 0x0A, "Max Number Of SCO Connections To A Device"},\r
+ { 0x0B, "ACL connection already exists" },\r
+ { 0x0C, "Command Disallowed" },\r
+ { 0x0D, "Host Rejected due to limited resources" },\r
+ { 0x0E, "Host Rejected due to security reasons" },\r
+ { 0x0F, "Host Rejected due to remote device is only a personal device" },\r
+ { 0x10, "Host Timeout" },\r
+ { 0x11, "Unsupported Feature or Parameter Value" },\r
+ { 0x12, "Invalid HCI Command Parameters" },\r
+ { 0x13, "Other End Terminated Connection: User Ended Connection" },\r
+ { 0x14, "Other End Terminated Connection: Low Resources" },\r
+ { 0x15, "Other End Terminated Connection: About to Power Off" },\r
+ { 0x16, "Connection Terminated by Local Host" },\r
+ { 0x17, "Repeated Attempts" },\r
+};\r
+\r
+/**\r
+* Output an error to a terminal unsing rs232\r
+*/\r
+void bth_error_detect_status(uint8_t status_num)\r
+{\r
+ char *message;\r
+ int i=0;\r
+ if(status_num<sizeof(status_command));\r
+ {\r
+ message=status_command[status_num].error_doc;\r
+ while(*(message+i)!=0)\r
+ {\r
+ #ifdef BTH_LX\r
+ sci_rs232_sendch(*(message+i),sci_rs232_chan_default); //to PC\r
+ #endif\r
+ i++;\r
+ };\r
+ };\r
+ return;\r
+};\r
+\r
+/**\r
+ * errors in program - it is necessary to modify return parameters - matches only 0 and 3\r
+*/\r
+static struct {\r
+ uint8_t error_code;\r
+ char *error_doc;\r
+ }event_command[] = {\r
+ { 0x00, "Status OK" },\r
+ { 0x01, "unspecified error" },\r
+ { 0x02, "confirmation queue is empty" },\r
+ { 0x03, "function is not implemented" },\r
+ };\r
+\r
+\r
+\r
+ /**\r
+ * Output an error to terminal through RS232\r
+ */\r
+ void bth_error_detect_event(uint8_t status_num)\r
+{\r
+ char *message;\r
+ int i=0;\r
+ if(status_num<sizeof(event_command));\r
+ {\r
+ message=event_command[status_num].error_doc;\r
+ while(*(message+i)!=0)\r
+ {\r
+ #ifdef BTH_LX\r
+ sci_rs232_sendch(*(message+i),sci_rs232_chan_default); //do PC\r
+ #endif\r
+ i++;\r
+ };\r
+ };\r
+ return;\r
+};\r