Rev 869 | Rev 955 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 869 | Rev 883 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | #include "sns_SimpleDTMF.h" |
2 | #include "sns_SimpleDTMF.h" |
| 3 | 3 | ||
| - | 4 | uint8_t pollrxbuffer[MT_MAX_TONES]; |
|
| - | 5 | uint8_t pollrxlen=0; |
|
| 4 | uint8_t rxbuffer[MT_MAX_TONES]; |
6 | uint8_t rxbuffer[MT_MAX_TONES]; |
| 5 | uint8_t state = SNS_SIMPLEDTMF_STATE_IDLE; |
7 | uint8_t state = SNS_SIMPLEDTMF_STATE_IDLE; |
| 6 | uint8_t rxlen = 0; |
8 | uint8_t rxlen = 0; |
| 7 | 9 | ||
| 8 | void sns_SimpleDTMF_Init(void) |
10 | void sns_SimpleDTMF_Init(void) |
| Line 10... | Line 12... | ||
| 10 | DTMFin_Init(); |
12 | DTMFin_Init(); |
| 11 | } |
13 | } |
| 12 | 14 | ||
| 13 | void sns_SimpleDTMF_Process(void) |
15 | void sns_SimpleDTMF_Process(void) |
| 14 | { |
16 | { |
| 15 | uint8_t retval; |
- | |
| 16 | StdCan_Msg_t txMsg; |
17 | StdCan_Msg_t txMsg; |
| - | 18 | DTMF_Ret_t retval; |
|
| 17 | 19 | ||
| 18 | switch (state) |
20 | switch (state) |
| 19 | { |
21 | { |
| 20 | case SNS_SIMPLEDTMF_STATE_IDLE: |
22 | case SNS_SIMPLEDTMF_STATE_IDLE: |
| 21 |
|
23 | if (DTMFin_Pop(pollrxbuffer, &pollrxlen) == DTMF_Ret_Data_avail) { |
| 22 | state = |
24 | state = SNS_SIMPLEDTMF_STATE_COPYDATA; |
| - | 25 | } else { |
|
| - | 26 | //go into sleep or something, incoming data from mt8870 is interrupted so we will wake up |
|
| - | 27 | } |
|
| 23 | break; |
28 | break; |
| 24 | 29 | ||
| 25 | case |
30 | case SNS_SIMPLEDTMF_STATE_COPYDATA: |
| 26 | state = SNS_SIMPLEDTMF_STATE_WAIT; |
31 | state = SNS_SIMPLEDTMF_STATE_WAIT; |
| - | 32 | for (uint8_t i=0; i<pollrxlen;i++) { |
|
| - | 33 | rxbuffer[rxlen++] = pollrxbuffer[i]; |
|
| - | 34 | if (rxlen >= MT_MAX_TONES) { |
|
| - | 35 | //overflow |
|
| - | 36 | rxlen = 0; |
|
| - | 37 | state = SNS_SIMPLEDTMF_STATE_IDLE; |
|
| - | 38 | break; |
|
| - | 39 | } |
|
| - | 40 | } |
|
| - | 41 | ||
| - | 42 | Timer_SetTimeout(MT_TIMER, MT_DIAL_TIMEOUT, TimerTypeOneShot, 0); |
|
| 27 | break; |
43 | break; |
| 28 | 44 | ||
| 29 | case SNS_SIMPLEDTMF_STATE_WAIT: |
45 | case SNS_SIMPLEDTMF_STATE_WAIT: |
| - | 46 | if (Timer_Expired(MT_TIMER)) { |
|
| 30 |
|
47 | state = SNS_SIMPLEDTMF_STATE_SEND; |
| - | 48 | } |
|
| 31 | 49 | ||
| - | 50 | retval = DTMFin_Pop(pollrxbuffer, &pollrxlen); |
|
| 32 | if |
51 | if (retval == DTMF_Ret_Data_avail) { |
| 33 | state = |
52 | state = SNS_SIMPLEDTMF_STATE_COPYDATA; |
| 34 | else |
53 | } else if (retval == DTMF_Ret_Overflow) { |
| - | 54 | rxlen=0; |
|
| 35 | state = SNS_SIMPLEDTMF_STATE_IDLE; |
55 | state = SNS_SIMPLEDTMF_STATE_IDLE; |
| 36 | 56 | } |
|
| 37 | break; |
57 | break; |
| 38 | 58 | ||
| 39 | case |
59 | case SNS_SIMPLEDTMF_STATE_SEND: |
| 40 | //if ((rxbuffer[0] == 0xa || rxbuffer[0] == 0xb) && rxbuffer[rxlen-1] == 0xc) { |
60 | //if ((rxbuffer[0] == 0xa || rxbuffer[0] == 0xb) && rxbuffer[rxlen-1] == 0xc) { |
| 41 | - | ||
| 42 | StdCan_Set_class(txMsg.Header, CAN_CLASS_MODULE_SNS); |
61 | StdCan_Set_class(txMsg.Header, CAN_CLASS_MODULE_SNS); |
| 43 | StdCan_Set_direction(txMsg.Header, DIR_FROM_OWNER); |
62 | StdCan_Set_direction(txMsg.Header, DIR_FROM_OWNER); |
| 44 | txMsg.Header.ModuleType = CAN_TYPE_MODULE_sns_SimpleDTMF; |
63 | txMsg.Header.ModuleType = CAN_TYPE_MODULE_sns_SimpleDTMF; |
| 45 | txMsg.Header.ModuleId = sns_SimpleDTMF_ID; |
64 | txMsg.Header.ModuleId = sns_SimpleDTMF_ID; |
| 46 | txMsg.Header.Command = CAN_CMD_MODULE_PHYS_PHONENUMBER; |
65 | txMsg.Header.Command = CAN_CMD_MODULE_PHYS_PHONENUMBER; |
| 47 | 66 | ||
| 48 | for (uint8_t i = 0; i < 16; i=i+2) { |
67 | for (uint8_t i = 0; i < 16; i=i+2) { |
| 49 | txMsg.Data[i>>1] = rxbuffer[i]<<4; |
68 | txMsg.Data[i>>1] = rxbuffer[i]<<4; |
| 50 | 69 | ||
| 51 | if (i+1 < rxlen) |
70 | if (i+1 < rxlen) |
| 52 | txMsg.Data[i>>1] |= rxbuffer[i+1]; |
71 | txMsg.Data[i>>1] |= rxbuffer[i+1]; |
| 53 | } |
72 | } |
| 54 | txMsg.Length = (rxlen>>1)+(rxlen&1); |
73 | txMsg.Length = (rxlen>>1)+(rxlen&1); |
| 55 | 74 | ||
| 56 | StdCan_Put(&txMsg); |
75 | StdCan_Put(&txMsg); |
| 57 | - | ||
| 58 | //} |
76 | //} |
| - | 77 | rxlen = 0; |
|
| 59 | state = SNS_SIMPLEDTMF_STATE_IDLE; |
78 | state = SNS_SIMPLEDTMF_STATE_IDLE; |
| 60 | break; |
79 | break; |
| 61 | } |
80 | } |
| 62 | } |
81 | } |
| 63 | 82 | ||