Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Arduino data pin - 11
- // Include RadioHead Amplitude Shift Keying Library
- #include <RH_ASK.h>
- // Include dependant SPI Library
- #include <SPI.h>
- int state = 0;
- #define LISTEN_GS 0
- #define SEND_TO_GS 1
- // Create Amplitude Shift Keying Object
- RH_ASK rf_driver;
- String currentMsg = "";
- char *msgToSend = "SATELLITE|03|NULL|120|aa";
- void setup() {
- state = SEND_TO_GS;
- rf_driver.init();
- // Setup Serial Monitor
- Serial.begin(9600);
- Serial.println("serial is opening SAT");
- }
- void sendMsg(char *inputMsgToSend, int times)
- {
- Serial.println("sending msg" );
- for(int i =0; i<times; i++)
- {
- rf_driver.send((uint8_t *)inputMsgToSend,strlen(inputMsgToSend));
- rf_driver.waitPacketSent();
- delay(10);
- }
- }
- void readFromGs()
- {
- uint8_t buf[24];
- uint8_t buflen = sizeof(buf);
- // Check if received packet is correct size
- if (rf_driver.recv(buf, &buflen))
- {
- // Message received with valid checksum
- Serial.print("Message Received: ");
- Serial.println((char*)buf);
- currentMsg = (char*)buf;
- }
- }
- void loop() {
- switch(state)
- {
- case LISTEN_GS:
- readFromGs();
- break;
- case SEND_TO_GS:
- sendMsg(msgToSend,3);
- state = LISTEN_GS;
- break;
- }
- readFromGs();
- // Serial.println(curre/ntMsg);
- }
- //-------------------------------------------------
- String gs_id_str;
- String gs_command_str;
- String gs_param_str;
- void getInfoFromMsg( char* inputMsg)
- {
- String tempStr = String(inputMsg);
- // Serial.println(tempStr.substring(3,5));
- // Serial.println("info starts: ");
- int firstDel = tempStr.indexOf('|',2);
- String gsID = tempStr.substring(firstDel+1, firstDel+3);
- gs_id_str = gsID;
- int secondDel = tempStr.indexOf('|', firstDel +1 );
- int thirdDel = tempStr.indexOf('|', secondDel+1);
- String gsCommand = tempStr.substring(secondDel+1, thirdDel);
- gs_command_str = gsCommand;
- //
- int fourthDel = tempStr.indexOf('|', thirdDel+1);
- String gsCommandParameter = tempStr.substring(thirdDel+1, fourthDel);
- Serial.print("GS id: ");
- Serial.println(gsID);
- Serial.print("Gs command: ");
- Serial.println(gsCommand);
- Serial.print("GS command parameter: ");
- Serial.print(gsCommandParameter); Serial.print(" ");
- gs_param_str = gsCommandParameter;
- // Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement