stingr lib for v8

Dependents:   PYL_v8

Committer:
jmoreno10
Date:
Tue Apr 30 22:15:00 2019 +0000
Revision:
2:31750bae95c8
Parent:
0:f10ccc94eb8a
1st Shared program to AguilaBoard team

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmoreno10 0:f10ccc94eb8a 1 /*
jmoreno10 2:31750bae95c8 2 * mbed STINGR Library
jmoreno10 0:f10ccc94eb8a 3 * Copyright (c) 2018
jmoreno10 0:f10ccc94eb8a 4 *
jmoreno10 0:f10ccc94eb8a 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
jmoreno10 0:f10ccc94eb8a 6 * of this software and associated documentation files (the "Software"), to deal
jmoreno10 0:f10ccc94eb8a 7 * in the Software without restriction, including without limitation the rights
jmoreno10 0:f10ccc94eb8a 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jmoreno10 0:f10ccc94eb8a 9 * copies of the Software, and to permit persons to whom the Software is
jmoreno10 0:f10ccc94eb8a 10 * furnished to do so, subject to the following conditions:
jmoreno10 0:f10ccc94eb8a 11 *
jmoreno10 0:f10ccc94eb8a 12 * The above copyright notice and this permission notice shall be included in
jmoreno10 0:f10ccc94eb8a 13 * all copies or substantial portions of the Software.
jmoreno10 0:f10ccc94eb8a 14 *
jmoreno10 0:f10ccc94eb8a 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jmoreno10 0:f10ccc94eb8a 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jmoreno10 0:f10ccc94eb8a 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jmoreno10 0:f10ccc94eb8a 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jmoreno10 0:f10ccc94eb8a 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jmoreno10 0:f10ccc94eb8a 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jmoreno10 0:f10ccc94eb8a 21 * THE SOFTWARE.
jmoreno10 0:f10ccc94eb8a 22 */
jmoreno10 0:f10ccc94eb8a 23
jmoreno10 0:f10ccc94eb8a 24 #ifndef MBED_STINGR_H
jmoreno10 0:f10ccc94eb8a 25 #define MBED_STINGR_H
jmoreno10 0:f10ccc94eb8a 26
jmoreno10 0:f10ccc94eb8a 27 #include "mbed.h"
jmoreno10 0:f10ccc94eb8a 28 #include "rtos.h"
jmoreno10 0:f10ccc94eb8a 29
jmoreno10 2:31750bae95c8 30 // Command codes
jmoreno10 2:31750bae95c8 31 #define QUERY_ESN 'a'
jmoreno10 2:31750bae95c8 32 #define QUERY_BURSTS 'b'
jmoreno10 2:31750bae95c8 33 #define QUERY_FIRMWARE 'c'
jmoreno10 2:31750bae95c8 34 #define QUERY_SETUP 'd'
jmoreno10 2:31750bae95c8 35 #define QUERY_HARDWARE 'e'
jmoreno10 2:31750bae95c8 36 #define NAK_COMMAND 'f'
jmoreno10 2:31750bae95c8 37 #define CHANGE_SETUP 'g'
jmoreno10 2:31750bae95c8 38 #define SEND_DATA 'h'
jmoreno10 2:31750bae95c8 39 #define ABORT_TRANSMISSION 'i'
jmoreno10 2:31750bae95c8 40 #define CONT_TRANSMISSION 'j'
jmoreno10 2:31750bae95c8 41 #define GET_STATUS 'k'
jmoreno10 2:31750bae95c8 42 #define SELF_TEST 'l'
jmoreno10 2:31750bae95c8 43 #define SOFT_RESET 'm'
jmoreno10 2:31750bae95c8 44 #define GET_TEMPERATURE 'n'
jmoreno10 2:31750bae95c8 45 #define GET_AB_SOFT_VERSION 'p'
jmoreno10 2:31750bae95c8 46 #define SETUP_RESET 'z'
jmoreno10 2:31750bae95c8 47
jmoreno10 2:31750bae95c8 48 // Send Data message sizes
jmoreno10 2:31750bae95c8 49 #define PYL_MSG_1_PKT 9
jmoreno10 2:31750bae95c8 50 #define PYL_MSG_2_PKT 18
jmoreno10 2:31750bae95c8 51 #define PYL_MSG_4_PKT 36
jmoreno10 2:31750bae95c8 52 #define PYL_MSG_8_PKT 72
jmoreno10 2:31750bae95c8 53 #define PYL_MSG_16_PKT 144
jmoreno10 2:31750bae95c8 54
jmoreno10 2:31750bae95c8 55 // Get status stuff - globals
jmoreno10 2:31750bae95c8 56 extern bool get_status_setup_flag;
jmoreno10 2:31750bae95c8 57 extern char get_status_setup_buffer[50];
jmoreno10 2:31750bae95c8 58
jmoreno10 0:f10ccc94eb8a 59 /** Stingr class.
jmoreno10 0:f10ccc94eb8a 60 * Used for Mbed communication to STINGR modem.
jmoreno10 0:f10ccc94eb8a 61 *
jmoreno10 0:f10ccc94eb8a 62 */
jmoreno10 0:f10ccc94eb8a 63 class Stingr {
jmoreno10 0:f10ccc94eb8a 64
jmoreno10 0:f10ccc94eb8a 65 public:
jmoreno10 0:f10ccc94eb8a 66
jmoreno10 2:31750bae95c8 67 // Constructor - This function runs first as it is the Constructor
jmoreno10 0:f10ccc94eb8a 68 Stingr();
jmoreno10 0:f10ccc94eb8a 69
jmoreno10 0:f10ccc94eb8a 70 // Accessors
jmoreno10 2:31750bae95c8 71 char get_respChar(); // _resp character
jmoreno10 2:31750bae95c8 72 void get_status_resp(char * buf); // _packet array of integers
jmoreno10 0:f10ccc94eb8a 73
jmoreno10 0:f10ccc94eb8a 74 // Mutators
jmoreno10 2:31750bae95c8 75 void setPacketByte(int incomingByte);// when STINGR readable, add byte to buffer
jmoreno10 2:31750bae95c8 76
jmoreno10 2:31750bae95c8 77 // Thread function
jmoreno10 2:31750bae95c8 78 void stingr_Response(); // store STINGR response bytes to buffer
jmoreno10 0:f10ccc94eb8a 79
jmoreno10 0:f10ccc94eb8a 80 // Serial Packet processing functions
jmoreno10 2:31750bae95c8 81 void clearResponse(); // clear response buffer
jmoreno10 2:31750bae95c8 82 void printResponse(); // print (STINGR) response to via PC serial
jmoreno10 2:31750bae95c8 83 void waitCTS(); // wait for CTS to go low
jmoreno10 2:31750bae95c8 84 void raiseRTS_CTS(); // Raise RTS. STINGR raises CTS
jmoreno10 2:31750bae95c8 85
jmoreno10 2:31750bae95c8 86 // Checksum function
jmoreno10 2:31750bae95c8 87 uint16_t ModRTU_CRC(char* buf, int len);
jmoreno10 2:31750bae95c8 88
jmoreno10 2:31750bae95c8 89 // STINGR metacommand function
jmoreno10 2:31750bae95c8 90 void command(char* com); // execute STINGR command
jmoreno10 0:f10ccc94eb8a 91
jmoreno10 0:f10ccc94eb8a 92 // STINGR command functions
jmoreno10 2:31750bae95c8 93 void query_ESN(); // command 'a'
jmoreno10 2:31750bae95c8 94 void query_Bursts(); // command 'b'
jmoreno10 2:31750bae95c8 95 void query_Firmware(); // command 'c'
jmoreno10 2:31750bae95c8 96 void query_Setup(); // command 'd'
jmoreno10 2:31750bae95c8 97 void query_Hardware(); // command 'e'
jmoreno10 0:f10ccc94eb8a 98
jmoreno10 2:31750bae95c8 99 void NAK_command(); // command 'f'
jmoreno10 2:31750bae95c8 100 void change_Setup(char* b); // command 'g'
jmoreno10 2:31750bae95c8 101 void send_Data(char* b); // command 'h'
jmoreno10 2:31750bae95c8 102 void abort_Transmission(); // command 'i'
jmoreno10 0:f10ccc94eb8a 103
jmoreno10 2:31750bae95c8 104 void get_Status(); // command 'k'
jmoreno10 2:31750bae95c8 105 void self_Test(); // command 'l'
jmoreno10 2:31750bae95c8 106 void soft_Reset(); // command 'm'
jmoreno10 2:31750bae95c8 107 void get_Temperature(); // command 'n'
jmoreno10 2:31750bae95c8 108 void get_Aguila_SF_version(); // command 'p'
jmoreno10 2:31750bae95c8 109 void setup_Reset(); // command 'z'
jmoreno10 2:31750bae95c8 110
jmoreno10 2:31750bae95c8 111 // public variables
jmoreno10 2:31750bae95c8 112 int CTS_flag;
jmoreno10 0:f10ccc94eb8a 113 int incomingByte;
jmoreno10 0:f10ccc94eb8a 114 int num;
jmoreno10 0:f10ccc94eb8a 115
jmoreno10 2:31750bae95c8 116 // Thread declaration
jmoreno10 2:31750bae95c8 117 Thread t1; // stingr_Response thread
jmoreno10 0:f10ccc94eb8a 118
jmoreno10 0:f10ccc94eb8a 119 private:
jmoreno10 2:31750bae95c8 120 char _respChar; // character response for payload status
jmoreno10 2:31750bae95c8 121 char _packet[50]; // STINGR response buffer
jmoreno10 0:f10ccc94eb8a 122 };
jmoreno10 0:f10ccc94eb8a 123
jmoreno10 2:31750bae95c8 124 #endif