]> rtime.felk.cvut.cz Git - mirosot.git/blob - bluetooth/bth_error.c
An unsucesfull attempt to clean bluetooth library and make it working.
[mirosot.git] / bluetooth / bth_error.c
1 #include <types.h>\r
2 #ifdef BTH_LX\r
3 #include <cpu_def.h>\r
4 #include <h8s2638h.h>\r
5 #include <system_def.h>\r
6 #include <periph/sci_rs232.h>\r
7 #endif\r
8 \r
9 #include <stdlib.h>\r
10 #include "hci.h"\r
11 #include "hci_error.h"\r
12 \r
13 \r
14 /**\r
15  * Errors generated by a bluetooth device\r
16 */\r
17 \r
18 static struct {\r
19         uint8_t error_code;\r
20         char *error_doc;\r
21 } status_command[] = {\r
22    { 0x00,   "Status OK"                                },\r
23    { 0x01,   "Unknown HCI Command"                      },\r
24    { 0x02,   "No Connection"                            },\r
25    { 0x03,   "Hardware Failure"                         },\r
26    { 0x04,   "Page Timeout"                             },\r
27    { 0x05,   "Authentication Failure"                   },\r
28    { 0x06,   "Key Missing"                              },\r
29    { 0x07,   "Memory Full"                              },\r
30    { 0x08,   "Connection Timeout"                       },\r
31    { 0x09,   "Max Number Of Connections"                },\r
32    { 0x0A,   "Max Number Of SCO Connections To A Device"},\r
33    { 0x0B,   "ACL connection already exists"            },\r
34    { 0x0C,   "Command Disallowed"                       },\r
35    { 0x0D,   "Host Rejected due to limited resources"   },\r
36    { 0x0E,   "Host Rejected due to security reasons"    },\r
37    { 0x0F,   "Host Rejected due to remote device is only a personal device" },\r
38    { 0x10,   "Host Timeout"                             },\r
39    { 0x11,   "Unsupported Feature or Parameter Value"   },\r
40    { 0x12,   "Invalid HCI Command Parameters"           },\r
41    { 0x13,   "Other End Terminated Connection: User Ended Connection" },\r
42    { 0x14,   "Other End Terminated Connection: Low Resources"         },\r
43    { 0x15,   "Other End Terminated Connection: About to Power Off"    },\r
44    { 0x16,   "Connection Terminated by Local Host"      },\r
45    { 0x17,   "Repeated Attempts"                        },\r
46 };\r
47 \r
48 /**\r
49 * Output an error to a terminal unsing rs232\r
50 */\r
51 void bth_error_detect_status(uint8_t status_num)\r
52 {\r
53   char *message;\r
54   int i=0;\r
55   if(status_num<sizeof(status_command));\r
56   {\r
57     message=status_command[status_num].error_doc;\r
58     while(*(message+i)!=0)\r
59     {\r
60       #ifdef BTH_LX\r
61       sci_rs232_sendch(*(message+i),sci_rs232_chan_default); //to PC\r
62       #endif\r
63       i++;\r
64     };\r
65   };\r
66   return;\r
67 };\r
68 \r
69 /**\r
70  * errors in program - it is necessary to modify return parameters - matches only 0 and 3\r
71 */\r
72 static struct {\r
73         uint8_t error_code;\r
74         char *error_doc;\r
75  }event_command[] = {\r
76    { 0x00,   "Status OK"                                },\r
77    { 0x01,   "unspecified error"                        },\r
78    { 0x02,   "confirmation queue is empty"              },\r
79    { 0x03,   "function is not implemented"              },\r
80    };\r
81 \r
82 \r
83 \r
84    /**\r
85     * Output an error to terminal through RS232\r
86  */\r
87    void bth_error_detect_event(uint8_t status_num)\r
88 {\r
89   char *message;\r
90   int i=0;\r
91   if(status_num<sizeof(event_command));\r
92   {\r
93     message=event_command[status_num].error_doc;\r
94     while(*(message+i)!=0)\r
95     {\r
96       #ifdef BTH_LX\r
97       sci_rs232_sendch(*(message+i),sci_rs232_chan_default); //do PC\r
98       #endif\r
99       i++;\r
100     };\r
101   };\r
102   return;\r
103 };\r